Merge pull request #4710 from TacoTheDank/more-cleanup

More miscellaneous little fixes and improvements
This commit is contained in:
Tobias Groza 2020-10-31 23:17:23 +01:00 committed by GitHub
commit 1500ce7490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 57 additions and 60 deletions

View File

@ -12,8 +12,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Lifecycle;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2; import androidx.viewpager2.widget.ViewPager2;
@ -95,8 +94,7 @@ public class AboutActivity extends AppCompatActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Create the adapter that will return a fragment for each of the three // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
mSectionsPagerAdapter = mSectionsPagerAdapter = new SectionsPagerAdapter(this);
new SectionsPagerAdapter(getSupportFragmentManager(), getLifecycle());
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container); mViewPager = findViewById(R.id.container);
@ -179,8 +177,8 @@ public class AboutActivity extends AppCompatActivity {
* one of the sections/tabs/pages. * one of the sections/tabs/pages.
*/ */
public static class SectionsPagerAdapter extends FragmentStateAdapter { public static class SectionsPagerAdapter extends FragmentStateAdapter {
public SectionsPagerAdapter(final FragmentManager fm, final Lifecycle lifecycle) { public SectionsPagerAdapter(final FragmentActivity fa) {
super(fm, lifecycle); super(fa);
} }
@NonNull @NonNull

View File

@ -646,7 +646,7 @@ public class DownloadDialog extends DialogFragment
mainStorage = mainStorageVideo; // subtitle & video files go together mainStorage = mainStorageVideo; // subtitle & video files go together
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat(); format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
mime = format.mimeType; mime = format.mimeType;
filename += format == MediaFormat.TTML ? MediaFormat.SRT.suffix : format.suffix; filename += (format == MediaFormat.TTML ? MediaFormat.SRT : format).suffix;
break; break;
default: default:
throw new RuntimeException("No stream selected"); throw new RuntimeException("No stream selected");

View File

@ -1246,9 +1246,9 @@ public class VideoDetailFragment
final DisplayMetrics metrics = getResources().getDisplayMetrics(); final DisplayMetrics metrics = getResources().getDisplayMetrics();
if (getView() != null) { if (getView() != null) {
final int height = isInMultiWindow() final int height = (isInMultiWindow()
? requireView().getHeight() ? requireView()
: activity.getWindow().getDecorView().getHeight(); : activity.getWindow().getDecorView()).getHeight();
setHeightThumbnail(height, metrics); setHeightThumbnail(height, metrics);
getView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener); getView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
} }
@ -1269,9 +1269,9 @@ public class VideoDetailFragment
requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener); requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
if (player != null && player.isFullscreen()) { if (player != null && player.isFullscreen()) {
final int height = isInMultiWindow() final int height = (isInMultiWindow()
? requireView().getHeight() ? requireView()
: activity.getWindow().getDecorView().getHeight(); : activity.getWindow().getDecorView()).getHeight();
// Height is zero when the view is not yet displayed like after orientation change // Height is zero when the view is not yet displayed like after orientation change
if (height != 0) { if (height != 0) {
setHeightThumbnail(height, metrics); setHeightThumbnail(height, metrics);
@ -1279,9 +1279,9 @@ public class VideoDetailFragment
requireView().getViewTreeObserver().addOnPreDrawListener(preDrawListener); requireView().getViewTreeObserver().addOnPreDrawListener(preDrawListener);
} }
} else { } else {
final int height = isPortrait final int height = (int) (isPortrait
? (int) (metrics.widthPixels / (16.0f / 9.0f)) ? metrics.widthPixels / (16.0f / 9.0f)
: (int) (metrics.heightPixels / 2.0f); : metrics.heightPixels / 2.0f);
setHeightThumbnail(height, metrics); setHeightThumbnail(height, metrics);
} }
} }

View File

@ -378,11 +378,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
final ActionBar supportActionBar = activity.getSupportActionBar(); final ActionBar supportActionBar = activity.getSupportActionBar();
if (supportActionBar != null) { if (supportActionBar != null) {
supportActionBar.setDisplayShowTitleEnabled(true); supportActionBar.setDisplayShowTitleEnabled(true);
if (useAsFrontPage) { supportActionBar.setDisplayHomeAsUpEnabled(!useAsFrontPage);
supportActionBar.setDisplayHomeAsUpEnabled(false);
} else {
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
} }
} }

View File

@ -50,7 +50,7 @@ class FeedDatabaseManager(context: Context) {
return streams.map<List<StreamInfoItem>> { return streams.map<List<StreamInfoItem>> {
val items = ArrayList<StreamInfoItem>(it.size) val items = ArrayList<StreamInfoItem>(it.size)
for (streamEntity in it) items.add(streamEntity.toStreamInfoItem()) it.mapTo(items) { it.toStreamInfoItem() }
return@map items return@map items
} }
} }

View File

@ -161,8 +161,8 @@ class FeedLoadService : Service() {
companion object { companion object {
fun wrapList(subscriptionId: Long, info: ListInfo<StreamInfoItem>): List<Throwable> { fun wrapList(subscriptionId: Long, info: ListInfo<StreamInfoItem>): List<Throwable> {
val toReturn = ArrayList<Throwable>(info.errors.size) val toReturn = ArrayList<Throwable>(info.errors.size)
for (error in info.errors) { info.errors.mapTo(toReturn) {
toReturn.add(RequestException(subscriptionId, info.serviceId.toString() + ":" + info.url, error)) RequestException(subscriptionId, info.serviceId.toString() + ":" + info.url, it)
} }
return toReturn return toReturn
} }

View File

@ -37,8 +37,8 @@ class FeedGroupDialogViewModel(
BiFunction { t1: String, t2: Boolean -> Filter(t1, t2) } BiFunction { t1: String, t2: Boolean -> Filter(t1, t2) }
) )
.distinctUntilChanged() .distinctUntilChanged()
.switchMap { filter -> .switchMap { (query, showOnlyUngrouped) ->
subscriptionManager.getSubscriptions(groupId, filter.query, filter.showOnlyUngrouped) subscriptionManager.getSubscriptions(groupId, query, showOnlyUngrouped)
}.map { list -> list.map { PickerSubscriptionItem(it) } } }.map { list -> list.map { PickerSubscriptionItem(it) } }
private val mutableGroupLiveData = MutableLiveData<FeedGroupEntity>() private val mutableGroupLiveData = MutableLiveData<FeedGroupEntity>()

View File

@ -225,9 +225,9 @@ public final class MainPlayer extends Service {
// DisplayMetrics from activity context knows about MultiWindow feature // DisplayMetrics from activity context knows about MultiWindow feature
// while DisplayMetrics from app context doesn't // while DisplayMetrics from app context doesn't
final DisplayMetrics metrics = (playerImpl != null final DisplayMetrics metrics = (playerImpl != null
&& playerImpl.getParentActivity() != null) && playerImpl.getParentActivity() != null
? playerImpl.getParentActivity().getResources().getDisplayMetrics() ? playerImpl.getParentActivity().getResources()
: getResources().getDisplayMetrics(); : getResources()).getDisplayMetrics();
return metrics.heightPixels < metrics.widthPixels; return metrics.heightPixels < metrics.widthPixels;
} }

View File

@ -748,11 +748,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
//2) Icon change accordingly to current App Theme //2) Icon change accordingly to current App Theme
// using rootView.getContext() because getApplicationContext() didn't work // using rootView.getContext() because getApplicationContext() didn't work
item.setIcon(player.isMuted() item.setIcon(ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(),
? ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), player.isMuted()
R.attr.ic_volume_off) ? R.attr.ic_volume_off
: ThemeHelper.resolveResourceIdFromAttr(rootView.getContext(), : R.attr.ic_volume_up));
R.attr.ic_volume_up));
} }
} }
} }

View File

@ -84,12 +84,12 @@ public final class PlayerHelper {
final int days = (milliSeconds % (86400000 * 7)) / 86400000; final int days = (milliSeconds % (86400000 * 7)) / 86400000;
STRING_BUILDER.setLength(0); STRING_BUILDER.setLength(0);
return days > 0 return (days > 0
? STRING_FORMATTER.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds) ? STRING_FORMATTER.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds)
.toString()
: hours > 0 : hours > 0
? STRING_FORMATTER.format("%d:%02d:%02d", hours, minutes, seconds).toString() ? STRING_FORMATTER.format("%d:%02d:%02d", hours, minutes, seconds)
: STRING_FORMATTER.format("%02d:%02d", minutes, seconds).toString(); : STRING_FORMATTER.format("%02d:%02d", minutes, seconds)
).toString();
} }
public static String formatSpeed(final double speed) { public static String formatSpeed(final double speed) {

View File

@ -186,7 +186,7 @@ public final class Localization {
} }
public static String shortCount(final Context context, final long count) { 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), return CompactDecimalFormat.getInstance(getAppLocale(context),
CompactDecimalFormat.CompactStyle.SHORT).format(count); CompactDecimalFormat.CompactStyle.SHORT).format(count);
} }

View File

@ -1,8 +1,7 @@
package org.schabi.newpipe.views; package org.schabi.newpipe.views;
import android.content.Context; import android.content.Context;
import android.os.Build.VERSION; import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.SurfaceView; import android.view.SurfaceView;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
@ -47,7 +46,8 @@ public class ExpandableSurfaceView extends SurfaceView {
if (resizeMode == RESIZE_MODE_FIT if (resizeMode == RESIZE_MODE_FIT
// KitKat doesn't work well when a view has a scale like needed for ZOOM // 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) { if (aspectDeformation > 0) {
height = (int) (width / videoAspectRatio); height = (int) (width / videoAspectRatio);
} else { } else {

View File

@ -270,7 +270,7 @@ public final class FocusOverlayView extends Drawable implements
clearFocusObstacles((ViewGroup) decor); clearFocusObstacles((ViewGroup) decor);
} }
@RequiresApi(api = 26) @RequiresApi(api = Build.VERSION_CODES.O)
private static void clearFocusObstacles(final ViewGroup viewGroup) { private static void clearFocusObstacles(final ViewGroup viewGroup) {
viewGroup.setTouchscreenBlocksFocus(false); viewGroup.setTouchscreenBlocksFocus(false);

View File

@ -212,7 +212,7 @@ public class StoredDirectoryHelper {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return docTree == null ? Uri.fromFile(ioTree).toString() : docTree.getUri().toString(); return (docTree == null ? Uri.fromFile(ioTree) : docTree.getUri()).toString();
} }

View File

@ -29,7 +29,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
@ -121,7 +120,7 @@ public class MissionAdapter extends Adapter<ViewHolder> implements Handler.Callb
mContext = context; mContext = context;
mDownloadManager = downloadManager; mDownloadManager = downloadManager;
mInflater = ContextCompat.getSystemService(mContext, LayoutInflater.class); mInflater = LayoutInflater.from(mContext);
mLayout = R.layout.mission_item; mLayout = R.layout.mission_item;
mHandler = new Handler(context.getMainLooper()); mHandler = new Handler(context.getMainLooper());

View File

@ -224,9 +224,10 @@ public class MissionsFragment extends Fragment {
mList.setAdapter(mAdapter); mList.setAdapter(mAdapter);
if (mSwitch != null) { if (mSwitch != null) {
mSwitch.setIcon(mLinear mSwitch.setIcon(ThemeHelper.resolveResourceIdFromAttr(
? ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_grid) requireContext(), mLinear
: ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_list)); ? R.attr.ic_grid
: R.attr.ic_list));
mSwitch.setTitle(mLinear ? R.string.grid : R.string.list); mSwitch.setTitle(mLinear ? R.string.grid : R.string.list);
mPrefs.edit().putBoolean("linear", mLinear).apply(); mPrefs.edit().putBoolean("linear", mLinear).apply();
} }

View File

@ -105,7 +105,8 @@
<PreferenceCategory <PreferenceCategory
android:layout="@layout/settings_category_header_layout" android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_feed_title"> android:title="@string/settings_category_feed_title"
app:iconSpaceReserved="false">
<org.schabi.newpipe.settings.custom.DurationListPreference <org.schabi.newpipe.settings.custom.DurationListPreference
android:defaultValue="@string/feed_update_threshold_default_value" android:defaultValue="@string/feed_update_threshold_default_value"

View File

@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/settings_category_notification_title"> android:title="@string/settings_category_notification_title">
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="@string/scale_to_square_image_in_notifications_key" android:key="@string/scale_to_square_image_in_notifications_key"
android:summary="@string/notification_scale_to_square_image_summary" android:summary="@string/notification_scale_to_square_image_summary"
android:title="@string/notification_scale_to_square_image_title" android:title="@string/notification_scale_to_square_image_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<PreferenceCategory
android:layout="@layout/settings_category_header_layout"
app:iconSpaceReserved="false">
<PreferenceCategory android:layout="@layout/settings_category_header_layout">
<org.schabi.newpipe.settings.custom.NotificationActionsPreference /> <org.schabi.newpipe.settings.custom.NotificationActionsPreference />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -84,7 +84,8 @@
<PreferenceCategory <PreferenceCategory
android:layout="@layout/settings_category_header_layout" android:layout="@layout/settings_category_header_layout"
android:title="@string/settings_category_player_behavior_title"> android:title="@string/settings_category_player_behavior_title"
app:iconSpaceReserved="false">
<ListPreference <ListPreference
android:defaultValue="@string/preferred_open_action_default" android:defaultValue="@string/preferred_open_action_default"