Search in sources :

Example 1 with RewardVerified

use of com.odysee.app.model.lbryinc.RewardVerified in project odysee-android by OdyseeTeam.

the class TwitterVerifyTask method doInBackground.

protected RewardVerified doInBackground(Void... params) {
    try {
        Map<String, String> options = new HashMap<>();
        options.put("oauth_token", twitterOauth.getOauthToken());
        options.put("oauth_token_secret", twitterOauth.getOauthTokenSecret());
        JSONObject object = (JSONObject) Lbryio.parseResponse(Lbryio.call("verification", "twitter_verify", options, context));
        Type type = new TypeToken<RewardVerified>() {
        }.getType();
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        return gson.fromJson(object.toString(), type);
    } catch (Exception ex) {
        error = ex;
        return null;
    }
}
Also used : Type(java.lang.reflect.Type) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) RewardVerified(com.odysee.app.model.lbryinc.RewardVerified) Gson(com.google.gson.Gson)

Example 2 with RewardVerified

use of com.odysee.app.model.lbryinc.RewardVerified in project odysee-android by OdyseeTeam.

the class AndroidPurchaseTask method doInBackground.

protected RewardVerified doInBackground(Void... params) {
    try {
        Map<String, String> options = new HashMap<>();
        options.put("purchase_token", purchaseToken);
        JSONObject object = (JSONObject) Lbryio.parseResponse(Lbryio.call("verification", "android_purchase", options, context));
        Type type = new TypeToken<RewardVerified>() {
        }.getType();
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        return gson.fromJson(object.toString(), type);
    } catch (Exception ex) {
        error = ex;
        return null;
    }
}
Also used : Type(java.lang.reflect.Type) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) RewardVerified(com.odysee.app.model.lbryinc.RewardVerified) Gson(com.google.gson.Gson)

Example 3 with RewardVerified

use of com.odysee.app.model.lbryinc.RewardVerified in project odysee-android by OdyseeTeam.

the class ManualVerificationFragment method twitterVerify.

private void twitterVerify(TwitterOauth twitterOauth) {
    Context context = getContext();
    if (context != null) {
        showLoading();
        twitterOauthInProgress = true;
        if (listener != null) {
            listener.onManualProgress(twitterOauthInProgress);
        }
        TwitterVerifyTask task = new TwitterVerifyTask(twitterOauth, null, context, new RewardVerifiedHandler() {

            @Override
            public void onSuccess(RewardVerified rewardVerified) {
                twitterOauthInProgress = false;
                if (listener != null) {
                    listener.onManualProgress(twitterOauthInProgress);
                }
                if (Lbryio.currentUser != null) {
                    Lbryio.currentUser.setRewardApproved(rewardVerified.isRewardApproved());
                }
                if (rewardVerified.isRewardApproved()) {
                    if (listener != null) {
                        listener.onTwitterVerified();
                    }
                } else {
                    View root = getView();
                    if (root != null) {
                        // reward approved wasn't set to true
                        Snackbar.make(root, getString(R.string.twitter_verification_not_approved), Snackbar.LENGTH_LONG).setTextColor(Color.WHITE).setBackgroundTint(Color.RED).show();
                    }
                    hideLoading();
                }
            }

            @Override
            public void onError(Exception error) {
                handleFlowError(error != null ? error.getMessage() : null);
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        twitterOauthInProgress = false;
        if (listener != null) {
            listener.onManualProgress(twitterOauthInProgress);
        }
        hideLoading();
    }
}
Also used : Context(android.content.Context) TwitterVerifyTask(com.odysee.app.tasks.lbryinc.TwitterVerifyTask) RewardVerifiedHandler(com.odysee.app.tasks.RewardVerifiedHandler) RewardVerified(com.odysee.app.model.lbryinc.RewardVerified) View(android.view.View) WebView(android.webkit.WebView)

Example 4 with RewardVerified

use of com.odysee.app.model.lbryinc.RewardVerified in project odysee-android by OdyseeTeam.

the class VerificationActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    verificationSkipQueue = new VerificationSkipQueue(this, new VerificationSkipQueue.ShowInProgressListener() {

        @Override
        public void maybeShowRequestInProgress() {
            showLoading();
        }
    }, new RewardVerifiedHandler() {

        @Override
        public void onSuccess(RewardVerified rewardVerified) {
            if (Lbryio.currentUser != null) {
                Lbryio.currentUser.setRewardApproved(rewardVerified.isRewardApproved());
            }
            if (!rewardVerified.isRewardApproved()) {
                // show pending purchase message (possible slow card tx)
                Snackbar.make(findViewById(R.id.verification_pager), R.string.purchase_request_pending, Snackbar.LENGTH_LONG).show();
            } else {
                Snackbar.make(findViewById(R.id.verification_pager), R.string.reward_verification_successful, Snackbar.LENGTH_LONG).show();
            }
            setResult(RESULT_OK);
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    finish();
                }
            }, 3000);
        }

        @Override
        public void onError(Exception error) {
            showFetchUserError(getString(R.string.purchase_request_failed_error));
            hideLoading();
        }
    });
    verificationSkipQueue.createBillingClientAndEstablishConnection();
    signedIn = Lbryio.isSignedIn();
    Intent intent = getIntent();
    if (intent != null) {
        flow = intent.getIntExtra("flow", -1);
        if (flow == -1 || (flow == VERIFICATION_FLOW_SIGN_IN && signedIn)) {
            // no flow specified (or user is already signed in), just exit
            setResult(signedIn ? RESULT_OK : RESULT_CANCELED);
            finish();
            return;
        }
    }
    if (!Arrays.asList(VERIFICATION_FLOW_SIGN_IN, VERIFICATION_FLOW_REWARDS, VERIFICATION_FLOW_WALLET).contains(flow)) {
        // invalid flow specified
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    IntentFilter filter = new IntentFilter();
    setContentView(R.layout.activity_verification);
    ViewPager2 viewPager = findViewById(R.id.verification_pager);
    viewPager.setUserInputEnabled(false);
    viewPager.setSaveEnabled(false);
    viewPager.setAdapter(new VerificationPagerAdapter(this));
    findViewById(R.id.verification_close_button).setVisibility(View.VISIBLE);
    findViewById(R.id.verification_close_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });
}
Also used : IntentFilter(android.content.IntentFilter) VerificationSkipQueue(com.odysee.app.utils.VerificationSkipQueue) RewardVerifiedHandler(com.odysee.app.tasks.RewardVerifiedHandler) Handler(android.os.Handler) RewardVerifiedHandler(com.odysee.app.tasks.RewardVerifiedHandler) Intent(android.content.Intent) View(android.view.View) ViewPager2(androidx.viewpager2.widget.ViewPager2) VerificationPagerAdapter(com.odysee.app.adapter.VerificationPagerAdapter) RewardVerified(com.odysee.app.model.lbryinc.RewardVerified)

Example 5 with RewardVerified

use of com.odysee.app.model.lbryinc.RewardVerified in project odysee-android by OdyseeTeam.

the class FirstRunActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setDefaultNightMode(isDarkMode() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
    if (Build.VERSION.SDK_INT >= M && !isDarkMode()) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }
    setContentView(R.layout.activity_first_run);
    verificationSkipQueue = new VerificationSkipQueue(this, new VerificationSkipQueue.ShowInProgressListener() {

        @Override
        public void maybeShowRequestInProgress() {
            if (currentStep == FIRST_RUN_STEP_REWARDS) {
                onRequestInProgress(true);
            }
        }
    }, new RewardVerifiedHandler() {

        @Override
        public void onSuccess(RewardVerified rewardVerified) {
            if (Lbryio.currentUser != null) {
                Lbryio.currentUser.setRewardApproved(rewardVerified.isRewardApproved());
            }
            if (!rewardVerified.isRewardApproved()) {
                // show pending purchase message (possible slow card tx)
                Snackbar.make(findViewById(R.id.first_run_pager), R.string.purchase_request_pending, Snackbar.LENGTH_LONG).show();
            } else {
                Snackbar.make(findViewById(R.id.first_run_pager), R.string.reward_verification_successful, Snackbar.LENGTH_LONG).show();
            }
            if (currentStep == FIRST_RUN_STEP_REWARDS) {
                onRequestCompleted(FIRST_RUN_STEP_REWARDS);
            }
        }

        @Override
        public void onError(Exception error) {
            showFetchUserError(getString(R.string.purchase_request_failed_error));
            if (currentStep == FIRST_RUN_STEP_REWARDS) {
                onRequestCompleted(FIRST_RUN_STEP_REWARDS);
            }
        }
    });
    verificationSkipQueue.createBillingClientAndEstablishConnection();
    viewPager = findViewById(R.id.first_run_pager);
    viewPager.setUserInputEnabled(false);
    viewPager.setSaveEnabled(false);
    viewPager.setAdapter(new FirstRunPagerAdapter(this));
    pagerIndicator1 = findViewById(R.id.pager_indicator_1);
    pagerIndicator2 = findViewById(R.id.pager_indicator_2);
    pagerIndicator3 = findViewById(R.id.pager_indicator_3);
    buttonContinue = findViewById(R.id.first_run_continue_button);
    buttonSkip = findViewById(R.id.first_run_skip_button);
    progressIndicator = findViewById(R.id.first_run_progress);
    buttonSkip.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            finishFirstRun();
        }
    });
    buttonContinue.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (currentStep == FIRST_RUN_STEP_CHANNEL) {
                if (!ytSyncOptInChecked) {
                    handleCreateChannel();
                } else {
                    proceedToRewardsStep();
                }
            } else if (currentStep == FIRST_RUN_STEP_REWARDS) {
                // final step (Use Odysee)
                finishFirstRun();
            }
        }
    });
    OnBackPressedCallback callback = new OnBackPressedCallback(true) {

        /* enabled by default */
        @Override
        public void handleOnBackPressed() {
            onBackPressed();
        }
    };
    getOnBackPressedDispatcher().addCallback(this, callback);
}
Also used : OnBackPressedCallback(androidx.activity.OnBackPressedCallback) VerificationSkipQueue(com.odysee.app.utils.VerificationSkipQueue) RewardVerifiedHandler(com.odysee.app.tasks.RewardVerifiedHandler) RewardVerified(com.odysee.app.model.lbryinc.RewardVerified) ImageView(android.widget.ImageView) View(android.view.View) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) IOException(java.io.IOException)

Aggregations

RewardVerified (com.odysee.app.model.lbryinc.RewardVerified)6 View (android.view.View)4 RewardVerifiedHandler (com.odysee.app.tasks.RewardVerifiedHandler)4 Context (android.content.Context)2 WebView (android.webkit.WebView)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 TwitterVerifyTask (com.odysee.app.tasks.lbryinc.TwitterVerifyTask)2 VerificationSkipQueue (com.odysee.app.utils.VerificationSkipQueue)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Handler (android.os.Handler)1 ImageView (android.widget.ImageView)1 OnBackPressedCallback (androidx.activity.OnBackPressedCallback)1 ViewPager2 (androidx.viewpager2.widget.ViewPager2)1 VerificationPagerAdapter (com.odysee.app.adapter.VerificationPagerAdapter)1 ApiCallException (com.odysee.app.exceptions.ApiCallException)1