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