From cee233db3920d1071206df6d6782d603e1df820c Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 5 Jul 2020 15:07:50 +0200 Subject: [PATCH] Code cleanup --- .../peertube/activity/VideoPlayActivity.java | 14 +- .../peertube/fragment/AddServerFragment.java | 7 +- .../fragment/VideoOptionsFragment.java | 18 ++- .../fragment/VideoPlayerFragment.java | 135 +++++++++--------- .../peertube/helper/VideoHelper.java | 40 ++++++ app/src/main/res/values-ar/strings.xml | 4 +- app/src/main/res/values-bn/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-es/strings.xml | 4 +- app/src/main/res/values-fi/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-gd/strings.xml | 4 +- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ja/strings.xml | 4 +- app/src/main/res/values-nb-rNO/strings.xml | 4 +- app/src/main/res/values-nl/strings.xml | 4 +- app/src/main/res/values-pl/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-sv/strings.xml | 4 +- app/src/main/res/values-tr/strings.xml | 4 +- app/src/main/res/values-zh-rCN/strings.xml | 4 +- app/src/main/res/values-zh-rTW/strings.xml | 4 +- app/src/main/res/values/constants.xml | 1 + app/src/main/res/values/strings.xml | 4 +- app/src/main/res/xml/root_preferences.xml | 2 +- 25 files changed, 166 insertions(+), 121 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/helper/VideoHelper.java diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index 9460e74..159b942 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -65,6 +65,7 @@ import androidx.fragment.app.FragmentTransaction; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; +import static net.schueller.peertube.helper.VideoHelper.canEnterPipMode; public class VideoPlayActivity extends AppCompatActivity { @@ -351,7 +352,7 @@ public class VideoPlayActivity extends AppCompatActivity { FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key)); assert videoPlayerFragment != null; assert backgroundBehavior != null; @@ -410,7 +411,7 @@ public class VideoPlayActivity extends AppCompatActivity { videoPlayerFragment.pauseVideo(); } - String backgroundBehavior = sharedPref.getString("pref_background_behavior", getString(R.string.pref_background_stop_key)); + String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key)); assert backgroundBehavior != null; @@ -448,15 +449,6 @@ public class VideoPlayActivity extends AppCompatActivity { } - public boolean canEnterPipMode(Context context) { - Log.v(TAG, "api version " + Build.VERSION.SDK_INT); - if (Build.VERSION.SDK_INT > 27) { - AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOp(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), context.getPackageName())); - } - return false; - } - @RequiresApi(api = Build.VERSION_CODES.O) public void enterPipMode() { Rational rational = new Rational(239, 100); diff --git a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java index 4c90721..9f761a8 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/AddServerFragment.java @@ -42,6 +42,8 @@ import net.schueller.peertube.activity.SearchServerActivity; import net.schueller.peertube.activity.ServerAddressBookActivity; import net.schueller.peertube.helper.APIUrlHelper; +import java.util.Objects; + import static android.app.Activity.RESULT_OK; @@ -78,14 +80,15 @@ public class AddServerFragment extends Fragment { Activity act = getActivity(); - Boolean formValid = true; + boolean formValid = true; // close keyboard try { + assert act != null; InputMethodManager inputManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE); - inputManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), + inputManager.hideSoftInputFromWindow(Objects.requireNonNull(act.getCurrentFocus()).getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception e) { diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index 2e9c3b4..ada3fdf 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -28,6 +28,7 @@ import android.widget.TextView; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.mikepenz.iconics.Iconics; + import net.schueller.peertube.R; import net.schueller.peertube.model.File; import net.schueller.peertube.service.VideoPlayerService; @@ -66,13 +67,22 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); TextView iconView = menuRow.findViewById(R.id.video_quality_icon); TextView textView = menuRow.findViewById(R.id.video_quality_text); - textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), getCurrentVideoPlaybackSpeedString(videoPlayerService.getPlayBackSpeed()))); + + textView.setText( + getString( + R.string.menu_video_options_playback_speed, + getCurrentVideoPlaybackSpeedString(videoPlayerService.getPlayBackSpeed() + ) + ) + ); + + iconView.setText(R.string.video_option_speed_icon); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build(); textView.setOnClickListener(view1 -> { VideoMenuSpeedFragment videoMenuSpeedFragment = VideoMenuSpeedFragment.newInstance(videoPlayerService); - videoMenuSpeedFragment.show(getActivity().getSupportFragmentManager(), + videoMenuSpeedFragment.show(requireActivity().getSupportFragmentManager(), VideoMenuSpeedFragment.TAG); }); menuHolder.addView(menuRow); @@ -87,8 +97,8 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { textView2.setOnClickListener(view1 -> { VideoMenuQualityFragment videoMenuQualityFragment = VideoMenuQualityFragment.newInstance(getContext(), files); - videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(), - videoMenuQualityFragment.TAG); + videoMenuQualityFragment.show(requireActivity().getSupportFragmentManager(), + VideoMenuQualityFragment.TAG); }); menuHolder.addView(menuRow2); diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 9fad3b3..16c75cf 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -18,7 +18,6 @@ package net.schueller.peertube.fragment; import android.app.Activity; -import android.app.AppOpsManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -66,15 +65,16 @@ import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; import net.schueller.peertube.service.VideoPlayerService; -import java.util.Objects; - import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.fragment.app.Fragment; + import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import static net.schueller.peertube.helper.VideoHelper.canEnterPipMode; + public class VideoPlayerFragment extends Fragment implements VideoRendererEventListener { private String mVideoUuid; @@ -134,6 +134,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL progressBar = activity.findViewById(R.id.torrent_progress); progressBar.setMax(100); + assert context != null; simpleExoPlayerView = new PlayerView(context); simpleExoPlayerView = activity.findViewById(R.id.video_view); @@ -195,23 +196,24 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL @Override public void onFailure(@NonNull Call