Skip to content

Commit

Permalink
Merge pull request lbryio#1163 from lbryio/iap-check
Browse files Browse the repository at this point in the history
allow users to initiate a purchase flow check
  • Loading branch information
akinwale authored Mar 8, 2021
2 parents d0a8b3b + 0849ce2 commit e9d70db
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
43 changes: 42 additions & 1 deletion app/src/main/java/io/lbry/browser/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
import okhttp3.OkHttpClient;

import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.P;

public class MainActivity extends AppCompatActivity implements SdkStatusListener,
SharedPreferences.OnSharedPreferenceChangeListener,
Expand Down Expand Up @@ -1271,7 +1272,7 @@ public boolean isFirstRunCompleted() {
return sp.getBoolean(PREFERENCE_KEY_INTERNAL_FIRST_RUN_COMPLETED, false);
}

private void checkPurchases() {
public void checkPurchases() {
if (billingClient != null) {
Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
if (result.getPurchasesList() != null) {
Expand All @@ -1282,6 +1283,24 @@ private void checkPurchases() {
}
}

public void checkPurchases(GenericTaskHandler handler) {
boolean purchaseFound = false;
if (billingClient != null) {
Purchase.PurchasesResult result = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
if (result.getPurchasesList() != null) {
for (Purchase purchase : result.getPurchasesList()) {
handlePurchase(purchase, handler);
purchaseFound = true;
return;
}
}
}

if (!purchaseFound) {
handler.onError(new Exception(getString(R.string.skip_queue_purchase_not_found)));
}
}

private void handlePurchase(Purchase purchase) {
handleBillingPurchase(purchase, billingClient, MainActivity.this, null, new RewardVerifiedHandler() {
@Override
Expand All @@ -1298,6 +1317,28 @@ public void onError(Exception error) {
});
}

private void handlePurchase(Purchase purchase, GenericTaskHandler handler) {
handleBillingPurchase(purchase, billingClient, MainActivity.this, null, new RewardVerifiedHandler() {
@Override
public void onSuccess(RewardVerified rewardVerified) {
if (Lbryio.currentUser != null) {
Lbryio.currentUser.setRewardApproved(rewardVerified.isRewardApproved());
}

if (handler != null) {
handler.onSuccess();
}
}

@Override
public void onError(Exception error) {
if (handler != null) {
handler.onError(error);
}
}
});
}

private void checkPendingOpens() {
if (pendingFollowingReload) {
loadFollowingContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import com.google.android.material.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;

import io.lbry.browser.MainActivity;
import io.lbry.browser.R;
import io.lbry.browser.listener.SignInListener;
import io.lbry.browser.model.TwitterOauth;
import io.lbry.browser.model.lbryinc.RewardVerified;
import io.lbry.browser.tasks.GenericTaskHandler;
import io.lbry.browser.tasks.RewardVerifiedHandler;
import io.lbry.browser.tasks.TwitterOauthHandler;
import io.lbry.browser.tasks.lbryinc.TwitterVerifyTask;
Expand Down Expand Up @@ -69,6 +71,33 @@ public void onClick(View view) {
}
});

root.findViewById(R.id.verification_manual_skip_queue_verify).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showLoading();
if (MainActivity.instance != null) {
MainActivity.instance.checkPurchases(new GenericTaskHandler() {
@Override
public void beforeStart() {

}

@Override
public void onSuccess() {
hideLoading();
listener.onManualVerifyContinue();
}

@Override
public void onError(Exception error) {
hideLoading();
showError(error.getMessage());
}
});
}
}
});


root.findViewById(R.id.verification_manual_continue_button).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -267,6 +296,16 @@ private void handleFlowError(String extra) {
showFlowError(extra);
}

private void showError(String message) {
Context context = getContext();
View root = getView();
if (context != null && root != null) {
Snackbar.make(root, message, Snackbar.LENGTH_LONG).
setTextColor(Color.WHITE).
setBackgroundTint(Color.RED).show();
}
}

private void showFlowError(String extra) {
Context context = getContext();
View root = getView();
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/res/layout/fragment_verification_manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,22 @@
android:layout_marginTop="4dp"
android:fontFamily="@font/inter"
android:text="@string/skip_queue_button_text" />

<TextView
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="@font/inter"
android:text="@string/skip_queue_manual_check"
android:textColor="@color/white"
android:textFontWeight="300" />
<com.google.android.material.button.MaterialButton
android:id="@+id/verification_manual_skip_queue_verify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:fontFamily="@font/inter"
android:text="@string/verify_purchase" />

<TextView
android:textSize="20sp"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@
<string name="twitter_verify">Verify with Twitter</string>
<string name="skip_queue_verification">Skip the Queue</string>
<string name="skip_queue_verification_desc">Skip the manual verification queue by paying a fee in order to start participating in the rewards program immediately.</string>
<string name="skip_queue_manual_check">If you previously completed a purchase successfully and you still see this screen, please tap the verify purchase button below.</string>
<string name="skip_queue_purchase_not_found">No purchase was found for this account.</string>
<string name="verify_purchase">Verify Purchase</string>
<string name="request_to_be_verified">Please request to be verified on the &lt;a href="https://discordapp.com/invite/Z3bERWA"&gt;LBRY Discord server&lt;/a&gt;. A manual review can take anywhere from several minutes to several days.</string>
<string name="enjoy_free_content">Please enjoy free content in the meantime!</string>
<string name="verify_phone_number">Verify Phone Number</string>
Expand Down

0 comments on commit e9d70db

Please sign in to comment.