From 1e1fb32558f93f617584b3d3296a27e8ea0e3912 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:54:02 -0400 Subject: [PATCH 1/7] Fix some version checks to use android.os.Build --- app/src/main/java/org/schabi/newpipe/util/Localization.java | 2 +- .../org/schabi/newpipe/views/ExpandableSurfaceView.java | 6 +++--- .../java/org/schabi/newpipe/views/FocusOverlayView.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 700d7b63d..96ba2808d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -186,7 +186,7 @@ public final class Localization { } public static String shortCount(final Context context, final long count) { - if (Build.VERSION.SDK_INT >= 24) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return CompactDecimalFormat.getInstance(getAppLocale(context), CompactDecimalFormat.CompactStyle.SHORT).format(count); } diff --git a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java index a23172bd3..e7a028d50 100644 --- a/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java +++ b/app/src/main/java/org/schabi/newpipe/views/ExpandableSurfaceView.java @@ -1,8 +1,7 @@ package org.schabi.newpipe.views; import android.content.Context; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; +import android.os.Build; import android.util.AttributeSet; import android.view.SurfaceView; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; @@ -47,7 +46,8 @@ public class ExpandableSurfaceView extends SurfaceView { if (resizeMode == RESIZE_MODE_FIT // KitKat doesn't work well when a view has a scale like needed for ZOOM - || (resizeMode == RESIZE_MODE_ZOOM && VERSION.SDK_INT < VERSION_CODES.LOLLIPOP)) { + || (resizeMode == RESIZE_MODE_ZOOM + && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)) { if (aspectDeformation > 0) { height = (int) (width / videoAspectRatio); } else { 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 dc5bf7133..29c38511c 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java @@ -270,7 +270,7 @@ public final class FocusOverlayView extends Drawable implements clearFocusObstacles((ViewGroup) decor); } - @RequiresApi(api = 26) + @RequiresApi(api = Build.VERSION_CODES.O) private static void clearFocusObstacles(final ViewGroup viewGroup) { viewGroup.setTouchscreenBlocksFocus(false); From 1a64d8aec99f5c3305e8834507812d2133b14241 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:54:19 -0400 Subject: [PATCH 2/7] Replace a ContextCompat with LayoutInflater.from --- .../main/java/us/shandian/giga/ui/adapter/MissionAdapter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 ca590a892..eb0fec596 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 @@ -29,7 +29,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.core.view.ViewCompat; import androidx.recyclerview.widget.DiffUtil; @@ -121,7 +120,7 @@ public class MissionAdapter extends Adapter implements Handler.Callb mContext = context; mDownloadManager = downloadManager; - mInflater = ContextCompat.getSystemService(mContext, LayoutInflater.class); + mInflater = LayoutInflater.from(mContext); mLayout = R.layout.mission_item; mHandler = new Handler(context.getMainLooper()); From 6db560fd2c996b8a26f7df5f459924d2ac9645d2 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:54:39 -0400 Subject: [PATCH 3/7] Use FragmentActivity for AboutActivity's viewpager2 --- .../java/org/schabi/newpipe/about/AboutActivity.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 c24636cf0..9d3aea546 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -12,8 +12,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Lifecycle; +import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; @@ -95,8 +94,7 @@ public class AboutActivity extends AppCompatActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. - mSectionsPagerAdapter = - new SectionsPagerAdapter(getSupportFragmentManager(), getLifecycle()); + mSectionsPagerAdapter = new SectionsPagerAdapter(this); // Set up the ViewPager with the sections adapter. mViewPager = findViewById(R.id.container); @@ -179,8 +177,8 @@ public class AboutActivity extends AppCompatActivity { * one of the sections/tabs/pages. */ public static class SectionsPagerAdapter extends FragmentStateAdapter { - public SectionsPagerAdapter(final FragmentManager fm, final Lifecycle lifecycle) { - super(fm, lifecycle); + public SectionsPagerAdapter(final FragmentActivity fa) { + super(fa); } @NonNull From 972235bfba3c082dfe3e6d2b48e6f33df42ab504 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:56:46 -0400 Subject: [PATCH 4/7] Add missing app:iconSpaceReserved --- app/src/main/res/xml/content_settings.xml | 3 ++- .../main/res/xml/notification_settings.xml | 20 ++++++++++--------- app/src/main/res/xml/video_audio_settings.xml | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index c36e7f0e2..c885366ec 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -105,7 +105,8 @@ + android:title="@string/settings_category_feed_title" + app:iconSpaceReserved="false"> + xmlns:app="http://schemas.android.com/apk/res-auto" + android:title="@string/settings_category_notification_title"> + android:defaultValue="false" + android:key="@string/scale_to_square_image_in_notifications_key" + android:summary="@string/notification_scale_to_square_image_summary" + android:title="@string/notification_scale_to_square_image_title" + app:iconSpaceReserved="false" /> + + - - diff --git a/app/src/main/res/xml/video_audio_settings.xml b/app/src/main/res/xml/video_audio_settings.xml index b0d9070a3..0b79d6d1c 100644 --- a/app/src/main/res/xml/video_audio_settings.xml +++ b/app/src/main/res/xml/video_audio_settings.xml @@ -84,7 +84,8 @@ + android:title="@string/settings_category_player_behavior_title" + app:iconSpaceReserved="false"> Date: Sat, 31 Oct 2020 15:57:01 -0400 Subject: [PATCH 5/7] Simplify an if else --- .../org/schabi/newpipe/fragments/list/BaseListFragment.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 6a8611d0e..79e1854e9 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 @@ -378,11 +378,7 @@ public abstract class BaseListFragment extends BaseStateFragment final ActionBar supportActionBar = activity.getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setDisplayShowTitleEnabled(true); - if (useAsFrontPage) { - supportActionBar.setDisplayHomeAsUpEnabled(false); - } else { - supportActionBar.setDisplayHomeAsUpEnabled(true); - } + supportActionBar.setDisplayHomeAsUpEnabled(!useAsFrontPage); } } From 31cffa68c5cef83726543e23e05e3837b2388cf0 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:57:26 -0400 Subject: [PATCH 6/7] Push conditionals inside branch expressions --- .../newpipe/download/DownloadDialog.java | 2 +- .../fragments/detail/VideoDetailFragment.java | 18 +++++++++--------- .../org/schabi/newpipe/player/MainPlayer.java | 6 +++--- .../newpipe/player/ServicePlayerActivity.java | 9 ++++----- .../newpipe/player/helper/PlayerHelper.java | 8 ++++---- .../giga/io/StoredDirectoryHelper.java | 2 +- .../giga/ui/fragment/MissionsFragment.java | 7 ++++--- 7 files changed, 26 insertions(+), 26 deletions(-) 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 17d079d50..93398d990 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -646,7 +646,7 @@ public class DownloadDialog extends DialogFragment mainStorage = mainStorageVideo; // subtitle & video files go together format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat(); mime = format.mimeType; - filename += format == MediaFormat.TTML ? MediaFormat.SRT.suffix : format.suffix; + filename += (format == MediaFormat.TTML ? MediaFormat.SRT : format).suffix; break; default: throw new RuntimeException("No stream selected"); 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 e71e7f19c..cd4a3a083 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 @@ -1246,9 +1246,9 @@ public class VideoDetailFragment final DisplayMetrics metrics = getResources().getDisplayMetrics(); if (getView() != null) { - final int height = isInMultiWindow() - ? requireView().getHeight() - : activity.getWindow().getDecorView().getHeight(); + final int height = (isInMultiWindow() + ? requireView() + : activity.getWindow().getDecorView()).getHeight(); setHeightThumbnail(height, metrics); getView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener); } @@ -1269,9 +1269,9 @@ public class VideoDetailFragment requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener); if (player != null && player.isFullscreen()) { - final int height = isInMultiWindow() - ? requireView().getHeight() - : activity.getWindow().getDecorView().getHeight(); + final int height = (isInMultiWindow() + ? requireView() + : activity.getWindow().getDecorView()).getHeight(); // Height is zero when the view is not yet displayed like after orientation change if (height != 0) { setHeightThumbnail(height, metrics); @@ -1279,9 +1279,9 @@ public class VideoDetailFragment requireView().getViewTreeObserver().addOnPreDrawListener(preDrawListener); } } else { - final int height = isPortrait - ? (int) (metrics.widthPixels / (16.0f / 9.0f)) - : (int) (metrics.heightPixels / 2.0f); + final int height = (int) (isPortrait + ? metrics.widthPixels / (16.0f / 9.0f) + : metrics.heightPixels / 2.0f); setHeightThumbnail(height, metrics); } } 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 e8554e5ac..ea205bbdf 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java @@ -225,9 +225,9 @@ public final class MainPlayer extends Service { // DisplayMetrics from activity context knows about MultiWindow feature // while DisplayMetrics from app context doesn't final DisplayMetrics metrics = (playerImpl != null - && playerImpl.getParentActivity() != null) - ? playerImpl.getParentActivity().getResources().getDisplayMetrics() - : getResources().getDisplayMetrics(); + && playerImpl.getParentActivity() != null + ? playerImpl.getParentActivity().getResources() + : getResources()).getDisplayMetrics(); return metrics.heightPixels < metrics.widthPixels; } diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java index 72f56cb1b..8b606260a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java @@ -748,11 +748,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity //2) Icon change accordingly to current App Theme // using rootView.getContext() because getApplicationContext() didn't work - item.setIcon(player.isMuted() - ? ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), - R.attr.ic_volume_off) - : ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), - R.attr.ic_volume_up)); + item.setIcon(ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), + player.isMuted() + ? R.attr.ic_volume_off + : R.attr.ic_volume_up)); } } } 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 1d1d056a8..4b52aa27d 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 @@ -84,12 +84,12 @@ public final class PlayerHelper { final int days = (milliSeconds % (86400000 * 7)) / 86400000; STRING_BUILDER.setLength(0); - return days > 0 + return (days > 0 ? STRING_FORMATTER.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds) - .toString() : hours > 0 - ? STRING_FORMATTER.format("%d:%02d:%02d", hours, minutes, seconds).toString() - : STRING_FORMATTER.format("%02d:%02d", minutes, seconds).toString(); + ? STRING_FORMATTER.format("%d:%02d:%02d", hours, minutes, seconds) + : STRING_FORMATTER.format("%02d:%02d", minutes, seconds) + ).toString(); } public static String formatSpeed(final double speed) { diff --git a/app/src/main/java/us/shandian/giga/io/StoredDirectoryHelper.java b/app/src/main/java/us/shandian/giga/io/StoredDirectoryHelper.java index 8f6070ff4..8f7e18a31 100644 --- a/app/src/main/java/us/shandian/giga/io/StoredDirectoryHelper.java +++ b/app/src/main/java/us/shandian/giga/io/StoredDirectoryHelper.java @@ -212,7 +212,7 @@ public class StoredDirectoryHelper { @NonNull @Override public String toString() { - return docTree == null ? Uri.fromFile(ioTree).toString() : docTree.getUri().toString(); + return (docTree == null ? Uri.fromFile(ioTree) : docTree.getUri()).toString(); } 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 35f40aa82..265491b8a 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 @@ -224,9 +224,10 @@ public class MissionsFragment extends Fragment { mList.setAdapter(mAdapter); if (mSwitch != null) { - mSwitch.setIcon(mLinear - ? ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_grid) - : ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_list)); + mSwitch.setIcon(ThemeHelper.resolveResourceIdFromAttr( + requireContext(), mLinear + ? R.attr.ic_grid + : R.attr.ic_list)); mSwitch.setTitle(mLinear ? R.string.grid : R.string.list); mPrefs.edit().putBoolean("linear", mLinear).apply(); } From a48529872d2166775c412058db25fdde9e2c4566 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 31 Oct 2020 15:57:49 -0400 Subject: [PATCH 7/7] Fix a few Kotlin style issues --- .../java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt | 2 +- .../org/schabi/newpipe/local/feed/service/FeedLoadService.kt | 4 ++-- .../local/subscription/dialog/FeedGroupDialogViewModel.kt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt index d319c9fa3..f77e13f69 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedDatabaseManager.kt @@ -50,7 +50,7 @@ class FeedDatabaseManager(context: Context) { return streams.map> { val items = ArrayList(it.size) - for (streamEntity in it) items.add(streamEntity.toStreamInfoItem()) + it.mapTo(items) { it.toStreamInfoItem() } return@map items } } 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 0181f2711..556c215d9 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 @@ -161,8 +161,8 @@ class FeedLoadService : Service() { companion object { fun wrapList(subscriptionId: Long, info: ListInfo): List { val toReturn = ArrayList(info.errors.size) - for (error in info.errors) { - toReturn.add(RequestException(subscriptionId, info.serviceId.toString() + ":" + info.url, error)) + info.errors.mapTo(toReturn) { + RequestException(subscriptionId, info.serviceId.toString() + ":" + info.url, it) } return toReturn } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt index e9a7e4eb7..4b1a4df5e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt @@ -37,8 +37,8 @@ class FeedGroupDialogViewModel( BiFunction { t1: String, t2: Boolean -> Filter(t1, t2) } ) .distinctUntilChanged() - .switchMap { filter -> - subscriptionManager.getSubscriptions(groupId, filter.query, filter.showOnlyUngrouped) + .switchMap { (query, showOnlyUngrouped) -> + subscriptionManager.getSubscriptions(groupId, query, showOnlyUngrouped) }.map { list -> list.map { PickerSubscriptionItem(it) } } private val mutableGroupLiveData = MutableLiveData()