Search in sources :

Example 6 with DefaultSyncTaskHandler

use of com.odysee.app.tasks.wallet.DefaultSyncTaskHandler in project odysee-android by OdyseeTeam.

the class SignInActivity method processExistingWalletWithPassword.

public void processExistingWalletWithPassword(String password) {
    Helper.setViewVisibility(textWalletSyncLoading, View.VISIBLE);
    Helper.setViewVisibility(inputWalletSyncPassword, View.GONE);
    if (currentWalletSync == null) {
        showError(getString(R.string.wallet_sync_op_failed));
        Helper.setViewText(textWalletSyncLoading, R.string.wallet_sync_op_failed);
        return;
    }
    Helper.setViewVisibility(walletSyncProgress, View.VISIBLE);
    Helper.setViewText(textWalletSyncLoading, R.string.apply_wallet_data);
    SyncApplyTask applyTask = new SyncApplyTask(password, currentWalletSync.getData(), null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncApplySuccess(String hash, String data) {
            Utils.setSecureValue(MainActivity.SECURE_VALUE_KEY_SAVED_PASSWORD, password, SignInActivity.this, Lbry.KEYSTORE);
            // check if local and remote hash are different, and then run sync set
            if (!hash.equalsIgnoreCase(Lbryio.lastRemoteHash) && !Helper.isNullOrEmpty(Lbryio.lastRemoteHash)) {
                new SyncSetTask(Lbryio.lastRemoteHash, hash, data, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            /*if (listener != null) {
                    listener.onWalletSyncEnabled();
                }*/
            loadSharedUserStateAndFinish();
        }

        @Override
        public void onSyncApplyError(Exception error) {
            // failed, request the user to enter a password
            showError(error.getMessage());
            Helper.setViewVisibility(walletSyncProgress, View.GONE);
            Helper.setViewVisibility(textWalletSyncLoading, View.GONE);
            Helper.setViewVisibility(inputWalletSyncPassword, View.VISIBLE);
            Helper.setViewVisibility(layoutWalletSyncInputArea, View.VISIBLE);
            Helper.setViewVisibility(closeSignupSignIn, View.VISIBLE);
            walletSyncStarted = false;
        }
    });
    applyTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) SyncSetTask(com.odysee.app.tasks.wallet.SyncSetTask) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException) SyncApplyTask(com.odysee.app.tasks.wallet.SyncApplyTask)

Example 7 with DefaultSyncTaskHandler

use of com.odysee.app.tasks.wallet.DefaultSyncTaskHandler in project odysee-android by OdyseeTeam.

the class SignInFragment method processExistingWalletWithPassword.

public void processExistingWalletWithPassword(String password) {
    Helper.setViewVisibility(textWalletSyncLoading, View.VISIBLE);
    Helper.setViewVisibility(inputWalletSyncPassword, View.GONE);
    if (currentWalletSync == null) {
        showError(getString(R.string.wallet_sync_op_failed));
        Helper.setViewText(textWalletSyncLoading, R.string.wallet_sync_op_failed);
        return;
    }
    Helper.setViewVisibility(walletSyncProgress, View.VISIBLE);
    Helper.setViewText(textWalletSyncLoading, R.string.apply_wallet_data);
    SyncApplyTask applyTask = new SyncApplyTask(password, currentWalletSync.getData(), null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncApplySuccess(String hash, String data) {
            Utils.setSecureValue(MainActivity.SECURE_VALUE_KEY_SAVED_PASSWORD, password, getContext(), Lbry.KEYSTORE);
            // check if local and remote hash are different, and then run sync set
            if (!hash.equalsIgnoreCase(Lbryio.lastRemoteHash) && !Helper.isNullOrEmpty(Lbryio.lastRemoteHash)) {
                new SyncSetTask(Lbryio.lastRemoteHash, hash, data, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            finishSignIn();
        }

        @Override
        public void onSyncApplyError(Exception error) {
            // failed, request the user to enter a password
            showError(error.getMessage());
            Helper.setViewVisibility(walletSyncProgress, View.GONE);
            Helper.setViewVisibility(textWalletSyncLoading, View.GONE);
            Helper.setViewVisibility(inputWalletSyncPassword, View.VISIBLE);
            Helper.setViewVisibility(layoutWalletSyncInputArea, View.VISIBLE);
            walletSyncStarted = false;
        }
    });
    applyTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) SyncSetTask(com.odysee.app.tasks.wallet.SyncSetTask) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException) SyncApplyTask(com.odysee.app.tasks.wallet.SyncApplyTask)

Example 8 with DefaultSyncTaskHandler

use of com.odysee.app.tasks.wallet.DefaultSyncTaskHandler in project odysee-android by OdyseeTeam.

the class MainActivity method syncWalletAndLoadPreferences.

public void syncWalletAndLoadPreferences() {
    if (!userSyncEnabled()) {
        return;
    }
    if (fullSyncInProgress) {
        queuedSyncCount++;
    }
    fullSyncInProgress = true;
    String password = getSecureValue(SECURE_VALUE_KEY_SAVED_PASSWORD, this, Lbry.KEYSTORE);
    SyncGetTask task = new SyncGetTask(password, true, null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncGetSuccess(WalletSync walletSync) {
            Lbryio.lastWalletSync = walletSync;
            Lbryio.lastRemoteHash = walletSync.getHash();
            loadSharedUserState();
        }

        @Override
        public void onSyncGetWalletNotFound() {
            // But if it does, send what we have
            if (Lbryio.isSignedIn()) {
                syncApplyAndSet();
            }
        }

        @Override
        public void onSyncGetError(Exception error) {
            // pass
            Log.e(TAG, String.format("sync get failed: %s", error != null ? error.getMessage() : "no error message"), error);
            fullSyncInProgress = false;
            if (queuedSyncCount > 0) {
                queuedSyncCount--;
                syncApplyAndSet();
            }
        }

        @Override
        public void onSyncApplySuccess(String hash, String data) {
            if (!hash.equalsIgnoreCase(Lbryio.lastRemoteHash)) {
                syncSet(hash, data);
            } else {
                fullSyncInProgress = false;
                queuedSyncCount = 0;
            }
            loadSharedUserState();
        }

        @Override
        public void onSyncApplyError(Exception error) {
            // pass
            Log.e(TAG, String.format("sync apply failed: %s", error != null ? error.getMessage() : "no error message"), error);
            fullSyncInProgress = false;
            if (queuedSyncCount > 0) {
                queuedSyncCount--;
                syncApplyAndSet();
            }
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : WalletSync(com.odysee.app.model.WalletSync) DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) SyncGetTask(com.odysee.app.tasks.wallet.SyncGetTask) SpannableString(android.text.SpannableString) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException)

Example 9 with DefaultSyncTaskHandler

use of com.odysee.app.tasks.wallet.DefaultSyncTaskHandler in project odysee-android by OdyseeTeam.

the class SignInActivity method runWalletSync.

private void runWalletSync(String password) {
    if (walletSyncStarted) {
        return;
    }
    walletSyncStarted = true;
    Helper.setViewVisibility(layoutCollect, View.GONE);
    Helper.setViewVisibility(layoutVerify, View.GONE);
    Helper.setViewVisibility(closeSignupSignIn, View.GONE);
    Helper.setViewVisibility(layoutWalletSyncContainer, View.VISIBLE);
    Helper.setViewVisibility(walletSyncProgress, View.VISIBLE);
    Helper.setViewVisibility(textWalletSyncLoading, View.VISIBLE);
    password = Utils.getSecureValue(MainActivity.SECURE_VALUE_KEY_SAVED_PASSWORD, this, Lbry.KEYSTORE);
    if (Helper.isNullOrEmpty(password)) {
        password = Helper.getValue(inputWalletSyncPassword.getText());
    }
    final String actual = password;
    SyncGetTask task = new SyncGetTask(password, false, null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncGetSuccess(WalletSync walletSync) {
            currentWalletSync = walletSync;
            Lbryio.lastRemoteHash = walletSync.getHash();
            if (Helper.isNullOrEmpty(actual)) {
                processExistingWallet(walletSync);
            } else {
                processExistingWalletWithPassword(actual);
            }
        }

        @Override
        public void onSyncGetWalletNotFound() {
            // no wallet found, get sync apply data and run the process
            processNewWallet();
        }

        @Override
        public void onSyncGetError(Exception error) {
            // try again
            Helper.setViewVisibility(walletSyncProgress, View.GONE);
            // Helper.setViewText(textWalletSyncLoading, error.getMessage());
            Helper.setViewVisibility(textWalletSyncLoading, View.GONE);
            Helper.setViewVisibility(layoutWalletSyncInputArea, View.VISIBLE);
            Helper.setViewVisibility(closeSignupSignIn, View.VISIBLE);
            walletSyncStarted = false;
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : WalletSync(com.odysee.app.model.WalletSync) DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) SyncGetTask(com.odysee.app.tasks.wallet.SyncGetTask) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with DefaultSyncTaskHandler

use of com.odysee.app.tasks.wallet.DefaultSyncTaskHandler in project odysee-android by OdyseeTeam.

the class SignInActivity method processNewWallet.

public void processNewWallet() {
    SyncApplyTask fetchTask = new SyncApplyTask(true, null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncApplySuccess(String hash, String data) {
            createNewRemoteSync(hash, data);
        }

        @Override
        public void onSyncApplyError(Exception error) {
            showError(error.getMessage());
            Helper.setViewVisibility(walletSyncProgress, View.GONE);
            Helper.setViewText(textWalletSyncLoading, R.string.wallet_sync_op_failed);
            Helper.setViewVisibility(closeSignupSignIn, View.VISIBLE);
            /*if (listener != null) {
                    listener.onWalletSyncFailed(error);
                }*/
            walletSyncStarted = false;
        }
    });
    fetchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException) SyncApplyTask(com.odysee.app.tasks.wallet.SyncApplyTask)

Aggregations

DefaultSyncTaskHandler (com.odysee.app.tasks.wallet.DefaultSyncTaskHandler)18 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)14 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)14 ExecutionException (java.util.concurrent.ExecutionException)14 SyncApplyTask (com.odysee.app.tasks.wallet.SyncApplyTask)11 SyncSetTask (com.odysee.app.tasks.wallet.SyncSetTask)9 SQLiteException (android.database.sqlite.SQLiteException)4 SpannableString (android.text.SpannableString)4 ApiCallException (com.odysee.app.exceptions.ApiCallException)4 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)4 LbryUriException (com.odysee.app.exceptions.LbryUriException)4 WalletSync (com.odysee.app.model.WalletSync)4 ParseException (java.text.ParseException)4 JSONException (org.json.JSONException)4 SyncGetTask (com.odysee.app.tasks.wallet.SyncGetTask)3