Merge pull request #230 from freeboub/bugfix/avoid_pip_when_share_or_download
[Bugfix] : avoid going to pip when leaving the app due to share button
This commit is contained in:
commit
810b894c66
|
@ -355,11 +355,17 @@ public class VideoPlayActivity extends AppCompatActivity {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment);
|
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));
|
String backgroundBehavior = sharedPref.getString(getString(R.string.pref_background_behavior_key), getString(R.string.pref_background_stop_key));
|
||||||
|
|
||||||
assert videoPlayerFragment != null;
|
assert videoPlayerFragment != null;
|
||||||
assert backgroundBehavior != null;
|
assert backgroundBehavior != null;
|
||||||
|
if ( videoMetaDataFragment.isLeaveAppExpected() )
|
||||||
|
{
|
||||||
|
super.onUserLeaveHint();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (backgroundBehavior.equals(getString(R.string.pref_background_stop_key))) {
|
if (backgroundBehavior.equals(getString(R.string.pref_background_stop_key))) {
|
||||||
Log.v(TAG, "stop the video");
|
Log.v(TAG, "stop the video");
|
||||||
|
|
|
@ -73,6 +73,8 @@ public class VideoMetaDataFragment extends Fragment {
|
||||||
private Rating videoRating;
|
private Rating videoRating;
|
||||||
private ColorStateList defaultTextColor;
|
private ColorStateList defaultTextColor;
|
||||||
|
|
||||||
|
private boolean leaveAppExpected = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
@ -81,6 +83,18 @@ public class VideoMetaDataFragment extends Fragment {
|
||||||
return inflater.inflate(R.layout.fragment_video_meta, container, false);
|
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) {
|
public void updateVideoMeta(Video video, VideoPlayerService mService) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
@ -133,7 +147,11 @@ public class VideoMetaDataFragment extends Fragment {
|
||||||
Button videoShareButton = activity.findViewById(R.id.video_share);
|
Button videoShareButton = activity.findViewById(R.id.video_share);
|
||||||
videoShareButton.setText(R.string.video_share_icon);
|
videoShareButton.setText(R.string.video_share_icon);
|
||||||
new Iconics.IconicsBuilder().ctx(context).on(videoShareButton).build();
|
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
|
// Download
|
||||||
Button videoDownloadButton = activity.findViewById(R.id.video_download);
|
Button videoDownloadButton = activity.findViewById(R.id.video_download);
|
||||||
|
@ -142,6 +160,7 @@ public class VideoMetaDataFragment extends Fragment {
|
||||||
videoDownloadButton.setOnClickListener(v -> {
|
videoDownloadButton.setOnClickListener(v -> {
|
||||||
// get permission to store file
|
// get permission to store file
|
||||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
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);
|
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||||
Intents.Download(context, video);
|
Intents.Download(context, video);
|
||||||
|
|
Loading…
Reference in New Issue