mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 04:09:21 +00:00
proper chip theming for you-mentions
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
9a2d7ee1ff
commit
9eb3cbc280
@ -246,7 +246,8 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
||||
individualHashMap["name"]!!,
|
||||
individualHashMap["type"]!!,
|
||||
message.activeUser!!,
|
||||
R.xml.chip_you
|
||||
R.xml.chip_you,
|
||||
viewThemeUtils
|
||||
)
|
||||
} else {
|
||||
messageStringInternal = DisplayUtils.searchAndReplaceWithMentionSpan(
|
||||
@ -256,7 +257,8 @@ class MagicIncomingTextMessageViewHolder(itemView: View, payload: Any) : Message
|
||||
individualHashMap["name"]!!,
|
||||
individualHashMap["type"]!!,
|
||||
message.activeUser!!,
|
||||
R.xml.chip_others
|
||||
R.xml.chip_others,
|
||||
viewThemeUtils
|
||||
)
|
||||
}
|
||||
} else if (individualHashMap["type"] == "file") {
|
||||
|
@ -180,7 +180,8 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
|
||||
individualHashMap["name"]!!,
|
||||
individualHashMap["type"]!!,
|
||||
message.activeUser,
|
||||
R.xml.chip_others
|
||||
R.xml.chip_others,
|
||||
viewThemeUtils
|
||||
)
|
||||
} else if (individualHashMap["type"] == "file") {
|
||||
realView.setOnClickListener { v: View? ->
|
||||
|
@ -31,6 +31,7 @@ import com.facebook.widget.text.span.BetterImageSpan;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
import com.nextcloud.talk.models.json.mention.Mention;
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.MagicCharPolicy;
|
||||
import com.nextcloud.talk.utils.text.Spans;
|
||||
@ -39,15 +40,19 @@ import com.vanniktech.emoji.EmojiRange;
|
||||
import com.vanniktech.emoji.Emojis;
|
||||
|
||||
public class MentionAutocompleteCallback implements AutocompleteCallback<Mention> {
|
||||
private final ViewThemeUtils viewThemeUtils;
|
||||
private Context context;
|
||||
private User conversationUser;
|
||||
private EditText editText;
|
||||
|
||||
public MentionAutocompleteCallback(Context context, User conversationUser,
|
||||
EditText editText) {
|
||||
public MentionAutocompleteCallback(Context context,
|
||||
User conversationUser,
|
||||
EditText editText,
|
||||
ViewThemeUtils viewThemeUtils) {
|
||||
this.context = context;
|
||||
this.conversationUser = conversationUser;
|
||||
this.editText = editText;
|
||||
this.viewThemeUtils = viewThemeUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,11 +78,14 @@ public class MentionAutocompleteCallback implements AutocompleteCallback<Mention
|
||||
conversationUser,
|
||||
item.getSource(),
|
||||
R.xml.chip_you,
|
||||
editText),
|
||||
editText,
|
||||
viewThemeUtils),
|
||||
BetterImageSpan.ALIGN_CENTER,
|
||||
item.getId(), item.getLabel());
|
||||
editable.setSpan(mentionChipSpan, start, start + replacementStringBuilder.toString().length(),
|
||||
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1679,7 +1679,8 @@ class ChatController(args: Bundle) :
|
||||
val callback = MentionAutocompleteCallback(
|
||||
activity,
|
||||
conversationUser!!,
|
||||
binding.messageInputView.inputEditText
|
||||
binding.messageInputView.inputEditText,
|
||||
viewThemeUtils
|
||||
)
|
||||
|
||||
if (mentionAutocomplete == null && binding.messageInputView.inputEditText != null) {
|
||||
|
@ -56,6 +56,7 @@ import com.google.android.material.appbar.MaterialToolbar
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipDrawable
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
@ -101,6 +102,10 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
|
||||
block(getScheme(view.context))
|
||||
}
|
||||
|
||||
private fun withScheme(context: Context, block: (Scheme) -> Unit) {
|
||||
block(getScheme(context))
|
||||
}
|
||||
|
||||
private fun withSchemeDark(block: (Scheme) -> Unit) {
|
||||
block(getSchemeDark())
|
||||
}
|
||||
@ -664,6 +669,13 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
|
||||
)
|
||||
}
|
||||
|
||||
fun themePrimaryMentionChip(context: Context, chip: ChipDrawable) {
|
||||
withScheme(context) { scheme ->
|
||||
chip.chipBackgroundColor = ColorStateList.valueOf(scheme.primary)
|
||||
chip.setTextColor(scheme.onPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val THEMEABLE_PLACEHOLDER_IDS = listOf(
|
||||
R.drawable.ic_mimetype_package_x_generic,
|
||||
|
@ -81,6 +81,7 @@ import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
import com.nextcloud.talk.events.UserMentionClickEvent;
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
|
||||
import com.nextcloud.talk.utils.text.Spans;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -297,11 +298,16 @@ public class DisplayUtils {
|
||||
User conversationUser,
|
||||
String type,
|
||||
@XmlRes int chipResource,
|
||||
@Nullable EditText emojiEditText) {
|
||||
@Nullable EditText emojiEditText,
|
||||
ViewThemeUtils viewThemeUtils) {
|
||||
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
|
||||
chip.setText(EmojiCompat.get().process(label));
|
||||
chip.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
||||
|
||||
if (chipResource == R.xml.chip_you) {
|
||||
viewThemeUtils.themePrimaryMentionChip(context, chip);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
chip.setLayoutDirection(config.getLayoutDirection());
|
||||
@ -367,7 +373,8 @@ public class DisplayUtils {
|
||||
public static Spannable searchAndReplaceWithMentionSpan(Context context, Spannable text,
|
||||
String id, String label, String type,
|
||||
User conversationUser,
|
||||
@XmlRes int chipXmlRes) {
|
||||
@XmlRes int chipXmlRes,
|
||||
ViewThemeUtils viewThemeUtils) {
|
||||
|
||||
Spannable spannableString = new SpannableString(text);
|
||||
String stringText = text.toString();
|
||||
@ -395,10 +402,18 @@ public class DisplayUtils {
|
||||
conversationUser,
|
||||
type,
|
||||
chipXmlRes,
|
||||
null),
|
||||
null,
|
||||
viewThemeUtils),
|
||||
BetterImageSpan.ALIGN_CENTER, id,
|
||||
label);
|
||||
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (chipXmlRes == R.xml.chip_you) {
|
||||
spannableString.setSpan(
|
||||
new ForegroundColorSpan(viewThemeUtils.getScheme(context).getOnPrimary()),
|
||||
start,
|
||||
end,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
if ("user".equals(type) && !conversationUser.getUserId().equals(id)) {
|
||||
spannableString.setSpan(clickableSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user