From 43b7b6ee0ab5f5adc4d776bd491b2f68a4643292 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet Date: Fri, 25 Sep 2020 18:20:18 +0200 Subject: [PATCH] [Bugfix] : avoid going to pip when leaving the app due to share button --- .../peertube/activity/VideoPlayActivity.java | 6 ++++++ .../fragment/VideoMetaDataFragment.java | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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 398312f..e3ca7af 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -351,11 +351,17 @@ public class VideoPlayActivity extends AppCompatActivity { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); FragmentManager fragmentManager = getSupportFragmentManager(); VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + VideoMetaDataFragment videoMetaDataFragment = (VideoMetaDataFragment) fragmentManager.findFragmentById(R.id.video_meta_data_fragment); String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key)); assert videoPlayerFragment != null; assert backgroundBehavior != null; + if ( videoMetaDataFragment.isLeaveAppExpected() ) + { + super.onUserLeaveHint(); + return; + } if (backgroundBehavior.equals(getString(R.string.pref_background_stop_key))) { Log.v(TAG, "stop the video"); diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java index 1d370e0..0b374ed 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -72,6 +72,8 @@ public class VideoMetaDataFragment extends Fragment { private Rating videoRating; private ColorStateList defaultTextColor; + private boolean leaveAppExpected = false; + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -80,6 +82,18 @@ public class VideoMetaDataFragment extends Fragment { return inflater.inflate(R.layout.fragment_video_meta, container, false); } + @Override + public void onPause() + { + leaveAppExpected = false; + super.onPause(); + } + + public boolean isLeaveAppExpected() + { + return leaveAppExpected; + } + public void updateVideoMeta(Video video, VideoPlayerService mService) { Context context = getContext(); Activity activity = getActivity(); @@ -131,7 +145,11 @@ public class VideoMetaDataFragment extends Fragment { Button videoShareButton = activity.findViewById(R.id.video_share); videoShareButton.setText(R.string.video_share_icon); new Iconics.IconicsBuilder().ctx(context).on(videoShareButton).build(); - videoShareButton.setOnClickListener(v -> Intents.Share(context, video)); + videoShareButton.setOnClickListener(v -> + { + leaveAppExpected = true; + Intents.Share( context, video ); + } ); // Download Button videoDownloadButton = activity.findViewById(R.id.video_download); @@ -140,6 +158,7 @@ public class VideoMetaDataFragment extends Fragment { videoDownloadButton.setOnClickListener(v -> { // get permission to store file if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + leaveAppExpected = true; ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Intents.Download(context, video);