diff --git a/app/build.gradle b/app/build.gradle index 345f45f665a..80171be62d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -84,7 +84,7 @@ ext { checkstyleVersion = '8.32' stethoVersion = '1.5.1' leakCanaryVersion = '2.2' - exoPlayerVersion = '2.11.6' + exoPlayerVersion = '2.11.8' androidxLifecycleVersion = '2.2.0' androidxRoomVersion = '2.2.5' groupieVersion = '2.8.0' @@ -139,7 +139,7 @@ afterEvaluate { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "frankiesardo:icepick:${icepickVersion}" kapt "frankiesardo:icepick-processor:${icepickVersion}" @@ -169,7 +169,7 @@ dependencies { implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" implementation "org.jsoup:jsoup:1.13.1" - implementation "com.squareup.okhttp3:okhttp:3.12.11" + implementation "com.squareup.okhttp3:okhttp:3.12.12" implementation "com.google.android.exoplayer:exoplayer:${exoPlayerVersion}" implementation "com.google.android.exoplayer:extension-mediasession:${exoPlayerVersion}" @@ -187,7 +187,6 @@ dependencies { implementation "androidx.lifecycle:lifecycle-livedata:${androidxLifecycleVersion}" implementation "androidx.lifecycle:lifecycle-viewmodel:${androidxLifecycleVersion}" - implementation "androidx.lifecycle:lifecycle-extensions:${androidxLifecycleVersion}" implementation "androidx.room:room-runtime:${androidxRoomVersion}" implementation "androidx.room:room-rxjava2:${androidxRoomVersion}" 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 972737d2500..a3aa28059ce 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java @@ -2,9 +2,9 @@ import android.os.Parcel; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; -import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import org.schabi.newpipe.R; diff --git a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java index 5840b0f7ecf..471360c604a 100644 --- a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java +++ b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java @@ -300,8 +300,8 @@ public void restoreState(@Nullable final Parcelable state, @Nullable final Class mSavedState.clear(); mFragments.clear(); if (fss != null) { - for (int i = 0; i < fss.length; i++) { - mSavedState.add((Fragment.SavedState) fss[i]); + for (final Parcelable parcelable : fss) { + mSavedState.add((Fragment.SavedState) parcelable); } } final Iterable keys = bundle.keySet(); diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 00842ec4615..962679cd0b8 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -220,7 +220,7 @@ protected void initACRA() { } public void initNotificationChannel() { - if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java index 0d211fdfd20..d9123076560 100644 --- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java +++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersionTask.java @@ -11,7 +11,7 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.os.AsyncTask; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import androidx.core.app.NotificationCompat; diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java index 9cba0667bbf..69bfdfc2ad8 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java +++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java @@ -2,7 +2,7 @@ import android.content.Context; import android.os.Build; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -114,8 +114,8 @@ private static void enableModernTLS(final OkHttpClient.Builder builder) { // Necessary because some servers (e.g. Framatube.org) // don't support the old cipher suites. // https://github.com/square/okhttp/issues/4053#issuecomment-402579554 - final List cipherSuites = new ArrayList<>(); - cipherSuites.addAll(ConnectionSpec.MODERN_TLS.cipherSuites()); + final List cipherSuites = + new ArrayList<>(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); final ConnectionSpec legacyTLS = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) diff --git a/app/src/main/java/org/schabi/newpipe/ExitActivity.java b/app/src/main/java/org/schabi/newpipe/ExitActivity.java index d4a4e3125e6..d457500aaf5 100644 --- a/app/src/main/java/org/schabi/newpipe/ExitActivity.java +++ b/app/src/main/java/org/schabi/newpipe/ExitActivity.java @@ -42,7 +42,7 @@ public static void exitAndRemoveFromRecentApps(final Activity activity) { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { finishAndRemoveTask(); } else { finish(); diff --git a/app/src/main/java/org/schabi/newpipe/ImageDownloader.java b/app/src/main/java/org/schabi/newpipe/ImageDownloader.java index ca61c965587..c2897cff19d 100644 --- a/app/src/main/java/org/schabi/newpipe/ImageDownloader.java +++ b/app/src/main/java/org/schabi/newpipe/ImageDownloader.java @@ -4,7 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import com.nostra13.universalimageloader.core.download.BaseImageDownloader; diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index c3086d02c18..aedf64231ef 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -27,7 +27,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.KeyEvent; diff --git a/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java index 75304a2b904..b4fbdfb2863 100644 --- a/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java @@ -40,7 +40,7 @@ protected void onCreate(final Bundle savedInstanceState) { ExitActivity.exitAndRemoveFromRecentApps(this); } - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { finishAndRemoveTask(); } else { finish(); diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index 70fceaf0753..27fa94bef33 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -8,7 +8,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.text.TextUtils; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; @@ -492,12 +492,8 @@ private void openDownloadDialog() { downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex); downloadDialog.show(fm, "downloadDialog"); fm.executePendingTransactions(); - downloadDialog.getDialog().setOnDismissListener(dialog -> { - finish(); - }); - }, (@NonNull Throwable throwable) -> { - onError(); - }); + downloadDialog.getDialog().setOnDismissListener(dialog -> finish()); + }, (@NonNull Throwable throwable) -> onError()); } @Override @@ -572,7 +568,7 @@ protected String[] getUris(final String sharedText) { } } } - return result.toArray(new String[result.size()]); + return result.toArray(new String[0]); } private static class AdapterChoiceItem { 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 3041c3d6cb1..81ba78ba997 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -167,7 +167,7 @@ public View onCreateView(final LayoutInflater inflater, final ViewGroup containe */ public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(final FragmentManager fm) { - super(fm); + super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); } @Override 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 bcb9ece10e2..dd526ecc8b8 100644 --- a/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java +++ b/app/src/main/java/org/schabi/newpipe/database/BasicDAO.java @@ -14,13 +14,13 @@ @Dao public interface BasicDAO { /* Inserts */ - @Insert(onConflict = OnConflictStrategy.FAIL) + @Insert(onConflict = OnConflictStrategy.ABORT) long insert(Entity entity); - @Insert(onConflict = OnConflictStrategy.FAIL) + @Insert(onConflict = OnConflictStrategy.ABORT) List insertAll(Entity... entities); - @Insert(onConflict = OnConflictStrategy.FAIL) + @Insert(onConflict = OnConflictStrategy.ABORT) List insertAll(Collection entities); /* Searches */ diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index bc160d87396..979f8be7533 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -1,6 +1,5 @@ package org.schabi.newpipe.download; -import android.app.FragmentTransaction; import android.content.Intent; import android.os.Bundle; import android.view.Menu; @@ -11,6 +10,7 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.FragmentTransaction; import org.schabi.newpipe.R; import org.schabi.newpipe.util.DeviceUtils; 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 ab44e0fc1a3..17d079d50ea 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -10,7 +10,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.IBinder; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; @@ -295,7 +295,7 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved initToolbar(view.findViewById(R.id.toolbar)); setupDownloadOptions(); - prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()); final int threads = prefs.getInt(getString(R.string.default_download_threads), 3); threadsCountTextView.setText(String.valueOf(threads)); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 472dc340901..d138a298cda 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -3,7 +3,7 @@ import android.content.Context; import android.content.res.ColorStateList; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -74,7 +74,7 @@ public void onCreate(final Bundle savedInstanceState) { youtubeRestrictedModeEnabledKey = getString(R.string.youtube_restricted_mode_enabled); previousYoutubeRestrictedModeEnabled = - PreferenceManager.getDefaultSharedPreferences(getContext()) + PreferenceManager.getDefaultSharedPreferences(requireContext()) .getBoolean(youtubeRestrictedModeEnabledKey, false); } @@ -105,7 +105,7 @@ public void onResume() { super.onResume(); final boolean youtubeRestrictedModeEnabled = - PreferenceManager.getDefaultSharedPreferences(getContext()) + PreferenceManager.getDefaultSharedPreferences(requireContext()) .getBoolean(youtubeRestrictedModeEnabledKey, false); if (previousYoutubeRestrictedModeEnabled != youtubeRestrictedModeEnabled) { previousYoutubeRestrictedModeEnabled = youtubeRestrictedModeEnabled; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java similarity index 76% rename from app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java rename to app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java index 74609777c6b..1a11836d48b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java @@ -2,6 +2,7 @@ import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -10,16 +11,20 @@ import java.util.ArrayList; import java.util.List; -public class TabAdaptor extends FragmentPagerAdapter { +public class TabAdapter extends FragmentPagerAdapter { private final List mFragmentList = new ArrayList<>(); private final List mFragmentTitleList = new ArrayList<>(); private final FragmentManager fragmentManager; - public TabAdaptor(final FragmentManager fm) { - super(fm); + public TabAdapter(final FragmentManager fm) { + // if changed to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT => crash if enqueueing stream in + // the background and then clicking on it to open VideoDetailFragment: + // "Cannot setMaxLifecycle for Fragment not attached to FragmentManager" + super(fm, BEHAVIOR_SET_USER_VISIBLE_HINT); this.fragmentManager = fm; } + @NonNull @Override public Fragment getItem(final int position) { return mFragmentList.get(position); @@ -57,7 +62,7 @@ public void updateItem(final String title, final Fragment fragment) { } @Override - public int getItemPosition(final Object object) { + public int getItemPosition(@NonNull final Object object) { if (mFragmentList.contains(object)) { return mFragmentList.indexOf(object); } else { @@ -82,7 +87,9 @@ public void notifyDataSetUpdate() { } @Override - public void destroyItem(final ViewGroup container, final int position, final Object object) { + public void destroyItem(@NonNull final ViewGroup container, + final int position, + @NonNull final Object object) { fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss(); } 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 b92becbd104..42a5cbf02a0 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 @@ -16,9 +16,9 @@ import android.os.Bundle; import android.os.Handler; import android.os.IBinder; -import android.preference.PreferenceManager; +import androidx.core.text.HtmlCompat; +import androidx.preference.PreferenceManager; import android.provider.Settings; -import android.text.Html; import android.text.Spanned; import android.text.TextUtils; import android.text.util.Linkify; @@ -244,7 +244,7 @@ public class VideoDetailFragment private AppBarLayout appBarLayout; private ViewPager viewPager; - private TabAdaptor pageAdapter; + private TabAdapter pageAdapter; private TabLayout tabLayout; private FrameLayout relatedStreamsLayout; @@ -427,7 +427,7 @@ public void onPause() { currentWorker.dispose(); } saveCurrentAndRestoreDefaultBrightness(); - PreferenceManager.getDefaultSharedPreferences(getContext()) + PreferenceManager.getDefaultSharedPreferences(requireContext()) .edit() .putString(getString(R.string.stream_info_selected_tab_key), pageAdapter.getItemTitle(viewPager.getCurrentItem())) @@ -553,7 +553,6 @@ protected void onRestoreInstanceState(@NonNull final Bundle savedState) { Serializable serializable = savedState.getSerializable(INFO_KEY); if (serializable instanceof StreamInfo) { - //noinspection unchecked currentInfo = (StreamInfo) serializable; InfoCache.getInstance().putInfo(serviceId, url, currentInfo, InfoItem.InfoType.STREAM); } @@ -673,7 +672,8 @@ public boolean onLongClick(final View v) { } break; case R.id.detail_title_root_layout: - ShareUtils.copyToClipboard(getContext(), videoTitleTextView.getText().toString()); + ShareUtils.copyToClipboard(requireContext(), + videoTitleTextView.getText().toString()); break; } @@ -752,7 +752,7 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) { appBarLayout = rootView.findViewById(R.id.appbarlayout); viewPager = rootView.findViewById(R.id.viewpager); - pageAdapter = new TabAdaptor(getChildFragmentManager()); + pageAdapter = new TabAdapter(getChildFragmentManager()); viewPager.setAdapter(pageAdapter); tabLayout = rootView.findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); @@ -1106,7 +1106,7 @@ private void openBackgroundPlayer(final boolean append) { player.toggleFullscreen(); } - if (!useExternalAudioPlayer && android.os.Build.VERSION.SDK_INT >= 16) { + if (!useExternalAudioPlayer) { openNormalBackgroundPlayer(append); } else { startOnExternalPlayer(activity, currentInfo, audioStream); @@ -1303,24 +1303,17 @@ private void prepareDescription(final Description description) { if (description.getType() == Description.HTML) { disposables.add(Single.just(description.getContent()) - .map((@NonNull String descriptionText) -> { - final Spanned parsedDescription; - if (Build.VERSION.SDK_INT >= 24) { - parsedDescription = Html.fromHtml(descriptionText, 0); - } else { - //noinspection deprecation - parsedDescription = Html.fromHtml(descriptionText); - } - return parsedDescription; - }) + .map((@NonNull final String descriptionText) -> + HtmlCompat.fromHtml(descriptionText, + HtmlCompat.FROM_HTML_MODE_LEGACY)) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe((@NonNull Spanned spanned) -> { + .subscribe((@NonNull final Spanned spanned) -> { videoDescriptionView.setText(spanned); videoDescriptionView.setVisibility(View.VISIBLE); })); } else if (description.getType() == Description.MARKDOWN) { - final Markwon markwon = Markwon.builder(getContext()) + final Markwon markwon = Markwon.builder(requireContext()) .usePlugin(LinkifyPlugin.create()) .build(); markwon.setMarkdown(videoDescriptionView, description.getContent()); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 152221c4c55..37598eb1aec 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -6,7 +6,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java index 86b093e453b..f21eb529184 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListInfoFragment.java @@ -133,7 +133,7 @@ public void startLoading(final boolean forceLoad) { currentInfo = result; currentNextPage = result.getNextPage(); handleResult(result); - }, (@NonNull Throwable throwable) -> onError(throwable)); + }, this::onError); } /** diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index ff02dd790b8..fc61a4518bd 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -26,8 +26,6 @@ public class CommentsFragment extends BaseListInfoFragment { private CompositeDisposable disposables = new CompositeDisposable(); - private boolean mIsVisibleToUser = false; - public static CommentsFragment getInstance(final int serviceId, final String url, final String name) { final CommentsFragment instance = new CommentsFragment(); @@ -39,12 +37,6 @@ public static CommentsFragment getInstance(final int serviceId, final String ur // LifeCycle //////////////////////////////////////////////////////////////////////////*/ - @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - mIsVisibleToUser = isVisibleToUser; - } - @Override public void onAttach(final Context context) { super.onAttach(context); @@ -92,7 +84,7 @@ public void showLoading() { public void handleResult(@NonNull final CommentsInfo result) { super.handleResult(result); - AnimationUtils.slideUp(getView(), 120, 150, 0.06f); + AnimationUtils.slideUp(requireView(), 120, 150, 0.06f); if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_COMMENTS, 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 44cdb816484..7ce4c6c84ff 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 @@ -5,7 +5,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.core.text.HtmlCompat; +import androidx.preference.PreferenceManager; import android.text.Editable; import android.text.Html; import android.text.TextUtils; @@ -73,7 +74,6 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import static android.text.Html.escapeHtml; import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags; import static java.util.Arrays.asList; import static org.schabi.newpipe.util.AnimationUtils.animateView; @@ -1005,10 +1005,9 @@ private void handleSearchSuggestion() { : R.string.did_you_mean); final String highlightedSearchSuggestion = - "" + escapeHtml(searchSuggestion) + ""; - correctSuggestion.setText( - Html.fromHtml(String.format(helperText, highlightedSearchSuggestion))); - + "" + Html.escapeHtml(searchSuggestion) + ""; + final String text = String.format(helperText, highlightedSearchSuggestion); + correctSuggestion.setText(HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)); correctSuggestion.setOnClickListener(v -> { correctSuggestion.setVisibility(View.GONE); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java index 0aef68d901c..da7e8df8b13 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedVideosFragment.java @@ -3,7 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -78,11 +78,11 @@ protected View getListHeader() { autoplaySwitch = headerRootLayout.findViewById(R.id.autoplay_switch); final SharedPreferences pref = PreferenceManager - .getDefaultSharedPreferences(getContext()); + .getDefaultSharedPreferences(requireContext()); final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false); autoplaySwitch.setChecked(autoplay); autoplaySwitch.setOnCheckedChangeListener((compoundButton, b) -> - PreferenceManager.getDefaultSharedPreferences(getContext()).edit() + PreferenceManager.getDefaultSharedPreferences(requireContext()).edit() .putBoolean(getString(R.string.auto_queue_key), b).apply()); return headerRootLayout; } else { @@ -166,12 +166,10 @@ protected boolean onError(final Throwable exception) { @Override public void setTitle(final String title) { - return; } @Override public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { - return; } private void setInitialData(final StreamInfo info) { @@ -201,7 +199,8 @@ protected void onRestoreInstanceState(@NonNull final Bundle savedState) { @Override public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String s) { - final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext()); + final SharedPreferences pref = + PreferenceManager.getDefaultSharedPreferences(requireContext()); final boolean autoplay = pref.getBoolean(getString(R.string.auto_queue_key), false); if (autoplaySwitch != null) { autoplaySwitch.setChecked(autoplay); diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java index 5fa0904de3e..86fad349945 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/StreamInfoItemHolder.java @@ -1,6 +1,6 @@ package org.schabi.newpipe.info_list.holder; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.text.TextUtils; import android.view.ViewGroup; import android.widget.TextView; diff --git a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java index 650953bea46..8e88ceaed4e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java @@ -4,7 +4,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index b27b1c1d1e6..d7555a79d7a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -271,9 +271,8 @@ private void showLocalDialog(final PlaylistMetadataEntry selectedItem) { final Builder builder = new AlertDialog.Builder(activity); builder.setView(dialogView) - .setPositiveButton(R.string.rename_playlist, (dialog, which) -> { - changeLocalPlaylistName(selectedItem.uid, editText.getText().toString()); - }) + .setPositiveButton(R.string.rename_playlist, (dialog, which) -> + changeLocalPlaylistName(selectedItem.uid, editText.getText().toString())) .setNegativeButton(R.string.cancel, null) .setNeutralButton(R.string.delete, (dialog, which) -> { showDeleteDialog(selectedItem.name, diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 8018e2cd819..915bc3ec063 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -30,7 +30,7 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AlertDialog import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProvider import androidx.preference.PreferenceManager import icepick.State import java.util.Calendar @@ -82,7 +82,7 @@ class FeedFragment : BaseListFragment() { override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) { super.onViewCreated(rootView, savedInstanceState) - viewModel = ViewModelProviders.of(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java) + viewModel = ViewModelProvider(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(::handleResult) }) } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt index 65860096c39..0181f2711ad 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt @@ -27,10 +27,10 @@ import android.content.Intent import android.content.IntentFilter import android.os.Build import android.os.IBinder -import android.preference.PreferenceManager import android.util.Log import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.preference.PreferenceManager import io.reactivex.Flowable import io.reactivex.Notification import io.reactivex.Single diff --git a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java index 1a70b6b73e1..01d909c3c17 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/HistoryRecordManager.java @@ -20,7 +20,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import androidx.annotation.NonNull; diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 4c0521e4445..3b66fd73f14 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -553,9 +553,8 @@ private void createRenameDialog() { .setView(dialogView) .setCancelable(true) .setNegativeButton(R.string.cancel, null) - .setPositiveButton(R.string.rename, (dialogInterface, i) -> { - changePlaylistName(nameEdit.getText().toString()); - }); + .setPositiveButton(R.string.rename, (dialogInterface, i) -> + changePlaylistName(nameEdit.getText().toString())); dialogBuilder.show(); } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 7fea3b5d848..b0d0fe801b9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -11,15 +11,15 @@ import android.content.res.Configuration import android.os.Bundle import android.os.Environment import android.os.Parcelable -import android.preference.PreferenceManager import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProvider import androidx.localbroadcastmanager.content.LocalBroadcastManager +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import com.nononsenseapps.filepicker.Utils import com.xwray.groupie.Group @@ -277,7 +277,7 @@ class SubscriptionFragment : BaseStateFragment() { } items_list.adapter = groupAdapter - viewModel = ViewModelProviders.of(this).get(SubscriptionViewModel::class.java) + viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner, androidx.lifecycle.Observer { it?.let(this::handleResult) }) viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, androidx.lifecycle.Observer { it?.let(this::handleFeedGroups) }) } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index 80036cd4a5c..5e9b6b6a49d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -252,7 +252,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable { } }) - subscriptionGroupAdapter?.setOnItemClickListener(subscriptionPickerItemListener) + subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener) } private fun handlePositiveButton() = when { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt index 92c063b4bf7..48f40e21934 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt @@ -6,7 +6,7 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback import androidx.recyclerview.widget.LinearLayoutManager @@ -49,7 +49,7 @@ class FeedGroupReorderDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - viewModel = ViewModelProviders.of(this).get(FeedGroupReorderDialogViewModel::class.java) + viewModel = ViewModelProvider(this).get(FeedGroupReorderDialogViewModel::class.java) viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups)) viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer { when (it) { diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java index 5e0f9ab94a4..813a1cdf46a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java @@ -27,7 +27,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.AudioManager; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.Toast; diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java index 8709174dc6a..273f37cc810 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -30,7 +30,7 @@ import android.os.Binder; import android.os.Build; import android.os.IBinder; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.DisplayMetrics; import android.view.ViewGroup; import android.view.WindowManager; @@ -310,9 +310,7 @@ private NotificationCompat.Builder createNotification() { setLockScreenThumbnail(builder); } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { - builder.setPriority(NotificationCompat.PRIORITY_MAX); - } + builder.setPriority(NotificationCompat.PRIORITY_MAX); return builder; } 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 2416403897b..a5a53f7a9e6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayer.java @@ -30,9 +30,10 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.os.Build; import android.os.Handler; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.Menu; @@ -210,18 +211,18 @@ public void initViews(final View view) { this.captionTextView = view.findViewById(R.id.captionTextView); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); - } - this.playbackSeekBar.getProgressDrawable(). - setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY); + playbackSeekBar.getThumb() + .setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); + this.playbackSeekBar.getProgressDrawable() + .setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY)); this.qualityPopupMenu = new PopupMenu(context, qualityTextView); this.playbackSpeedPopupMenu = new PopupMenu(context, playbackSpeedTextView); this.captionPopupMenu = new PopupMenu(context, captionTextView); ((ProgressBar) this.loadingPanel.findViewById(R.id.progressBarLoadingPanel)) - .getIndeterminateDrawable().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY); + .getIndeterminateDrawable() + .setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY)); } protected abstract void setupSubtitleView(@NonNull SubtitleView view, float captionScale, @@ -249,7 +250,7 @@ public void initPlayer(final boolean playOnReady) { simpleExoPlayer.addTextOutput(cues -> subtitleView.onCues(cues)); // Setup audio session with onboard equalizer - if (Build.VERSION.SDK_INT >= 21) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { trackSelector.setParameters(trackSelector.buildUponParameters() .setTunnelingAudioSessionId(C.generateAudioSessionIdV21(context))); } @@ -456,11 +457,8 @@ public void onBlocked() { animateView(controlsRoot, false, DEFAULT_CONTROLS_DURATION); playbackSeekBar.setEnabled(false); - // Bug on lower api, disabling and enabling the seekBar resets the thumb color -.-, - // so sets the color again - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); - } + playbackSeekBar.getThumb() + .setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); loadingPanel.setBackgroundColor(Color.BLACK); animateView(loadingPanel, true, 0); @@ -476,11 +474,8 @@ public void onPlaying() { showAndAnimateControl(-1, true); playbackSeekBar.setEnabled(true); - // Bug on lower api, disabling and enabling the seekBar resets the thumb color -.-, - // so sets the color again - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN); - } + playbackSeekBar.getThumb() + .setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN)); loadingPanel.setVisibility(View.GONE); diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 0e06c1aaf4e..05680baebe3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -32,7 +32,7 @@ import android.net.Uri; import android.os.Build; import android.os.Handler; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.provider.Settings; import android.util.DisplayMetrics; import android.util.Log; @@ -1925,7 +1925,7 @@ private void updateWindowFlags(final int flags) { } private int popupLayoutParamType() { - return Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O + return Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java index 2b6560534c9..8b2c0e92515 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlaybackParameterDialog.java @@ -3,7 +3,7 @@ import android.app.Dialog; import android.content.Context; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.view.View; import android.widget.CheckBox; @@ -239,12 +239,13 @@ private void setupHookingControl(@NonNull final View rootView) { unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox); if (unhookingCheckbox != null) { // restore whether pitch and tempo are unhooked or not - unhookingCheckbox.setChecked(PreferenceManager.getDefaultSharedPreferences(getContext()) + unhookingCheckbox.setChecked(PreferenceManager + .getDefaultSharedPreferences(requireContext()) .getBoolean(getString(R.string.playback_unhook_key), true)); unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> { // save whether pitch and tempo are unhooked or not - PreferenceManager.getDefaultSharedPreferences(getContext()) + PreferenceManager.getDefaultSharedPreferences(requireContext()) .edit() .putBoolean(getString(R.string.playback_unhook_key), isChecked) .apply(); 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 09072340b1e..6667d0ecb31 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 @@ -2,8 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.os.Build; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.provider.Settings; import android.view.accessibility.CaptioningManager; @@ -303,10 +302,6 @@ public static int getTossFlingVelocity(@NonNull final Context context) { @NonNull public static CaptionStyleCompat getCaptionStyle(@NonNull final Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - return CaptionStyleCompat.DEFAULT; - } - final CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); if (captioningManager == null || !captioningManager.isEnabled()) { @@ -331,10 +326,6 @@ public static CaptionStyleCompat getCaptionStyle(@NonNull final Context context) * @return caption scaling */ public static float getCaptionScale(@NonNull final Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - return 1f; - } - final CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); if (captioningManager == null || !captioningManager.isEnabled()) { diff --git a/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java b/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java index 814fda4ba98..a2b3a1d3de9 100644 --- a/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java +++ b/app/src/main/java/org/schabi/newpipe/player/resolver/VideoPlaybackResolver.java @@ -115,7 +115,7 @@ public MediaSource resolve(@NonNull final StreamInfo info) { return mediaSources.get(0); } else { return new MergingMediaSource(mediaSources.toArray( - new MediaSource[mediaSources.size()])); + new MediaSource[0])); } } diff --git a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java index 7ff3af91a32..b83f9fd97f8 100644 --- a/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/report/ErrorActivity.java @@ -216,18 +216,16 @@ protected void onCreate(final Bundle savedInstanceState) { addGuruMeditation(); currentTimeStamp = getCurrentTimeStamp(); - reportEmailButton.setOnClickListener((View v) -> { - openPrivacyPolicyDialog(this, "EMAIL"); - }); + reportEmailButton.setOnClickListener((View v) -> + openPrivacyPolicyDialog(this, "EMAIL")); copyButton.setOnClickListener((View v) -> { ShareUtils.copyToClipboard(this, buildMarkdown()); Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show(); }); - reportGithubButton.setOnClickListener((View v) -> { - openPrivacyPolicyDialog(this, "GITHUB"); - }); + reportGithubButton.setOnClickListener((View v) -> + openPrivacyPolicyDialog(this, "GITHUB")); // normal bugreport @@ -278,10 +276,9 @@ private void openPrivacyPolicyDialog(final Context context, final String action) .setTitle(R.string.privacy_policy_title) .setMessage(R.string.start_accept_privacy_policy) .setCancelable(false) - .setNeutralButton(R.string.read_privacy_policy, (dialog, which) -> { - ShareUtils.openUrlInBrowser(context, - context.getString(R.string.privacy_policy_url)); - }) + .setNeutralButton(R.string.read_privacy_policy, (dialog, which) -> + ShareUtils.openUrlInBrowser(context, + context.getString(R.string.privacy_policy_url))) .setPositiveButton(R.string.accept, (dialog, which) -> { if (action.equals("EMAIL")) { // send on email final Intent i = new Intent(Intent.ACTION_SENDTO) @@ -469,7 +466,8 @@ private String getAppLanguage() { } private String getOsString() { - final String osBase = Build.VERSION.SDK_INT >= 23 ? Build.VERSION.BASE_OS : "Android"; + final String osBase = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + ? Build.VERSION.BASE_OS : "Android"; return System.getProperty("os.name") + " " + (osBase.isEmpty() ? "Android" : osBase) + " " + Build.VERSION.RELEASE 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 d8b68629791..c49be8c565d 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/BasePreferenceFragment.java @@ -2,7 +2,7 @@ import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.view.View; import androidx.annotation.Nullable; @@ -20,7 +20,7 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat { @Override public void onCreate(@Nullable final Bundle savedInstanceState) { - defaultPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + defaultPreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); super.onCreate(savedInstanceState); } 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 6ea2cc8a6c7..df30a21f3ba 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -7,7 +7,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.widget.Toast; @@ -74,7 +74,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) { initialSelectedContentCountry = org.schabi.newpipe.util.Localization .getPreferredContentCountry(requireContext()); initialLanguage = PreferenceManager - .getDefaultSharedPreferences(getContext()).getString("app_language_key", "en"); + .getDefaultSharedPreferences(requireContext()).getString("app_language_key", "en"); } @Override @@ -148,7 +148,7 @@ public void onDestroy() { final ContentCountry selectedContentCountry = org.schabi.newpipe.util.Localization .getPreferredContentCountry(requireContext()); final String selectedLanguage = PreferenceManager - .getDefaultSharedPreferences(getContext()).getString("app_language_key", "en"); + .getDefaultSharedPreferences(requireContext()).getString("app_language_key", "en"); if (!selectedLocalization.equals(initialSelectedLocalization) || !selectedContentCountry.equals(initialSelectedContentCountry) @@ -217,7 +217,7 @@ private void saveSharedPreferencesToFile(final File dst) { try { output = new ObjectOutputStream(new FileOutputStream(dst)); final SharedPreferences pref - = PreferenceManager.getDefaultSharedPreferences(getContext()); + = PreferenceManager.getDefaultSharedPreferences(requireContext()); output.writeObject(pref.getAll()); } catch (final IOException e) { @@ -299,7 +299,7 @@ private void loadSharedPreferences(final File src) { try { input = new ObjectInputStream(new FileInputStream(src)); final SharedPreferences.Editor prefEdit = PreferenceManager - .getDefaultSharedPreferences(getContext()).edit(); + .getDefaultSharedPreferences(requireContext()).edit(); prefEdit.clear(); final Map entries = (Map) input.readObject(); for (final Map.Entry entry : entries.entrySet()) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java index dfa975eefaa..61cee7b20db 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/PeertubeInstanceListFragment.java @@ -4,7 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.text.InputType; import android.view.LayoutInflater; import android.view.Menu; @@ -213,9 +213,8 @@ private void restoreDefaults() { private void initButton(final View rootView) { final FloatingActionButton fab = rootView.findViewById(R.id.addInstanceButton); - fab.setOnClickListener(v -> { - showAddItemDialog(requireContext()); - }); + fab.setOnClickListener(v -> + showAddItemDialog(requireContext())); } private void showAddItemDialog(final Context c) { 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 1bc65da7038..96e2781f5b1 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectChannelFragment.java @@ -208,12 +208,7 @@ public SelectChannelItemHolder onCreateViewHolder(final ViewGroup parent, public void onBindViewHolder(final SelectChannelItemHolder holder, final int position) { final SubscriptionEntity entry = subscriptions.get(position); holder.titleView.setText(entry.getName()); - holder.view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - clickedItem(position); - } - }); + holder.view.setOnClickListener(view -> clickedItem(position)); imageLoader.displayImage(entry.getAvatarUrl(), holder.thumbnailView, DISPLAY_IMAGE_OPTIONS); } diff --git a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java index ce6d6dad5b8..5eca99822f6 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/VideoAudioSettingsFragment.java @@ -87,7 +87,7 @@ private void updateSeekOptions() { } } - final ListPreference durations = (ListPreference) findPreference( + final ListPreference durations = findPreference( getString(R.string.seek_duration_key)); durations.setEntryValues(displayedDurationValues.toArray(new CharSequence[0])); durations.setEntries(displayedDescriptionValues.toArray(new CharSequence[0])); diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsManager.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsManager.java index 316e3a8357b..02b0c3df5c3 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsManager.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/TabsManager.java @@ -2,7 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.widget.Toast; import org.schabi.newpipe.R; diff --git a/app/src/main/java/org/schabi/newpipe/streams/DataReader.java b/app/src/main/java/org/schabi/newpipe/streams/DataReader.java index b9d1026f08b..dc6e29d7ddf 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/DataReader.java +++ b/app/src/main/java/org/schabi/newpipe/streams/DataReader.java @@ -236,7 +236,7 @@ private void primitiveRead(final int amount) throws IOException { if (read != amount) { throw new EOFException("Truncated stream, missing " - + String.valueOf(amount - read) + " bytes"); + + (amount - read) + " bytes"); } for (int i = 0; i < amount; i++) { diff --git a/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java b/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java index 60390946b75..e1eb0e9e5ce 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java +++ b/app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java @@ -5,8 +5,8 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.NoSuchElementException; @@ -259,11 +259,7 @@ private String boxName(final Box ref) { } private String boxName(final int type) { - try { - return new String(ByteBuffer.allocate(4).putInt(type).array(), "UTF-8"); - } catch (final UnsupportedEncodingException e) { - return "0x" + Integer.toHexString(type); - } + return new String(ByteBuffer.allocate(4).putInt(type).array(), StandardCharsets.UTF_8); } private Box readBox() throws IOException { diff --git a/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java b/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java index 6e2ba8360bd..193f89996be 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java +++ b/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java @@ -293,7 +293,7 @@ private Segment readSegment(final Element ref, final int trackLacingExpected, if (metadataExpected && (obj.info == null || obj.tracks == null)) { throw new RuntimeException( "Cluster element found without Info and/or Tracks element at position " - + String.valueOf(ref.offset)); + + ref.offset); } return obj; @@ -389,7 +389,7 @@ private Cluster readCluster(final Element ref) throws IOException { final Element elem = untilElement(ref, ID_TIMECODE); if (elem == null) { - throw new NoSuchElementException("Cluster at " + String.valueOf(ref.offset) + throw new NoSuchElementException("Cluster at " + ref.offset + " without Timecode element"); } obj.timecode = readNumber(elem); @@ -520,7 +520,7 @@ public SimpleBlock getNextSimpleBlock() throws IOException { currentSimpleBlock = readSimpleBlock(elem); if (currentSimpleBlock.trackNumber == tracks[selectedTrack].trackNumber) { - currentSimpleBlock.data = stream.getView((int) currentSimpleBlock.dataSize); + currentSimpleBlock.data = stream.getView(currentSimpleBlock.dataSize); // calculate the timestamp in nanoseconds currentSimpleBlock.absoluteTimeCodeNs = currentSimpleBlock.relativeTimeCode diff --git a/app/src/main/java/org/schabi/newpipe/util/AnimationUtils.java b/app/src/main/java/org/schabi/newpipe/util/AnimationUtils.java index 9220891a98a..152521018e0 100644 --- a/app/src/main/java/org/schabi/newpipe/util/AnimationUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/AnimationUtils.java @@ -162,13 +162,9 @@ public static void animateBackgroundColor(final View view, final long duration, .ofObject(new ArgbEvaluator(), colorStart, colorEnd); viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator()); viewPropertyAnimator.setDuration(duration); - viewPropertyAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(final ValueAnimator animation) { + viewPropertyAnimator.addUpdateListener(animation -> ViewCompat.setBackgroundTintList(view, - new ColorStateList(empty, new int[]{(int) animation.getAnimatedValue()})); - } - }); + new ColorStateList(empty, new int[]{(int) animation.getAnimatedValue()}))); viewPropertyAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { @@ -205,12 +201,8 @@ public static void animateTextColor(final TextView view, final long duration, .ofObject(new ArgbEvaluator(), colorStart, colorEnd); viewPropertyAnimator.setInterpolator(new FastOutSlowInInterpolator()); viewPropertyAnimator.setDuration(duration); - viewPropertyAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(final ValueAnimator animation) { - view.setTextColor((int) animation.getAnimatedValue()); - } - }); + viewPropertyAnimator.addUpdateListener(animation -> + view.setTextColor((int) animation.getAnimatedValue())); viewPropertyAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { @@ -430,7 +422,7 @@ private static void animateLightSlideAndAlpha(final View view, final boolean ent final long duration, final long delay, final Runnable execOnEnd) { if (enterOrExit) { - view.setTranslationY(-view.getHeight() / 2); + view.setTranslationY(-view.getHeight() / 2.0f); view.setAlpha(0f); view.animate() .setInterpolator(new FastOutSlowInInterpolator()).alpha(1f).translationY(0) @@ -445,7 +437,7 @@ public void onAnimationEnd(final Animator animation) { }).start(); } else { view.animate().setInterpolator(new FastOutSlowInInterpolator()) - .alpha(0f).translationY(-view.getHeight() / 2) + .alpha(0f).translationY(-view.getHeight() / 2.0f) .setDuration(duration).setStartDelay(delay) .setListener(new AnimatorListenerAdapter() { @Override diff --git a/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java b/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java index dda01b60cee..27e1f304887 100644 --- a/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java +++ b/app/src/main/java/org/schabi/newpipe/util/FilenameUtils.java @@ -2,7 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.R; 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 be0630cace8..7a428a05d1f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ListHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ListHelper.java @@ -3,7 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.net.ConnectivityManager; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import androidx.annotation.Nullable; import androidx.annotation.StringRes; diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 3642216ff95..767cebcea6e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -5,7 +5,7 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.text.TextUtils; import android.util.DisplayMetrics; diff --git a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java index 96dfc1925df..693265fcd6e 100644 --- a/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java @@ -7,7 +7,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.widget.Toast; diff --git a/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.java b/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.java index 5481b519ce7..e2809579885 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PeertubeHelper.java @@ -2,7 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; diff --git a/app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java b/app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java index ba157e6bea8..03400bdbb0b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java @@ -26,10 +26,8 @@ public final class PermissionHelper { private PermissionHelper() { } public static boolean checkStoragePermissions(final Activity activity, final int requestCode) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - if (!checkReadStoragePermissions(activity, requestCode)) { - return false; - } + if (!checkReadStoragePermissions(activity, requestCode)) { + return false; } return checkWriteStoragePermissions(activity, requestCode); } diff --git a/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java b/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java index 2526956c55a..81e203b1f3b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java +++ b/app/src/main/java/org/schabi/newpipe/util/RelatedStreamInfo.java @@ -20,8 +20,7 @@ public static RelatedStreamInfo getInfo(final StreamInfo info) { info.getOriginalUrl(), info.getUrl(), info.getId(), Collections.emptyList(), null); final RelatedStreamInfo relatedStreamInfo = new RelatedStreamInfo( info.getServiceId(), handler, info.getName()); - final List streams = new ArrayList<>(); - streams.addAll(info.getRelatedStreams()); + final List streams = new ArrayList<>(info.getRelatedStreams()); relatedStreamInfo.setRelatedItems(streams); return relatedStreamInfo; } diff --git a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java index 1ab54343a74..8f3423b2253 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java @@ -2,7 +2,7 @@ import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import androidx.annotation.DrawableRes; import androidx.annotation.StringRes; diff --git a/app/src/main/java/org/schabi/newpipe/util/StateSaver.java b/app/src/main/java/org/schabi/newpipe/util/StateSaver.java index cfe2b32721c..ba095a4c58c 100644 --- a/app/src/main/java/org/schabi/newpipe/util/StateSaver.java +++ b/app/src/main/java/org/schabi/newpipe/util/StateSaver.java @@ -36,7 +36,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FilenameFilter; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -254,12 +253,8 @@ private static SavedState tryToSave(final boolean isChangingConfig, final String return new SavedState(prefixFileName, file.getAbsolutePath()); } else { // Delete any file that contains the prefix - final File[] files = cacheDir.listFiles(new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.contains(prefixFileName); - } - }); + final File[] files = cacheDir.listFiles((dir, name) -> + name.contains(prefixFileName)); for (final File fileToDelete : files) { fileToDelete.delete(); } diff --git a/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java b/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java index a83e844eade..89dc08f38df 100644 --- a/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java +++ b/app/src/main/java/org/schabi/newpipe/util/TLSSocketFactoryCompat.java @@ -106,7 +106,7 @@ public Socket createSocket(final InetAddress address, final int port, } private Socket enableTLSOnSocket(final Socket socket) { - if (socket != null && (socket instanceof SSLSocket)) { + if (socket instanceof SSLSocket) { ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"}); } return socket; diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java index 88e1a31cda1..051fbbcf82d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -21,7 +21,7 @@ import android.content.Context; import android.content.res.TypedArray; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.TypedValue; import android.view.ContextThemeWrapper; diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java index 4a342784e21..dc5bf7133b3 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java @@ -259,7 +259,7 @@ private static void fixFocusHierarchy(final View decor) { // keyboard META key for moving between clusters). We have to fix this unfortunate accident // While we are at it, let's deal with touchscreenBlocksFocus too. - if (Build.VERSION.SDK_INT < 26) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; } diff --git a/app/src/main/java/org/schabi/newpipe/views/LargeTextMovementMethod.java b/app/src/main/java/org/schabi/newpipe/views/LargeTextMovementMethod.java index 36e0eabb05b..1219304e1d0 100644 --- a/app/src/main/java/org/schabi/newpipe/views/LargeTextMovementMethod.java +++ b/app/src/main/java/org/schabi/newpipe/views/LargeTextMovementMethod.java @@ -155,13 +155,13 @@ private boolean gotoPrev(final TextView view, final Spannable buffer) { int bestStart = -1; int bestEnd = -1; - for (int i = 0; i < candidates.length; i++) { - final int start = buffer.getSpanStart(candidates[i]); - final int end = buffer.getSpanEnd(candidates[i]); + for (final ClickableSpan candidate : candidates) { + final int start = buffer.getSpanStart(candidate); + final int end = buffer.getSpanEnd(candidate); if ((end < selEnd || selStart == selEnd) && start >= visibleStart) { if (end > bestEnd) { - bestStart = buffer.getSpanStart(candidates[i]); + bestStart = buffer.getSpanStart(candidate); bestEnd = end; } } @@ -224,14 +224,14 @@ private boolean gotoNext(final TextView view, final Spannable buffer) { int bestStart = Integer.MAX_VALUE; int bestEnd = Integer.MAX_VALUE; - for (int i = 0; i < candidates.length; i++) { - final int start = buffer.getSpanStart(candidates[i]); - final int end = buffer.getSpanEnd(candidates[i]); + for (final ClickableSpan candidate : candidates) { + final int start = buffer.getSpanStart(candidate); + final int end = buffer.getSpanEnd(candidate); if ((start > selStart || selStart == selEnd) && end <= visibleEnd) { if (start < bestStart) { bestStart = start; - bestEnd = buffer.getSpanEnd(candidates[i]); + bestEnd = buffer.getSpanEnd(candidate); } } } diff --git a/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java b/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java index 6350f80a5ae..a4f7a0506f3 100644 --- a/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java +++ b/app/src/main/java/org/schabi/newpipe/views/NewPipeRecyclerView.java @@ -142,7 +142,7 @@ public boolean dispatchUnhandledMove(final View focused, final int direction) { } private boolean tryFocusFinder(final int direction) { - if (Build.VERSION.SDK_INT >= 28) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // Android 9 implemented bunch of handy changes to focus, that render code below less // useful, and also broke findNextFocusFromRect in way, that render this hack useless return false; 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 3f651d2ee1b..d7c586083ba 100644 --- a/app/src/main/java/us/shandian/giga/get/DownloadMission.java +++ b/app/src/main/java/us/shandian/giga/get/DownloadMission.java @@ -633,7 +633,7 @@ public long getLength() { calculated = offsets[current < offsets.length ? current : (offsets.length - 1)] + length; calculated -= offsets[0];// don't count reserved space - return calculated > nearLength ? calculated : nearLength; + return Math.max(calculated, nearLength); } /** diff --git a/app/src/main/java/us/shandian/giga/io/FileStream.java b/app/src/main/java/us/shandian/giga/io/FileStream.java index 2cc4d5db8be..bbc56b20c21 100644 --- a/app/src/main/java/us/shandian/giga/io/FileStream.java +++ b/app/src/main/java/us/shandian/giga/io/FileStream.java @@ -30,12 +30,12 @@ public int read() throws IOException { } @Override - public int read(byte b[]) throws IOException { + public int read(byte[] b) throws IOException { return source.read(b); } @Override - public int read(byte b[], int off, int len) throws IOException { + public int read(byte[] b, int off, int len) throws IOException { return source.read(b, off, len); } diff --git a/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java b/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java index 680f484e629..50dbd1c3d94 100644 --- a/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java +++ b/app/src/main/java/us/shandian/giga/postprocessing/Postprocessing.java @@ -115,7 +115,7 @@ public void run(DownloadMission target) throws IOException { mission.done = 0; long length = mission.storage.length() - mission.offsets[0]; - mission.length = length > mission.nearLength ? length : mission.nearLength; + mission.length = Math.max(length, mission.nearLength); final ProgressReport readProgress = (long position) -> { position -= mission.offsets[0]; 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 3da0e75b85d..828f1adaf91 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -24,7 +24,7 @@ import android.os.IBinder; import android.os.Message; import android.os.Parcelable; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.util.Log; import android.util.SparseArray; import android.widget.Toast; @@ -160,7 +160,7 @@ public void onCreate() { mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mNetworkStateListenerL = new ConnectivityManager.NetworkCallback() { @Override public void onAvailable(Network network) { @@ -240,7 +240,7 @@ public void onDestroy() { manageLock(false); - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mConnectivityManager.unregisterNetworkCallback(mNetworkStateListenerL); else unregisterReceiver(mNetworkStateListener); @@ -466,7 +466,7 @@ public void notifyFinishedDownload(String name) { if (downloadDoneCount < 1) { downloadDoneList.append(name); - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { downloadDoneNotification.setContentTitle(getString(R.string.app_name)); } else { downloadDoneNotification.setContentTitle(null); @@ -505,7 +505,7 @@ public void notifyFailedDownload(DownloadMission mission) { .setContentIntent(mOpenDownloadList); } - if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { downloadFailedNotification.setContentTitle(getString(R.string.app_name)); downloadFailedNotification.setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.download_failed).concat(": ").concat(mission.storage.getName()))); 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 d490bcb0f46..c9518e477fc 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 @@ -49,6 +49,7 @@ import java.lang.ref.WeakReference; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import us.shandian.giga.get.DownloadMission; @@ -302,9 +303,7 @@ private void updateProgress(ViewHolderItem h) { float averageSpeed = speed; if (h.lastSpeedIdx < 0) { - for (int i = 0; i < h.lastSpeed.length; i++) { - h.lastSpeed[i] = speed; - } + Arrays.fill(h.lastSpeed, speed); h.lastSpeedIdx = 0; } else { for (int i = 0; i < h.lastSpeed.length; i++) { 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 09f4d0c7942..35f40aa825b 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 @@ -11,7 +11,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.IBinder; -import android.preference.PreferenceManager; +import androidx.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -97,7 +97,7 @@ public void onServiceDisconnected(ComponentName name) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.missions, container, false); - mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mPrefs = PreferenceManager.getDefaultSharedPreferences(requireActivity()); mLinear = mPrefs.getBoolean("linear", false); // Bind the service diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index 31be267af9a..8049da86833 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -13,7 +13,7 @@ android:summary="%s" android:title="@string/theme_title"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -