diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index f61e320c9..93af9d872 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -33,6 +33,7 @@ with your GitHub account.
## Code contribution
+* If you want to add a feature or change one, please open an issue describing your change. This gives the team and community a chance to give feedback before you spend any time on something that could be done differently or not done at all. It also prevents two contributors from working on the same thing and one being disappointed when only one user's code can be added.
* Stick to NewPipe's style conventions: follow [checkStyle](https://github.com/checkstyle/checkstyle). It will run each time you build the project.
* Do not bring non-free software (e.g. binary blobs) into the project. Also, make sure you do not introduce Google
libraries.
diff --git a/app/build.gradle b/app/build.gradle
index 02edafd74..345f45f66 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -164,7 +164,7 @@ dependencies {
exclude module: 'support-annotations'
}
- implementation 'com.github.TeamNewPipe:NewPipeExtractor:5ac80624a40f4c600ae493e66881b5bf008f0ddb'
+ implementation 'com.github.TeamNewPipe:NewPipeExtractor:6633f26ec5a73a8e932de575b7a0643b6ad6c890'
implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
implementation "org.jsoup:jsoup:1.13.1"
diff --git a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java
index 55e747cd5..972737d25 100644
--- a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java
+++ b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java
@@ -21,13 +21,13 @@ public class ErrorInfoTest {
@Test
public void errorInfoTestParcelable() {
- ErrorInfo info = ErrorInfo.make(UserAction.USER_REPORT, "youtube", "request",
+ final ErrorInfo info = ErrorInfo.make(UserAction.USER_REPORT, "youtube", "request",
R.string.general_error);
// Obtain a Parcel object and write the parcelable object to it:
- Parcel parcel = Parcel.obtain();
+ final Parcel parcel = Parcel.obtain();
info.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
- ErrorInfo infoFromParcel = ErrorInfo.CREATOR.createFromParcel(parcel);
+ final ErrorInfo infoFromParcel = ErrorInfo.CREATOR.createFromParcel(parcel);
assertEquals(UserAction.USER_REPORT, infoFromParcel.userAction);
assertEquals("youtube", infoFromParcel.serviceName);
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 16ed422e0..1b3b80d88 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -23,6 +23,7 @@
android:logo="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:theme="@style/OpeningTheme"
+ android:resizeableActivity="true"
tools:ignore="AllowBackup">
+
+
+
+
+
+
diff --git a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java
index 11f457b6c..5840b0f7e 100644
--- a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java
+++ b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java
@@ -150,7 +150,7 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
// from its saved state, where the fragment manager has already
// taken care of restoring the fragments we previously had instantiated.
if (mFragments.size() > position) {
- Fragment f = mFragments.get(position);
+ final Fragment f = mFragments.get(position);
if (f != null) {
return f;
}
@@ -160,12 +160,12 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
mCurTransaction = mFragmentManager.beginTransaction();
}
- Fragment fragment = getItem(position);
+ final Fragment fragment = getItem(position);
if (DEBUG) {
Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
}
if (mSavedState.size() > position) {
- Fragment.SavedState fss = mSavedState.get(position);
+ final Fragment.SavedState fss = mSavedState.get(position);
if (fss != null) {
fragment.setInitialSavedState(fss);
}
@@ -191,7 +191,7 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
@Override
public void destroyItem(@NonNull final ViewGroup container, final int position,
@NonNull final Object object) {
- Fragment fragment = (Fragment) object;
+ final Fragment fragment = (Fragment) object;
if (mCurTransaction == null) {
mCurTransaction = mFragmentManager.beginTransaction();
@@ -217,7 +217,7 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
@SuppressWarnings({"ReferenceEquality", "deprecation"})
public void setPrimaryItem(@NonNull final ViewGroup container, final int position,
@NonNull final Object object) {
- Fragment fragment = (Fragment) object;
+ final Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false);
@@ -267,17 +267,17 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
Bundle state = null;
if (mSavedState.size() > 0) {
state = new Bundle();
- Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
+ final Fragment.SavedState[] fss = new Fragment.SavedState[mSavedState.size()];
mSavedState.toArray(fss);
state.putParcelableArray("states", fss);
}
for (int i = 0; i < mFragments.size(); i++) {
- Fragment f = mFragments.get(i);
+ final Fragment f = mFragments.get(i);
if (f != null && f.isAdded()) {
if (state == null) {
state = new Bundle();
}
- String key = "f" + i;
+ final String key = "f" + i;
mFragmentManager.putFragment(state, key, f);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -294,9 +294,9 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
@Override
public void restoreState(@Nullable final Parcelable state, @Nullable final ClassLoader loader) {
if (state != null) {
- Bundle bundle = (Bundle) state;
+ final Bundle bundle = (Bundle) state;
bundle.setClassLoader(loader);
- Parcelable[] fss = bundle.getParcelableArray("states");
+ final Parcelable[] fss = bundle.getParcelableArray("states");
mSavedState.clear();
mFragments.clear();
if (fss != null) {
@@ -304,11 +304,11 @@ public abstract class FragmentStatePagerAdapterMenuWorkaround extends PagerAdapt
mSavedState.add((Fragment.SavedState) fss[i]);
}
}
- Iterable keys = bundle.keySet();
- for (String key: keys) {
+ final Iterable keys = bundle.keySet();
+ for (final String key : keys) {
if (key.startsWith("f")) {
- int index = Integer.parseInt(key.substring(1));
- Fragment f = mFragmentManager.getFragment(bundle, key);
+ final int index = Integer.parseInt(key.substring(1));
+ final Fragment f = mFragmentManager.getFragment(bundle, key);
if (f != null) {
while (mFragments.size() <= index) {
mFragments.add(null);
diff --git a/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java b/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java
index 90e5edcd3..b5c7fc564 100644
--- a/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java
+++ b/app/src/main/java/com/google/android/material/appbar/FlingBehavior.java
@@ -30,19 +30,18 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
public boolean onRequestChildRectangleOnScreen(
@NonNull final CoordinatorLayout coordinatorLayout, @NonNull final AppBarLayout child,
@NonNull final Rect rectangle, final boolean immediate) {
-
focusScrollRect.set(rectangle);
coordinatorLayout.offsetDescendantRectToMyCoords(child, focusScrollRect);
- int height = coordinatorLayout.getHeight();
+ final int height = coordinatorLayout.getHeight();
if (focusScrollRect.top <= 0 && focusScrollRect.bottom >= height) {
// the child is too big to fit inside ourselves completely, ignore request
return false;
}
- int dy;
+ final int dy;
if (focusScrollRect.bottom > height) {
dy = focusScrollRect.top;
@@ -54,7 +53,7 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
return false;
}
- int consumed = scroll(coordinatorLayout, child, dy, getMaxDragOffset(child), 0);
+ final int consumed = scroll(coordinatorLayout, child, dy, getMaxDragOffset(child), 0);
return consumed == dy;
}
@@ -69,6 +68,14 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
return false;
}
}
+ final View seekBar = child.findViewById(R.id.playbackSeekBar);
+ if (seekBar != null) {
+ final boolean visible = seekBar.getGlobalVisibleRect(globalRect);
+ if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
+ allowScroll = false;
+ return false;
+ }
+ }
allowScroll = true;
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
@@ -106,14 +113,14 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
@Nullable
private OverScroller getScrollerField() {
try {
- Class> headerBehaviorType = this.getClass()
+ final Class> headerBehaviorType = this.getClass()
.getSuperclass().getSuperclass().getSuperclass();
if (headerBehaviorType != null) {
- Field field = headerBehaviorType.getDeclaredField("scroller");
+ final Field field = headerBehaviorType.getDeclaredField("scroller");
field.setAccessible(true);
return ((OverScroller) field.get(this));
}
- } catch (NoSuchFieldException | IllegalAccessException e) {
+ } catch (final NoSuchFieldException | IllegalAccessException e) {
// ?
}
return null;
@@ -122,34 +129,35 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
@Nullable
private Field getLastNestedScrollingChildRefField() {
try {
- Class> headerBehaviorType = this.getClass().getSuperclass().getSuperclass();
+ final Class> headerBehaviorType = this.getClass().getSuperclass().getSuperclass();
if (headerBehaviorType != null) {
- Field field = headerBehaviorType.getDeclaredField("lastNestedScrollingChildRef");
+ final Field field
+ = headerBehaviorType.getDeclaredField("lastNestedScrollingChildRef");
field.setAccessible(true);
return field;
}
- } catch (NoSuchFieldException e) {
+ } catch (final NoSuchFieldException e) {
// ?
}
return null;
}
private void resetNestedScrollingChild() {
- Field field = getLastNestedScrollingChildRefField();
+ final Field field = getLastNestedScrollingChildRefField();
if (field != null) {
try {
- Object value = field.get(this);
+ final Object value = field.get(this);
if (value != null) {
field.set(this, null);
}
- } catch (IllegalAccessException e) {
+ } catch (final IllegalAccessException e) {
// ?
}
}
}
private void stopAppBarLayoutFling() {
- OverScroller scroller = getScrollerField();
+ final OverScroller scroller = getScrollerField();
if (scroller != null) {
scroller.forceFinished(true);
}
diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java
index 0071d2efe..00842ec46 100644
--- a/app/src/main/java/org/schabi/newpipe/App.java
+++ b/app/src/main/java/org/schabi/newpipe/App.java
@@ -104,7 +104,7 @@ public class App extends Application {
}
protected Downloader getDownloader() {
- DownloaderImpl downloader = DownloaderImpl.init(null);
+ final DownloaderImpl downloader = DownloaderImpl.init(null);
setCookiesToDownloader(downloader);
return downloader;
}
@@ -208,7 +208,7 @@ public class App extends Application {
.setBuildConfigClass(BuildConfig.class)
.build();
ACRA.init(this, acraConfig);
- } catch (ACRAConfigurationException ace) {
+ } catch (final ACRAConfigurationException ace) {
ace.printStackTrace();
ErrorActivity.reportError(this,
ace,
@@ -231,10 +231,10 @@ public class App extends Application {
// Keep this below DEFAULT to avoid making noise on every notification update
final int importance = NotificationManager.IMPORTANCE_LOW;
- NotificationChannel mChannel = new NotificationChannel(id, name, importance);
+ final NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
- NotificationManager mNotificationManager =
+ final NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
@@ -255,11 +255,11 @@ public class App extends Application {
final String appUpdateDescription
= getString(R.string.app_update_notification_channel_description);
- NotificationChannel appUpdateChannel
+ final NotificationChannel appUpdateChannel
= new NotificationChannel(appUpdateId, appUpdateName, importance);
appUpdateChannel.setDescription(appUpdateDescription);
- NotificationManager appUpdateNotificationManager
+ final NotificationManager appUpdateNotificationManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
}
diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java
index 625f514e9..0d211fdfd 100644
--- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java
+++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java
@@ -62,7 +62,7 @@ public class CheckForNewAppVersionTask extends AsyncTask {
try {
packageInfo = pm.getPackageInfo(packageName, flags);
- } catch (PackageManager.NameNotFoundException e) {
+ } catch (final PackageManager.NameNotFoundException e) {
ErrorActivity.reportError(APP, e, null, null,
ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none",
"Could not find package info", R.string.app_ui_crash));
@@ -77,7 +77,7 @@ public class CheckForNewAppVersionTask extends AsyncTask {
try {
final CertificateFactory cf = CertificateFactory.getInstance("X509");
c = (X509Certificate) cf.generateCertificate(input);
- } catch (CertificateException e) {
+ } catch (final CertificateException e) {
ErrorActivity.reportError(APP, e, null, null,
ErrorActivity.ErrorInfo.make(UserAction.SOMETHING_ELSE, "none",
"Certificate error", R.string.app_ui_crash));
@@ -86,7 +86,7 @@ public class CheckForNewAppVersionTask extends AsyncTask {
String hexString = null;
try {
- MessageDigest md = MessageDigest.getInstance("SHA1");
+ final MessageDigest md = MessageDigest.getInstance("SHA1");
final byte[] publicKey = md.digest(c.getEncoded());
hexString = byte2HexFormatted(publicKey);
} catch (NoSuchAlgorithmException | CertificateEncodingException e) {
@@ -167,7 +167,7 @@ public class CheckForNewAppVersionTask extends AsyncTask {
compareAppVersionAndShowNotification(versionName, apkLocationUrl, versionCode);
- } catch (JsonParserException e) {
+ } catch (final JsonParserException e) {
// connectivity problems, do not alarm user and fail silently
if (DEBUG) {
Log.w(TAG, Log.getStackTraceString(e));
@@ -187,7 +187,7 @@ public class CheckForNewAppVersionTask extends AsyncTask {
private void compareAppVersionAndShowNotification(final String versionName,
final String apkLocationUrl,
final int versionCode) {
- int notificationId = 2000;
+ final int notificationId = 2000;
if (BuildConfig.VERSION_CODE < versionCode) {
diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java
index 95d3c2b7c..9cba0667b 100644
--- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java
+++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java
@@ -94,18 +94,18 @@ public final class DownloaderImpl extends Downloader {
private static void enableModernTLS(final OkHttpClient.Builder builder) {
try {
// get the default TrustManager
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
+ final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
- TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
+ final TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:"
+ Arrays.toString(trustManagers));
}
- X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
+ final X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
// insert our own TLSSocketFactory
- SSLSocketFactory sslSocketFactory = TLSSocketFactoryCompat.getInstance();
+ final SSLSocketFactory sslSocketFactory = TLSSocketFactoryCompat.getInstance();
builder.sslSocketFactory(sslSocketFactory, trustManager);
@@ -114,16 +114,16 @@ public final class DownloaderImpl extends Downloader {
// Necessary because some servers (e.g. Framatube.org)
// don't support the old cipher suites.
// https://github.com/square/okhttp/issues/4053#issuecomment-402579554
- List cipherSuites = new ArrayList<>();
+ final List cipherSuites = new ArrayList<>();
cipherSuites.addAll(ConnectionSpec.MODERN_TLS.cipherSuites());
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
- ConnectionSpec legacyTLS = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
+ final ConnectionSpec legacyTLS = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
.build();
builder.connectionSpecs(Arrays.asList(legacyTLS, ConnectionSpec.CLEARTEXT));
- } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
+ } catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
if (DEBUG) {
e.printStackTrace();
}
@@ -131,15 +131,15 @@ public final class DownloaderImpl extends Downloader {
}
public String getCookies(final String url) {
- List resultCookies = new ArrayList<>();
+ final List resultCookies = new ArrayList<>();
if (url.contains(YOUTUBE_DOMAIN)) {
- String youtubeCookie = getCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY);
+ final String youtubeCookie = getCookie(YOUTUBE_RESTRICTED_MODE_COOKIE_KEY);
if (youtubeCookie != null) {
resultCookies.add(youtubeCookie);
}
}
// Recaptcha cookie is always added TODO: not sure if this is necessary
- String recaptchaCookie = getCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY);
+ final String recaptchaCookie = getCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY);
if (recaptchaCookie != null) {
resultCookies.add(recaptchaCookie);
}
@@ -159,9 +159,9 @@ public final class DownloaderImpl extends Downloader {
}
public void updateYoutubeRestrictedModeCookies(final Context context) {
- String restrictedModeEnabledKey =
+ final String restrictedModeEnabledKey =
context.getString(R.string.youtube_restricted_mode_enabled);
- boolean restrictedModeEnabled = PreferenceManager.getDefaultSharedPreferences(context)
+ final boolean restrictedModeEnabled = PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(restrictedModeEnabledKey, false);
updateYoutubeRestrictedModeCookies(restrictedModeEnabled);
}
@@ -186,9 +186,9 @@ public final class DownloaderImpl extends Downloader {
try {
final Response response = head(url);
return Long.parseLong(response.getHeader("Content-Length"));
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
throw new IOException("Invalid content length", e);
- } catch (ReCaptchaException e) {
+ } catch (final ReCaptchaException e) {
throw new IOException(e);
}
}
@@ -199,7 +199,7 @@ public final class DownloaderImpl extends Downloader {
.method("GET", null).url(siteUrl)
.addHeader("User-Agent", USER_AGENT);
- String cookies = getCookies(siteUrl);
+ final String cookies = getCookies(siteUrl);
if (!cookies.isEmpty()) {
requestBuilder.addHeader("Cookie", cookies);
}
@@ -218,7 +218,7 @@ public final class DownloaderImpl extends Downloader {
}
return body.byteStream();
- } catch (ReCaptchaException e) {
+ } catch (final ReCaptchaException e) {
throw new IOException(e.getMessage(), e.getCause());
}
}
@@ -240,18 +240,18 @@ public final class DownloaderImpl extends Downloader {
.method(httpMethod, requestBody).url(url)
.addHeader("User-Agent", USER_AGENT);
- String cookies = getCookies(url);
+ final String cookies = getCookies(url);
if (!cookies.isEmpty()) {
requestBuilder.addHeader("Cookie", cookies);
}
- for (Map.Entry> pair : headers.entrySet()) {
+ for (final Map.Entry> pair : headers.entrySet()) {
final String headerName = pair.getKey();
final List headerValueList = pair.getValue();
if (headerValueList.size() > 1) {
requestBuilder.removeHeader(headerName);
- for (String headerValue : headerValueList) {
+ for (final String headerValue : headerValueList) {
requestBuilder.addHeader(headerName, headerValue);
}
} else if (headerValueList.size() == 1) {
diff --git a/app/src/main/java/org/schabi/newpipe/ExitActivity.java b/app/src/main/java/org/schabi/newpipe/ExitActivity.java
index 94eff9560..d4a4e3125 100644
--- a/app/src/main/java/org/schabi/newpipe/ExitActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/ExitActivity.java
@@ -27,7 +27,7 @@ import android.os.Bundle;
public class ExitActivity extends Activity {
public static void exitAndRemoveFromRecentApps(final Activity activity) {
- Intent intent = new Intent(activity, ExitActivity.class);
+ final Intent intent = new Intent(activity, ExitActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index fb1ca2342..c3086d02c 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -140,7 +140,7 @@ public class MainActivity extends AppCompatActivity {
setSupportActionBar(findViewById(R.id.toolbar));
try {
setupDrawer();
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorActivity.reportUiError(this, e);
}
@@ -155,8 +155,8 @@ public class MainActivity extends AppCompatActivity {
drawerItems = findViewById(R.id.navigation);
//Tabs
- int currentServiceId = ServiceHelper.getSelectedServiceId(this);
- StreamingService service = NewPipe.getService(currentServiceId);
+ final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
+ final StreamingService service = NewPipe.getService(currentServiceId);
int kioskId = 0;
@@ -228,7 +228,7 @@ public class MainActivity extends AppCompatActivity {
case R.id.menu_tabs_group:
try {
tabSelected(item);
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorActivity.reportUiError(this, e);
}
break;
@@ -269,8 +269,8 @@ public class MainActivity extends AppCompatActivity {
NavigationHelper.openStatisticFragment(getSupportFragmentManager());
break;
default:
- int currentServiceId = ServiceHelper.getSelectedServiceId(this);
- StreamingService service = NewPipe.getService(currentServiceId);
+ final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
+ final StreamingService service = NewPipe.getService(currentServiceId);
String serviceName = "";
int kioskId = 0;
@@ -299,8 +299,8 @@ public class MainActivity extends AppCompatActivity {
}
private void setupDrawerHeader() {
- NavigationView navigationView = findViewById(R.id.navigation);
- View hView = navigationView.getHeaderView(0);
+ final NavigationView navigationView = findViewById(R.id.navigation);
+ final View hView = navigationView.getHeaderView(0);
serviceArrow = hView.findViewById(R.id.drawer_arrow);
headerServiceIcon = hView.findViewById(R.id.drawer_header_service_icon);
@@ -335,7 +335,7 @@ public class MainActivity extends AppCompatActivity {
} else {
try {
showTabs();
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorActivity.reportUiError(this, e);
}
}
@@ -344,11 +344,11 @@ public class MainActivity extends AppCompatActivity {
private void showServices() {
serviceArrow.setImageResource(R.drawable.ic_arrow_drop_up_white_24dp);
- for (StreamingService s : NewPipe.getServices()) {
+ for (final StreamingService s : NewPipe.getServices()) {
final String title = s.getServiceInfo().getName()
+ (ServiceHelper.isBeta(s) ? " (beta)" : "");
- MenuItem menuItem = drawerItems.getMenu()
+ final MenuItem menuItem = drawerItems.getMenu()
.add(R.id.menu_services_group, s.getServiceId(), ORDER, title)
.setIcon(ServiceHelper.getIcon(s.getServiceId()));
@@ -362,20 +362,20 @@ public class MainActivity extends AppCompatActivity {
}
private void enhancePeertubeMenu(final StreamingService s, final MenuItem menuItem) {
- PeertubeInstance currentInstace = PeertubeHelper.getCurrentInstance();
+ final PeertubeInstance currentInstace = PeertubeHelper.getCurrentInstance();
menuItem.setTitle(currentInstace.getName() + (ServiceHelper.isBeta(s) ? " (beta)" : ""));
- Spinner spinner = (Spinner) LayoutInflater.from(this)
+ final Spinner spinner = (Spinner) LayoutInflater.from(this)
.inflate(R.layout.instance_spinner_layout, null);
- List instances = PeertubeHelper.getInstanceList(this);
- List items = new ArrayList<>();
+ final List instances = PeertubeHelper.getInstanceList(this);
+ final List items = new ArrayList<>();
int defaultSelect = 0;
- for (PeertubeInstance instance : instances) {
+ for (final PeertubeInstance instance : instances) {
items.add(instance.getName());
if (instance.getUrl().equals(currentInstace.getUrl())) {
defaultSelect = items.size() - 1;
}
}
- ArrayAdapter adapter = new ArrayAdapter<>(this,
+ final ArrayAdapter adapter = new ArrayAdapter<>(this,
R.layout.instance_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
@@ -384,7 +384,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onItemSelected(final AdapterView> parent, final View view,
final int position, final long id) {
- PeertubeInstance newInstance = instances.get(position);
+ final PeertubeInstance newInstance = instances.get(position);
if (newInstance.getUrl().equals(PeertubeHelper.getCurrentInstance().getUrl())) {
return;
}
@@ -410,8 +410,8 @@ public class MainActivity extends AppCompatActivity {
serviceArrow.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp);
//Tabs
- int currentServiceId = ServiceHelper.getSelectedServiceId(this);
- StreamingService service = NewPipe.getService(currentServiceId);
+ final int currentServiceId = ServiceHelper.getSelectedServiceId(this);
+ final StreamingService service = NewPipe.getService(currentServiceId);
int kioskId = 0;
@@ -476,11 +476,12 @@ public class MainActivity extends AppCompatActivity {
headerServiceView.post(() -> headerServiceView.setSelected(true));
toggleServiceButton.setContentDescription(
getString(R.string.drawer_header_description) + selectedServiceName);
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorActivity.reportUiError(this, e);
}
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ final SharedPreferences sharedPreferences
+ = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPreferences.getBoolean(Constants.KEY_THEME_CHANGE, false)) {
if (DEBUG) {
Log.d(TAG, "Theme has changed, recreating activity...");
@@ -513,7 +514,7 @@ public class MainActivity extends AppCompatActivity {
if (intent != null) {
// Return if launched from a launcher (e.g. Nova Launcher, Pixel Launcher ...)
// to not destroy the already created backstack
- String action = intent.getAction();
+ final String action = intent.getAction();
if ((action != null && action.equals(Intent.ACTION_MAIN))
&& intent.hasCategory(Intent.CATEGORY_LAUNCHER)) {
return;
@@ -546,7 +547,7 @@ public class MainActivity extends AppCompatActivity {
}
if (DeviceUtils.isTv(this)) {
- View drawerPanel = findViewById(R.id.navigation);
+ final View drawerPanel = findViewById(R.id.navigation);
if (drawer.isDrawerOpen(drawerPanel)) {
drawer.closeDrawers();
return;
@@ -594,7 +595,7 @@ public class MainActivity extends AppCompatActivity {
public void onRequestPermissionsResult(final int requestCode,
@NonNull final String[] permissions,
@NonNull final int[] grantResults) {
- for (int i : grantResults) {
+ for (final int i : grantResults) {
if (i == PackageManager.PERMISSION_DENIED) {
return;
}
@@ -604,7 +605,7 @@ public class MainActivity extends AppCompatActivity {
NavigationHelper.openDownloads(this);
break;
case PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE:
- Fragment fragment = getSupportFragmentManager()
+ final Fragment fragment = getSupportFragmentManager()
.findFragmentById(R.id.fragment_player_holder);
if (fragment instanceof VideoDetailFragment) {
((VideoDetailFragment) fragment).openDownloadDialog();
@@ -656,13 +657,14 @@ public class MainActivity extends AppCompatActivity {
}
super.onCreateOptionsMenu(menu);
- Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
+ final Fragment fragment
+ = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
if (!(fragment instanceof SearchFragment)) {
findViewById(R.id.toolbar).findViewById(R.id.toolbar_search_container)
.setVisibility(View.GONE);
}
- ActionBar actionBar = getSupportActionBar();
+ final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
@@ -677,7 +679,7 @@ public class MainActivity extends AppCompatActivity {
if (DEBUG) {
Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]");
}
- int id = item.getItemId();
+ final int id = item.getItemId();
switch (id) {
case android.R.id.home:
@@ -745,13 +747,13 @@ public class MainActivity extends AppCompatActivity {
}
if (intent.hasExtra(Constants.KEY_LINK_TYPE)) {
- String url = intent.getStringExtra(Constants.KEY_URL);
- int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
- String title = intent.getStringExtra(Constants.KEY_TITLE);
+ final String url = intent.getStringExtra(Constants.KEY_URL);
+ final int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
+ final String title = intent.getStringExtra(Constants.KEY_TITLE);
switch (((StreamingService.LinkType) intent
.getSerializableExtra(Constants.KEY_LINK_TYPE))) {
case STREAM:
- boolean autoPlay = intent
+ final boolean autoPlay = intent
.getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false);
final String intentCacheKey = intent
.getStringExtra(VideoPlayer.PLAY_QUEUE_KEY);
@@ -780,7 +782,7 @@ public class MainActivity extends AppCompatActivity {
if (searchString == null) {
searchString = "";
}
- int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
+ final int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
NavigationHelper.openSearchFragment(
getSupportFragmentManager(),
serviceId,
@@ -789,7 +791,7 @@ public class MainActivity extends AppCompatActivity {
} else {
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
}
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorActivity.reportUiError(this, e);
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java b/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java
index c59c48367..988a5ed98 100644
--- a/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java
+++ b/app/src/main/java/org/schabi/newpipe/NewPipeDatabase.java
@@ -46,7 +46,7 @@ public final class NewPipeDatabase {
if (databaseInstance == null) {
throw new IllegalStateException("database is not initialized");
}
- Cursor c = databaseInstance.query("pragma wal_checkpoint(full)", null);
+ final Cursor c = databaseInstance.query("pragma wal_checkpoint(full)", null);
if (c.moveToFirst() && c.getInt(0) == 1) {
throw new RuntimeException("Checkpoint was blocked from completing");
}
diff --git a/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java
index 2e1abd598..75304a2b9 100644
--- a/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java
@@ -31,7 +31,7 @@ public class PanicResponderActivity extends Activity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Intent intent = getIntent();
+ final Intent intent = getIntent();
if (intent != null && PANIC_TRIGGER_ACTION.equals(intent.getAction())) {
// TODO: Explicitly clear the search results
// once they are restored when the app restarts
diff --git a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java
index 40ea4fd58..c962ed99d 100644
--- a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java
@@ -61,7 +61,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
ThemeHelper.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recaptcha);
- Toolbar toolbar = findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String url = getIntent().getStringExtra(RECAPTCHA_URL_EXTRA);
@@ -76,7 +76,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
webView = findViewById(R.id.reCaptchaWebView);
// enable Javascript
- WebSettings webSettings = webView.getSettings();
+ final WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@@ -84,7 +84,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
@Override
public boolean shouldOverrideUrlLoading(final WebView view,
final WebResourceRequest request) {
- String url = request.getUrl().toString();
+ final String url = request.getUrl().toString();
if (MainActivity.DEBUG) {
Log.d(TAG, "shouldOverrideUrlLoading: request.url=" + url);
}
@@ -113,7 +113,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
// cleaning cache, history and cookies from webView
webView.clearCache(true);
webView.clearHistory();
- android.webkit.CookieManager cookieManager = CookieManager.getInstance();
+ final android.webkit.CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(aBoolean -> {
});
@@ -128,7 +128,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_recaptcha, menu);
- ActionBar actionBar = getSupportActionBar();
+ final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setTitle(R.string.title_activity_recaptcha);
@@ -145,7 +145,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
- int id = item.getItemId();
+ final int id = item.getItemId();
switch (id) {
case R.id.menu_item_done:
saveCookiesAndFinish();
@@ -173,7 +173,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
setResult(RESULT_OK);
}
- Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
+ final Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, intent);
}
@@ -188,13 +188,13 @@ public class ReCaptchaActivity extends AppCompatActivity {
return;
}
- String cookies = CookieManager.getInstance().getCookie(url);
+ final String cookies = CookieManager.getInstance().getCookie(url);
handleCookies(cookies);
// sometimes cookies are inside the url
- int abuseStart = url.indexOf("google_abuse=");
+ final int abuseStart = url.indexOf("google_abuse=");
if (abuseStart != -1) {
- int abuseEnd = url.indexOf("+path");
+ final int abuseEnd = url.indexOf("+path");
try {
String abuseCookie = url.substring(abuseStart + 13, abuseEnd);
diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java
index e9e166c22..70fceaf07 100644
--- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java
@@ -310,7 +310,7 @@ public class RouterActivity extends AppCompatActivity {
};
int id = 12345;
- for (AdapterChoiceItem item : choices) {
+ for (final AdapterChoiceItem item : choices) {
final RadioButton radioButton
= (RadioButton) inflater.inflate(R.layout.list_radio_icon_item, null);
radioButton.setText(item.description);
@@ -330,7 +330,7 @@ public class RouterActivity extends AppCompatActivity {
getString(R.string.preferred_open_action_last_selected_key), null);
if (!TextUtils.isEmpty(lastSelectedPlayer)) {
for (int i = 0; i < choices.size(); i++) {
- AdapterChoiceItem c = choices.get(i);
+ final AdapterChoiceItem c = choices.get(i);
if (lastSelectedPlayer.equals(c.key)) {
selectedRadioPosition = i;
break;
@@ -362,9 +362,9 @@ public class RouterActivity extends AppCompatActivity {
final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
- boolean isExtVideoEnabled = preferences.getBoolean(
+ final boolean isExtVideoEnabled = preferences.getBoolean(
getString(R.string.use_external_video_player_key), false);
- boolean isExtAudioEnabled = preferences.getBoolean(
+ final boolean isExtAudioEnabled = preferences.getBoolean(
getString(R.string.use_external_audio_player_key), false);
returnList.add(new AdapterChoiceItem(getString(R.string.show_info_key),
@@ -410,9 +410,9 @@ public class RouterActivity extends AppCompatActivity {
}
private void handleText() {
- String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
- int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
- Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
+ final String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+ final int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
+ final Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
NavigationHelper.openSearch(getThemeWrapperContext(), serviceId, searchString);
@@ -479,14 +479,14 @@ public class RouterActivity extends AppCompatActivity {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull StreamInfo result) -> {
- List sortedVideoStreams = ListHelper
+ final List sortedVideoStreams = ListHelper
.getSortedStreamVideosList(this, result.getVideoStreams(),
result.getVideoOnlyStreams(), false);
- int selectedVideoStreamIndex = ListHelper
+ final int selectedVideoStreamIndex = ListHelper
.getDefaultResolutionIndex(this, sortedVideoStreams);
- FragmentManager fm = getSupportFragmentManager();
- DownloadDialog downloadDialog = DownloadDialog.newInstance(result);
+ final FragmentManager fm = getSupportFragmentManager();
+ final DownloadDialog downloadDialog = DownloadDialog.newInstance(result);
downloadDialog.setVideoStreams(sortedVideoStreams);
downloadDialog.setAudioStreams(result.getAudioStreams());
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
@@ -504,7 +504,7 @@ public class RouterActivity extends AppCompatActivity {
public void onRequestPermissionsResult(final int requestCode,
@NonNull final String[] permissions,
@NonNull final int[] grantResults) {
- for (int i : grantResults) {
+ for (final int i : grantResults) {
if (i == PackageManager.PERMISSION_DENIED) {
finish();
return;
@@ -634,7 +634,7 @@ public class RouterActivity extends AppCompatActivity {
if (!(serializable instanceof Choice)) {
return;
}
- Choice playerChoice = (Choice) serializable;
+ final Choice playerChoice = (Choice) serializable;
handleChoice(playerChoice);
}
@@ -682,13 +682,13 @@ public class RouterActivity extends AppCompatActivity {
final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this);
- boolean isExtVideoEnabled = preferences.getBoolean(
+ final boolean isExtVideoEnabled = preferences.getBoolean(
getString(R.string.use_external_video_player_key), false);
- boolean isExtAudioEnabled = preferences.getBoolean(
+ final boolean isExtAudioEnabled = preferences.getBoolean(
getString(R.string.use_external_audio_player_key), false);
PlayQueue playQueue;
- String playerChoice = choice.playerChoice;
+ final String playerChoice = choice.playerChoice;
if (info instanceof StreamInfo) {
if (playerChoice.equals(backgroundPlayerKey) && isExtAudioEnabled) {
diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
index b5be2dde6..3041c3d6c 100644
--- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
@@ -88,7 +88,7 @@ public class AboutActivity extends AppCompatActivity {
setContentView(R.layout.activity_about);
- Toolbar toolbar = findViewById(R.id.toolbar);
+ final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Create the adapter that will return a fragment for each of the three
@@ -99,13 +99,13 @@ public class AboutActivity extends AppCompatActivity {
mViewPager = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
- TabLayout tabLayout = findViewById(R.id.tabs);
+ final TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
- int id = item.getItemId();
+ final int id = item.getItemId();
switch (id) {
case android.R.id.home:
@@ -134,25 +134,25 @@ public class AboutActivity extends AppCompatActivity {
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_about, container, false);
- Context context = this.getContext();
+ final View rootView = inflater.inflate(R.layout.fragment_about, container, false);
+ final Context context = this.getContext();
- TextView version = rootView.findViewById(R.id.app_version);
+ final TextView version = rootView.findViewById(R.id.app_version);
version.setText(BuildConfig.VERSION_NAME);
- View githubLink = rootView.findViewById(R.id.github_link);
+ final View githubLink = rootView.findViewById(R.id.github_link);
githubLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.github_url)));
- View donationLink = rootView.findViewById(R.id.donation_link);
+ final View donationLink = rootView.findViewById(R.id.donation_link);
donationLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.donation_url)));
- View websiteLink = rootView.findViewById(R.id.website_link);
+ final View websiteLink = rootView.findViewById(R.id.website_link);
websiteLink.setOnClickListener(nv ->
openUrlInBrowser(context, context.getString(R.string.website_url)));
- View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link);
+ final View privacyPolicyLink = rootView.findViewById(R.id.privacy_policy_link);
privacyPolicyLink.setOnClickListener(v ->
openUrlInBrowser(context, context.getString(R.string.privacy_policy_url)));
diff --git a/app/src/main/java/org/schabi/newpipe/about/License.java b/app/src/main/java/org/schabi/newpipe/about/License.java
index 370009860..877b51fd8 100644
--- a/app/src/main/java/org/schabi/newpipe/about/License.java
+++ b/app/src/main/java/org/schabi/newpipe/about/License.java
@@ -4,10 +4,12 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
+import java.io.Serializable;
+
/**
* Class for storing information about a software license.
*/
-public class License implements Parcelable {
+public class License implements Parcelable, Serializable {
public static final Creator CREATOR = new Creator() {
@Override
public License createFromParcel(final Parcel source) {
diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java
index bc6310601..e869dbb14 100644
--- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java
@@ -1,7 +1,6 @@
package org.schabi.newpipe.about;
import android.app.Activity;
-import android.content.Context;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
@@ -11,12 +10,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.ShareUtils;
+import java.io.Serializable;
import java.util.Arrays;
/**
@@ -26,13 +27,15 @@ public class LicenseFragment extends Fragment {
private static final String ARG_COMPONENTS = "components";
private SoftwareComponent[] softwareComponents;
private SoftwareComponent componentForContextMenu;
+ private License activeLicense;
+ private static final String LICENSE_KEY = "ACTIVE_LICENSE";
public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) {
if (softwareComponents == null) {
throw new NullPointerException("softwareComponents is null");
}
- LicenseFragment fragment = new LicenseFragment();
- Bundle bundle = new Bundle();
+ final LicenseFragment fragment = new LicenseFragment();
+ final Bundle bundle = new Bundle();
bundle.putParcelableArray(ARG_COMPONENTS, softwareComponents);
fragment.setArguments(bundle);
return fragment;
@@ -44,8 +47,8 @@ public class LicenseFragment extends Fragment {
* @param context the context to use
* @param license the license to show
*/
- private static void showLicense(final Context context, final License license) {
- new LicenseFragmentHelper((Activity) context).execute(license);
+ private static void showLicense(final Activity context, final License license) {
+ new LicenseFragmentHelper(context).execute(license);
}
@Override
@@ -54,6 +57,12 @@ public class LicenseFragment extends Fragment {
softwareComponents = (SoftwareComponent[]) getArguments()
.getParcelableArray(ARG_COMPONENTS);
+ if (savedInstanceState != null) {
+ final Serializable license = savedInstanceState.getSerializable(LICENSE_KEY);
+ if (license != null) {
+ activeLicense = (License) license;
+ }
+ }
// Sort components by name
Arrays.sort(softwareComponents, (o1, o2) -> o1.getName().compareTo(o2.getName()));
}
@@ -66,8 +75,10 @@ public class LicenseFragment extends Fragment {
final ViewGroup softwareComponentsView = rootView.findViewById(R.id.software_components);
final View licenseLink = rootView.findViewById(R.id.app_read_license);
- licenseLink.setOnClickListener(v ->
- showLicense(getActivity(), StandardLicenses.GPL3));
+ licenseLink.setOnClickListener(v -> {
+ activeLicense = StandardLicenses.GPL3;
+ showLicense(getActivity(), StandardLicenses.GPL3);
+ });
for (final SoftwareComponent component : softwareComponents) {
final View componentView = inflater
@@ -81,11 +92,16 @@ public class LicenseFragment extends Fragment {
component.getLicense().getAbbreviation()));
componentView.setTag(component);
- componentView.setOnClickListener(v ->
- showLicense(getActivity(), component.getLicense()));
+ componentView.setOnClickListener(v -> {
+ activeLicense = component.getLicense();
+ showLicense(getActivity(), component.getLicense());
+ });
softwareComponentsView.addView(componentView);
registerForContextMenu(componentView);
}
+ if (activeLicense != null) {
+ showLicense(getActivity(), activeLicense);
+ }
return rootView;
}
@@ -101,7 +117,7 @@ public class LicenseFragment extends Fragment {
}
@Override
- public boolean onContextItemSelected(final MenuItem item) {
+ public boolean onContextItemSelected(@NonNull final MenuItem item) {
// item.getMenuInfo() is null so we use the tag of the view
final SoftwareComponent component = componentForContextMenu;
if (component == null) {
@@ -116,4 +132,12 @@ public class LicenseFragment extends Fragment {
}
return false;
}
+
+ @Override
+ public void onSaveInstanceState(@NonNull final Bundle savedInstanceState) {
+ super.onSaveInstanceState(savedInstanceState);
+ if (activeLicense != null) {
+ savedInstanceState.putSerializable(LICENSE_KEY, activeLicense);
+ }
+ }
}
diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java
index 1c425567f..01a01bc88 100644
--- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java
+++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java
@@ -51,7 +51,7 @@ public class LicenseFragmentHelper extends AsyncTask