From 0ab86937d24f3f3caf97d51e4a981727f7697e08 Mon Sep 17 00:00:00 2001 From: BO41 Date: Tue, 28 Aug 2018 20:02:25 +0200 Subject: [PATCH] data flow issue + declaration redundancy make final unused methods make final BUILD SUCCESSFUL in 0s 39 actionable tasks: 39 up-to-date --- .../java/org/schabi/newpipe/BaseFragment.java | 2 +- .../java/org/schabi/newpipe/Downloader.java | 2 +- .../org/schabi/newpipe/ReCaptchaActivity.java | 2 +- .../org/schabi/newpipe/RouterActivity.java | 2 +- .../newpipe/about/LicenseFragmentHelper.java | 2 +- .../org/schabi/newpipe/database/BasicDAO.java | 4 ++-- .../download/DeleteDownloadManager.java | 8 ++++---- .../newpipe/download/DownloadDialog.java | 2 +- .../newpipe/fragments/detail/StackItem.java | 4 ++-- .../fragments/detail/VideoDetailFragment.java | 2 +- .../list/channel/ChannelFragment.java | 3 +-- .../fragments/list/search/SearchFragment.java | 4 ++-- .../newpipe/info_list/InfoItemBuilder.java | 2 +- .../newpipe/local/LocalItemBuilder.java | 2 +- .../history/StatisticsPlaylistFragment.java | 2 +- .../subscription/SubscriptionService.java | 6 +++--- .../services/BaseImportExportService.java | 16 +++++++-------- .../schabi/newpipe/player/VideoPlayer.java | 8 ++++---- .../newpipe/player/helper/AudioReactor.java | 8 ++++---- .../newpipe/player/helper/PlayerHelper.java | 6 +++--- .../playback/BasePlayerMediaSession.java | 2 +- .../player/playback/MediaSourceManager.java | 9 ++++----- .../playqueue/AbstractInfoPlayQueue.java | 4 ++-- .../settings/AppearanceSettingsFragment.java | 2 +- .../settings/BasePreferenceFragment.java | 2 +- .../settings/ContentSettingsFragment.java | 8 +------- .../settings/SelectChannelFragment.java | 11 +++++----- .../newpipe/settings/SelectKioskFragment.java | 19 +++++++++--------- .../org/schabi/newpipe/util/InfoCache.java | 20 ++++++++----------- .../org/schabi/newpipe/util/ListHelper.java | 7 +++---- .../newpipe/util/StreamItemAdapter.java | 4 ++-- .../schabi/newpipe/views/CollapsibleView.java | 2 +- .../us/shandian/giga/get/DownloadMission.java | 2 +- .../shandian/giga/get/DownloadRunnable.java | 6 +++--- .../giga/service/DownloadManagerService.java | 2 +- .../giga/ui/adapter/MissionAdapter.java | 18 ++++++++--------- .../giga/ui/common/ProgressDrawable.java | 3 ++- .../giga/ui/fragment/MissionsFragment.java | 2 +- 38 files changed, 98 insertions(+), 112 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index b125ab02f..8048c2262 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -19,7 +19,7 @@ import icepick.State; public abstract class BaseFragment extends Fragment { protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()); - protected boolean DEBUG = MainActivity.DEBUG; + protected final boolean DEBUG = MainActivity.DEBUG; protected AppCompatActivity activity; public static final ImageLoader imageLoader = ImageLoader.getInstance(); diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index 17dc5859d..68f7e080f 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -43,7 +43,7 @@ public class Downloader implements org.schabi.newpipe.extractor.Downloader { private static Downloader instance; private String mCookies; - private OkHttpClient client; + private final OkHttpClient client; private Downloader(OkHttpClient.Builder builder) { this.client = builder diff --git a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java index a4e6730da..74c818bf9 100644 --- a/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ReCaptchaActivity.java @@ -85,7 +85,7 @@ public class ReCaptchaActivity extends AppCompatActivity { } private class ReCaptchaWebViewClient extends WebViewClient { - private Activity context; + private final Activity context; private String mCookies; ReCaptchaWebViewClient(Activity ctx) { diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index 4f1fdeab2..79cee214f 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -86,7 +86,7 @@ public class RouterActivity extends AppCompatActivity { protected int selectedPreviously = -1; protected String currentUrl; - protected CompositeDisposable disposables = new CompositeDisposable(); + protected final CompositeDisposable disposables = new CompositeDisposable(); private boolean selectionIsDownload = false; 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 701e18cbf..f4a6d7552 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragmentHelper.java @@ -17,7 +17,7 @@ import java.lang.ref.WeakReference; public class LicenseFragmentHelper extends AsyncTask { - WeakReference weakReference; + final WeakReference weakReference; private License license; public LicenseFragmentHelper(@Nullable Activity activity) { diff --git a/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java b/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java index 425c122ca..13117145a 100644 --- a/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java +++ b/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java @@ -30,7 +30,7 @@ public interface BasicDAO { /* Deletes */ @Delete - int delete(final Entity entity); + void delete(final Entity entity); @Delete int delete(final Collection entities); @@ -42,5 +42,5 @@ public interface BasicDAO { int update(final Entity entity); @Update - int update(final Collection entities); + void update(final Collection entities); } diff --git a/app/src/main/java/org/schabi/newpipe/download/DeleteDownloadManager.java b/app/src/main/java/org/schabi/newpipe/download/DeleteDownloadManager.java index f2912a6fa..5a2d4a486 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DeleteDownloadManager.java +++ b/app/src/main/java/org/schabi/newpipe/download/DeleteDownloadManager.java @@ -28,11 +28,11 @@ public class DeleteDownloadManager { private static final String KEY_STATE = "delete_manager_state"; - private View mView; - private HashSet mPendingMap; - private List mDisposableList; + private final View mView; + private final HashSet mPendingMap; + private final List mDisposableList; private DownloadManager mDownloadManager; - private PublishSubject publishSubject = PublishSubject.create(); + private final PublishSubject publishSubject = PublishSubject.create(); DeleteDownloadManager(Activity activity) { mPendingMap = new HashSet<>(); diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index 75f05cd16..9bbda6032 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -55,7 +55,7 @@ public class DownloadDialog extends DialogFragment implements RadioGroup.OnCheck private StreamItemAdapter audioStreamsAdapter; private StreamItemAdapter videoStreamsAdapter; - private CompositeDisposable disposables = new CompositeDisposable(); + private final CompositeDisposable disposables = new CompositeDisposable(); private EditText nameEditText; private Spinner streamsSpinner; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java index b8957f33c..f7f8ad702 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/StackItem.java @@ -3,9 +3,9 @@ package org.schabi.newpipe.fragments.detail; import java.io.Serializable; class StackItem implements Serializable { - private int serviceId; + private final int serviceId; private String title; - private String url; + private final String url; StackItem(int serviceId, String url, String title) { this.serviceId = serviceId; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index c726f8cee..2ca4fd78d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -760,7 +760,7 @@ public class VideoDetailFragment * Stack that contains the "navigation history".
* The peek is the current video. */ - protected LinkedList stack = new LinkedList<>(); + protected final LinkedList stack = new LinkedList<>(); public void clearHistory() { stack.clear(); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 562ee7f0d..6a3b3eb50 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -68,7 +68,7 @@ import static org.schabi.newpipe.util.AnimationUtils.animateView; public class ChannelFragment extends BaseListInfoFragment { - private CompositeDisposable disposables = new CompositeDisposable(); + private final CompositeDisposable disposables = new CompositeDisposable(); private Disposable subscribeButtonMonitor; private SubscriptionService subscriptionService; @@ -103,7 +103,6 @@ public class ChannelFragment extends BaseListInfoFragment { @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - boolean mIsVisibleToUser = isVisibleToUser; if(activity != null && useAsFrontPage && isVisibleToUser) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index b7831d4ab..19c7d463e 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -123,10 +123,10 @@ public class SearchFragment private String contentCountry; private boolean isSuggestionsEnabled = true; - private PublishSubject suggestionPublisher = PublishSubject.create(); + private final PublishSubject suggestionPublisher = PublishSubject.create(); private Disposable searchDisposable; private Disposable suggestionDisposable; - private CompositeDisposable disposables = new CompositeDisposable(); + private final CompositeDisposable disposables = new CompositeDisposable(); private SuggestionListAdapter suggestionListAdapter; private HistoryRecordManager historyRecordManager; diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java index 78867c81f..f473e5d08 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java @@ -45,7 +45,7 @@ public class InfoItemBuilder { private static final String TAG = InfoItemBuilder.class.toString(); private final Context context; - private ImageLoader imageLoader = ImageLoader.getInstance(); + private final ImageLoader imageLoader = ImageLoader.getInstance(); private OnClickGesture onStreamSelectedListener; private OnClickGesture onChannelSelectedListener; diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemBuilder.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemBuilder.java index 148f93075..0fbab0398 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemBuilder.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemBuilder.java @@ -33,7 +33,7 @@ public class LocalItemBuilder { private static final String TAG = LocalItemBuilder.class.toString(); private final Context context; - private ImageLoader imageLoader = ImageLoader.getInstance(); + private final ImageLoader imageLoader = ImageLoader.getInstance(); private OnClickGesture onSelectedListener; diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 95aeb09d7..e12045ddb 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -57,7 +57,7 @@ public class StatisticsPlaylistFragment /* Used for independent events */ private Subscription databaseSubscription; private HistoryRecordManager recordManager; - private CompositeDisposable disposables = new CompositeDisposable(); + private final CompositeDisposable disposables = new CompositeDisposable(); private enum StatisticSortMode { LAST_PLAYED, diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionService.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionService.java index b4545a2dd..f9e2d9583 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionService.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionService.java @@ -55,10 +55,10 @@ public class SubscriptionService { private static final int SUBSCRIPTION_DEBOUNCE_INTERVAL = 500; private static final int SUBSCRIPTION_THREAD_POOL_SIZE = 4; - private AppDatabase db; - private Flowable> subscription; + private final AppDatabase db; + private final Flowable> subscription; - private Scheduler subscriptionScheduler; + private final Scheduler subscriptionScheduler; private SubscriptionService(Context context) { db = NewPipeDatabase.getInstance(context.getApplicationContext()); diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java index 9d055b82a..e3db6e12c 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java @@ -58,8 +58,8 @@ public abstract class BaseImportExportService extends Service { protected NotificationCompat.Builder notificationBuilder; protected SubscriptionService subscriptionService; - protected CompositeDisposable disposables = new CompositeDisposable(); - protected PublishProcessor notificationUpdater = PublishProcessor.create(); + protected final CompositeDisposable disposables = new CompositeDisposable(); + protected final PublishProcessor notificationUpdater = PublishProcessor.create(); @Nullable @Override @@ -90,9 +90,9 @@ public abstract class BaseImportExportService extends Service { private static final int NOTIFICATION_SAMPLING_PERIOD = 2500; - protected AtomicInteger currentProgress = new AtomicInteger(-1); - protected AtomicInteger maxProgress = new AtomicInteger(-1); - protected ImportExportEventListener eventListener = new ImportExportEventListener() { + protected final AtomicInteger currentProgress = new AtomicInteger(-1); + protected final AtomicInteger maxProgress = new AtomicInteger(-1); + protected final ImportExportEventListener eventListener = new ImportExportEventListener() { @Override public void onSizeReceived(int size) { maxProgress.set(size); @@ -187,13 +187,13 @@ public abstract class BaseImportExportService extends Service { protected Toast toast; protected void showToast(@StringRes int message) { - showToast(getString(message), Toast.LENGTH_SHORT); + showToast(getString(message)); } - protected void showToast(String message, int duration) { + protected void showToast(String message) { if (toast != null) toast.cancel(); - toast = Toast.makeText(this, message, duration); + toast = Toast.makeText(this, message, Toast.LENGTH_SHORT); toast.show(); } diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java index 679fc6645..8e7db0dae 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -137,16 +137,16 @@ public abstract class VideoPlayer extends BasePlayer private TextView captionTextView; private ValueAnimator controlViewAnimator; - private Handler controlsVisibilityHandler = new Handler(); + private final Handler controlsVisibilityHandler = new Handler(); boolean isSomePopupMenuVisible = false; - private int qualityPopupMenuGroupId = 69; + private final int qualityPopupMenuGroupId = 69; private PopupMenu qualityPopupMenu; - private int playbackSpeedPopupMenuGroupId = 79; + private final int playbackSpeedPopupMenuGroupId = 79; private PopupMenu playbackSpeedPopupMenu; - private int captionPopupMenuGroupId = 89; + private final int captionPopupMenuGroupId = 89; private PopupMenu captionPopupMenu; /////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java index 5b9cce947..46d20c7e1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java @@ -116,7 +116,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, private void onAudioFocusGain() { Log.d(TAG, "onAudioFocusGain() called"); player.setVolume(DUCK_AUDIO_TO); - animateAudio(DUCK_AUDIO_TO, 1f, DUCK_DURATION); + animateAudio(DUCK_AUDIO_TO, 1f); if (PlayerHelper.isResumeAfterAudioFocusGain(context)) { player.setPlayWhenReady(true); @@ -131,13 +131,13 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, private void onAudioFocusLossCanDuck() { Log.d(TAG, "onAudioFocusLossCanDuck() called"); // Set the volume to 1/10 on ducking - animateAudio(player.getVolume(), DUCK_AUDIO_TO, DUCK_DURATION); + animateAudio(player.getVolume(), DUCK_AUDIO_TO); } - private void animateAudio(final float from, final float to, int duration) { + private void animateAudio(final float from, final float to) { ValueAnimator valueAnimator = new ValueAnimator(); valueAnimator.setFloatValues(from, to); - valueAnimator.setDuration(duration); + valueAnimator.setDuration(AudioReactor.DUCK_DURATION); valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java index ae187a834..05afe2859 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java @@ -203,7 +203,7 @@ public class PlayerHelper { @NonNull public static SeekParameters getSeekParameters(@NonNull final Context context) { - return isUsingInexactSeek(context, false) ? + return isUsingInexactSeek(context) ? SeekParameters.CLOSEST_SYNC : SeekParameters.EXACT; } @@ -318,8 +318,8 @@ public class PlayerHelper { return getPreferences(context).getBoolean(context.getString(R.string.popup_remember_size_pos_key), b); } - private static boolean isUsingInexactSeek(@NonNull final Context context, final boolean b) { - return getPreferences(context).getBoolean(context.getString(R.string.use_inexact_seek_key), b); + private static boolean isUsingInexactSeek(@NonNull final Context context) { + return getPreferences(context).getBoolean(context.getString(R.string.use_inexact_seek_key), false); } private static boolean isAutoQueueEnabled(@NonNull final Context context, final boolean b) { diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/BasePlayerMediaSession.java b/app/src/main/java/org/schabi/newpipe/player/playback/BasePlayerMediaSession.java index 3365828d1..00604b236 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/BasePlayerMediaSession.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/BasePlayerMediaSession.java @@ -8,7 +8,7 @@ import org.schabi.newpipe.player.mediasession.MediaSessionCallback; import org.schabi.newpipe.player.playqueue.PlayQueueItem; public class BasePlayerMediaSession implements MediaSessionCallback { - private BasePlayer player; + private final BasePlayer player; public BasePlayerMediaSession(final BasePlayer player) { this.player = player; diff --git a/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java b/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java index b27dc3dd6..3c5642d51 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/playback/MediaSourceManager.java @@ -335,7 +335,7 @@ public class MediaSourceManager { private void loadImmediate() { if (DEBUG) Log.d(TAG, "MediaSource - loadImmediate() called"); - final ItemsToLoad itemsToLoad = getItemsToLoad(playQueue, WINDOW_SIZE); + final ItemsToLoad itemsToLoad = getItemsToLoad(playQueue); if (itemsToLoad == null) return; // Evict the previous items being loaded to free up memory, before start loading new ones @@ -472,8 +472,7 @@ public class MediaSourceManager { // Manager Helpers //////////////////////////////////////////////////////////////////////////*/ @Nullable - private static ItemsToLoad getItemsToLoad(@NonNull final PlayQueue playQueue, - final int windowSize) { + private static ItemsToLoad getItemsToLoad(@NonNull final PlayQueue playQueue) { // The current item has higher priority final int currentIndex = playQueue.getIndex(); final PlayQueueItem currentItem = playQueue.getItem(currentIndex); @@ -482,8 +481,8 @@ public class MediaSourceManager { // The rest are just for seamless playback // Although timeline is not updated prior to the current index, these sources are still // loaded into the cache for faster retrieval at a potentially later time. - final int leftBound = Math.max(0, currentIndex - windowSize); - final int rightLimit = currentIndex + windowSize + 1; + final int leftBound = Math.max(0, currentIndex - MediaSourceManager.WINDOW_SIZE); + final int rightLimit = currentIndex + MediaSourceManager.WINDOW_SIZE + 1; final int rightBound = Math.min(playQueue.size(), rightLimit); final Set neighbors = new ArraySet<>( playQueue.getStreams().subList(leftBound,rightBound)); diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/AbstractInfoPlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/AbstractInfoPlayQueue.java index 5ff766313..676c0ca72 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/AbstractInfoPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/AbstractInfoPlayQueue.java @@ -19,8 +19,8 @@ abstract class AbstractInfoPlayQueue ext boolean isInitial; boolean isComplete; - int serviceId; - String baseUrl; + final int serviceId; + final String baseUrl; String nextUrl; transient Disposable fetchReactor; diff --git a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java index 806b30a5b..77d59e9cb 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java @@ -49,7 +49,7 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { return super.onPreferenceTreeClick(preference); } - private Preference.OnPreferenceChangeListener themePreferenceChange = new Preference.OnPreferenceChangeListener() { + private final Preference.OnPreferenceChangeListener themePreferenceChange = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); diff --git a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java index e3c52cdad..e4fae3e1f 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java @@ -13,7 +13,7 @@ import org.schabi.newpipe.MainActivity; public abstract class BasePreferenceFragment extends PreferenceFragmentCompat { protected final String TAG = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()); - protected boolean DEBUG = MainActivity.DEBUG; + protected final boolean DEBUG = MainActivity.DEBUG; protected SharedPreferences defaultPreferences; diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index 5f02dd785..81c0a1712 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -9,8 +9,6 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.util.Log; import android.widget.Toast; @@ -19,12 +17,9 @@ import com.nononsenseapps.filepicker.Utils; import com.nostra13.universalimageloader.core.ImageLoader; import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.FilePickerActivityHelper; -import org.schabi.newpipe.util.KioskTranslator; import org.schabi.newpipe.util.ZipHelper; import java.io.BufferedOutputStream; @@ -285,13 +280,12 @@ public class ContentSettingsFragment extends BasePreferenceFragment { // Error //////////////////////////////////////////////////////////////////////////*/ - protected boolean onError(Throwable e) { + protected void onError(Throwable e) { final Activity activity = getActivity(); ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); - return true; } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java index c1b2f1703..61bd4077e 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -51,7 +51,7 @@ import io.reactivex.schedulers.Schedulers; */ public class SelectChannelFragment extends DialogFragment { - private ImageLoader imageLoader = ImageLoader.getInstance(); + private final ImageLoader imageLoader = ImageLoader.getInstance(); private ProgressBar progressBar; private TextView emptyView; @@ -201,9 +201,9 @@ public class SelectChannelFragment extends DialogFragment { thumbnailView = v.findViewById(R.id.itemThumbnailView); titleView = v.findViewById(R.id.itemTitleView); } - public View view; - public CircleImageView thumbnailView; - public TextView titleView; + public final View view; + public final CircleImageView thumbnailView; + public final TextView titleView; } } @@ -211,14 +211,13 @@ public class SelectChannelFragment extends DialogFragment { // Error //////////////////////////////////////////////////////////////////////////*/ - protected boolean onError(Throwable e) { + protected void onError(Throwable e) { final Activity activity = getActivity(); ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); - return true; } diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java index 16ba6fec6..8c3bd56e7 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectKioskFragment.java @@ -112,13 +112,13 @@ public class SelectKioskFragment extends DialogFragment { public Entry (int i, int si, String ki, String kn){ icon = i; serviceId=si; kioskId=ki; kioskName = kn; } - int icon; - int serviceId; - String kioskId; - String kioskName; + final int icon; + final int serviceId; + final String kioskId; + final String kioskName; } - private List kioskList = new Vector<>(); + private final List kioskList = new Vector<>(); public SelectKioskAdapter() throws Exception { @@ -157,9 +157,9 @@ public class SelectKioskFragment extends DialogFragment { thumbnailView = v.findViewById(R.id.itemThumbnailView); titleView = v.findViewById(R.id.itemTitleView); } - public View view; - public ImageView thumbnailView; - public TextView titleView; + public final View view; + public final ImageView thumbnailView; + public final TextView titleView; } public void onBindViewHolder(SelectKioskItemHolder holder, final int position) { @@ -179,13 +179,12 @@ public class SelectKioskFragment extends DialogFragment { // Error //////////////////////////////////////////////////////////////////////////*/ - protected boolean onError(Throwable e) { + protected void onError(Throwable e) { final Activity activity = getActivity(); ErrorActivity.reportError(activity, e, activity.getClass(), null, ErrorActivity.ErrorInfo.make(UserAction.UI_ERROR, "none", "", R.string.app_ui_crash)); - return true; } } diff --git a/app/src/main/java/org/schabi/newpipe/util/InfoCache.java b/app/src/main/java/org/schabi/newpipe/util/InfoCache.java index ecc66bb40..318db37a1 100644 --- a/app/src/main/java/org/schabi/newpipe/util/InfoCache.java +++ b/app/src/main/java/org/schabi/newpipe/util/InfoCache.java @@ -28,9 +28,6 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.extractor.Info; import java.util.Map; -import java.util.concurrent.TimeUnit; - -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; public final class InfoCache { @@ -58,7 +55,7 @@ public final class InfoCache { public Info getFromKey(int serviceId, @NonNull String url) { if (DEBUG) Log.d(TAG, "getFromKey() called with: serviceId = [" + serviceId + "], url = [" + url + "]"); synchronized (lruCache) { - return getInfo(lruCache, keyOf(serviceId, url)); + return getInfo(keyOf(serviceId, url)); } } @@ -89,7 +86,7 @@ public final class InfoCache { public void trimCache() { if (DEBUG) Log.d(TAG, "trimCache() called"); synchronized (lruCache) { - removeStaleCache(lruCache); + removeStaleCache(); lruCache.trimToSize(TRIM_CACHE_TO); } } @@ -105,23 +102,22 @@ public final class InfoCache { return serviceId + url; } - private static void removeStaleCache(@NonNull final LruCache cache) { - for (Map.Entry entry : cache.snapshot().entrySet()) { + private static void removeStaleCache() { + for (Map.Entry entry : InfoCache.lruCache.snapshot().entrySet()) { final CacheData data = entry.getValue(); if (data != null && data.isExpired()) { - cache.remove(entry.getKey()); + InfoCache.lruCache.remove(entry.getKey()); } } } @Nullable - private static Info getInfo(@NonNull final LruCache cache, - @NonNull final String key) { - final CacheData data = cache.get(key); + private static Info getInfo(@NonNull final String key) { + final CacheData data = InfoCache.lruCache.get(key); if (data == null) return null; if (data.isExpired()) { - cache.remove(key); + InfoCache.lruCache.remove(key); return null; } diff --git a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java index 1a5bf14f7..871d0578f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java @@ -204,7 +204,7 @@ public final class ListHelper { */ private static void sortStreamList(List videoStreams, final boolean ascendingOrder) { Collections.sort(videoStreams, (o1, o2) -> { - int result = compareVideoStreamResolution(o1, o2, VIDEO_FORMAT_QUALITY_RANKING); + int result = compareVideoStreamResolution(o1, o2); return result == 0 ? 0 : (ascendingOrder ? result : -result); }); } @@ -399,8 +399,7 @@ public final class ListHelper { } // Compares the quality of two video streams. - private static int compareVideoStreamResolution(VideoStream streamA, VideoStream streamB, - List formatRanking) { + private static int compareVideoStreamResolution(VideoStream streamA, VideoStream streamB) { if (streamA == null) { return -1; } @@ -414,7 +413,7 @@ public final class ListHelper { } // Same bitrate and format - return formatRanking.indexOf(streamA.getFormat()) - formatRanking.indexOf(streamB.getFormat()); + return ListHelper.VIDEO_FORMAT_QUALITY_RANKING.indexOf(streamA.getFormat()) - ListHelper.VIDEO_FORMAT_QUALITY_RANKING.indexOf(streamB.getFormat()); } diff --git a/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java b/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java index e3fe4a679..e100a447b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java @@ -31,7 +31,7 @@ import us.shandian.giga.util.Utility; public class StreamItemAdapter extends BaseAdapter { private final Context context; - private StreamSizeWrapper streamsWrapper; + private final StreamSizeWrapper streamsWrapper; private final boolean showIconNoAudio; public StreamItemAdapter(Context context, StreamSizeWrapper streamsWrapper, boolean showIconNoAudio) { @@ -124,7 +124,7 @@ public class StreamItemAdapter extends BaseAdapter { public static class StreamSizeWrapper implements Serializable { private static final StreamSizeWrapper EMPTY = new StreamSizeWrapper<>(Collections.emptyList()); private final List streamsList; - private long[] streamSizes; + private final long[] streamSizes; public StreamSizeWrapper(List streamsList) { this.streamsList = streamsList; diff --git a/app/src/main/java/org/schabi/newpipe/views/CollapsibleView.java b/app/src/main/java/org/schabi/newpipe/views/CollapsibleView.java index adef7e76f..88d525625 100644 --- a/app/src/main/java/org/schabi/newpipe/views/CollapsibleView.java +++ b/app/src/main/java/org/schabi/newpipe/views/CollapsibleView.java @@ -81,7 +81,7 @@ public class CollapsibleView extends LinearLayout { private int targetHeight = -1; private ValueAnimator currentAnimator; - private List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); /** * This method recalculates the height of this view so it must be called when diff --git a/app/src/main/java/us/shandian/giga/get/DownloadMission.java b/app/src/main/java/us/shandian/giga/get/DownloadMission.java index f02eaae28..05ea7cbd4 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadMission.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadMission.java @@ -67,7 +67,7 @@ public class DownloadMission implements Serializable { public long done; public int threadCount = 3; public int finishCount; - private List threadPositions = new ArrayList(); + private final List threadPositions = new ArrayList(); public final Map blockState = new HashMap(); public boolean running; public boolean finished; diff --git a/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java b/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java index b53f8aea9..6ad8626c3 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadRunnable.java @@ -92,7 +92,7 @@ public class DownloadRunnable implements Runnable { // A server may be ignoring the range request if (conn.getResponseCode() != 206) { mMission.errCode = DownloadMission.ERROR_SERVER_UNSUPPORTED; - notifyError(DownloadMission.ERROR_SERVER_UNSUPPORTED); + notifyError(); if (DEBUG) { Log.e(TAG, mId + ":Unsupported " + conn.getResponseCode()); @@ -161,9 +161,9 @@ public class DownloadRunnable implements Runnable { } } - private void notifyError(final int err) { + private void notifyError() { synchronized (mMission) { - mMission.notifyError(err); + mMission.notifyError(DownloadMission.ERROR_SERVER_UNSUPPORTED); mMission.pause(); } } diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java index 59f5e2225..ff410a79a 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -56,7 +56,7 @@ public class DownloadManagerService extends Service { private DownloadDataSource mDataSource; - private MissionListener missionListener = new MissionListener(); + private final MissionListener missionListener = new MissionListener(); private void notifyMediaScanner(DownloadMission mission) { diff --git a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java index 8127c3467..d5555c2be 100644 --- a/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java +++ b/app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java @@ -306,12 +306,12 @@ public class MissionAdapter extends RecyclerView.Adapter { ProgressDialog prog; - WeakReference weakReference; + final WeakReference weakReference; ChecksumTask(@NonNull Activity activity) { weakReference = new WeakReference<>(activity); diff --git a/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java b/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java index 6a0e35cff..955ce4c65 100644 --- a/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java +++ b/app/src/main/java/us/shandian/giga/ui/common/ProgressDrawable.java @@ -12,7 +12,8 @@ import android.support.v4.content.ContextCompat; public class ProgressDrawable extends Drawable { private float mProgress; - private int mBackgroundColor, mForegroundColor; + private final int mBackgroundColor; + private final int mForegroundColor; public ProgressDrawable(Context context, @ColorRes int background, @ColorRes int foreground) { this(ContextCompat.getColor(context, background), ContextCompat.getColor(context, foreground)); diff --git a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java index 14439f6c8..7b42f90c9 100644 --- a/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java +++ b/app/src/main/java/us/shandian/giga/ui/fragment/MissionsFragment.java @@ -44,7 +44,7 @@ public abstract class MissionsFragment extends Fragment { private DeleteDownloadManager mDeleteDownloadManager; private Disposable mDeleteDisposable; - private ServiceConnection mConnection = new ServiceConnection() { + private final ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder binder) {