From 2231119d36fbdf8b03867cf7a8acdb235c3ce85e Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 22 May 2020 03:17:33 +0100 Subject: [PATCH] Implement file and channel page delete actions. UI action cleanup. --- .../java/io/lbry/browser/MainActivity.java | 50 +++-- .../io/lbry/browser/VerificationActivity.java | 3 +- .../browser/adapter/RewardListAdapter.java | 3 +- .../browser/listener/FetchClaimsListener.java | 9 + .../java/io/lbry/browser/ui/BaseFragment.java | 1 - .../browser/ui/channel/ChannelFragment.java | 52 ++++- .../AllContentFragment.java | 2 +- .../EditorsChoiceFragment.java | 2 +- .../FileViewFragment.java | 200 +++++++++++++----- .../FollowingFragment.java | 2 +- .../SearchFragment.java | 2 +- .../ui/publish/PublishFormFragment.java | 4 - .../EmailVerificationFragment.java | 10 +- .../PhoneVerificationFragment.java | 46 ++-- .../browser/ui/wallet/InvitesFragment.java | 3 +- .../browser/ui/wallet/RewardsFragment.java | 8 +- .../browser/ui/wallet/WalletFragment.java | 8 +- app/src/main/res/values/strings.xml | 8 + 18 files changed, 297 insertions(+), 116 deletions(-) create mode 100644 app/src/main/java/io/lbry/browser/listener/FetchClaimsListener.java rename app/src/main/java/io/lbry/browser/ui/{allcontent => findcontent}/AllContentFragment.java (99%) rename app/src/main/java/io/lbry/browser/ui/{editorschoice => findcontent}/EditorsChoiceFragment.java (99%) rename app/src/main/java/io/lbry/browser/ui/{following => findcontent}/FileViewFragment.java (91%) rename app/src/main/java/io/lbry/browser/ui/{following => findcontent}/FollowingFragment.java (99%) rename app/src/main/java/io/lbry/browser/ui/{search => findcontent}/SearchFragment.java (99%) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index cc50c4a9..4fb4c373 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -104,6 +104,7 @@ import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.CameraPermissionListener; 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.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; @@ -135,17 +136,17 @@ import io.lbry.browser.ui.BaseFragment; import io.lbry.browser.ui.channel.ChannelFormFragment; import io.lbry.browser.ui.channel.ChannelFragment; import io.lbry.browser.ui.channel.ChannelManagerFragment; -import io.lbry.browser.ui.editorschoice.EditorsChoiceFragment; -import io.lbry.browser.ui.following.FileViewFragment; -import io.lbry.browser.ui.following.FollowingFragment; +import io.lbry.browser.ui.findcontent.EditorsChoiceFragment; +import io.lbry.browser.ui.findcontent.FileViewFragment; +import io.lbry.browser.ui.findcontent.FollowingFragment; import io.lbry.browser.ui.library.LibraryFragment; import io.lbry.browser.ui.other.AboutFragment; import io.lbry.browser.ui.publish.PublishFormFragment; import io.lbry.browser.ui.publish.PublishFragment; import io.lbry.browser.ui.publish.PublishesFragment; -import io.lbry.browser.ui.search.SearchFragment; +import io.lbry.browser.ui.findcontent.SearchFragment; import io.lbry.browser.ui.other.SettingsFragment; -import io.lbry.browser.ui.allcontent.AllContentFragment; +import io.lbry.browser.ui.findcontent.AllContentFragment; import io.lbry.browser.ui.wallet.InvitesFragment; import io.lbry.browser.ui.wallet.RewardsFragment; import io.lbry.browser.ui.wallet.WalletFragment; @@ -294,6 +295,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener private List sdkStatusListeners; private List storagePermissionListeners; private List walletBalanceListeners; + private List fetchClaimsListeners; private List fetchChannelsListeners; @Getter private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); @@ -412,6 +414,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener sdkStatusListeners = new ArrayList<>(); storagePermissionListeners = new ArrayList<>(); walletBalanceListeners = new ArrayList<>(); + fetchClaimsListeners = new ArrayList<>(); fetchChannelsListeners = new ArrayList<>(); sdkStatusListeners.add(this); @@ -601,6 +604,15 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fetchChannelsListeners.remove(listener); } + public void addFetchClaimsListener(FetchClaimsListener listener) { + if (!fetchClaimsListeners.contains(listener)) { + fetchClaimsListeners.add(listener); + } + } + public void removeFetchClaimsListener(FetchClaimsListener listener) { + fetchClaimsListeners.remove(listener); + } + private void openSelectedMenuItem() { switch (selectedMenuItemId) { // TODO: reverse map lookup for class? @@ -830,9 +842,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener applyNavbarSigninPadding(); checkFirstRun(); checkNowPlaying(); - if (Lbryio.totalUnclaimedRewardAmount > 0) { - showFloatingUnclaimedRewards(); - } + fetchRewards(); // check (and start) the LBRY SDK service serviceRunning = isServiceRunning(this, LbrynetService.class); @@ -1326,7 +1336,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (getSupportFragmentManager().getBackStackEntryCount() == 0) { openFragment(FollowingFragment.class, false, NavMenuItem.ID_ITEM_FOLLOWING); - fetchRewards(); } } @@ -2157,13 +2166,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (Lbryio.totalUnclaimedRewardAmount > 0) { showFloatingUnclaimedRewards(); - double usdRewardAmount = Lbryio.totalUnclaimedRewardAmount * Lbryio.LBCUSDRate; - if (navMenuAdapter != null) { - navMenuAdapter.setExtraLabelForItem( - NavMenuItem.ID_ITEM_REWARDS, - Lbryio.LBCUSDRate > 0 ? String.format("$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(usdRewardAmount)) : null - ); - } + updateRewardsUsdVale(); } } @@ -2174,6 +2177,18 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + public void updateRewardsUsdVale() { + if (Lbryio.totalUnclaimedRewardAmount > 0) { + double usdRewardAmount = Lbryio.totalUnclaimedRewardAmount * Lbryio.LBCUSDRate; + if (navMenuAdapter != null) { + navMenuAdapter.setExtraLabelForItem( + NavMenuItem.ID_ITEM_REWARDS, + Lbryio.LBCUSDRate > 0 ? String.format("$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(usdRewardAmount)) : null + ); + } + } + } + public void showFloatingUnclaimedRewards() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); boolean notInterestedInRewards = sp.getBoolean(PREFERENCE_KEY_INTERNAL_REWARDS_NOT_INTERESTED, false); @@ -2647,6 +2662,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener @Override public void onSuccess(List claims) { Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims)); + for (FetchClaimsListener listener : fetchClaimsListeners) { + listener.onClaimsFetched(claims); + } } @Override diff --git a/app/src/main/java/io/lbry/browser/VerificationActivity.java b/app/src/main/java/io/lbry/browser/VerificationActivity.java index f616ffce..cf819cb6 100644 --- a/app/src/main/java/io/lbry/browser/VerificationActivity.java +++ b/app/src/main/java/io/lbry/browser/VerificationActivity.java @@ -239,7 +239,8 @@ public class VerificationActivity extends FragmentActivity implements SignInList } private void showFetchUserError(String message) { - Snackbar.make(findViewById(R.id.verification_pager), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); + Snackbar.make(findViewById(R.id.verification_pager), message, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); } @Override diff --git a/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java index 71d1bee2..f3895452 100644 --- a/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java @@ -197,7 +197,8 @@ public class RewardListAdapter extends RecyclerView.Adapter claims); +} diff --git a/app/src/main/java/io/lbry/browser/ui/BaseFragment.java b/app/src/main/java/io/lbry/browser/ui/BaseFragment.java index 9e16adc3..a6e6bd3e 100644 --- a/app/src/main/java/io/lbry/browser/ui/BaseFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/BaseFragment.java @@ -7,7 +7,6 @@ import androidx.fragment.app.Fragment; import java.util.Map; import io.lbry.browser.MainActivity; -import io.lbry.browser.ui.following.FileViewFragment; import lombok.Getter; import lombok.Setter; diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java index bfc43bd2..c06a50f8 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java @@ -1,7 +1,9 @@ package io.lbry.browser.ui.channel; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; @@ -9,8 +11,10 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -26,12 +30,12 @@ import com.google.android.material.tabs.TabLayoutMediator; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.Arrays; import java.util.List; import java.util.Map; import io.lbry.browser.MainActivity; import io.lbry.browser.R; -import io.lbry.browser.data.DatabaseHelper; import io.lbry.browser.dialog.SendTipDialogFragment; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.FetchChannelsListener; @@ -39,13 +43,15 @@ import io.lbry.browser.model.Claim; import io.lbry.browser.model.ClaimCacheKey; import io.lbry.browser.model.UrlSuggestion; import io.lbry.browser.model.lbryinc.Subscription; +import io.lbry.browser.tasks.claim.AbandonChannelTask; +import io.lbry.browser.tasks.claim.AbandonHandler; import io.lbry.browser.tasks.lbryinc.ChannelSubscribeTask; import io.lbry.browser.tasks.claim.ClaimListResultHandler; import io.lbry.browser.tasks.claim.ResolveTask; import io.lbry.browser.tasks.lbryinc.FetchStatCountTask; import io.lbry.browser.ui.BaseFragment; import io.lbry.browser.ui.controls.SolidIconView; -import io.lbry.browser.ui.following.FollowingFragment; +import io.lbry.browser.ui.findcontent.FollowingFragment; import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Lbry; import io.lbry.browser.utils.LbryAnalytics; @@ -122,8 +128,16 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen @Override public void onClick(View view) { if (claim != null) { - // show confirmation? - // delete claim task and redirect + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()). + setTitle(R.string.delete_channel). + setMessage(R.string.confirm_delete_channel) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + deleteCurrentClaim(); + } + }).setNegativeButton(R.string.no, null); + builder.show(); } } }); @@ -228,6 +242,33 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen return root; } + private void deleteCurrentClaim() { + if (claim != null) { + Helper.setViewVisibility(layoutDisplayArea, View.GONE); + Helper.setViewVisibility(layoutLoadingState, View.VISIBLE); + AbandonChannelTask task = new AbandonChannelTask(Arrays.asList(claim.getClaimId()), layoutResolving, new AbandonHandler() { + @Override + public void onComplete(List successfulClaimIds, List failedClaimIds, List errors) { + Context context = getContext(); + if (context instanceof MainActivity) { + if (failedClaimIds.size() == 0) { + MainActivity activity = (MainActivity) context; + activity.showMessage(R.string.channel_deleted); + activity.onBackPressed(); + } else { + View root = getView(); + if (root != null) { + Snackbar.make(root, R.string.channel_failed_delete, Toast.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } + } + } + } + }); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + private void checkIsFollowing() { if (claim != null) { boolean isFollowing = Lbryio.isFollowing(claim); @@ -324,7 +365,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen } private void resolveUrl() { - layoutDisplayArea.setVisibility(View.INVISIBLE); + Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE); + Helper.setViewVisibility(layoutLoadingState, View.VISIBLE); ResolveTask task = new ResolveTask(url, Lbry.LBRY_TV_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() { @Override public void onSuccess(List claims) { diff --git a/app/src/main/java/io/lbry/browser/ui/allcontent/AllContentFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java similarity index 99% rename from app/src/main/java/io/lbry/browser/ui/allcontent/AllContentFragment.java rename to app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java index 139b48c6..9eb90191 100644 --- a/app/src/main/java/io/lbry/browser/ui/allcontent/AllContentFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java @@ -1,4 +1,4 @@ -package io.lbry.browser.ui.allcontent; +package io.lbry.browser.ui.findcontent; import android.content.Context; import android.content.SharedPreferences; diff --git a/app/src/main/java/io/lbry/browser/ui/editorschoice/EditorsChoiceFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java similarity index 99% rename from app/src/main/java/io/lbry/browser/ui/editorschoice/EditorsChoiceFragment.java rename to app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java index aab5d4cc..cd8dd19e 100644 --- a/app/src/main/java/io/lbry/browser/ui/editorschoice/EditorsChoiceFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java @@ -1,4 +1,4 @@ -package io.lbry.browser.ui.editorschoice; +package io.lbry.browser.ui.findcontent; import android.content.Context; import android.content.SharedPreferences; diff --git a/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java similarity index 91% rename from app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java rename to app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index 9bf42718..1e64b58d 100644 --- a/app/src/main/java/io/lbry/browser/ui/following/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -1,4 +1,4 @@ -package io.lbry.browser.ui.following; +package io.lbry.browser.ui.findcontent; import android.Manifest; import android.annotation.SuppressLint; @@ -80,6 +80,7 @@ import io.lbry.browser.dialog.RepostClaimDialogFragment; 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.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; import io.lbry.browser.model.Claim; @@ -94,6 +95,8 @@ import io.lbry.browser.tasks.GenericTaskHandler; import io.lbry.browser.tasks.LighthouseSearchTask; import io.lbry.browser.tasks.ReadTextFileTask; import io.lbry.browser.tasks.SetSdkSettingTask; +import io.lbry.browser.tasks.claim.AbandonHandler; +import io.lbry.browser.tasks.claim.AbandonStreamTask; import io.lbry.browser.tasks.claim.ClaimListResultHandler; import io.lbry.browser.tasks.claim.ClaimSearchResultHandler; import io.lbry.browser.tasks.claim.ResolveTask; @@ -116,7 +119,7 @@ import io.lbry.lbrysdk.LbrynetService; import io.lbry.lbrysdk.Utils; public class FileViewFragment extends BaseFragment implements - MainActivity.BackPressInterceptor, DownloadActionListener, SdkStatusListener, StoragePermissionListener { + MainActivity.BackPressInterceptor, DownloadActionListener, FetchClaimsListener, SdkStatusListener, StoragePermissionListener { private static final int RELATED_CONTENT_SIZE = 16; private PlayerControlView castControlView; private Player currentPlayer; @@ -195,6 +198,7 @@ public class FileViewFragment extends BaseFragment implements MainActivity activity = (MainActivity) context; activity.setBackPressInterceptor(this); activity.addDownloadActionListener(this); + activity.addFetchClaimsListener(this); if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { activity.addStoragePermissionListener(this); } @@ -378,6 +382,7 @@ public class FileViewFragment extends BaseFragment implements if (loadFilePending) { loadFile(); } + checkOwnClaim(); } private String getStreamingUrl() { @@ -504,6 +509,7 @@ public class FileViewFragment extends BaseFragment implements if (context instanceof MainActivity) { MainActivity activity = (MainActivity) context; activity.removeDownloadActionListener(this); + activity.removeFetchClaimsListener(this); activity.removeSdkStatusListener(this); activity.removeStoragePermissionListener(this); } @@ -667,6 +673,21 @@ public class FileViewFragment extends BaseFragment implements } }); + root.findViewById(R.id.file_view_action_edit).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (!Lbry.SDK_READY) { + Snackbar.make(root.findViewById(R.id.file_view_claim_display_area), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show(); + return; + } + + Context context = getContext(); + if (claim != null && context instanceof MainActivity) { + ((MainActivity) context).openPublishForm(claim); + } + } + }); + root.findViewById(R.id.file_view_action_delete).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -675,16 +696,32 @@ public class FileViewFragment extends BaseFragment implements return; } - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()). - setTitle(R.string.delete_file). - setMessage(R.string.confirm_delete_file_message) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - deleteClaimFile(); - } - }).setNegativeButton(R.string.no, null); - builder.show(); + if (claim != null) { + boolean isOwnClaim = Lbry.ownClaims.contains(claim); + if (isOwnClaim) { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()). + setTitle(R.string.delete_content). + setMessage(R.string.confirm_delete_content_message) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + deleteCurrentClaim(); + } + }).setNegativeButton(R.string.no, null); + builder.show(); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()). + setTitle(R.string.delete_file). + setMessage(R.string.confirm_delete_file_message) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + deleteClaimFile(); + } + }).setNegativeButton(R.string.no, null); + builder.show(); + } + } } }); @@ -803,6 +840,30 @@ public class FileViewFragment extends BaseFragment implements relatedContentList.setLayoutManager(llm); } + private void deleteCurrentClaim() { + if (claim != null) { + Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE); + Helper.setViewVisibility(layoutLoadingState, View.VISIBLE); + Helper.setViewVisibility(layoutNothingAtLocation, View.GONE); + AbandonStreamTask task = new AbandonStreamTask(Arrays.asList(claim.getClaimId()), layoutResolving, new AbandonHandler() { + @Override + public void onComplete(List successfulClaimIds, List failedClaimIds, List errors) { + Context context = getContext(); + if (context instanceof MainActivity) { + if (failedClaimIds.size() == 0) { + MainActivity activity = (MainActivity) context; + activity.showMessage(R.string.content_deleted); + activity.onBackPressed(); + } else { + showError(getString(R.string.content_failed_delete)); + } + } + } + }); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + private void checkStoragePermissionAndStartDownload() { Context context = getContext(); if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { @@ -904,10 +965,13 @@ public class FileViewFragment extends BaseFragment implements @Override public void onSuccess() { - actionDelete.setVisibility(View.GONE); - getView().findViewById(R.id.file_view_action_download).setVisibility(View.VISIBLE); - getView().findViewById(R.id.file_view_unsupported_container).setVisibility(View.GONE); - actionDelete.setEnabled(true); + Helper.setViewVisibility(actionDelete, View.GONE); + View root = getView(); + if (root != null) { + root.findViewById(R.id.file_view_action_download).setVisibility(View.VISIBLE); + root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.GONE); + } + Helper.setViewEnabled(actionDelete, true); claim.setFile(null); Lbry.unsetFilesForCachedClaims(Arrays.asList(claim.getClaimId())); @@ -1057,6 +1121,7 @@ public class FileViewFragment extends BaseFragment implements loadRelatedContent(); } } + checkOwnClaim(); } private void showUnsupportedView() { @@ -1484,53 +1549,58 @@ public class FileViewFragment extends BaseFragment implements // reset the list view String title = claim.getTitle(); String claimId = claim.getClaimId(); - ProgressBar relatedLoading = getView().findViewById(R.id.file_view_related_content_progress); - - Context context = getContext(); - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); - boolean 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 - public void onSuccess(List claims, boolean hasReachedEnd) { - List filteredClaims = new ArrayList<>(); - for (Claim c : claims) { - if (!c.getClaimId().equalsIgnoreCase(claim.getClaimId())) { - filteredClaims.add(c); - } - } - - relatedContentAdapter = new ClaimListAdapter(filteredClaims, context); - relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() { - @Override - public void onClaimClicked(Claim claim) { - if (context instanceof MainActivity) { - MainActivity activity = (MainActivity) context; - if (claim.getName().startsWith("@")) { - activity.openChannelUrl(claim.getPermanentUrl()); - } else { - activity.openFileUrl(claim.getPermanentUrl()); //openClaimUrl(claim.getPermanentUrl()); - } + View root = getView(); + if (root != null) { + ProgressBar relatedLoading = root.findViewById(R.id.file_view_related_content_progress); + Context context = getContext(); + boolean canShowMatureContent = false; + if (context != null) { + 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 + public void onSuccess(List claims, boolean hasReachedEnd) { + List filteredClaims = new ArrayList<>(); + for (Claim c : claims) { + if (!c.getClaimId().equalsIgnoreCase(claim.getClaimId())) { + filteredClaims.add(c); } } - }); - View view = getView(); - if (view != null) { - RecyclerView relatedContentList = view.findViewById(R.id.file_view_related_content_list); - relatedContentList.setAdapter(relatedContentAdapter); - relatedContentAdapter.notifyDataSetChanged(); + relatedContentAdapter = new ClaimListAdapter(filteredClaims, context); + relatedContentAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() { + @Override + public void onClaimClicked(Claim claim) { + if (context instanceof MainActivity) { + MainActivity activity = (MainActivity) context; + if (claim.getName().startsWith("@")) { + activity.openChannelUrl(claim.getPermanentUrl()); + } else { + activity.openFileUrl(claim.getPermanentUrl()); //openClaimUrl(claim.getPermanentUrl()); + } + } + } + }); - Helper.setViewVisibility(view.findViewById(R.id.file_view_no_related_content), relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE); + View view = getView(); + if (view != null) { + RecyclerView relatedContentList = view.findViewById(R.id.file_view_related_content_list); + relatedContentList.setAdapter(relatedContentAdapter); + relatedContentAdapter.notifyDataSetChanged(); + + Helper.setViewVisibility(view.findViewById(R.id.file_view_no_related_content), relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE); + } } - } - @Override - public void onError(Exception error) { + @Override + public void onError(Exception error) { - } - }); - relatedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + }); + relatedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } } public boolean onBackPressed() { @@ -1888,6 +1958,11 @@ public class FileViewFragment extends BaseFragment implements } } + @Override + public void onClaimsFetched(List claims) { + checkOwnClaim(); + } + private static class LbryWebViewClient extends WebViewClient { private Context context; public LbryWebViewClient(Context context) { @@ -1928,4 +2003,17 @@ public class FileViewFragment extends BaseFragment implements public boolean shouldHideGlobalPlayer() { return true; } + + private void checkOwnClaim() { + if (claim != null) { + boolean isOwnClaim = Lbry.ownClaims.contains(claim); + View root = getView(); + if (root != null) { + Helper.setViewVisibility(root.findViewById(R.id.file_view_action_download), isOwnClaim ? View.GONE : View.VISIBLE); + Helper.setViewVisibility(root.findViewById(R.id.file_view_action_report), isOwnClaim ? View.GONE : View.VISIBLE); + Helper.setViewVisibility(root.findViewById(R.id.file_view_action_edit), isOwnClaim ? View.VISIBLE : View.GONE); + Helper.setViewVisibility(root.findViewById(R.id.file_view_action_delete), isOwnClaim ? View.VISIBLE : View.GONE); + } + } + } } diff --git a/app/src/main/java/io/lbry/browser/ui/following/FollowingFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java similarity index 99% rename from app/src/main/java/io/lbry/browser/ui/following/FollowingFragment.java rename to app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java index b64c6fe9..de7052ca 100644 --- a/app/src/main/java/io/lbry/browser/ui/following/FollowingFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java @@ -1,4 +1,4 @@ -package io.lbry.browser.ui.following; +package io.lbry.browser.ui.findcontent; import android.content.Context; import android.content.SharedPreferences; diff --git a/app/src/main/java/io/lbry/browser/ui/search/SearchFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/SearchFragment.java similarity index 99% rename from app/src/main/java/io/lbry/browser/ui/search/SearchFragment.java rename to app/src/main/java/io/lbry/browser/ui/findcontent/SearchFragment.java index 50fb3cfd..c938805b 100644 --- a/app/src/main/java/io/lbry/browser/ui/search/SearchFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/SearchFragment.java @@ -1,4 +1,4 @@ -package io.lbry.browser.ui.search; +package io.lbry.browser.ui.findcontent; import android.content.Context; import android.content.SharedPreferences; diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index af3e2f38..8c0b5266 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -1369,15 +1369,12 @@ public class PublishFormFragment extends BaseFragment implements return; } - android.util.Log.d("#HELP", "FilePicked: " + filePath); Context context = getContext(); if (context != null) { if (filePath.equalsIgnoreCase(lastSelectedThumbnailFile)) { // previous selected cover was uploaded successfully - android.util.Log.d("#HELP", "lastSelectedThumbnailFile the same"); return; } - android.util.Log.d("#HELP", "PickedFilePath=" + filePath); Uri fileUri = Uri.fromFile(new File(filePath)); Glide.with(context.getApplicationContext()).load(fileUri).centerCrop().into(imageThumbnail); @@ -1456,7 +1453,6 @@ public class PublishFormFragment extends BaseFragment implements "-pix_fmt yuv420p " + "-maxrate 5000K -bufsize 5000K " + "-movflags +faststart \"%s\"", filePath, scaleFlag, outputFilePath) : movFlagsCommand; - android.util.Log.d("#HELP", command); Config.enableStatisticsCallback(new StatisticsCallback() { @Override diff --git a/app/src/main/java/io/lbry/browser/ui/verification/EmailVerificationFragment.java b/app/src/main/java/io/lbry/browser/ui/verification/EmailVerificationFragment.java index 55f9a4f3..3721ca27 100644 --- a/app/src/main/java/io/lbry/browser/ui/verification/EmailVerificationFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/verification/EmailVerificationFragment.java @@ -1,5 +1,6 @@ package io.lbry.browser.ui.verification; +import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; @@ -95,7 +96,8 @@ public class EmailVerificationFragment extends Fragment { private void addEmail() { currentEmail = Helper.getValue(inputEmail.getText()); if (Helper.isNullOrEmpty(currentEmail) || currentEmail.indexOf("@") == -1) { - Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show(); + Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return; } @@ -125,7 +127,8 @@ public class EmailVerificationFragment extends Fragment { @Override public void onError(Exception error) { - Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show(); + Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); Helper.setViewVisibility(buttonContinue, View.VISIBLE); } }); @@ -188,7 +191,8 @@ public class EmailVerificationFragment extends Fragment { @Override public void onError(Exception error) { - Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show(); + Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); Helper.setViewEnabled(buttonResend, true); } }); diff --git a/app/src/main/java/io/lbry/browser/ui/verification/PhoneVerificationFragment.java b/app/src/main/java/io/lbry/browser/ui/verification/PhoneVerificationFragment.java index 77547269..72789af0 100644 --- a/app/src/main/java/io/lbry/browser/ui/verification/PhoneVerificationFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/verification/PhoneVerificationFragment.java @@ -74,7 +74,8 @@ public class PhoneVerificationFragment extends Fragment { currentPhoneNumber = Helper.getValue(inputPhoneNumber.getText()); if (Helper.isNullOrEmpty(currentPhoneNumber) || !countryCodePicker.isValidFullNumber()) { - Snackbar.make(getView(), R.string.please_enter_valid_phone, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); + Snackbar.make(getView(), R.string.please_enter_valid_phone, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return; } @@ -87,7 +88,8 @@ public class PhoneVerificationFragment extends Fragment { public void onClick(View view) { String code = Helper.getValue(inputVerificationCode.getText()); if (Helper.isNullOrEmpty(code)) { - Snackbar.make(getView(), R.string.please_enter_verification_code, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); + Snackbar.make(getView(), R.string.please_enter_verification_code, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return; } verifyPhoneNumber(code); @@ -109,8 +111,8 @@ public class PhoneVerificationFragment extends Fragment { PhoneNewVerifyTask task = new PhoneNewVerifyTask(currentCountryCode, currentPhoneNumber, null, newLoading, new GenericTaskHandler() { @Override public void beforeStart() { - continueButton.setEnabled(false); - continueButton.setVisibility(View.GONE); + Helper.setViewEnabled(continueButton, false); + Helper.setViewVisibility(continueButton, View.GONE); } @Override @@ -119,18 +121,21 @@ public class PhoneVerificationFragment extends Fragment { listener.onPhoneAdded(currentCountryCode, currentPhoneNumber); } - textVerifyParagraph.setText(getString(R.string.enter_phone_verify_code, countryCodePicker.getFullNumberWithPlus())); - layoutCollect.setVisibility(View.GONE); - layoutVerify.setVisibility(View.VISIBLE); - continueButton.setEnabled(true); - continueButton.setVisibility(View.VISIBLE); + Helper.setViewText(textVerifyParagraph, getString(R.string.enter_phone_verify_code, countryCodePicker.getFullNumberWithPlus())); + Helper.setViewVisibility(layoutCollect, View.GONE); + Helper.setViewVisibility(layoutVerify, View.VISIBLE); + Helper.setViewEnabled(continueButton, true); + Helper.setViewVisibility(continueButton, View.VISIBLE); } @Override public void onError(Exception error) { - Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); - continueButton.setEnabled(true); - continueButton.setVisibility(View.VISIBLE); + if (error != null && getView() != null) { + Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } + Helper.setViewEnabled(continueButton, true); + Helper.setViewVisibility(continueButton, View.VISIBLE); } }); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -140,8 +145,8 @@ public class PhoneVerificationFragment extends Fragment { PhoneNewVerifyTask task = new PhoneNewVerifyTask(currentCountryCode, currentPhoneNumber, verificationCode, verifyLoading, new GenericTaskHandler() { @Override public void beforeStart() { - verifyButton.setEnabled(false); - editButton.setEnabled(false); + Helper.setViewEnabled(verifyButton, false); + Helper.setViewEnabled(editButton, false); } @Override @@ -149,15 +154,18 @@ public class PhoneVerificationFragment extends Fragment { if (listener != null) { listener.onPhoneVerified(); } - verifyButton.setEnabled(true); - editButton.setEnabled(true); + Helper.setViewEnabled(verifyButton, true); + Helper.setViewEnabled(editButton, true); } @Override public void onError(Exception error) { - Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); - verifyButton.setEnabled(true); - editButton.setEnabled(true); + if (getView() != null && error != null) { + Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } + Helper.setViewEnabled(verifyButton, true); + Helper.setViewEnabled(editButton, true); } }); task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 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 13f57273..a718f106 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 @@ -565,7 +565,8 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener, private void showError(String message) { Context context = getContext(); if (context != null) { - Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); + Snackbar.make(getView(), message, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); } } } diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/RewardsFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/RewardsFragment.java index b0b27915..b404885b 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/RewardsFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/RewardsFragment.java @@ -237,6 +237,11 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R } catch (IllegalStateException ex) { // pass } + + Context context = getContext(); + if (context instanceof MainActivity) { + ((MainActivity) context).updateRewardsUsdVale(); + } } @Override @@ -278,7 +283,8 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R @Override public void onError(Exception error) { - Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show(); + Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); Helper.setViewEnabled(buttonClaim, true); Helper.setViewEnabled(inputClaimCode, true); rewardClaimInProgress = false; diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java index c1d035fb..41e24e52 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java @@ -198,7 +198,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W String amountString = Helper.getValue(inputSendAmount.getText()); if (!recipientAddress.matches(LbryUri.REGEX_ADDRESS)) { Snackbar.make(getView(), R.string.invalid_recipient_address, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).show(); + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return false; } @@ -208,13 +208,13 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W double availableAmount = Lbry.walletBalance.getAvailable().doubleValue(); if (availableAmount < amountValue) { Snackbar.make(getView(), R.string.insufficient_balance, Snackbar.LENGTH_LONG). - setBackgroundTint(getResources().getColor(R.color.red)).show(); + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return false; } } catch (NumberFormatException ex) { // pass Snackbar.make(getView(), R.string.invalid_amount, Snackbar.LENGTH_LONG). - setBackgroundTint(getResources().getColor(R.color.red)).show(); + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); return false; } } @@ -390,7 +390,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W @Override public void onError(Exception error) { Snackbar.make(getView(), R.string.send_credit_error, Snackbar.LENGTH_LONG). - setBackgroundTint(getResources().getColor(R.color.red)).show(); + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); enableSendControls(); } }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6f60f156..09916496 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,6 +74,10 @@ Are you sure you want to remove this file from your device? Failed to load %1$s. Please try again later. There is no cast session available at this time. + Delete content? + Are you sure you want to unpublish this content? No files will be removed from your device. + The content was successfully deleted from the blockchain. + The content could not be deleted at this time. Please try again later. %1$s view %1$s views @@ -390,6 +394,10 @@ Create a channel... Edit channel Delete selection? + Delete channel? + Are you sure you want to delete this channel? + The channel was successfully deleted. + The channel could not be deleted at this time. Please try again later. Description Yes No