Search in sources :

Example 1 with MergeSubscriptionsTask

use of com.odysee.app.tasks.MergeSubscriptionsTask 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

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 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 Tag (com.odysee.app.model.Tag)1 Subscription (com.odysee.app.model.lbryinc.Subscription)1 MergeSubscriptionsTask (com.odysee.app.tasks.MergeSubscriptionsTask)1 LoadSharedUserStateTask (com.odysee.app.tasks.wallet.LoadSharedUserStateTask)1 AllContentFragment (com.odysee.app.ui.findcontent.AllContentFragment)1 FollowingFragment (com.odysee.app.ui.findcontent.FollowingFragment)1 LbryUri (com.odysee.app.utils.LbryUri)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 JSONException (org.json.JSONException)1