diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-08-05 12:36:18 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-08-05 12:36:18 +0200 |
commit | 3f55a61c250c5b9dd81dd4dcfd4c9531369d2152 (patch) | |
tree | 91cd1cb9076fe04a5a063938d8584c99bdc91649 /src/main/java/de/pixart/messenger/ui/util | |
parent | 7414a4e5a2567b312099e82f818d46608d8bbdfb (diff) |
introduced config flag to show attachment button instead of quick actions
Diffstat (limited to '')
3 files changed, 55 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java b/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java index 03f7638e3..98a73addc 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java +++ b/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java @@ -53,9 +53,21 @@ public class ConversationMenuConfigurator { locationAvailable = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK); } - public static void configureAttachmentMenu(@NonNull Conversation conversation, Menu menu) { - final MenuItem menuAttach = menu.findItem(R.id.action_attach_file); + public static void configureQuickShareAttachmentMenu(@NonNull Conversation conversation, Menu menu) { + final boolean visible = SendButtonTool.AttachmentsVisible(conversation); + if (!visible) { + return; + } + menu.findItem(R.id.attach_record_voice).setVisible(microphoneAvailable); + menu.findItem(R.id.attach_location).setVisible(locationAvailable); + } + public static void configureAttachmentMenu(@NonNull Conversation conversation, Menu menu, Boolean Quick_share_attachment_choice) { + final MenuItem menuAttach = menu.findItem(R.id.action_attach_file); + if (Quick_share_attachment_choice) { + menuAttach.setVisible(false); + return; + } final boolean visible; if (conversation.getMode() == Conversation.MODE_MULTI) { visible = conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating(); diff --git a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java index 6258b49c6..9f9fabc5a 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonAction.java @@ -29,13 +29,14 @@ package de.pixart.messenger.ui.util; +import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_CHOOSE_IMAGE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_LOCATION; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_RECORD_VOICE; import static de.pixart.messenger.ui.ConversationFragment.ATTACHMENT_CHOICE_TAKE_FROM_CAMERA; public enum SendButtonAction { - TEXT, TAKE_FROM_CAMERA, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE; + TEXT, TAKE_FROM_CAMERA, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE, CHOOSE_ATTACHMENT; public static SendButtonAction valueOfOrDefault(String setting, SendButtonAction text) { try { @@ -55,6 +56,8 @@ public enum SendButtonAction { return TAKE_FROM_CAMERA; case ATTACHMENT_CHOICE_CHOOSE_IMAGE: return CHOOSE_PICTURE; + case ATTACHMENT_CHOICE: + return CHOOSE_ATTACHMENT; default: throw new IllegalArgumentException("Not a known attachment choice"); } @@ -70,6 +73,8 @@ public enum SendButtonAction { return ATTACHMENT_CHOICE_RECORD_VOICE; case CHOOSE_PICTURE: return ATTACHMENT_CHOICE_CHOOSE_IMAGE; + case CHOOSE_ATTACHMENT: + return ATTACHMENT_CHOICE; default: return 0; } 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 fdff0b4dc..291edb822 100644 --- a/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java +++ b/src/main/java/de/pixart/messenger/ui/util/SendButtonTool.java @@ -40,6 +40,8 @@ import de.pixart.messenger.entities.Presence; import de.pixart.messenger.ui.ConversationFragment; 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) { @@ -59,15 +61,21 @@ public class SendButtonTool { if (conference && c.getNextCounterpart() != null) { return SendButtonAction.CANCEL; } 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; + if (QUICK_SHARE_ATTACHMENT_CHOICE && AttachmentsVisible(c)) { + return SendButtonAction.CHOOSE_ATTACHMENT; + } else if (QUICK_SHARE_ATTACHMENT_CHOICE && !AttachmentsVisible(c)) { + return SendButtonAction.TEXT; } else { - if (setting.equals("recent")) { - setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString()); - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + 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 { - return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + if (setting.equals("recent")) { + setting = preferences.getString(ConversationFragment.RECENTLY_USED_QUICK_ACTION, SendButtonAction.TEXT.toString()); + return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + } else { + return SendButtonAction.valueOfOrDefault(setting, SendButtonAction.TEXT); + } } } } @@ -77,6 +85,12 @@ public class SendButtonTool { } } + public static boolean AttachmentsVisible(Conversation conversation) { + final boolean visible; + visible = conversation.getMode() != Conversation.MODE_MULTI || conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating(); + return visible; + } + public static int getSendButtonImageResource(Activity activity, SendButtonAction action, Presence.Status status) { switch (action) { case TEXT: @@ -157,6 +171,20 @@ public class SendButtonTool { default: return getThemeResource(activity, R.attr.ic_send_picture_offline, R.drawable.ic_send_picture_offline); } + + case CHOOSE_ATTACHMENT: + switch (status) { + case CHAT: + case ONLINE: + return R.drawable.ic_send_attachment_online; + case AWAY: + return R.drawable.ic_send_attachment_away; + case XA: + case DND: + return R.drawable.ic_send_attachment_dnd; + default: + return getThemeResource(activity, R.attr.ic_send_attachment_offline, R.drawable.ic_send_attachment_offline); + } } return getThemeResource(activity, R.attr.ic_send_text_offline, R.drawable.ic_send_text_offline); } |