diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-05-11 19:02:22 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-05-11 19:02:22 +0300 |
commit | 2ca59d8df9601a1a290a5045fca61350c7f5aafd (patch) | |
tree | 72122d06740181e52b83d3d62eeed6c7499d12e2 /app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments | |
parent | 3680b65badec9c454b46c4ae961584d66e7797a9 (diff) |
#454 💬↩️ Reply to comments
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments')
2 files changed, 3 insertions, 59 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java index cd977313f..101bd8f7e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java @@ -1,29 +1,17 @@ package it.niedermann.nextcloud.deck.ui.card.comments; import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.drawable.Drawable; -import android.text.Spannable; -import android.text.SpannableStringBuilder; -import android.text.style.ImageSpan; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.widget.TooltipCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.RequestOptions; -import com.bumptech.glide.request.target.CustomTarget; -import com.bumptech.glide.request.transition.Transition; - import java.text.DateFormat; import java.util.ArrayList; import java.util.List; @@ -33,7 +21,6 @@ import it.niedermann.nextcloud.deck.databinding.ItemCommentBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; -import it.niedermann.nextcloud.deck.model.ocs.comment.Mention; import it.niedermann.nextcloud.deck.util.DateUtil; import it.niedermann.nextcloud.deck.util.DimensionUtil; import it.niedermann.nextcloud.deck.util.ViewUtil; @@ -41,6 +28,7 @@ import it.niedermann.nextcloud.deck.util.ViewUtil; import static it.niedermann.nextcloud.deck.Application.readBrandMainColor; import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getSecondaryForegroundColorDependingOnTheme; import static it.niedermann.nextcloud.deck.util.ClipboardUtil.copyToClipboard; +import static it.niedermann.nextcloud.deck.util.ViewUtil.setupMentions; public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHolder> { @@ -118,51 +106,6 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHol setupMentions(account, comment.getMentions(), holder.binding.message); } - public static void setupMentions(@NonNull Account account, @NonNull List<Mention> mentions, TextView tv) { - Context context = tv.getContext(); - SpannableStringBuilder messageBuilder = new SpannableStringBuilder(tv.getText()); - - // Step 1 - // Add avatar icons and display names - for (Mention m : mentions) { - final String mentionId = "@" + m.getMentionId(); - final String mentionDisplayName = " " + m.getMentionDisplayName(); - int index = messageBuilder.toString().lastIndexOf(mentionId); - while (index >= 0) { - messageBuilder.setSpan(new ImageSpan(context, R.drawable.ic_person_grey600_24dp), index, index + mentionId.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - messageBuilder.insert(index + mentionId.length(), mentionDisplayName); - index = messageBuilder.toString().substring(0, index).lastIndexOf(mentionId); - } - } - tv.setText(messageBuilder); - - // Step 2 - // Replace avatar icons with real avatars - final ImageSpan[] list = messageBuilder.getSpans(0, messageBuilder.length(), ImageSpan.class); - for (ImageSpan span : list) { - final int spanStart = messageBuilder.getSpanStart(span); - final int spanEnd = messageBuilder.getSpanEnd(span); - Glide.with(context) - .asBitmap() - .placeholder(R.drawable.ic_person_grey600_24dp) - .load(account.getUrl() + "/index.php/avatar/" + messageBuilder.subSequence(spanStart + 1, spanEnd).toString() + "/" + DimensionUtil.dpToPx(context, R.dimen.icon_size_details)) - .apply(RequestOptions.circleCropTransform()) - .into(new CustomTarget<Bitmap>() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { - messageBuilder.removeSpan(span); - messageBuilder.setSpan(new ImageSpan(context, resource), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - // silence is gold - } - }); - } - tv.setText(messageBuilder); - } - @SuppressWarnings("WeakerAccess") public void updateComments(@NonNull List<DeckComment> comments) { this.comments.clear(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java index 5605d9513..dd76c380e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java @@ -26,6 +26,7 @@ import static android.view.View.GONE; import static android.view.View.VISIBLE; import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.applyBrandToEditText; import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.applyBrandToFAB; +import static it.niedermann.nextcloud.deck.util.ViewUtil.setupMentions; public class CardCommentsFragment extends BrandedFragment implements CommentEditedListener, CommentDeletedListener, CommentSelectAsReplyListener { @@ -59,7 +60,7 @@ public class CardCommentsFragment extends BrandedFragment implements CommentEdit } else { binding.replyCommentText.setText(comment.getMessage()); binding.replyComment.setVisibility(VISIBLE); - CardCommentsAdapter.setupMentions(mainViewModel.getAccount(), comment.getMentions(), binding.replyCommentText); + setupMentions(mainViewModel.getAccount(), comment.getMentions(), binding.replyCommentText); } }); syncManager.getCommentsForLocalCardId(mainViewModel.getFullCard().getLocalId()).observe(getViewLifecycleOwner(), |