Search in sources :

Example 1 with LoadSharedUserStateTask

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

the class SignInActivity method loadSharedUserStateAndFinish.

private void loadSharedUserStateAndFinish() {
    // load the shared user state after wallet sync is done
    LoadSharedUserStateTask loadTask = new LoadSharedUserStateTask(SignInActivity.this, new LoadSharedUserStateTask.LoadSharedUserStateHandler() {

        @Override
        public void onSuccess(List<Subscription> subscriptions, List<Tag> followedTags, List<LbryUri> blockedChannels) {
            Lbryio.subscriptions = new ArrayList<>(subscriptions);
            Lbryio.blockedChannels = new ArrayList<>(blockedChannels);
            finishSignInActivity();
        }

        @Override
        public void onError(Exception error) {
            // shouldn't happen, but if it does, finish anyway
            finishSignInActivity();
        }
    }, Lbryio.AUTH_TOKEN);
    loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : LoadSharedUserStateTask(com.odysee.app.tasks.wallet.LoadSharedUserStateTask) ArrayList(java.util.ArrayList) Tag(com.odysee.app.model.Tag) Subscription(com.odysee.app.model.lbryinc.Subscription) LbryUri(com.odysee.app.utils.LbryUri) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with LoadSharedUserStateTask

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

the class MainActivity method loadSharedUserState.

private void loadSharedUserState() {
    // load wallet preferences
    LoadSharedUserStateTask loadTask = new LoadSharedUserStateTask(MainActivity.this, new LoadSharedUserStateTask.LoadSharedUserStateHandler() {

        @Override
        public void onSuccess(List<Subscription> subscriptions, List<Tag> followedTags, List<LbryUri> blockedChannels) {
            if (subscriptions != null && subscriptions.size() > 0) {
                // reload subscriptions if wallet fragment is FollowingFragment
                // openNavFragments.get
                MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask(subscriptions, initialSubscriptionMergeDone(), MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() {

                    @Override
                    public void onSuccess(List<Subscription> subscriptions, List<Subscription> diff) {
                        Lbryio.subscriptions = new ArrayList<>(subscriptions);
                        if (!diff.isEmpty()) {
                            saveSharedUserState();
                        }
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                        sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_SUBSCRIPTION_MERGE_DONE, true).apply();
                        Lbryio.cacheResolvedSubscriptions.clear();
                        FollowingFragment f = (FollowingFragment) getSupportFragmentManager().findFragmentByTag("FOLLOWING");
                        if (f != null) {
                            f.fetchLoadedSubscriptions(true);
                        }
                    }

                    @Override
                    public void onError(Exception error) {
                        Log.e(TAG, String.format("merge subscriptions failed: %s", error.getMessage()), error);
                    }
                });
                mergeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            if (followedTags != null && followedTags.size() > 0) {
                List<Tag> previousTags = new ArrayList<>(Lbry.followedTags);
                Lbry.followedTags = new ArrayList<>(followedTags);
                AllContentFragment f = (AllContentFragment) getSupportFragmentManager().findFragmentByTag("HOME");
                if (f != null) {
                    if (!f.isSingleTagView() && f.getCurrentContentScope() == ContentScopeDialogFragment.ITEM_TAGS && !previousTags.equals(followedTags)) {
                        f.fetchClaimSearchContent(true);
                    }
                }
            }
            if (blockedChannels != null && !blockedChannels.isEmpty()) {
                if (!initialBlockedListLoaded()) {
                    // first time the blocked list is loaded, so we attempt to merge the entries
                    List<LbryUri> newBlockedChannels = new ArrayList<>(Lbryio.blockedChannels);
                    for (LbryUri uri : blockedChannels) {
                        if (!newBlockedChannels.contains(uri)) {
                            newBlockedChannels.add(uri);
                        }
                    }
                    Lbryio.blockedChannels = new ArrayList<>(newBlockedChannels);
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                    sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_BLOCKED_LIST_LOADED, true).apply();
                } else {
                    // replace the blocked channels list entirely
                    Lbryio.blockedChannels = new ArrayList<>(blockedChannels);
                }
            }
            if (!initialCollectionsLoaded()) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_COLLECTIONS_LOADED, true).apply();
            }
        }

        @Override
        public void onError(Exception error) {
            Log.e(TAG, String.format("load shared user state failed: %s", error != null ? error.getMessage() : "no error message"), error);
        }
    }, Lbryio.AUTH_TOKEN);
    loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) LoadSharedUserStateTask(com.odysee.app.tasks.wallet.LoadSharedUserStateTask) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) 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) MergeSubscriptionsTask(com.odysee.app.tasks.MergeSubscriptionsTask) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.odysee.app.model.Tag) Subscription(com.odysee.app.model.lbryinc.Subscription) LbryUri(com.odysee.app.utils.LbryUri)

Aggregations

LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)2 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)2 Tag (com.odysee.app.model.Tag)2 Subscription (com.odysee.app.model.lbryinc.Subscription)2 LoadSharedUserStateTask (com.odysee.app.tasks.wallet.LoadSharedUserStateTask)2 LbryUri (com.odysee.app.utils.LbryUri)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 SharedPreferences (android.content.SharedPreferences)1 SQLiteException (android.database.sqlite.SQLiteException)1 ApiCallException (com.odysee.app.exceptions.ApiCallException)1 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)1 LbryUriException (com.odysee.app.exceptions.LbryUriException)1 MergeSubscriptionsTask (com.odysee.app.tasks.MergeSubscriptionsTask)1 AllContentFragment (com.odysee.app.ui.findcontent.AllContentFragment)1 FollowingFragment (com.odysee.app.ui.findcontent.FollowingFragment)1 ParseException (java.text.ParseException)1 List (java.util.List)1 JSONException (org.json.JSONException)1