From e21da762dc99cfa6e8881a5c1ac2aa892de7762e Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 26 Aug 2018 20:28:26 +0200 Subject: make QUICK_SHARE_ATTACHMENT_CHOICE configurable --- src/main/java/de/pixart/messenger/Config.java | 2 -- .../pixart/messenger/services/XmppConnectionService.java | 4 ++++ .../java/de/pixart/messenger/ui/ConversationFragment.java | 8 ++++++-- src/main/java/de/pixart/messenger/ui/SettingsActivity.java | 14 +++++++++++++- .../java/de/pixart/messenger/ui/util/SendButtonTool.java | 11 +++++------ src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 2 ++ src/main/res/xml/preferences.xml | 5 +++++ 8 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 644b0af82..e2914f9d3 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -88,8 +88,6 @@ public final class Config { public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG; public static final int IMAGE_QUALITY = 75; - public static final boolean QUICK_SHARE_ATTACHMENT_CHOICE = true; // set to true to use attachment choice instead of quick share for send button - public static final int DEFAULT_ZOOM = 15; //for locations public final static long LOCATION_FIX_TIME_DELTA = 1000 * 10; // ms public final static float LOCATION_FIX_SPACE_DELTA = 10; // m diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 71d61dc55..f4e0bf877 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -924,6 +924,10 @@ public class XmppConnectionService extends Service { } } + public boolean getAttachmentChoicePreference() { + return getBooleanPreference(SettingsActivity.QUICK_SHARE_ATTACHMENT_CHOICE, R.bool.quick_share_attachment_choice); + } + private Presence.Status getTargetPresence() { if (dndOnSilentMode() && isPhoneSilenced()) { return Presence.Status.DND; diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 504fae76c..ec9dcf8f0 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -126,6 +126,7 @@ import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT; import static de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION; +import static de.pixart.messenger.ui.util.SendButtonAction.TEXT; import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS; @@ -1186,7 +1187,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } menuNeedHelp.setVisible(true); menuSearchUpdates.setVisible(false); - ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu, Config.QUICK_SHARE_ATTACHMENT_CHOICE); + ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu, activity.xmppConnectionService.getAttachmentChoicePreference()); ConversationMenuConfigurator.configureEncryptionMenu(conversation, menu); } else { menuNeedHelp.setVisible(false); @@ -2557,7 +2558,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final Conversation c = this.conversation; final Presence.Status status; final String text = this.binding.textinput == null ? "" : this.binding.textinput.getText().toString(); - final SendButtonAction action = SendButtonTool.getAction(getActivity(), c, text); + SendButtonAction action = SendButtonTool.getAction(getActivity(), c, text); if (useSendButtonToIndicateStatus && c.getAccount().getStatus() == Account.State.ONLINE) { if (activity.xmppConnectionService != null && activity.xmppConnectionService.getMessageArchiveService().isCatchingUp(c)) { status = Presence.Status.OFFLINE; @@ -2569,6 +2570,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } else { status = Presence.Status.OFFLINE; } + if (action.toString().equals("CHOOSE_ATTACHMENT") && !activity.xmppConnectionService.getAttachmentChoicePreference()) { + action = TEXT; + } this.binding.textSendButton.setTag(action); this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(getActivity(), action, status)); } diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 9ee11bd0b..1ace03e5e 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -58,12 +58,15 @@ public class SettingsActivity extends XmppActivity implements public static final String SHOW_FOREGROUND_SERVICE = "show_foreground_service"; public static final String USE_BUNDLED_EMOJIS = "use_bundled_emoji"; public static final String USE_MULTI_ACCOUNTS = "use_multi_accounts"; + public static final String QUICK_SHARE_ATTACHMENT_CHOICE = "quick_share_attachment_choice"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; Preference multiAccountPreference; Preference BundledEmojiPreference; + Preference QuickShareAttachmentChoicePreference; boolean isMultiAccountChecked = false; boolean isBundledEmojiChecked; + boolean isQuickShareAttachmentChoiceChecked = false; private SettingsFragment mSettingsFragment; @Override @@ -105,6 +108,15 @@ public class SettingsActivity extends XmppActivity implements isBundledEmojiChecked = ((CheckBoxPreference) BundledEmojiPreference).isChecked(); } + QuickShareAttachmentChoicePreference = mSettingsFragment.findPreference("quick_share_attachment_choice"); + if (QuickShareAttachmentChoicePreference != null) { + QuickShareAttachmentChoicePreference.setOnPreferenceChangeListener((preference, newValue) -> { + recreate(); + return true; + }); + isQuickShareAttachmentChoiceChecked = ((CheckBoxPreference) QuickShareAttachmentChoicePreference).isChecked(); + } + changeOmemoSettingSummary(); if (Config.FORCE_ORBOT) { @@ -173,7 +185,7 @@ public class SettingsActivity extends XmppActivity implements quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()])); } - if (Config.QUICK_SHARE_ATTACHMENT_CHOICE) { + if (isQuickShareAttachmentChoiceChecked) { if (UIPreferenceScreen != null && quickAction != null) { UIPreferenceScreen.removePreference(quickAction); } diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java index 291edb822..b4b0ecc28 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java @@ -38,10 +38,9 @@ import de.pixart.messenger.R; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.ui.ConversationFragment; +import de.pixart.messenger.ui.SettingsActivity; import de.pixart.messenger.utils.UIHelper; -import static de.pixart.messenger.Config.QUICK_SHARE_ATTACHMENT_CHOICE; - public class SendButtonTool { public static SendButtonAction getAction(Activity activity, Conversation c, String text) { @@ -61,12 +60,13 @@ public class SendButtonTool { if (conference && c.getNextCounterpart() != null) { return SendButtonAction.CANCEL; } else { - if (QUICK_SHARE_ATTACHMENT_CHOICE && AttachmentsVisible(c)) { + boolean quickShareChoice = preferences.getBoolean(SettingsActivity.QUICK_SHARE_ATTACHMENT_CHOICE, activity.getResources().getBoolean(R.bool.quick_share_attachment_choice)); + String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action)); + if (quickShareChoice && AttachmentsVisible(c)) { return SendButtonAction.CHOOSE_ATTACHMENT; - } else if (QUICK_SHARE_ATTACHMENT_CHOICE && !AttachmentsVisible(c)) { + } else if (quickShareChoice && !AttachmentsVisible(c)) { return SendButtonAction.TEXT; } else { - String setting = preferences.getString("quick_action", activity.getResources().getString(R.string.quick_action)); if (!setting.equals("none") && UIHelper.receivedLocationQuestion(c.getLatestMessage())) { return SendButtonAction.SEND_LOCATION; } else { @@ -198,5 +198,4 @@ public class SendButtonTool { return res; } - } \ No newline at end of file diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 98509a48e..214dbe642 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -108,6 +108,7 @@ small false true + true pix-art.de diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 47a01d3c9..f5dabc615 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -810,4 +810,6 @@ Pix-Art Messenger needs access to location services Show record voice button in chats as quick action Show record voice button + Replace send button with attachment choice if no message is typed. Otherwise show quick actions, which can be cofigured in the following setting. + Attachment choice diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 31ca6158b..b4edb7a34 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -38,6 +38,11 @@ android:key="presence_colored_names" android:summary="@string/pref_use_colored_names_to_indicate_status_summary" android:title="@string/pref_use_colored_names_to_indicate_status" /> +