From 898218e7402bdb22d0a439dea376665a28729a49 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 11 Feb 2020 20:16:03 +0100 Subject: make colored muc names configurable * default = off --- .../messenger/services/NotificationService.java | 6 ++-- .../messenger/services/XmppConnectionService.java | 4 +++ .../messenger/ui/adapter/ConversationAdapter.java | 12 +++++-- .../messenger/ui/adapter/MessageAdapter.java | 39 ++-------------------- .../java/de/pixart/messenger/utils/UIHelper.java | 7 ++-- src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 2 ++ src/main/res/xml/preferences.xml | 5 +++ 8 files changed, 33 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 0848d0c2c..826b5172d 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -657,7 +657,7 @@ public class NotificationService { builder.setUri(uri.toString()); } } else { - builder.setName(UIHelper.getColoredUsername(message)); + builder.setName(UIHelper.getColoredUsername(mXmppConnectionService, message)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false))); @@ -704,14 +704,14 @@ public class NotificationService { final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); SpannableString styledString; for (Message message : messages) { - final SpannableString name = UIHelper.getColoredUsername(message); + final SpannableString name = UIHelper.getColoredUsername(mXmppConnectionService, message); styledString = new SpannableString(name + ": " + message.getBody()); style.addLine(styledString); } builder.setStyle(style); int count = messages.size(); if (count == 1) { - final SpannableString name = UIHelper.getColoredUsername(messages.get(0)); + final SpannableString name = UIHelper.getColoredUsername(mXmppConnectionService, messages.get(0)); styledString = new SpannableString(name + ": " + messages.get(0).getBody()); builder.setContentText(styledString); builder.setTicker(styledString); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index e5b6582d1..9b165ca5c 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1013,6 +1013,10 @@ public class XmppConnectionService extends Service { return getBooleanPreference("alternative_voice_settings", R.bool.alternative_voice_settings); } + public boolean colored_muc_names() { + return getBooleanPreference("colored_muc_names", R.bool.use_colored_muc_names); + } + public int getCompressImageResolutionPreference() { switch (getPreferences().getString("image_compression", getResources().getString(R.string.image_compression))) { case "low": diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java index cf4a72bee..7ce7573a3 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java @@ -3,7 +3,10 @@ package de.pixart.messenger.ui.adapter; import android.content.SharedPreferences; import android.graphics.Typeface; import android.preference.PreferenceManager; +import android.text.Spannable; +import android.text.SpannableString; import android.text.SpannableStringBuilder; +import android.text.style.StyleSpan; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -183,13 +186,18 @@ public class ConversationAdapter extends RecyclerView.Adapter implements CopyTextVie default: if (multiReceived) { viewHolder.username.setVisibility(View.VISIBLE); - viewHolder.username.setText(UIHelper.getColoredUsername(message)); + viewHolder.username.setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message)); } if (singleReceived) { viewHolder.username.setVisibility(View.GONE); @@ -584,7 +584,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.messageBody.setHighlightColor(darkBackground ? type == SENT ? StyledAttributes.getColor(activity, R.attr.colorAccent) : StyledAttributes.getColor(activity, R.attr.colorAccent) : StyledAttributes.getColor(activity, R.attr.colorAccent)); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); if (message.getBody() != null) { - final SpannableString nick = UIHelper.getColoredUsername(message); + final SpannableString nick = UIHelper.getColoredUsername(activity.xmppConnectionService, message); SpannableStringBuilder body = new SpannableStringBuilder(replaceYoutube(activity.getApplicationContext(), message.getMergedBody().toString())); if (message.getBody().equals(DELETED_MESSAGE_BODY)) { body = body.replace(0, DELETED_MESSAGE_BODY.length(), activity.getString(R.string.message_deleted)); @@ -682,14 +682,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie private void displayOpenableMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) { toggleWhisperInfo(viewHolder, message, false, darkBackground); final String mimeType = message.getMimeType(); - if (mimeType != null && message.getMimeType().contains("pdf")) { - try { - showPDF(message, viewHolder, false); - } catch (Exception e) { - e.printStackTrace(); - showPDF(message, viewHolder, true); - } - } else if (mimeType != null && message.getMimeType().contains("vcard")) { + if (mimeType != null && message.getMimeType().contains("vcard")) { try { showVCard(message, viewHolder); } catch (Exception e) { @@ -735,32 +728,6 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.download_button.setOnClickListener(v -> openDownloadable(message)); } - private void showPDF(final Message message, final ViewHolder viewHolder, boolean compat) { - if (runsTwentyOne() && !compat) { - viewHolder.audioPlayer.setVisibility(View.GONE); - viewHolder.image.setVisibility(View.VISIBLE); - viewHolder.gifImage.setVisibility(View.GONE); - viewHolder.richlinkview.setVisibility(View.GONE); - viewHolder.progressBar.setVisibility(View.GONE); - viewHolder.download_button.setVisibility(View.GONE); - activity.loadBitmap(message, viewHolder.image); - viewHolder.image.setOnClickListener(v -> openDownloadable(message)); - } else { - viewHolder.audioPlayer.setVisibility(View.GONE); - viewHolder.image.setVisibility(View.GONE); - viewHolder.gifImage.setVisibility(View.GONE); - viewHolder.richlinkview.setVisibility(View.GONE); - viewHolder.progressBar.setVisibility(View.GONE); - viewHolder.download_button.setVisibility(View.VISIBLE); - final Drawable icon = activity.getResources().getDrawable(R.drawable.ic_file_pdf_grey600_48dp); - final Drawable drawable = DrawableCompat.wrap(icon); - DrawableCompat.setTint(drawable, StyledAttributes.getColor(getContext(), R.attr.colorAccent)); - viewHolder.download_button.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); - viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity, message))); - viewHolder.download_button.setOnClickListener(v -> openDownloadable(message)); - } - } - private void showAPK(final Message message, final ViewHolder viewHolder) { String APKName = ""; if (message.getFileParams().subject.length() != 0) { diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index 5c3db105a..e2b3c2f2c 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -34,6 +34,7 @@ import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.Transferable; import de.pixart.messenger.services.ExportBackupService; +import de.pixart.messenger.services.XmppConnectionService; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.entities.Message.DELETED_MESSAGE_BODY; @@ -504,11 +505,13 @@ public class UIHelper { } } - public static SpannableString getColoredUsername(final Message message) { + public static SpannableString getColoredUsername(final XmppConnectionService service, final Message message) { final SpannableString user; user = SpannableString.valueOf(UIHelper.getMessageDisplayName(message)); user.setSpan(new StyleSpan(Typeface.BOLD), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - user.setSpan(new ForegroundColorSpan(message.getAvatarBackgroundColor()), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (service.colored_muc_names()) { + user.setSpan(new ForegroundColorSpan(message.getAvatarBackgroundColor()), 0, user.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } return user; } diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 2c3ea9331..c32c092f4 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -73,6 +73,7 @@ JABBER_NETWORK false false + false pix-art.de diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 260e74077..f61da74b9 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1000,4 +1000,6 @@ Use unicolored background If you have problems during voice recording, use this setting to change the codec. Alternative voice recording method + Colorize nicknames in group chats or channels like default avatar backgrounds. + Colorize nicknames diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 8bc0d0372..291172702 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -40,6 +40,11 @@ android:key="unicolored_chatbg" android:summary="@string/pref_use_unicolored_chatbg_summary" android:title="@string/pref_use_unicolored_chatbg" /> +