diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-11-22 17:42:58 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-11-22 17:42:58 +0300 |
commit | 751a62932cd1709008b15d372563bbb88d129e7d (patch) | |
tree | e9c1615b63050578a82408ca6431f92347f7a78d /app/src/main/java/it/niedermann/nextcloud/deck | |
parent | 5965c8b0f3aa3a811d622fbeac8790c60727b449 (diff) |
Provide default implementation for MD editor to globally switch impl
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck')
3 files changed, 14 insertions, 20 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/ItemCommentViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/ItemCommentViewHolder.java index 4ee74d3a7..56230d3c3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/ItemCommentViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/ItemCommentViewHolder.java @@ -15,7 +15,6 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import it.niedermann.android.markdown.MarkdownEditor; import it.niedermann.android.util.ClipboardUtil; import it.niedermann.android.util.DimensionUtil; import it.niedermann.nextcloud.deck.R; @@ -30,19 +29,17 @@ import static it.niedermann.nextcloud.deck.util.ViewUtil.setupMentions; public class ItemCommentViewHolder extends RecyclerView.ViewHolder { private final ItemCommentBinding binding; - private final MarkdownEditor markdownViewer; private final DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); @SuppressWarnings("WeakerAccess") public ItemCommentViewHolder(ItemCommentBinding binding) { super(binding.getRoot()); this.binding = binding; - this.markdownViewer = this.binding.message; } public void bind(@NonNull FullDeckComment comment, @NonNull Account account, @ColorInt int mainColor, @NonNull MenuInflater inflater, @NonNull CommentDeletedListener deletedListener, @NonNull CommentSelectAsReplyListener selectAsReplyListener, @NonNull FragmentManager fragmentManager) { ViewUtil.addAvatar(binding.avatar, account.getUrl(), comment.getComment().getActorId(), DimensionUtil.INSTANCE.dpToPx(binding.avatar.getContext(), R.dimen.icon_size_details), R.drawable.ic_person_grey600_24dp); - this.markdownViewer.setMarkdownString(comment.getComment().getMessage()); + binding.message.setMarkdownString(comment.getComment().getMessage()); binding.actorDisplayName.setText(comment.getComment().getActorDisplayName()); binding.creationDateTime.setText(DateUtil.getRelativeDateTimeString(binding.creationDateTime.getContext(), comment.getComment().getCreationDateTime().toEpochMilli())); itemView.setOnClickListener(View::showContextMenu); @@ -79,7 +76,7 @@ public class ItemCommentViewHolder extends RecyclerView.ViewHolder { binding.notSyncedYet.setVisibility(DBStatus.LOCAL_EDITED.equals(comment.getStatusEnum()) ? View.VISIBLE : View.GONE); TooltipCompat.setTooltipText(binding.creationDateTime, comment.getComment().getCreationDateTime().atZone(ZoneId.systemDefault()).format(dateFormatter)); - setupMentions(account, comment.getComment().getMentions(), binding.message); + setupMentions(account, binding.message.getContext(), comment.getComment().getMessage(), comment.getComment().getMentions(), this.binding.message); if (comment.getParent() == null) { binding.parentContainer.setVisibility(View.GONE); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java index c82ed654a..1422620a7 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java @@ -35,7 +35,6 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import it.niedermann.android.markdown.MarkdownEditor; import it.niedermann.android.util.ColorUtil; import it.niedermann.android.util.DimensionUtil; import it.niedermann.nextcloud.deck.DeckLog; @@ -70,7 +69,6 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis private final DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); private final DateTimeFormatter timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); private AppCompatActivity activity; - private MarkdownEditor description; @Override public void onAttach(@NonNull Context context) { @@ -91,7 +89,6 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis ViewGroup container, Bundle savedInstanceState) { binding = FragmentCardEditTabDetailsBinding.inflate(inflater, container, false); - this.description = binding.description; viewModel = new ViewModelProvider(activity).get(EditCardViewModel.class); // This might be a zombie fragment with an empty EditCardViewModel after Android killed the activity (but not the fragment instance @@ -103,8 +100,7 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis syncManager = new SyncManager(requireContext()); - @Px - final int avatarSize = DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.avatar_size); + @Px final int avatarSize = DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.avatar_size); final LinearLayout.LayoutParams avatarLayoutParams = new LinearLayout.LayoutParams(avatarSize, avatarSize); avatarLayoutParams.setMargins(0, 0, DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.spacer_1x), 0); @@ -113,7 +109,6 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis setupDueDate(); setupDescription(); setupProjects(); - description.setMarkdownString(viewModel.getFullCard().getCard().getDescription()); return binding.getRoot(); } @@ -143,14 +138,17 @@ public class CardDetailsFragment extends BrandedFragment implements OnDateSetLis } private void setupDescription() { + binding.description.setMarkdownString(viewModel.getFullCard().getCard().getDescription()); if (viewModel.canEdit()) { - description.setTextChangedListener((newText) -> { + binding.description.getMarkdownString().observe(getViewLifecycleOwner(), (newText) -> { if (viewModel.getFullCard() != null) { - viewModel.getFullCard().getCard().setDescription(newText); + viewModel.getFullCard().getCard().setDescription(newText == null ? "" : newText.toString()); + } else { + DeckLog.logError(new IllegalStateException("FullCard was empty when trying to setup description")); } }); } else { - description.setEnabled(false); + binding.description.setEnabled(false); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java index c7870ddd7..ffc06e33d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ViewUtil.java @@ -98,11 +98,10 @@ public final class ViewUtil { * * @param account {@link Account} where the users of those mentions belong to * @param mentions {@link List} of all mentions that should be substituted - * @param textView target {@link TextView} + * @param target target {@link TextView} */ - public static void setupMentions(@NonNull Account account, @NonNull List<Mention> mentions, MarkdownEditor textView) { - Context context = textView.getContext(); - SpannableStringBuilder messageBuilder = new SpannableStringBuilder(textView.getText()); + public static void setupMentions(@NonNull Account account, @NonNull Context context, String text, @NonNull List<Mention> mentions, MarkdownEditor target) { + SpannableStringBuilder messageBuilder = new SpannableStringBuilder(text); // Step 1 // Add avatar icons and display names @@ -116,7 +115,7 @@ public final class ViewUtil { index = messageBuilder.toString().substring(0, index).lastIndexOf(mentionId); } } - textView.setMarkdownString(messageBuilder); + target.setMarkdownString(messageBuilder); // Step 2 // Replace avatar icons with real avatars @@ -142,7 +141,7 @@ public final class ViewUtil { } }); } - textView.setMarkdownString(messageBuilder); + target.setMarkdownString(messageBuilder); } public static void setImageColor(@NonNull Context context, @NonNull ImageView imageView, @ColorRes int colorRes) { |