Instant verification (#974)
* add instant verification options and Google Play Billing bumpversion 0.15.16 --> 0.15.17 restore account_undergo_review default string twitter sign-in flow fix build error final changes update api key and secret * tweak build script
This commit is contained in:
parent
4d024c06cc
commit
6931dbe79c
29 changed files with 1042 additions and 72 deletions
app/src/main/java/io/lbry/browser
|
@ -47,6 +47,13 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.BillingClientStateListener;
|
||||
import com.android.billingclient.api.BillingResult;
|
||||
import com.android.billingclient.api.ConsumeParams;
|
||||
import com.android.billingclient.api.ConsumeResponseListener;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.PurchasesUpdatedListener;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
@ -140,10 +147,13 @@ import io.lbry.browser.model.WalletBalance;
|
|||
import io.lbry.browser.model.WalletSync;
|
||||
import io.lbry.browser.model.lbryinc.LbryNotification;
|
||||
import io.lbry.browser.model.lbryinc.Reward;
|
||||
import io.lbry.browser.model.lbryinc.RewardVerified;
|
||||
import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.tasks.RewardVerifiedHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.tasks.lbryinc.AndroidPurchaseTask;
|
||||
import io.lbry.browser.tasks.lbryinc.ClaimRewardTask;
|
||||
import io.lbry.browser.tasks.lbryinc.FetchRewardsTask;
|
||||
import io.lbry.browser.tasks.LighthouseAutoCompleteTask;
|
||||
|
@ -192,6 +202,7 @@ import okhttp3.OkHttpClient;
|
|||
|
||||
public class MainActivity extends AppCompatActivity implements SdkStatusListener {
|
||||
|
||||
static final String SKU_SKIP = "lbryskip";
|
||||
private Map<String, Class> specialRouteFragmentClassMap;
|
||||
@Getter
|
||||
private boolean inPictureInPictureMode;
|
||||
|
@ -213,7 +224,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
public static boolean startingPermissionRequest = false;
|
||||
public static boolean startingSignInFlowActivity = false;
|
||||
|
||||
|
||||
private BillingClient billingClient;
|
||||
@Getter
|
||||
private boolean enteringPIPMode = false;
|
||||
private boolean fullSyncInProgress = false;
|
||||
|
@ -408,6 +419,24 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// setup the billing client in main activity (to handle cases where the verification purchase flow may have been interrupted)
|
||||
billingClient = BillingClient.newBuilder(this)
|
||||
.setListener(new PurchasesUpdatedListener() {
|
||||
@Override
|
||||
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
|
||||
int responseCode = billingResult.getResponseCode();
|
||||
if (responseCode == BillingClient.BillingResponseCode.OK && purchases != null)
|
||||
{
|
||||
for (Purchase purchase : purchases) {
|
||||
handlePurchase(purchase);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.enablePendingPurchases()
|
||||
.build();
|
||||
establishBillingClientConnection();
|
||||
|
||||
playerNotificationManager = new PlayerNotificationManager(
|
||||
this, LbrynetService.NOTIFICATION_CHANNEL_ID, PLAYBACK_NOTIFICATION_ID, new PlayerNotificationDescriptionAdapter());
|
||||
|
||||
|
@ -1024,6 +1053,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
checkPurchases();
|
||||
enteringPIPMode = false;
|
||||
|
||||
applyNavbarSigninPadding();
|
||||
|
@ -1046,6 +1076,33 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
}*/
|
||||
}
|
||||
|
||||
private void checkPurchases() {
|
||||
if (billingClient != null) {
|
||||
Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
|
||||
if (result.getPurchasesList() != null) {
|
||||
for (Purchase purchase : result.getPurchasesList()) {
|
||||
handlePurchase(purchase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePurchase(Purchase purchase) {
|
||||
handleBillingPurchase(purchase, billingClient, MainActivity.this, null, new RewardVerifiedHandler() {
|
||||
@Override
|
||||
public void onSuccess(RewardVerified rewardVerified) {
|
||||
if (Lbryio.currentUser != null) {
|
||||
Lbryio.currentUser.setRewardApproved(rewardVerified.isRewardApproved());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
// pass
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkPendingOpens() {
|
||||
if (pendingFollowingReload) {
|
||||
loadFollowingContent();
|
||||
|
@ -2536,8 +2593,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// nope
|
||||
android.util.Log.e(TAG, String.format("App startup failed: %s", ex.getMessage()), ex);
|
||||
// nopecd
|
||||
Log.e(TAG, String.format("App startup failed: %s", ex.getMessage()), ex);
|
||||
return false;
|
||||
} finally {
|
||||
Helper.closeCloseable(reader);
|
||||
|
@ -3269,6 +3326,53 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
return (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED);
|
||||
}
|
||||
|
||||
private void establishBillingClientConnection() {
|
||||
if (billingClient != null) {
|
||||
billingClient.startConnection(new BillingClientStateListener() {
|
||||
@Override
|
||||
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
|
||||
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
|
||||
// no need to do anything here. purchases are always checked server-side
|
||||
checkPurchases();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingServiceDisconnected() {
|
||||
establishBillingClientConnection();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleBillingPurchase(
|
||||
Purchase purchase,
|
||||
BillingClient billingClient,
|
||||
Context context,
|
||||
View progressView,
|
||||
RewardVerifiedHandler handler) {
|
||||
String sku = purchase.getSku();
|
||||
if (SKU_SKIP.equalsIgnoreCase(sku)) {
|
||||
// send purchase token for verification
|
||||
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED
|
||||
/*&& isSignatureValid(purchase)*/) {
|
||||
// consume the purchase
|
||||
String purchaseToken = purchase.getPurchaseToken();
|
||||
ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build();
|
||||
billingClient.consumeAsync(consumeParams, new ConsumeResponseListener() {
|
||||
@Override
|
||||
public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String s) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// send the purchase token to the backend to complete verification
|
||||
AndroidPurchaseTask task = new AndroidPurchaseTask(purchaseToken, progressView, context, handler);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface BackPressInterceptor {
|
||||
boolean onBackPressed();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue