Search in sources :

Example 1 with SyncSetTask

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

the class MainActivity method syncSet.

public void syncSet(String hash, String data) {
    if (syncSetTask == null || syncSetTask.getStatus() == AsyncTask.Status.FINISHED) {
        syncSetTask = new SyncSetTask(Lbryio.lastRemoteHash, hash, data, new DefaultSyncTaskHandler() {

            @Override
            public void onSyncSetSuccess(String hash) {
                Lbryio.lastRemoteHash = hash;
                Lbryio.lastWalletSync = new WalletSync(hash, data);
                if (!pendingSyncSetQueue.isEmpty()) {
                    fullSyncInProgress = true;
                    WalletSync nextSync = pendingSyncSetQueue.remove(0);
                    syncSet(nextSync.getHash(), nextSync.getData());
                } else if (queuedSyncCount > 0) {
                    queuedSyncCount--;
                    syncApplyAndSet();
                }
                fullSyncInProgress = false;
            }

            @Override
            public void onSyncSetError(Exception error) {
                // log app exceptions
                if (!pendingSyncSetQueue.isEmpty()) {
                    WalletSync nextSync = pendingSyncSetQueue.remove(0);
                    syncSet(nextSync.getHash(), nextSync.getData());
                } else if (queuedSyncCount > 0) {
                    queuedSyncCount--;
                    syncApplyAndSet();
                }
                fullSyncInProgress = false;
            }
        });
        syncSetTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        WalletSync pending = new WalletSync(hash, data);
        pendingSyncSetQueue.add(pending);
    }
}
Also used : WalletSync(com.odysee.app.model.WalletSync) DefaultSyncTaskHandler(com.odysee.app.tasks.wallet.DefaultSyncTaskHandler) SpannableString(android.text.SpannableString) SyncSetTask(com.odysee.app.tasks.wallet.SyncSetTask) 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 2 with SyncSetTask

use of com.odysee.app.tasks.wallet.SyncSetTask 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 3 with SyncSetTask

use of com.odysee.app.tasks.wallet.SyncSetTask 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 4 with SyncSetTask

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

the class SignInActivity method processExistingWallet.

public void processExistingWallet(WalletSync walletSync) {
    // Try first sync apply
    SyncApplyTask applyTask = new SyncApplyTask("", walletSync.getData(), null, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncApplySuccess(String hash, String data) {
            // check if local and remote hash are different, and then run sync set
            Utils.setSecureValue(MainActivity.SECURE_VALUE_KEY_SAVED_PASSWORD, "", SignInActivity.this, Lbry.KEYSTORE);
            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
            Helper.setViewVisibility(walletSyncProgress, View.GONE);
            Helper.setViewVisibility(textWalletSyncLoading, View.GONE);
            Helper.setViewVisibility(inputWalletSyncPassword, View.VISIBLE);
            /*if (listener != null) {
                    listener.onWalletSyncWaitingForInput();
                }*/
            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 5 with SyncSetTask

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

the class SignInActivity method createNewRemoteSync.

private void createNewRemoteSync(String hash, String data) {
    SyncSetTask setTask = new SyncSetTask("", hash, data, new DefaultSyncTaskHandler() {

        @Override
        public void onSyncSetSuccess(String hash) {
            Lbryio.lastRemoteHash = hash;
            /*if (listener != null) {
                    listener.onWalletSyncEnabled();
                }*/
            loadSharedUserStateAndFinish();
        }

        @Override
        public void onSyncSetError(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;
        }
    });
    setTask.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)

Aggregations

DefaultSyncTaskHandler (com.odysee.app.tasks.wallet.DefaultSyncTaskHandler)9 SyncSetTask (com.odysee.app.tasks.wallet.SyncSetTask)9 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)8 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)8 ExecutionException (java.util.concurrent.ExecutionException)8 SyncApplyTask (com.odysee.app.tasks.wallet.SyncApplyTask)5 SQLiteException (android.database.sqlite.SQLiteException)2 SpannableString (android.text.SpannableString)2 ApiCallException (com.odysee.app.exceptions.ApiCallException)2 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)2 LbryUriException (com.odysee.app.exceptions.LbryUriException)2 ParseException (java.text.ParseException)2 JSONException (org.json.JSONException)2 WalletSync (com.odysee.app.model.WalletSync)1