Search in sources :

Example 1 with ClaimListSupplier

use of com.odysee.app.supplier.ClaimListSupplier in project odysee-android by OdyseeTeam.

the class ChannelManagerFragment method fetchChannels.

private void fetchChannels() {
    Helper.setViewVisibility(emptyView, View.GONE);
    AccountManager am = AccountManager.get(getContext());
    Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
    String authToken = am.peekAuthToken(odyseeAccount, "auth_token_type");
    MainActivity activity = (MainActivity) getActivity();
    final View progressView = getLoading();
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
        progressView.setVisibility(View.VISIBLE);
        Supplier<List<Claim>> s = new ClaimListSupplier(Collections.singletonList(Claim.TYPE_CHANNEL), authToken);
        CompletableFuture<List<Claim>> cf = CompletableFuture.supplyAsync(s);
        cf.whenComplete((result, e) -> {
            if (e != null && activity != null) {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Throwable t = e.getCause();
                        if (t != null) {
                            activity.showError(t.getMessage());
                        }
                    }
                });
            }
            if (result != null && activity != null) {
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(result));
                        if (adapter == null) {
                            Context context = getContext();
                            if (context != null) {
                                adapter = new ClaimListAdapter(result, context);
                                adapter.setCanEnterSelectionMode(true);
                                adapter.setSelectionModeListener(ChannelManagerFragment.this);
                                adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                                    @Override
                                    public void onClaimClicked(Claim claim, int position) {
                                        if (context instanceof MainActivity) {
                                            ((MainActivity) context).openChannelClaim(claim);
                                        }
                                    }
                                });
                                if (channelList != null) {
                                    channelList.setAdapter(adapter);
                                }
                            }
                        } else {
                            adapter.setItems(result);
                        }
                        checkNoChannels();
                    }
                });
            }
            if (activity != null)
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        progressView.setVisibility(View.GONE);
                    }
                });
        });
    } else {
        ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, getLoading(), Lbryio.AUTH_TOKEN, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(claims));
                if (adapter == null) {
                    Context context = getContext();
                    if (context != null) {
                        adapter = new ClaimListAdapter(claims, context);
                        adapter.setCanEnterSelectionMode(true);
                        adapter.setSelectionModeListener(ChannelManagerFragment.this);
                        adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                            @Override
                            public void onClaimClicked(Claim claim, int position) {
                                if (context instanceof MainActivity) {
                                    ((MainActivity) context).openChannelClaim(claim);
                                }
                            }
                        });
                        if (channelList != null) {
                            channelList.setAdapter(adapter);
                        }
                    }
                } else {
                    adapter.setItems(claims);
                }
                checkNoChannels();
            }

            @Override
            public void onError(Exception error) {
                checkNoChannels();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) ClaimListSupplier(com.odysee.app.supplier.ClaimListSupplier) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) MainActivity(com.odysee.app.MainActivity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) AccountManager(android.accounts.AccountManager) ArrayList(java.util.ArrayList) List(java.util.List) Claim(com.odysee.app.model.Claim)

Aggregations

Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 Context (android.content.Context)1 View (android.view.View)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MainActivity (com.odysee.app.MainActivity)1 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)1 Claim (com.odysee.app.model.Claim)1 ClaimListSupplier (com.odysee.app.supplier.ClaimListSupplier)1 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)1 ClaimListTask (com.odysee.app.tasks.claim.ClaimListTask)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1