From a42442b13b9aad1bb5fbc28eba239223acac50fd Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sun, 17 May 2020 20:52:38 +0100 Subject: [PATCH] Better handling of file view URLs. Some issue list fixes. --- .../java/io/lbry/browser/MainActivity.java | 3 +- .../ui/channel/ChannelFormFragment.java | 6 ++ .../ui/following/FileViewFragment.java | 72 ++++++++----------- .../browser/ui/wallet/InvitesFragment.java | 5 +- app/src/main/res/drawable/bg_small_icon.xml | 6 ++ .../main/res/layout/fragment_channel_form.xml | 40 +++++++---- app/src/main/res/values-night/colors.xml | 1 + app/src/main/res/values/colors.xml | 1 + 8 files changed, 75 insertions(+), 59 deletions(-) create mode 100644 app/src/main/res/drawable/bg_small_icon.xml diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 6f119af4..8af3048e 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -181,6 +181,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fragmentClassNavIdMap.put(AllContentFragment.class, NavMenuItem.ID_ITEM_ALL_CONTENT); fragmentClassNavIdMap.put(ChannelManagerFragment.class, NavMenuItem.ID_ITEM_CHANNELS); + fragmentClassNavIdMap.put(LibraryFragment.class, NavMenuItem.ID_ITEM_LIBRARY); fragmentClassNavIdMap.put(WalletFragment.class, NavMenuItem.ID_ITEM_WALLET); fragmentClassNavIdMap.put(RewardsFragment.class, NavMenuItem.ID_ITEM_REWARDS); @@ -190,11 +191,11 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fragmentClassNavIdMap.put(AboutFragment.class, NavMenuItem.ID_ITEM_ABOUT); // Internal (sub-)pages + fragmentClassNavIdMap.put(FileViewFragment.class, NavMenuItem.ID_ITEM_FOLLOWING); fragmentClassNavIdMap.put(ChannelFragment.class, NavMenuItem.ID_ITEM_FOLLOWING); fragmentClassNavIdMap.put(SearchFragment.class, NavMenuItem.ID_ITEM_FOLLOWING); } - public static final int REQUEST_STORAGE_PERMISSION = 1001; public static final int REQUEST_SIMPLE_SIGN_IN = 2001; public static final int REQUEST_WALLET_SYNC_SIGN_IN = 2002; diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java index 43fa49b8..6a3cc146 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java @@ -438,6 +438,12 @@ public class ChannelFormFragment extends BaseFragment implements Snackbar.make(getView(), R.string.image_upload_failed, Snackbar.LENGTH_LONG).setBackgroundTint( ContextCompat.getColor(context, R.color.red) ).show(); + if (coverFilePickerActive) { + // cover selected + imageCover.setImageResource(R.drawable.default_channel_cover); + } else if (thumbnailFilePickerActive) { + imageThumbnail.setImageDrawable(null); + } coverFilePickerActive = false; thumbnailFilePickerActive = false; uploading = false; diff --git a/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java index 0caf70cd..a5aa6602 100644 --- a/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java @@ -257,6 +257,8 @@ public class FileViewFragment extends BaseFragment implements // nothing at this location renderNothingAtLocation(); } + } else { + checkAndResetNowPlayingClaim(); } if (!Helper.isNullOrEmpty(currentUrl)) { @@ -266,6 +268,11 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { Helper.saveViewHistory(currentUrl, claim); renderClaim(); + if (claim.getFile() == null) { + loadFile(); + } else { + initialFileLoadDone = true; + } } checkIsFileComplete(); @@ -305,7 +312,6 @@ public class FileViewFragment extends BaseFragment implements } } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -337,11 +343,16 @@ public class FileViewFragment extends BaseFragment implements } private void checkAndResetNowPlayingClaim() { - if (MainActivity.nowPlayingClaim != null && claim != null && + if (MainActivity.nowPlayingClaim != null + && claim != null && !MainActivity.nowPlayingClaim.getClaimId().equalsIgnoreCase(claim.getClaimId())) { Context context = getContext(); if (context instanceof MainActivity) { - ((MainActivity) context).clearNowPlayingClaim(); + MainActivity activity = (MainActivity) context; + activity.clearNowPlayingClaim(); + if (claim != null && !claim.isPlayable()) { + activity.stopExoplayer(); + } } } } @@ -363,30 +374,6 @@ public class FileViewFragment extends BaseFragment implements resetPlayer(); } - private void loadClaimForCacheKey(ClaimCacheKey key, String url) { - if (Lbry.claimCache.containsKey(key)) { - claim = Lbry.claimCache.get(key); - Helper.saveUrlHistory(url, claim.getTitle(), UrlSuggestion.TYPE_FILE); - Helper.saveViewHistory(url, claim); - checkAndResetNowPlayingClaim(); - if (claim.getFile() == null) { - loadFile(); - } else { - initialFileLoadDone = true; - checkInitialFileLoadDone(); - } - renderClaim(); - } else { - Helper.saveUrlHistory(url, null, UrlSuggestion.TYPE_FILE); - getView().findViewById(R.id.file_view_claim_display_area).setVisibility(View.INVISIBLE); - Context context = getContext(); - if (context instanceof MainActivity) { - ((MainActivity) context).clearNowPlayingClaim(); - } - resolveUrl(url); - } - } - public void onSdkReady() { if (loadFilePending) { loadFile(); @@ -432,27 +419,16 @@ public class FileViewFragment extends BaseFragment implements checkIsFileComplete(); } initialFileLoadDone = true; - checkInitialFileLoadDone(); } @Override public void onError(Exception error) { initialFileLoadDone = true; - checkInitialFileLoadDone(); } }); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - private void checkInitialFileLoadDone() { - if (initialFileLoadDone) { - restoreMainActionButton(); - } - if (claim != null && claim.isFree() && (claim.isPlayable() || claim.isViewable())) { - onMainActionButtonClicked(); - } - } - public void openClaimUrl(String url) { resetViewCount(); currentUrl = url; @@ -832,7 +808,7 @@ public class FileViewFragment extends BaseFragment implements private void checkStoragePermissionAndFileGet() { Context context = getContext(); - if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { + if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { fileGetPending = true; MainActivity.requestPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE, @@ -840,6 +816,8 @@ public class FileViewFragment extends BaseFragment implements getString(R.string.storage_permission_rationale_download), context, true); + } else { + fileGet(true); } } @@ -1040,7 +1018,11 @@ public class FileViewFragment extends BaseFragment implements } } else if (claim.isViewable() && Lbry.SDK_READY) { onMainActionButtonClicked(); + } else if (!Lbry.SDK_READY) { + restoreMainActionButton(); } + } else { + restoreMainActionButton(); } RecyclerView relatedContentList = getView().findViewById(R.id.file_view_related_content_list); @@ -1192,6 +1174,11 @@ public class FileViewFragment extends BaseFragment implements // not free (and the user does not own the claim yet), perform a purchase confirmPurchaseUrl(); } else { + if (!claim.isPlayable() && !Lbry.SDK_READY) { + Snackbar.make(getView().findViewById(R.id.file_view_global_layout), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show(); + return; + } + getView().findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE); getView().findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE); handleMainActionForClaim(); @@ -1237,18 +1224,15 @@ public class FileViewFragment extends BaseFragment implements public void onSuccess(List files, boolean hasReachedEnd) { if (files.size() > 0) { claim.setFile(files.get(0)); + handleMainActionForClaim(); checkIsFileComplete(); } else { checkStoragePermissionAndFileGet(); } - initialFileLoadDone = true; - checkInitialFileLoadDone(); } @Override public void onError(Exception error) { - initialFileLoadDone = true; - checkInitialFileLoadDone(); checkStoragePermissionAndFileGet(); } }); @@ -1470,7 +1454,7 @@ public class FileViewFragment extends BaseFragment implements if (claim.getName().startsWith("@")) { activity.openChannelUrl(claim.getPermanentUrl()); } else { - openClaimUrl(claim.getPermanentUrl()); + activity.openFileUrl(claim.getPermanentUrl()); //openClaimUrl(claim.getPermanentUrl()); } } } diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java index ad19fb8f..3d0ac7fa 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/InvitesFragment.java @@ -248,7 +248,10 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, } private void updateInviteLink(Claim claim) { - String link = String.format(INVITE_LINK_FORMAT, claim.getName(), claim.getClaimId()); + LbryUri canonical = LbryUri.tryParse(claim.getCanonicalUrl()); + String link = String.format(INVITE_LINK_FORMAT, + canonical != null ? String.format("@%s", canonical.getChannelName()) : claim.getName(), + canonical != null ? canonical.getChannelClaimId() : claim.getClaimId()); textInviteLink.setText(link); } private void copyInviteLink() { diff --git a/app/src/main/res/drawable/bg_small_icon.xml b/app/src/main/res/drawable/bg_small_icon.xml new file mode 100644 index 00000000..c7ac9951 --- /dev/null +++ b/app/src/main/res/drawable/bg_small_icon.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_channel_form.xml b/app/src/main/res/layout/fragment_channel_form.xml index 8ee27cff..9d867b41 100644 --- a/app/src/main/res/layout/fragment_channel_form.xml +++ b/app/src/main/res/layout/fragment_channel_form.xml @@ -25,15 +25,22 @@ android:layout_height="match_parent" android:src="@drawable/default_channel_cover" android:scaleType="centerCrop" /> - + android:layout_alignParentBottom="true"> + + + - + android:layout_centerHorizontal="true"> + + diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index a58380f8..74026d86 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -12,6 +12,7 @@ #AAAAAA #0E0E0E #CC000000 + #55000000 #F4E866 #33000000 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2cf458cf..8f93dacb 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -12,6 +12,7 @@ #444444 #F1F1F1 #CC000000 + #55000000 #F4E866 #33000000