switch to fullscreen mode on rotate when viewing media #883

Merged
akinwale merged 1 commit from fullscreen-on-rotate into master 2020-05-23 10:03:01 +02:00
4 changed files with 137 additions and 68 deletions
Showing only changes of commit de4e6eee25 - Show all commits

View file

@ -52,7 +52,7 @@ task printVersionName {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) 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 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha06' implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation "androidx.cardview:cardview:1.0.0" implementation "androidx.cardview:cardview:1.0.0"

View file

@ -111,6 +111,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.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;
import io.lbry.browser.listener.WalletBalanceListener; import io.lbry.browser.listener.WalletBalanceListener;
@ -173,6 +174,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private Map<String, Class> specialRouteFragmentClassMap; private Map<String, Class> specialRouteFragmentClassMap;
private boolean inPictureInPictureMode; private boolean inPictureInPictureMode;
@Getter
private boolean inFullscreenMode;
public static SimpleExoPlayer appPlayer; public static SimpleExoPlayer appPlayer;
public static Cache playerCache; public static Cache playerCache;
public static boolean playerReassigned; public static boolean playerReassigned;
@ -300,6 +303,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<ScreenOrientationListener> screenOrientationListeners;
private List<SdkStatusListener> sdkStatusListeners; private List<SdkStatusListener> sdkStatusListeners;
private List<StoragePermissionListener> storagePermissionListeners; private List<StoragePermissionListener> storagePermissionListeners;
private List<WalletBalanceListener> walletBalanceListeners; private List<WalletBalanceListener> walletBalanceListeners;
@ -394,31 +398,19 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
// setup uri bar // setup uri bar
setupUriBar(); 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 // other
pendingSyncSetQueue = new ArrayList<>(); pendingSyncSetQueue = new ArrayList<>();
openNavFragments = new HashMap<>(); openNavFragments = new HashMap<>();
cameraPermissionListeners = new ArrayList<>(); cameraPermissionListeners = new ArrayList<>();
downloadActionListeners = new ArrayList<>(); downloadActionListeners = new ArrayList<>();
fetchChannelsListeners = new ArrayList<>();
fetchClaimsListeners = new ArrayList<>();
filePickerListeners = new ArrayList<>(); filePickerListeners = new ArrayList<>();
screenOrientationListeners = new ArrayList<>();
sdkStatusListeners = new ArrayList<>(); sdkStatusListeners = new ArrayList<>();
storagePermissionListeners = new ArrayList<>(); storagePermissionListeners = new ArrayList<>();
walletBalanceListeners = new ArrayList<>(); walletBalanceListeners = new ArrayList<>();
fetchClaimsListeners = new ArrayList<>();
fetchChannelsListeners = new ArrayList<>();
sdkStatusListeners.add(this); sdkStatusListeners.add(this);
@ -531,14 +523,30 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
checkNotificationOpenIntent(intent); checkNotificationOpenIntent(intent);
} }
public void addCameraPermissionListener(CameraPermissionListener listener) { public void onConfigurationChanged(Configuration newConfig) {
if (!cameraPermissionListeners.contains(listener)) { super.onConfigurationChanged(newConfig);
cameraPermissionListeners.add(listener); 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) { public void addScreenOrientationListener(ScreenOrientationListener listener) {
cameraPermissionListeners.remove(listener); if (!screenOrientationListeners.contains(listener)) {
screenOrientationListeners.add(listener);
}
}
public void removeScreenOrientationListener(ScreenOrientationListener listener) {
screenOrientationListeners.remove(listener);
} }
public void addDownloadActionListener(DownloadActionListener listener) { public void addDownloadActionListener(DownloadActionListener listener) {
@ -561,6 +569,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
filePickerListeners.remove(listener); 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) { public void addSdkStatusListener(SdkStatusListener listener) {
if (!sdkStatusListeners.contains(listener)) { if (!sdkStatusListeners.contains(listener)) {
sdkStatusListeners.add(listener); sdkStatusListeners.add(listener);
@ -764,7 +783,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private void renderFullMode() { private void renderFullMode() {
getSupportActionBar().show(); getSupportActionBar().show();
findViewById(R.id.content_main).setVisibility(View.VISIBLE); 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(); Fragment fragment = getCurrentFragment();
if (!(fragment instanceof FileViewFragment)) { if (!(fragment instanceof FileViewFragment)) {
findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE); findViewById(R.id.global_now_playing_card).setVisibility(View.VISIBLE);
@ -1294,6 +1313,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
} }
public void enterFullScreenMode() { public void enterFullScreenMode() {
inFullscreenMode = true;
hideFloatingWalletBalance(); hideFloatingWalletBalance();
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
@ -1337,6 +1357,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (actionBar != null) { if (actionBar != null) {
actionBar.show(); actionBar.show();
} }
inFullscreenMode = false;
} }
private void initKeyStore() { private void initKeyStore() {

View file

@ -0,0 +1,6 @@
package io.lbry.browser.listener;
public interface ScreenOrientationListener {
void onPortraitOrientationEntered();
void onLandscapeOrientationEntered();
}

View file

@ -94,6 +94,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.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;
import io.lbry.browser.model.Claim; import io.lbry.browser.model.Claim;
@ -135,7 +136,11 @@ 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, FetchClaimsListener, SdkStatusListener, StoragePermissionListener { MainActivity.BackPressInterceptor, DownloadActionListener,
FetchClaimsListener,
ScreenOrientationListener,
SdkStatusListener,
StoragePermissionListener {
private static final int RELATED_CONTENT_SIZE = 16; private static final int RELATED_CONTENT_SIZE = 16;
private static final String DEFAULT_PLAYBACK_SPEED = "1x"; private static final String DEFAULT_PLAYBACK_SPEED = "1x";
@ -218,6 +223,7 @@ public class FileViewFragment extends BaseFragment implements
MainActivity activity = (MainActivity) context; MainActivity activity = (MainActivity) context;
activity.setBackPressInterceptor(this); activity.setBackPressInterceptor(this);
activity.addDownloadActionListener(this); activity.addDownloadActionListener(this);
activity.addScreenOrientationListener(this);
activity.addFetchClaimsListener(this); activity.addFetchClaimsListener(this);
if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
activity.addStoragePermissionListener(this); activity.addStoragePermissionListener(this);
@ -290,6 +296,7 @@ public class FileViewFragment extends BaseFragment implements
if (claim != null) { if (claim != null) {
Helper.saveViewHistory(currentUrl, claim); Helper.saveViewHistory(currentUrl, claim);
checkAndLoadRelatedContent();
renderClaim(); renderClaim();
if (claim.getFile() == null) { if (claim.getFile() == null) {
loadFile(); loadFile();
@ -352,8 +359,8 @@ public class FileViewFragment extends BaseFragment implements
} }
} }
private void initWebView(View view) { private void initWebView(View root) {
WebView webView = view.findViewById(R.id.file_view_webview); WebView webView = root.findViewById(R.id.file_view_webview);
webView.setWebViewClient(new LbryWebViewClient(getContext())); webView.setWebViewClient(new LbryWebViewClient(getContext()));
WebSettings webSettings = webView.getSettings(); WebSettings webSettings = webView.getSettings();
webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccess(true);
@ -389,6 +396,7 @@ public class FileViewFragment extends BaseFragment implements
logUrlEvent(url); logUrlEvent(url);
resetViewCount(); resetViewCount();
resetFee(); resetFee();
View root = getView(); View root = getView();
if (root != null) { if (root != null) {
((RecyclerView) root.findViewById(R.id.file_view_related_content_list)).setAdapter(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) { if (claim != null) {
Helper.saveViewHistory(url, claim); Helper.saveViewHistory(url, claim);
checkAndLoadRelatedContent();
renderClaim(); renderClaim();
} }
} }
@ -531,8 +540,10 @@ 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.removeScreenOrientationListener(this);
activity.removeSdkStatusListener(this); activity.removeSdkStatusListener(this);
activity.removeStoragePermissionListener(this); activity.removeStoragePermissionListener(this);
//activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
} }
} }
@ -578,6 +589,8 @@ public class FileViewFragment extends BaseFragment implements
checkAndResetNowPlayingClaim(); checkAndResetNowPlayingClaim();
loadFile(); loadFile();
checkAndLoadRelatedContent();
renderClaim(); renderClaim();
} else { } else {
// render nothing at location // render nothing at location
@ -594,8 +607,6 @@ public class FileViewFragment extends BaseFragment implements
} }
private void initUi(View root) { private void initUi(View root) {
initWebView(root);
buttonPublishSomething.setOnClickListener(new View.OnClickListener() { buttonPublishSomething.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -1189,13 +1200,18 @@ public class FileViewFragment extends BaseFragment implements
} else { } else {
restoreMainActionButton(); restoreMainActionButton();
} }
}
checkOwnClaim();
}
private void checkAndLoadRelatedContent() {
View root = getView();
if (root != null) {
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list); RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
if (relatedContentList == null || relatedContentList.getAdapter() == null || relatedContentList.getAdapter().getItemCount() == 0) { if (relatedContentList == null || relatedContentList.getAdapter() == null || relatedContentList.getAdapter().getItemCount() == 0) {
loadRelatedContent(); loadRelatedContent();
} }
} }
checkOwnClaim();
} }
private void showUnsupportedView() { private void showUnsupportedView() {
@ -1553,25 +1569,31 @@ public class FileViewFragment extends BaseFragment implements
if (!fileExists) { if (!fileExists) {
showError(getString(R.string.claim_file_not_found, claimFile != null ? claimFile.getDownloadPath() : "")); showError(getString(R.string.claim_file_not_found, claimFile != null ? claimFile.getDownloadPath() : ""));
} else if (fileUri != null) { } else if (fileUri != null) {
if (mediaType.startsWith("image")) { View root = getView();
// display the image Context context = getContext();
View container = getView().findViewById(R.id.file_view_imageviewer_container); if (root != null) {
PhotoView photoView = getView().findViewById(R.id.file_view_imageviewer); if (mediaType.startsWith("image")) {
// display the image
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) {
hideFloatingWalletBalance(); Glide.with(context.getApplicationContext()).load(fileUri).centerInside().into(photoView);
container.setVisibility(View.VISIBLE); }
} else if (mediaType.startsWith("text")) { hideFloatingWalletBalance();
// show web view (and parse markdown too) container.setVisibility(View.VISIBLE);
View container = getView().findViewById(R.id.file_view_webview_container); } else if (mediaType.startsWith("text")) {
WebView webView = getView().findViewById(R.id.file_view_webview); // show web view (and parse markdown too)
if (Arrays.asList("text/markdown", "text/md").contains(mediaType.toLowerCase())) { View container = root.findViewById(R.id.file_view_webview_container);
loadMarkdownFromFile(claimFile.getDownloadPath()); WebView webView = root.findViewById(R.id.file_view_webview);
} else { if (Arrays.asList("text/markdown", "text/md").contains(mediaType.toLowerCase())) {
webView.loadUrl(fileUri.toString()); loadMarkdownFromFile(claimFile.getDownloadPath());
} else {
webView.loadUrl(fileUri.toString());
}
hideFloatingWalletBalance();
container.setVisibility(View.VISIBLE);
} }
hideFloatingWalletBalance();
container.setVisibility(View.VISIBLE);
} }
handled = true; handled = true;
} }
@ -1644,6 +1666,7 @@ public class FileViewFragment extends BaseFragment implements
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false); canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
} }
LighthouseSearchTask relatedTask = new LighthouseSearchTask( LighthouseSearchTask relatedTask = new LighthouseSearchTask(
title, RELATED_CONTENT_SIZE, 0, canShowMatureContent, claimId, relatedLoading, new ClaimSearchResultHandler() { title, RELATED_CONTENT_SIZE, 0, canShowMatureContent, claimId, relatedLoading, new ClaimSearchResultHandler() {
@Override @Override
@ -1655,30 +1678,33 @@ public class FileViewFragment extends BaseFragment implements
} }
} }
relatedContentAdapter = new ClaimListAdapter(filteredClaims, context); Context ctx = getContext();
relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() { if (ctx != null) {
@Override relatedContentAdapter = new ClaimListAdapter(filteredClaims, ctx);
public void onClaimClicked(Claim claim) { relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
if (context instanceof MainActivity) { @Override
MainActivity activity = (MainActivity) context; public void onClaimClicked(Claim claim) {
if (claim.getName().startsWith("@")) { if (context instanceof MainActivity) {
activity.openChannelUrl(claim.getPermanentUrl()); MainActivity activity = (MainActivity) context;
} else { if (claim.getName().startsWith("@")) {
activity.openFileUrl(claim.getPermanentUrl()); //openClaimUrl(claim.getPermanentUrl()); activity.openChannelUrl(claim.getPermanentUrl());
} else {
activity.openFileUrl(claim.getPermanentUrl()); //openClaimUrl(claim.getPermanentUrl());
}
} }
} }
});
View v = getView();
if (v != null) {
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
relatedContentList.setAdapter(relatedContentAdapter);
relatedContentAdapter.notifyDataSetChanged();
Helper.setViewVisibility(
v.findViewById(R.id.file_view_no_related_content),
relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
} }
});
View v = getView();
if (v != null) {
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
relatedContentList.setAdapter(relatedContentAdapter);
relatedContentAdapter.notifyDataSetChanged();
Helper.setViewVisibility(
v.findViewById(R.id.file_view_no_related_content),
relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
} }
} }
@ -1748,12 +1774,12 @@ public class FileViewFragment extends BaseFragment implements
} }
} }
@SuppressLint("SourceLockedOrientationActivity")
private void disableFullScreenMode() { private void disableFullScreenMode() {
Context context = getContext(); Context context = getContext();
if (context instanceof MainActivity) { if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context; MainActivity activity = (MainActivity) context;
View root = getView(); View root = getView();
RelativeLayout mediaContainer = root.findViewById(R.id.file_view_media_container); RelativeLayout mediaContainer = root.findViewById(R.id.file_view_media_container);
View exoplayerContainer = root.findViewById(R.id.file_view_exoplayer_container); View exoplayerContainer = root.findViewById(R.id.file_view_exoplayer_container);
((ViewGroup) exoplayerContainer.getParent()).removeView(exoplayerContainer); ((ViewGroup) exoplayerContainer.getParent()).removeView(exoplayerContainer);
@ -2055,6 +2081,22 @@ public class FileViewFragment extends BaseFragment implements
checkOwnClaim(); 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 static class LbryWebViewClient extends WebViewClient {
private Context context; private Context context;
public LbryWebViewClient(Context context) { public LbryWebViewClient(Context context) {