Search in sources :

Example 6 with ClaimListResultHandler

use of com.odysee.app.tasks.claim.ClaimListResultHandler in project odysee-android by OdyseeTeam.

the class LibraryFragment method resolveMissingChannelNames.

private void resolveMissingChannelNames(List<String> urls) {
    if (urls.size() > 0) {
        ResolveTask task = new ResolveTask(urls, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                boolean updated = false;
                for (Claim claim : claims) {
                    if (claim.getClaimId() == null) {
                        continue;
                    }
                    if (contentListAdapter != null) {
                        contentListAdapter.updateSigningChannelForClaim(claim);
                        updated = true;
                    }
                }
                if (updated) {
                    contentListAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onError(Exception error) {
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) Claim(com.odysee.app.model.Claim) JSONException(org.json.JSONException) ApiCallException(com.odysee.app.exceptions.ApiCallException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 7 with ClaimListResultHandler

use of com.odysee.app.tasks.claim.ClaimListResultHandler in project odysee-android by OdyseeTeam.

the class RepostClaimDialogFragment method fetchChannels.

private void fetchChannels() {
    if (Lbry.ownChannels == null || Lbry.ownChannels.size() == 0) {
        startLoading();
        ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, repostProgress, new ClaimListResultHandler() {

            @Override
            public void onSuccess(List<Claim> claims) {
                Lbry.ownChannels = new ArrayList<>(claims);
                loadChannels(claims);
                finishLoading();
            }

            @Override
            public void onError(Exception error) {
                // could not fetch channels
                Context context = getContext();
                if (context instanceof MainActivity) {
                    ((MainActivity) context).showError(error.getMessage());
                }
                dismiss();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loadChannels(Lbry.ownChannels);
    }
}
Also used : Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) MainActivity(com.odysee.app.MainActivity) Claim(com.odysee.app.model.Claim)

Example 8 with ClaimListResultHandler

use of com.odysee.app.tasks.claim.ClaimListResultHandler in project odysee-android by OdyseeTeam.

the class FileViewFragment method resolveCommentPosters.

private void resolveCommentPosters() {
    if (commentListAdapter != null) {
        long st = System.currentTimeMillis();
        List<String> urlsToResolve = new ArrayList<>(commentListAdapter.getClaimUrlsToResolve());
        if (urlsToResolve.size() > 0) {
            ResolveTask task = new ResolveTask(urlsToResolve, Lbry.API_CONNECTION_STRING, null, new ClaimListResultHandler() {

                @Override
                public void onSuccess(List<Claim> claims) {
                    if (commentListAdapter != null) {
                        for (Claim claim : claims) {
                            if (claim.getClaimId() != null) {
                                commentListAdapter.updatePosterForComment(claim.getClaimId(), claim);
                            }
                        }
                        // filter for blocked comments
                        commentListAdapter.filterBlockedChannels(Lbryio.blockedChannels);
                        commentListAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onError(Exception error) {
                // pass
                }
            });
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
}
Also used : ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ArrayList(java.util.ArrayList) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Claim(com.odysee.app.model.Claim) LbryRequestException(com.odysee.app.exceptions.LbryRequestException) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) ResolveTask(com.odysee.app.tasks.claim.ResolveTask)

Example 9 with ClaimListResultHandler

use of com.odysee.app.tasks.claim.ClaimListResultHandler in project odysee-android by OdyseeTeam.

the class PublishesFragment method fetchPublishes.

private void fetchPublishes() {
    Helper.setViewVisibility(emptyView, View.GONE);
    ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), getLoading(), new ClaimListResultHandler() {

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

                        @Override
                        public void onClaimClicked(Claim claim, int position) {
                            if (context instanceof MainActivity) {
                                MainActivity activity = (MainActivity) context;
                                if (claim.getName().startsWith("@")) {
                                    activity.openChannelClaim(claim);
                                } else {
                                    activity.openFileClaim(claim);
                                }
                            }
                        }
                    });
                    if (contentList != null) {
                        contentList.setAdapter(adapter);
                    }
                }
            } else {
                adapter.setItems(claims);
            }
            checkNoPublishes();
        }

        @Override
        public void onError(Exception error) {
            checkNoPublishes();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) ClaimListResultHandler(com.odysee.app.tasks.claim.ClaimListResultHandler) ClaimListTask(com.odysee.app.tasks.claim.ClaimListTask) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) Claim(com.odysee.app.model.Claim)

Example 10 with ClaimListResultHandler

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

Claim (com.odysee.app.model.Claim)20 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)20 JSONException (org.json.JSONException)12 ApiCallException (com.odysee.app.exceptions.ApiCallException)11 ClaimListTask (com.odysee.app.tasks.claim.ClaimListTask)11 LbryUriException (com.odysee.app.exceptions.LbryUriException)9 ResolveTask (com.odysee.app.tasks.claim.ResolveTask)9 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)8 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)8 ExecutionException (java.util.concurrent.ExecutionException)8 ArrayList (java.util.ArrayList)7 Context (android.content.Context)5 SQLiteException (android.database.sqlite.SQLiteException)5 MainActivity (com.odysee.app.MainActivity)5 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)4 IOException (java.io.IOException)4 ParseException (java.text.ParseException)4 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)3 ClaimListAdapter (com.odysee.app.adapter.ClaimListAdapter)3 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)3