fix PIP mode display for Android version < 10

This commit is contained in:
Akinwale Ariwodola 2020-05-27 11:20:51 +01:00
parent a49cfe91da
commit c844c4f896
3 changed files with 49 additions and 4 deletions

View file

@ -115,6 +115,7 @@ import io.lbry.browser.listener.DownloadActionListener;
import io.lbry.browser.listener.FetchChannelsListener; import io.lbry.browser.listener.FetchChannelsListener;
import io.lbry.browser.listener.FetchClaimsListener; import io.lbry.browser.listener.FetchClaimsListener;
import io.lbry.browser.listener.FilePickerListener; import io.lbry.browser.listener.FilePickerListener;
import io.lbry.browser.listener.PIPModeListener;
import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.ScreenOrientationListener;
import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.SdkStatusListener;
import io.lbry.browser.listener.StoragePermissionListener; import io.lbry.browser.listener.StoragePermissionListener;
@ -316,6 +317,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private List<CameraPermissionListener> cameraPermissionListeners; private List<CameraPermissionListener> cameraPermissionListeners;
private List<DownloadActionListener> downloadActionListeners; private List<DownloadActionListener> downloadActionListeners;
private List<FilePickerListener> filePickerListeners; private List<FilePickerListener> filePickerListeners;
private List<PIPModeListener> pipModeListeners;
private List<ScreenOrientationListener> screenOrientationListeners; private List<ScreenOrientationListener> screenOrientationListeners;
private List<SdkStatusListener> sdkStatusListeners; private List<SdkStatusListener> sdkStatusListeners;
private List<StoragePermissionListener> storagePermissionListeners; private List<StoragePermissionListener> storagePermissionListeners;
@ -426,6 +428,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
fetchChannelsListeners = new ArrayList<>(); fetchChannelsListeners = new ArrayList<>();
fetchClaimsListeners = new ArrayList<>(); fetchClaimsListeners = new ArrayList<>();
filePickerListeners = new ArrayList<>(); filePickerListeners = new ArrayList<>();
pipModeListeners = new ArrayList<>();
screenOrientationListeners = new ArrayList<>(); screenOrientationListeners = new ArrayList<>();
sdkStatusListeners = new ArrayList<>(); sdkStatusListeners = new ArrayList<>();
storagePermissionListeners = new ArrayList<>(); storagePermissionListeners = new ArrayList<>();
@ -598,6 +601,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
filePickerListeners.remove(listener); 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) { public void addCameraPermissionListener(CameraPermissionListener listener) {
if (!cameraPermissionListeners.contains(listener)) { if (!cameraPermissionListeners.contains(listener)) {
cameraPermissionListeners.add(listener); cameraPermissionListeners.add(listener);
@ -808,6 +821,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true); findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true);
hideActionBar(); hideActionBar();
for (PIPModeListener listener : pipModeListeners) {
listener.onEnterPIPMode();
}
PlayerView pipPlayer = findViewById(R.id.pip_player); PlayerView pipPlayer = findViewById(R.id.pip_player);
pipPlayer.setVisibility(View.VISIBLE); pipPlayer.setVisibility(View.VISIBLE);
pipPlayer.setPlayer(appPlayer); pipPlayer.setPlayer(appPlayer);
@ -838,6 +855,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (!Lbry.SDK_READY && !inFullscreenMode) { if (!Lbry.SDK_READY && !inFullscreenMode) {
findViewById(R.id.global_sdk_initializing_status).setVisibility(View.VISIBLE); findViewById(R.id.global_sdk_initializing_status).setVisibility(View.VISIBLE);
} }
for (PIPModeListener listener : pipModeListeners) {
listener.onExitPIPMode();
}
PlayerView pipPlayer = findViewById(R.id.pip_player); PlayerView pipPlayer = findViewById(R.id.pip_player);
pipPlayer.setVisibility(View.INVISIBLE); pipPlayer.setVisibility(View.INVISIBLE);
@ -996,7 +1016,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public boolean canShowUrlSuggestions() { public boolean canShowUrlSuggestions() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); 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() { public boolean keepSdkBackground() {

View file

@ -0,0 +1,6 @@
package io.lbry.browser.listener;
public interface PIPModeListener {
void onEnterPIPMode();
void onExitPIPMode();
}

View file

@ -9,7 +9,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -31,7 +30,6 @@ import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat; 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.exceptions.LbryUriException;
import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.DownloadActionListener;
import io.lbry.browser.listener.FetchClaimsListener; import io.lbry.browser.listener.FetchClaimsListener;
import io.lbry.browser.listener.PIPModeListener;
import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.ScreenOrientationListener;
import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.SdkStatusListener;
import io.lbry.browser.listener.StoragePermissionListener; import io.lbry.browser.listener.StoragePermissionListener;
@ -140,8 +139,10 @@ import io.lbry.lbrysdk.LbrynetService;
import io.lbry.lbrysdk.Utils; import io.lbry.lbrysdk.Utils;
public class FileViewFragment extends BaseFragment implements public class FileViewFragment extends BaseFragment implements
MainActivity.BackPressInterceptor, DownloadActionListener, MainActivity.BackPressInterceptor,
DownloadActionListener,
FetchClaimsListener, FetchClaimsListener,
PIPModeListener,
ScreenOrientationListener, ScreenOrientationListener,
SdkStatusListener, SdkStatusListener,
StoragePermissionListener, StoragePermissionListener,
@ -240,6 +241,7 @@ public class FileViewFragment extends BaseFragment implements
activity.setBackPressInterceptor(this); activity.setBackPressInterceptor(this);
activity.addDownloadActionListener(this); activity.addDownloadActionListener(this);
activity.addFetchClaimsListener(this); activity.addFetchClaimsListener(this);
activity.addPIPModeListener(this);
activity.addScreenOrientationListener(this); activity.addScreenOrientationListener(this);
activity.addWalletBalanceListener(this); activity.addWalletBalanceListener(this);
if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
@ -584,6 +586,7 @@ public class FileViewFragment extends BaseFragment implements
MainActivity activity = (MainActivity) context; MainActivity activity = (MainActivity) context;
activity.removeDownloadActionListener(this); activity.removeDownloadActionListener(this);
activity.removeFetchClaimsListener(this); activity.removeFetchClaimsListener(this);
activity.removePIPModeListener(this);
activity.removeScreenOrientationListener(this); activity.removeScreenOrientationListener(this);
activity.removeSdkStatusListener(this); activity.removeSdkStatusListener(this);
activity.removeStoragePermissionListener(this); activity.removeStoragePermissionListener(this);
@ -2351,4 +2354,20 @@ public class FileViewFragment extends BaseFragment implements
return Integer.MAX_VALUE; 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);
}
}
} }