From 03764f64b95f2388d2038448e1e342f7c3bb07f5 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 22 May 2020 15:01:01 +0100 Subject: [PATCH] Claim new_android reward. Use canonical_url for share links. --- .../java/io/lbry/browser/MainActivity.java | 41 +++++++++++++++++++ .../browser/ui/channel/ChannelFragment.java | 3 +- .../ui/findcontent/FileViewFragment.java | 3 +- .../browser/ui/wallet/RewardsFragment.java | 5 ++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index d65db3e8..ed711318 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -87,6 +87,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.net.ConnectException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -124,6 +125,7 @@ import io.lbry.browser.model.lbryinc.Reward; import io.lbry.browser.model.lbryinc.Subscription; import io.lbry.browser.tasks.claim.ClaimListResultHandler; import io.lbry.browser.tasks.claim.ClaimListTask; +import io.lbry.browser.tasks.lbryinc.ClaimRewardTask; import io.lbry.browser.tasks.lbryinc.FetchRewardsTask; import io.lbry.browser.tasks.LighthouseAutoCompleteTask; import io.lbry.browser.tasks.MergeSubscriptionsTask; @@ -262,6 +264,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener public static final String PREFERENCE_KEY_INTERNAL_WALLET_SYNC_ENABLED = "io.lbry.browser.preference.internal.WalletSyncEnabled"; public static final String PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS = "io.lbry.browser.preference.internal.WalletReceiveAddress"; public static final String PREFERENCE_KEY_INTERNAL_REWARDS_NOT_INTERESTED = "io.lbry.browser.preference.internal.RewardsNotInterested"; + public static final String PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED = "io.lbry.browser.preference.internal.NewAndroidRewardClaimed"; public static final String PREFERENCE_KEY_INTERNAL_FIRST_RUN_COMPLETED = "io.lbry.browser.preference.internal.FirstRunCompleted"; public static final String PREFERENCE_KEY_INTERNAL_FIRST_AUTH_COMPLETED = "io.lbry.browser.preference.internal.FirstAuthCompleted"; @@ -1419,6 +1422,44 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fetchOwnClaims(); initFloatingWalletBalance(); + + checkAndClaimNewAndroidReward(); + } + + public void checkAndClaimNewAndroidReward() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + boolean rewardClaimed = sp.getBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, false); + if (!rewardClaimed) { + ClaimRewardTask task = new ClaimRewardTask( + Reward.TYPE_NEW_ANDROID, + null, + null, + this, + new ClaimRewardTask.ClaimRewardHandler() { + @Override + public void onSuccess(double amountClaimed, String message) { + if (Helper.isNullOrEmpty(message)) { + message = getResources().getQuantityString( + R.plurals.claim_reward_message, + amountClaimed == 1 ? 1 : 2, + new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed)); + } + Snackbar.make(findViewById(R.id.content_main), message, Snackbar.LENGTH_LONG).show(); + if (sp != null) { + sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, true).apply(); + } + } + + @Override + public void onError(Exception error) { + // pass. fail silently + if (sp != null) { + sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_NEW_ANDROID_REWARD_CLAIMED, true).apply(); + } + } + }); + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } } public void initMediaSession() { 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 ddd41dcd..3299aec7 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 @@ -147,7 +147,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen if (claim != null) { try { String shareUrl = LbryUri.parse( - !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()).toTvString(); + !Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() : + (!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toTvString(); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index a16d5cda..a11355e5 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -634,7 +634,8 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { try { String shareUrl = LbryUri.parse( - !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()).toTvString(); + !Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() : + (!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toTvString(); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); 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 b404885b..eee6ebb0 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 @@ -273,7 +273,10 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R amountClaimed == 1 ? 1 : 2, new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed)); } - Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).show(); + View view = getView(); + if (view != null) { + Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); + } Helper.setViewEnabled(buttonClaim, true); Helper.setViewEnabled(inputClaimCode, true); rewardClaimInProgress = false;