diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-02-11 20:16:03 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2020-02-11 20:16:03 +0100 |
commit | 898218e7402bdb22d0a439dea376665a28729a49 (patch) | |
tree | 3282d594ffc1e640b6ac682f6db1402b078c2df1 /src | |
parent | 71780abb89b56e976bccecea721581794df0f62b (diff) |
make colored muc names configurable
* default = off
Diffstat (limited to 'src')
8 files changed, 33 insertions, 43 deletions
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<ConversationAdapte if (message.getStatus() == Message.STATUS_RECEIVED) { if (conversation.getMode() == Conversation.MODE_MULTI) { viewHolder.binding.senderName.setVisibility(View.VISIBLE); - viewHolder.binding.senderName.setText(UIHelper.getColoredUsername(message)); + viewHolder.binding.senderName.setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message)); + viewHolder.binding.senderName.append(":"); } else { viewHolder.binding.senderName.setVisibility(View.GONE); } } else if (message.getType() != Message.TYPE_STATUS) { viewHolder.binding.senderName.setVisibility(View.VISIBLE); - viewHolder.binding.senderName.setText(activity.getString(R.string.me) + ':'); + final SpannableString me; + me = SpannableString.valueOf(activity.getString(R.string.me)); + me.setSpan(new StyleSpan(Typeface.BOLD), 0, me.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + viewHolder.binding.senderName.setText(me); + viewHolder.binding.senderName.append(":"); } else { viewHolder.binding.senderName.setVisibility(View.GONE); } diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index d66b5cf5a..0593869ca 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -306,7 +306,7 @@ public class MessageAdapter extends ArrayAdapter<Message> 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<Message> 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<Message> 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<Message> 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 @@ <string name="default_channel_discovery">JABBER_NETWORK</string> <bool name="use_unicolored_chatbg">false</bool> <bool name="alternative_voice_settings">false</bool> + <bool name="use_colored_muc_names">false</bool> <string-array name="domains"> <item>pix-art.de</item> 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 @@ <string name="pref_use_unicolored_chatbg">Use unicolored background</string> <string name="pref_alternative_voice_settings_summary">If you have problems during voice recording, use this setting to change the codec.</string> <string name="pref_alternative_voice_settings">Alternative voice recording method</string> + <string name="pref_use_colored_muc_names_summary">Colorize nicknames in group chats or channels like default avatar backgrounds.</string> + <string name="pref_use_colored_muc_names">Colorize nicknames</string> </resources> 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 @@ -41,6 +41,11 @@ android:summary="@string/pref_use_unicolored_chatbg_summary" android:title="@string/pref_use_unicolored_chatbg" /> <CheckBoxPreference + android:defaultValue="@bool/use_colored_muc_names" + android:key="colored_muc_names" + android:summary="@string/pref_use_colored_muc_names_summary" + android:title="@string/pref_use_colored_muc_names" /> + <CheckBoxPreference android:defaultValue="@bool/send_button_status" android:key="send_button_status" android:summary="@string/pref_use_send_button_to_indicate_status_summary" |