Search in sources :

Example 1 with PollViewData

use of com.keylesspalace.tusky.viewdata.PollViewData in project Tusky by Vavassor.

the class StatusBaseViewHolder method setupPoll.

private void setupPoll(PollViewData poll, List<Emoji> emojis, StatusDisplayOptions statusDisplayOptions, StatusActionListener listener) {
    long timestamp = System.currentTimeMillis();
    boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime());
    Context context = pollDescription.getContext();
    pollOptions.setVisibility(View.VISIBLE);
    if (expired || poll.getVoted()) {
        // no voting possible
        View.OnClickListener viewThreadListener = v -> {
            int position = getBindingAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                listener.onViewThread(position);
            }
        };
        pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, PollAdapter.RESULT, viewThreadListener, statusDisplayOptions.animateEmojis());
        pollButton.setVisibility(View.GONE);
    } else {
        // voting possible
        pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE, null, statusDisplayOptions.animateEmojis());
        pollButton.setVisibility(View.VISIBLE);
        pollButton.setOnClickListener(v -> {
            int position = getBindingAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                List<Integer> pollResult = pollAdapter.getSelected();
                if (!pollResult.isEmpty()) {
                    listener.onVoteInPoll(position, pollResult);
                }
            }
        });
    }
    pollDescription.setVisibility(View.VISIBLE);
    pollDescription.setText(getPollInfoText(timestamp, poll, statusDisplayOptions, context));
}
Also used : Context(android.content.Context) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) DateUtils(android.text.format.DateUtils) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) RequestBuilder(com.bumptech.glide.RequestBuilder) Utils(at.connyduck.sparkbutton.helpers.Utils) ColorDrawable(android.graphics.drawable.ColorDrawable) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) Card(com.keylesspalace.tusky.entity.Card) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) MetaData(com.keylesspalace.tusky.entity.Attachment.MetaData) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewMediaActivity(com.keylesspalace.tusky.ViewMediaActivity) SparkButton(at.connyduck.sparkbutton.SparkButton) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) Focus(com.keylesspalace.tusky.entity.Attachment.Focus) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) HtmlCompat(androidx.core.text.HtmlCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Attachment(com.keylesspalace.tusky.entity.Attachment) PollOptionViewData(com.keylesspalace.tusky.viewdata.PollOptionViewData) CollectionsKt(kotlin.collections.CollectionsKt) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TimestampUtils(com.keylesspalace.tusky.util.TimestampUtils) PollViewDataKt(com.keylesspalace.tusky.viewdata.PollViewDataKt) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) PollViewData(com.keylesspalace.tusky.viewdata.PollViewData) Status(com.keylesspalace.tusky.entity.Status) SimpleDateFormat(java.text.SimpleDateFormat) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) NumberFormat(java.text.NumberFormat) MaterialButton(com.google.android.material.button.MaterialButton) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) CustomEmojiHelper(com.keylesspalace.tusky.util.CustomEmojiHelper) Toast(android.widget.Toast) PollViewDataKt.buildDescription(com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) Emoji(com.keylesspalace.tusky.entity.Emoji) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) TextUtils(android.text.TextUtils) Glide(com.bumptech.glide.Glide) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) ImageLoadingHelper(com.keylesspalace.tusky.util.ImageLoadingHelper) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView)

Example 2 with PollViewData

use of com.keylesspalace.tusky.viewdata.PollViewData in project Tusky by Vavassor.

the class StatusBaseViewHolder method getPollDescription.

private CharSequence getPollDescription(@NonNull StatusViewData.Concrete status, Context context, StatusDisplayOptions statusDisplayOptions) {
    PollViewData poll = PollViewDataKt.toViewData(status.getActionable().getPoll());
    if (poll == null) {
        return "";
    } else {
        Object[] args = new CharSequence[5];
        List<PollOptionViewData> options = poll.getOptions();
        for (int i = 0; i < args.length; i++) {
            if (i < options.size()) {
                int percent = PollViewDataKt.calculatePercent(options.get(i).getVotesCount(), poll.getVotersCount(), poll.getVotesCount());
                args[i] = buildDescription(options.get(i).getTitle(), percent, options.get(i).getVoted(), context);
            } else {
                args[i] = "";
            }
        }
        args[4] = getPollInfoText(System.currentTimeMillis(), poll, statusDisplayOptions, context);
        return context.getString(R.string.description_poll, args);
    }
}
Also used : PollOptionViewData(com.keylesspalace.tusky.viewdata.PollOptionViewData) PollViewData(com.keylesspalace.tusky.viewdata.PollViewData)

Aggregations

Context (android.content.Context)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Spanned (android.text.Spanned)1 TextUtils (android.text.TextUtils)1 DateUtils (android.text.format.DateUtils)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 DrawableRes (androidx.annotation.DrawableRes)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 HtmlCompat (androidx.core.text.HtmlCompat)1