Search in sources :

Example 81 with Claim

use of com.odysee.app.model.Claim 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)

Example 82 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelCommentsFragment method initCommentForm.

private void initCommentForm(View root) {
    MainActivity activity = (MainActivity) getActivity();
    if (activity != null) {
        activity.refreshChannelCreationRequired(root);
    }
    textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));
    buttonUserSignedInRequired.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            MainActivity activity = (MainActivity) getActivity();
            if (activity != null) {
                activity.simpleSignIn(0);
            }
        }
    });
    buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            clearReplyToComment();
        }
    });
    buttonPostComment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            validateAndCheckPostComment();
        }
    });
    buttonCreateChannel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!fetchingChannels) {
                showChannelCreator();
            }
        }
    });
    inputComment.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            int len = charSequence.length();
            textCommentLimit.setText(String.format("%d / %d", len, Comment.MAX_LENGTH));
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    commentChannelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
            Object item = adapterView.getItemAtPosition(position);
            if (item instanceof Claim) {
                Claim claim = (Claim) item;
                if (claim.isPlaceholder()) {
                    if (!fetchingChannels) {
                        showChannelCreator();
                        if (commentChannelSpinnerAdapter.getCount() > 1) {
                            commentChannelSpinner.setSelection(commentChannelSpinnerAdapter.getCount() - 1);
                        }
                    }
                } else {
                    updatePostAsChannel(claim);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}
Also used : MainActivity(com.odysee.app.MainActivity) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) Claim(com.odysee.app.model.Claim)

Example 83 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelContentFragment method fetchClaimSearchContent.

private void fetchClaimSearchContent(boolean reset) {
    if (reset && contentListAdapter != null) {
        contentListAdapter.clearItems();
        currentClaimSearchPage = 1;
    }
    contentClaimSearchLoading = true;
    Helper.setViewVisibility(noContentView, View.GONE);
    Map<String, Object> claimSearchOptions = buildContentOptions();
    contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {

        @Override
        public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
            claims = Helper.filterClaimsByOutpoint(claims);
            if (contentListAdapter == null) {
                Context context = getContext();
                if (context != null) {
                    contentListAdapter = new ClaimListAdapter(claims, context);
                    contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

                        @Override
                        public void onClaimClicked(Claim claim, int position) {
                            Context context = getContext();
                            if (context instanceof MainActivity) {
                                MainActivity activity = (MainActivity) context;
                                if (claim.getName().startsWith("@")) {
                                    // channel claim
                                    activity.openChannelClaim(claim);
                                } else {
                                    activity.openFileClaim(claim);
                                }
                            }
                        }
                    });
                }
            } else {
                contentListAdapter.addItems(claims);
            }
            if (contentList != null && contentList.getAdapter() == null) {
                contentList.setAdapter(contentListAdapter);
            }
            contentHasReachedEnd = hasReachedEnd;
            contentClaimSearchLoading = false;
            checkNoContent();
        }

        @Override
        public void onError(Exception error) {
            contentClaimSearchLoading = false;
            checkNoContent();
        }
    });
    contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) MainActivity(com.odysee.app.MainActivity) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) JSONException(org.json.JSONException) ClaimSearchTask(com.odysee.app.tasks.claim.ClaimSearchTask) ClaimSearchResultHandler(com.odysee.app.tasks.claim.ClaimSearchResultHandler) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Claim(com.odysee.app.model.Claim)

Example 84 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelFormFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_channel_form, container, false);
    scrollView = root.findViewById(R.id.channel_form_scroll_view);
    linkCancel = root.findViewById(R.id.channel_form_cancel_link);
    linkShowOptional = root.findViewById(R.id.channel_form_toggle_optional);
    buttonSave = root.findViewById(R.id.channel_form_save_button);
    containerOptionalFields = root.findViewById(R.id.channel_form_optional_fields_container);
    inputTitle = root.findViewById(R.id.channel_form_input_title);
    inputChannelName = root.findViewById(R.id.channel_form_input_channel_name);
    inputDeposit = root.findViewById(R.id.channel_form_input_deposit);
    inputDescription = root.findViewById(R.id.channel_form_input_description);
    inputWebsite = root.findViewById(R.id.channel_form_input_website);
    inputEmail = root.findViewById(R.id.channel_form_input_email);
    inputTagFilter = root.findViewById(R.id.form_tag_filter_input);
    coverEditArea = root.findViewById(R.id.channel_form_cover_edit_area);
    iconContainer = root.findViewById(R.id.channel_form_icon_container);
    imageCover = root.findViewById(R.id.channel_form_cover_image);
    imageThumbnail = root.findViewById(R.id.channel_form_thumbnail);
    balanceView = root.findViewById(R.id.channel_form_balance);
    uploadProgress = root.findViewById(R.id.channel_form_upload_progress);
    channelSaveProgress = root.findViewById(R.id.channel_form_save_progress);
    Context context = getContext();
    FlexboxLayoutManager flm1 = new FlexboxLayoutManager(context);
    FlexboxLayoutManager flm2 = new FlexboxLayoutManager(context);
    addedTagsList = root.findViewById(R.id.form_added_tags);
    addedTagsList.setLayoutManager(flm1);
    suggestedTagsList = root.findViewById(R.id.form_suggested_tags);
    suggestedTagsList.setLayoutManager(flm2);
    addedTagsAdapter = new TagListAdapter(new ArrayList<>(), context);
    addedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_REMOVE);
    addedTagsAdapter.setClickListener(this);
    addedTagsList.setAdapter(addedTagsAdapter);
    suggestedTagsAdapter = new TagListAdapter(new ArrayList<>(), getContext());
    suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
    suggestedTagsAdapter.setClickListener(this);
    suggestedTagsList.setAdapter(suggestedTagsAdapter);
    noTagsView = root.findViewById(R.id.form_no_added_tags);
    noTagResultsView = root.findViewById(R.id.form_no_tag_results);
    buttonSave = root.findViewById(R.id.channel_form_save_button);
    inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            Helper.setViewVisibility(balanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
        }
    });
    linkShowOptional.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (containerOptionalFields.getVisibility() != View.VISIBLE) {
                containerOptionalFields.setVisibility(View.VISIBLE);
                linkShowOptional.setText(R.string.hide_optional_fields);
                scrollView.post(new Runnable() {

                    @Override
                    public void run() {
                        scrollView.fullScroll(NestedScrollView.FOCUS_DOWN);
                    }
                });
            } else {
                containerOptionalFields.setVisibility(View.GONE);
                linkShowOptional.setText(R.string.show_optional_fields);
            }
        }
    });
    linkCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            clearInputFocus();
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).onBackPressed();
            }
        }
    });
    coverEditArea.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (uploading) {
                Snackbar.make(getView(), R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
                return;
            }
            checkPermissionsAndLaunchFilePicker(true);
        }
    });
    iconContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (uploading) {
                Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
                return;
            }
            checkPermissionsAndLaunchFilePicker(false);
        }
    });
    buttonSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (uploading) {
                Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
                return;
            }
            Claim claimToSave = buildChannelClaimToSave();
            validateAndSaveClaim(claimToSave);
        }
    });
    inputTagFilter.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            String value = Helper.getValue(charSequence);
            setFilter(value);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    return root;
}
Also used : Context(android.content.Context) TagListAdapter(com.odysee.app.adapter.TagListAdapter) FlexboxLayoutManager(com.google.android.flexbox.FlexboxLayoutManager) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) CreditsBalanceView(com.odysee.app.views.CreditsBalanceView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Claim(com.odysee.app.model.Claim)

Example 85 with Claim

use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.

the class ChannelCommentsFragment method ensureCommentListAdapterCreated.

private void ensureCommentListAdapterCreated(final List<Comment> comments) {
    if (commentListAdapter == null) {
        Context ctx = getContext();
        View root = getView();
        commentListAdapter = new CommentListAdapter(comments, ctx, claim, new CommentListAdapter.CommentListListener() {

            @Override
            public void onListChanged() {
                checkNoComments();
            }

            @Override
            public void onCommentReactClicked(Comment c, boolean liked) {
            // Not used for now.
            }

            @Override
            public void onReplyClicked(Comment comment) {
                setReplyToComment(comment);
            }
        });
        commentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {

            @Override
            public void onClaimClicked(Claim claim, int position) {
                if (!Helper.isNullOrEmpty(claim.getName()) && claim.getName().startsWith("@") && ctx instanceof MainActivity) {
                    ((MainActivity) ctx).openChannelClaim(claim);
                }
            }
        });
        RecyclerView commentList = root.findViewById(R.id.channel_comments_list);
        int marginInPx = Math.round(40 * ((float) ctx.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
        commentList.addItemDecoration(new CommentItemDecoration(marginInPx));
        commentList.setAdapter(commentListAdapter);
        commentListAdapter.notifyItemRangeInserted(0, comments.size());
        commentListAdapter.setCollapsed(false);
        checkNoComments();
        resolveCommentPosters();
        scrollToCommentHash();
    }
}
Also used : Context(android.content.Context) Comment(com.odysee.app.model.Comment) CommentListAdapter(com.odysee.app.adapter.CommentListAdapter) MainActivity(com.odysee.app.MainActivity) CommentItemDecoration(com.odysee.app.adapter.CommentItemDecoration) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ClaimListAdapter(com.odysee.app.adapter.ClaimListAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23