switch to fullscreen mode on rotate when viewing media
This commit is contained in:
parent
d5b4e6990f
commit
de4e6eee25
4 changed files with 137 additions and 68 deletions
|
@ -52,7 +52,7 @@ task printVersionName {
|
|||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.2.0-alpha06'
|
||||
implementation "androidx.cardview:cardview:1.0.0"
|
||||
|
|
|
@ -111,6 +111,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.ScreenOrientationListener;
|
||||
import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.StoragePermissionListener;
|
||||
import io.lbry.browser.listener.WalletBalanceListener;
|
||||
|
@ -173,6 +174,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
|
||||
private Map<String, Class> specialRouteFragmentClassMap;
|
||||
private boolean inPictureInPictureMode;
|
||||
@Getter
|
||||
private boolean inFullscreenMode;
|
||||
public static SimpleExoPlayer appPlayer;
|
||||
public static Cache playerCache;
|
||||
public static boolean playerReassigned;
|
||||
|
@ -300,6 +303,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
private List<CameraPermissionListener> cameraPermissionListeners;
|
||||
private List<DownloadActionListener> downloadActionListeners;
|
||||
private List<FilePickerListener> filePickerListeners;
|
||||
private List<ScreenOrientationListener> screenOrientationListeners;
|
||||
private List<SdkStatusListener> sdkStatusListeners;
|
||||
private List<StoragePermissionListener> storagePermissionListeners;
|
||||
private List<WalletBalanceListener> walletBalanceListeners;
|
||||
|
@ -394,31 +398,19 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
// setup uri bar
|
||||
setupUriBar();
|
||||
|
||||
/*View decorView = getWindow().getDecorView();
|
||||
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
||||
@Override
|
||||
public void onSystemUiVisibilityChange(int visibility) {
|
||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||
findViewById(R.id.app_bar_main_container).setFitsSystemWindows(false);
|
||||
findViewById(R.id.drawer_layout).setFitsSystemWindows(false);
|
||||
} else {
|
||||
findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true);
|
||||
findViewById(R.id.drawer_layout).setFitsSystemWindows(true);
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
// other
|
||||
pendingSyncSetQueue = new ArrayList<>();
|
||||
openNavFragments = new HashMap<>();
|
||||
|
||||
cameraPermissionListeners = new ArrayList<>();
|
||||
downloadActionListeners = new ArrayList<>();
|
||||
fetchChannelsListeners = new ArrayList<>();
|
||||
fetchClaimsListeners = new ArrayList<>();
|
||||
filePickerListeners = new ArrayList<>();
|
||||
screenOrientationListeners = new ArrayList<>();
|
||||
sdkStatusListeners = new ArrayList<>();
|
||||
storagePermissionListeners = new ArrayList<>();
|
||||
walletBalanceListeners = new ArrayList<>();
|
||||
fetchClaimsListeners = new ArrayList<>();
|
||||
fetchChannelsListeners = new ArrayList<>();
|
||||
|
||||
sdkStatusListeners.add(this);
|
||||
|
||||
|
@ -531,14 +523,30 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
checkNotificationOpenIntent(intent);
|
||||
}
|
||||
|
||||
public void addCameraPermissionListener(CameraPermissionListener listener) {
|
||||
if (!cameraPermissionListeners.contains(listener)) {
|
||||
cameraPermissionListeners.add(listener);
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
switch (newConfig.orientation) {
|
||||
case Configuration.ORIENTATION_PORTRAIT:
|
||||
for (ScreenOrientationListener listener : screenOrientationListeners) {
|
||||
listener.onPortraitOrientationEntered();
|
||||
}
|
||||
break;
|
||||
case Configuration.ORIENTATION_LANDSCAPE:
|
||||
for (ScreenOrientationListener listener : screenOrientationListeners) {
|
||||
listener.onLandscapeOrientationEntered();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCameraPermissionListener(CameraPermissionListener listener) {
|
||||
cameraPermissionListeners.remove(listener);
|
||||
public void addScreenOrientationListener(ScreenOrientationListener listener) {
|
||||
if (!screenOrientationListeners.contains(listener)) {
|
||||
screenOrientationListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeScreenOrientationListener(ScreenOrientationListener listener) {
|
||||
screenOrientationListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addDownloadActionListener(DownloadActionListener listener) {
|
||||
|
@ -561,6 +569,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
filePickerListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void addCameraPermissionListener(CameraPermissionListener listener) {
|
||||
if (!cameraPermissionListeners.contains(listener)) {
|
||||
cameraPermissionListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCameraPermissionListener(CameraPermissionListener listener) {
|
||||
cameraPermissionListeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
public void addSdkStatusListener(SdkStatusListener listener) {
|
||||
if (!sdkStatusListeners.contains(listener)) {
|
||||
sdkStatusListeners.add(listener);
|
||||
|
@ -764,7 +783,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
private void renderFullMode() {
|
||||
getSupportActionBar().show();
|
||||
findViewById(R.id.content_main).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.floating_balance_main_container).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.floating_balance_main_container).setVisibility(inFullscreenMode ? View.INVISIBLE : View.VISIBLE);
|
||||
Fragment fragment = getCurrentFragment();
|
||||
if (!(fragment instanceof FileViewFragment)) {
|
||||
findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE);
|
||||
|
@ -1294,6 +1313,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
}
|
||||
|
||||
public void enterFullScreenMode() {
|
||||
inFullscreenMode = true;
|
||||
hideFloatingWalletBalance();
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
|
@ -1337,6 +1357,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
if (actionBar != null) {
|
||||
actionBar.show();
|
||||
}
|
||||
inFullscreenMode = false;
|
||||
}
|
||||
|
||||
private void initKeyStore() {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package io.lbry.browser.listener;
|
||||
|
||||
public interface ScreenOrientationListener {
|
||||
void onPortraitOrientationEntered();
|
||||
void onLandscapeOrientationEntered();
|
||||
}
|
|
@ -94,6 +94,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.ScreenOrientationListener;
|
||||
import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.StoragePermissionListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
|
@ -135,7 +136,11 @@ import io.lbry.lbrysdk.LbrynetService;
|
|||
import io.lbry.lbrysdk.Utils;
|
||||
|
||||
public class FileViewFragment extends BaseFragment implements
|
||||
MainActivity.BackPressInterceptor, DownloadActionListener, FetchClaimsListener, SdkStatusListener, StoragePermissionListener {
|
||||
MainActivity.BackPressInterceptor, DownloadActionListener,
|
||||
FetchClaimsListener,
|
||||
ScreenOrientationListener,
|
||||
SdkStatusListener,
|
||||
StoragePermissionListener {
|
||||
private static final int RELATED_CONTENT_SIZE = 16;
|
||||
private static final String DEFAULT_PLAYBACK_SPEED = "1x";
|
||||
|
||||
|
@ -218,6 +223,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
MainActivity activity = (MainActivity) context;
|
||||
activity.setBackPressInterceptor(this);
|
||||
activity.addDownloadActionListener(this);
|
||||
activity.addScreenOrientationListener(this);
|
||||
activity.addFetchClaimsListener(this);
|
||||
if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
|
||||
activity.addStoragePermissionListener(this);
|
||||
|
@ -290,6 +296,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
|
||||
if (claim != null) {
|
||||
Helper.saveViewHistory(currentUrl, claim);
|
||||
checkAndLoadRelatedContent();
|
||||
renderClaim();
|
||||
if (claim.getFile() == null) {
|
||||
loadFile();
|
||||
|
@ -352,8 +359,8 @@ public class FileViewFragment extends BaseFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private void initWebView(View view) {
|
||||
WebView webView = view.findViewById(R.id.file_view_webview);
|
||||
private void initWebView(View root) {
|
||||
WebView webView = root.findViewById(R.id.file_view_webview);
|
||||
webView.setWebViewClient(new LbryWebViewClient(getContext()));
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setAllowFileAccess(true);
|
||||
|
@ -389,6 +396,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
logUrlEvent(url);
|
||||
resetViewCount();
|
||||
resetFee();
|
||||
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
((RecyclerView) root.findViewById(R.id.file_view_related_content_list)).setAdapter(null);
|
||||
|
@ -480,6 +488,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
|
||||
if (claim != null) {
|
||||
Helper.saveViewHistory(url, claim);
|
||||
checkAndLoadRelatedContent();
|
||||
renderClaim();
|
||||
}
|
||||
}
|
||||
|
@ -531,8 +540,10 @@ public class FileViewFragment extends BaseFragment implements
|
|||
MainActivity activity = (MainActivity) context;
|
||||
activity.removeDownloadActionListener(this);
|
||||
activity.removeFetchClaimsListener(this);
|
||||
activity.removeScreenOrientationListener(this);
|
||||
activity.removeSdkStatusListener(this);
|
||||
activity.removeStoragePermissionListener(this);
|
||||
//activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -578,6 +589,8 @@ public class FileViewFragment extends BaseFragment implements
|
|||
|
||||
checkAndResetNowPlayingClaim();
|
||||
loadFile();
|
||||
|
||||
checkAndLoadRelatedContent();
|
||||
renderClaim();
|
||||
} else {
|
||||
// render nothing at location
|
||||
|
@ -594,8 +607,6 @@ public class FileViewFragment extends BaseFragment implements
|
|||
}
|
||||
|
||||
private void initUi(View root) {
|
||||
initWebView(root);
|
||||
|
||||
buttonPublishSomething.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -1189,13 +1200,18 @@ public class FileViewFragment extends BaseFragment implements
|
|||
} else {
|
||||
restoreMainActionButton();
|
||||
}
|
||||
}
|
||||
checkOwnClaim();
|
||||
}
|
||||
|
||||
private void checkAndLoadRelatedContent() {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
|
||||
if (relatedContentList == null || relatedContentList.getAdapter() == null || relatedContentList.getAdapter().getItemCount() == 0) {
|
||||
loadRelatedContent();
|
||||
}
|
||||
}
|
||||
checkOwnClaim();
|
||||
}
|
||||
|
||||
private void showUnsupportedView() {
|
||||
|
@ -1553,18 +1569,23 @@ public class FileViewFragment extends BaseFragment implements
|
|||
if (!fileExists) {
|
||||
showError(getString(R.string.claim_file_not_found, claimFile != null ? claimFile.getDownloadPath() : ""));
|
||||
} else if (fileUri != null) {
|
||||
View root = getView();
|
||||
Context context = getContext();
|
||||
if (root != null) {
|
||||
if (mediaType.startsWith("image")) {
|
||||
// display the image
|
||||
View container = getView().findViewById(R.id.file_view_imageviewer_container);
|
||||
PhotoView photoView = getView().findViewById(R.id.file_view_imageviewer);
|
||||
View container = root.findViewById(R.id.file_view_imageviewer_container);
|
||||
PhotoView photoView = root.findViewById(R.id.file_view_imageviewer);
|
||||
|
||||
Glide.with(getContext().getApplicationContext()).load(fileUri).centerInside().into(photoView);
|
||||
if (context != null) {
|
||||
Glide.with(context.getApplicationContext()).load(fileUri).centerInside().into(photoView);
|
||||
}
|
||||
hideFloatingWalletBalance();
|
||||
container.setVisibility(View.VISIBLE);
|
||||
} else if (mediaType.startsWith("text")) {
|
||||
// show web view (and parse markdown too)
|
||||
View container = getView().findViewById(R.id.file_view_webview_container);
|
||||
WebView webView = getView().findViewById(R.id.file_view_webview);
|
||||
View container = root.findViewById(R.id.file_view_webview_container);
|
||||
WebView webView = root.findViewById(R.id.file_view_webview);
|
||||
if (Arrays.asList("text/markdown", "text/md").contains(mediaType.toLowerCase())) {
|
||||
loadMarkdownFromFile(claimFile.getDownloadPath());
|
||||
} else {
|
||||
|
@ -1573,6 +1594,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
hideFloatingWalletBalance();
|
||||
container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -1644,6 +1666,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
}
|
||||
|
||||
LighthouseSearchTask relatedTask = new LighthouseSearchTask(
|
||||
title, RELATED_CONTENT_SIZE, 0, canShowMatureContent, claimId, relatedLoading, new ClaimSearchResultHandler() {
|
||||
@Override
|
||||
|
@ -1655,7 +1678,9 @@ public class FileViewFragment extends BaseFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
relatedContentAdapter = new ClaimListAdapter(filteredClaims, context);
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
relatedContentAdapter = new ClaimListAdapter(filteredClaims, ctx);
|
||||
relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
|
@ -1681,6 +1706,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
|
@ -1748,12 +1774,12 @@ public class FileViewFragment extends BaseFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
private void disableFullScreenMode() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
View root = getView();
|
||||
|
||||
RelativeLayout mediaContainer = root.findViewById(R.id.file_view_media_container);
|
||||
View exoplayerContainer = root.findViewById(R.id.file_view_exoplayer_container);
|
||||
((ViewGroup) exoplayerContainer.getParent()).removeView(exoplayerContainer);
|
||||
|
@ -2055,6 +2081,22 @@ public class FileViewFragment extends BaseFragment implements
|
|||
checkOwnClaim();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPortraitOrientationEntered() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity && ((MainActivity) context).isInFullscreenMode()) {
|
||||
disableFullScreenMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLandscapeOrientationEntered() {
|
||||
Context context = getContext();
|
||||
if (claim != null && claim.isPlayable() && context instanceof MainActivity && !((MainActivity) context).isInFullscreenMode()) {
|
||||
enableFullScreenMode();
|
||||
}
|
||||
}
|
||||
|
||||
private static class LbryWebViewClient extends WebViewClient {
|
||||
private Context context;
|
||||
public LbryWebViewClient(Context context) {
|
||||
|
|
Loading…
Reference in a new issue