From c844c4f896933ec3a1688f80e83fe4f0a12d701b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 11:20:51 +0100 Subject: [PATCH] fix PIP mode display for Android version < 10 --- .../java/io/lbry/browser/MainActivity.java | 22 +++++++++++++++- .../browser/listener/PIPModeListener.java | 6 +++++ .../ui/findcontent/FileViewFragment.java | 25 ++++++++++++++++--- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/lbry/browser/listener/PIPModeListener.java diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 586ea4d4..755236bd 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -115,6 +115,7 @@ import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.FetchChannelsListener; import io.lbry.browser.listener.FetchClaimsListener; import io.lbry.browser.listener.FilePickerListener; +import io.lbry.browser.listener.PIPModeListener; import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; @@ -316,6 +317,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener private List cameraPermissionListeners; private List downloadActionListeners; private List filePickerListeners; + private List pipModeListeners; private List screenOrientationListeners; private List sdkStatusListeners; private List storagePermissionListeners; @@ -426,6 +428,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fetchChannelsListeners = new ArrayList<>(); fetchClaimsListeners = new ArrayList<>(); filePickerListeners = new ArrayList<>(); + pipModeListeners = new ArrayList<>(); screenOrientationListeners = new ArrayList<>(); sdkStatusListeners = new ArrayList<>(); storagePermissionListeners = new ArrayList<>(); @@ -598,6 +601,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener filePickerListeners.remove(listener); } + public void addPIPModeListener(PIPModeListener listener) { + if (!pipModeListeners.contains(listener)) { + pipModeListeners.add(listener); + } + } + + public void removePIPModeListener(PIPModeListener listener) { + pipModeListeners.remove(listener); + } + public void addCameraPermissionListener(CameraPermissionListener listener) { if (!cameraPermissionListeners.contains(listener)) { cameraPermissionListeners.add(listener); @@ -808,6 +821,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true); hideActionBar(); + for (PIPModeListener listener : pipModeListeners) { + listener.onEnterPIPMode(); + } + PlayerView pipPlayer = findViewById(R.id.pip_player); pipPlayer.setVisibility(View.VISIBLE); pipPlayer.setPlayer(appPlayer); @@ -838,6 +855,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (!Lbry.SDK_READY && !inFullscreenMode) { findViewById(R.id.global_sdk_initializing_status).setVisibility(View.VISIBLE); } + for (PIPModeListener listener : pipModeListeners) { + listener.onExitPIPMode(); + } PlayerView pipPlayer = findViewById(R.id.pip_player); pipPlayer.setVisibility(View.INVISIBLE); @@ -996,7 +1016,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener public boolean canShowUrlSuggestions() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, false); + return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, true); } public boolean keepSdkBackground() { diff --git a/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java b/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java new file mode 100644 index 00000000..0638e6be --- /dev/null +++ b/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java @@ -0,0 +1,6 @@ +package io.lbry.browser.listener; + +public interface PIPModeListener { + void onEnterPIPMode(); + void onExitPIPMode(); +} diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index 61e328b7..b86c13e1 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -9,7 +9,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.graphics.Color; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -31,7 +30,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; @@ -97,6 +95,7 @@ import io.lbry.browser.dialog.SendTipDialogFragment; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.FetchClaimsListener; +import io.lbry.browser.listener.PIPModeListener; import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; @@ -140,8 +139,10 @@ import io.lbry.lbrysdk.LbrynetService; import io.lbry.lbrysdk.Utils; public class FileViewFragment extends BaseFragment implements - MainActivity.BackPressInterceptor, DownloadActionListener, + MainActivity.BackPressInterceptor, + DownloadActionListener, FetchClaimsListener, + PIPModeListener, ScreenOrientationListener, SdkStatusListener, StoragePermissionListener, @@ -240,6 +241,7 @@ public class FileViewFragment extends BaseFragment implements activity.setBackPressInterceptor(this); activity.addDownloadActionListener(this); activity.addFetchClaimsListener(this); + activity.addPIPModeListener(this); activity.addScreenOrientationListener(this); activity.addWalletBalanceListener(this); if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { @@ -584,6 +586,7 @@ public class FileViewFragment extends BaseFragment implements MainActivity activity = (MainActivity) context; activity.removeDownloadActionListener(this); activity.removeFetchClaimsListener(this); + activity.removePIPModeListener(this); activity.removeScreenOrientationListener(this); activity.removeSdkStatusListener(this); activity.removeStoragePermissionListener(this); @@ -2351,4 +2354,20 @@ public class FileViewFragment extends BaseFragment implements return Integer.MAX_VALUE; } } + + public void onEnterPIPMode() { + View root = getView(); + if (root != null) { + PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view); + playerView.setVisibility(View.GONE); + } + } + + public void onExitPIPMode() { + View root = getView(); + if (root != null) { + PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view); + playerView.setVisibility(View.VISIBLE); + } + } }