Search in sources :

Example 21 with LbryUri

use of com.odysee.app.utils.LbryUri 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)

Example 22 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class ClaimListAdapter method filterBlockedChannels.

public void filterBlockedChannels(List<LbryUri> blockedChannels) {
    if (blockedChannels.size() == 0) {
        return;
    }
    List<String> blockedChannelClaimIds = new ArrayList<>();
    for (LbryUri uri : blockedChannels) {
        blockedChannelClaimIds.add(uri.getClaimId());
    }
    for (Claim claim : items) {
        if (claim.getSigningChannel() != null && blockedChannelClaimIds.contains(claim.getSigningChannel().getClaimId())) {
            int position = items.indexOf(claim);
            items.remove(claim);
            notifyItemRemoved(position);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LbryUri(com.odysee.app.utils.LbryUri) Claim(com.odysee.app.model.Claim) SuppressLint(android.annotation.SuppressLint)

Example 23 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class DatabaseHelper method getBlockedChannels.

public static List<LbryUri> getBlockedChannels(SQLiteDatabase db) {
    List<LbryUri> blockedChannels = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery(SQL_GET_BLOCKED_CHANNELS, null);
        while (cursor.moveToNext()) {
            LbryUri uri = LbryUri.tryParse(String.format("lbry://%s:%s", cursor.getString(1), cursor.getString(0)));
            if (uri != null) {
                blockedChannels.add(uri);
            }
        }
    } finally {
        Helper.closeCursor(cursor);
    }
    return blockedChannels;
}
Also used : ArrayList(java.util.ArrayList) LbryUri(com.odysee.app.utils.LbryUri) Cursor(android.database.Cursor)

Example 24 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class TransactionListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(TransactionListAdapter.ViewHolder vh, int position) {
    Transaction item = items.get(position);
    vh.descView.setText(item.getDescriptionStringId());
    vh.amountView.setText(TX_LIST_AMOUNT_FORMAT.format(item.getValue().doubleValue()));
    vh.claimView.setText(item.getClaim());
    vh.feeView.setText(context.getString(R.string.tx_list_fee, TX_LIST_AMOUNT_FORMAT.format(item.getFee().doubleValue())));
    vh.txidLinkView.setText(item.getTxid().substring(0, 7));
    vh.dateView.setVisibility(item.getConfirmations() > 0 ? View.VISIBLE : View.GONE);
    vh.dateView.setText(item.getConfirmations() > 0 ? TX_LIST_DATE_FORMAT.format(item.getTxDate()) : null);
    vh.pendingView.setVisibility(item.getConfirmations() == 0 ? View.VISIBLE : View.GONE);
    vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ? View.VISIBLE : View.GONE);
    vh.claimView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            LbryUri claimUrl = item.getClaimUrl();
            if (claimUrl != null && listener != null) {
                listener.onClaimUrlClicked(claimUrl);
            }
        }
    });
    vh.txidLinkView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (context != null) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s/%s", Helper.EXPLORER_TX_PREFIX, item.getTxid())));
                context.startActivity(intent);
            }
        }
    });
    vh.itemView.setOnClickListener(view -> {
        if (listener != null) {
            listener.onTransactionClicked(item);
        }
    });
}
Also used : Transaction(com.odysee.app.model.Transaction) Intent(android.content.Intent) LbryUri(com.odysee.app.utils.LbryUri) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 25 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class InvitesFragment method updateInviteLink.

private void updateInviteLink(Claim claim) {
    LbryUri canonical = LbryUri.tryParse(claim.getCanonicalUrl());
    String link = String.format(INVITE_LINK_FORMAT, canonical != null ? String.format("@%s", canonical.getChannelName()) : claim.getName(), canonical != null ? canonical.getChannelClaimId() : claim.getClaimId());
    textInviteLink.setText(link);
}
Also used : LbryUri(com.odysee.app.utils.LbryUri)

Aggregations

LbryUri (com.odysee.app.utils.LbryUri)30 LbryUriException (com.odysee.app.exceptions.LbryUriException)10 ArrayList (java.util.ArrayList)10 JSONException (org.json.JSONException)9 Subscription (com.odysee.app.model.lbryinc.Subscription)8 ApiCallException (com.odysee.app.exceptions.ApiCallException)7 Claim (com.odysee.app.model.Claim)7 JSONObject (org.json.JSONObject)7 SQLiteException (android.database.sqlite.SQLiteException)6 MainActivity (com.odysee.app.MainActivity)6 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)6 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)6 ExecutionException (java.util.concurrent.ExecutionException)6 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Tag (com.odysee.app.model.Tag)4 HashMap (java.util.HashMap)4 AccountManager (android.accounts.AccountManager)3 View (android.view.View)3