diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-08-05 18:13:19 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-08-05 18:13:19 +0200 |
commit | bbb53526f80c14d9ddc0f25ad5516a600e1868fa (patch) | |
tree | b2493a52a8eefd377e2b5986f42a82886d2b3247 /src/main | |
parent | b890f6e78f69f55a553d2fff92b0e82e10d97af2 (diff) |
add a quick action for voice recording
* is enabled as default
* can be disabled in settings
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 27 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java | 5 | ||||
-rw-r--r-- | src/main/res/layout/fragment_conversation.xml | 16 | ||||
-rw-r--r-- | src/main/res/values/defaults.xml | 1 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/main/res/xml/preferences.xml | 5 |
6 files changed, 51 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 743c96826..0374e643c 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -444,6 +444,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } }; + private OnClickListener mRecordVoiceButtonListener = new OnClickListener() { + + @Override + public void onClick(View v) { + attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); + } + }; + private OnClickListener mSendButtonListener = new OnClickListener() { @Override @@ -485,10 +493,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @SuppressLint("RestrictedApi") private void choose_attachment(View v) { + SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); + final boolean hideVoice = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn)); PopupMenu popup = new PopupMenu(activity, v); popup.inflate(R.menu.choose_attachment); Menu menu = popup.getMenu(); - ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu); + ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoice); popup.setOnMenuItemClickListener(attachmentItem -> { switch (attachmentItem.getItemId()) { case R.id.attach_choose_picture: @@ -496,7 +506,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke case R.id.attach_choose_file: case R.id.attach_record_voice: case R.id.attach_location: - Log.d(Config.LOGTAG, "ATTACHMENT: " + attachmentItem.getTitle()); handleAttachmentSelection(attachmentItem); default: return false; @@ -1199,6 +1208,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke binding.textSendButton.setOnClickListener(this.mSendButtonListener); binding.textSendButton.setOnLongClickListener(this.mSendButtonLongListener); binding.scrollToBottomButton.setOnClickListener(this.mScrollButtonListener); + binding.recordVoiceButton.setOnClickListener(this.mRecordVoiceButtonListener); binding.messagesView.setOnScrollListener(mOnScrollListener); binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); @@ -1289,6 +1299,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } + private void showRecordVoiceButton() { + SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); + final boolean ShowRecordVoiceButton = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn)); + Log.d(Config.LOGTAG, "Recorder " + ShowRecordVoiceButton); + if (ShowRecordVoiceButton) { + binding.recordVoiceButton.setVisibility(View.VISIBLE); + } else { + binding.recordVoiceButton.setVisibility(View.GONE); + } + binding.recordVoiceButton.setImageResource(activity.getThemeResource(R.attr.ic_send_voice_offline, R.drawable.ic_send_voice_offline)); + } + private void quoteMessage(Message message) { quoteText(MessageUtils.prepareQuote(message)); } @@ -2178,6 +2200,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textSendButton.setContentDescription(activity.getString(R.string.send_message_to_x, conversation.getName())); this.binding.textinput.setKeyboardListener(null); this.binding.textinput.setText(""); + showRecordVoiceButton(); final boolean participating = conversation.getMode() == Conversational.MODE_SINGLE || conversation.getMucOptions().participating(); if (participating) { this.binding.textinput.append(this.conversation.getNextMessage()); 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 98a73addc..5c86b4a1b 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java +++ b/src/main/java/de/pixart/messenger/ui/util/ConversationMenuConfigurator.java @@ -53,11 +53,14 @@ public class ConversationMenuConfigurator { locationAvailable = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK); } - public static void configureQuickShareAttachmentMenu(@NonNull Conversation conversation, Menu menu) { + public static void configureQuickShareAttachmentMenu(@NonNull Conversation conversation, Menu menu, boolean hideVoice) { final boolean visible = SendButtonTool.AttachmentsVisible(conversation); if (!visible) { return; } + if (hideVoice) { + microphoneAvailable = false; + } menu.findItem(R.id.attach_record_voice).setVisible(microphoneAvailable); menu.findItem(R.id.attach_location).setVisible(locationAvailable); } diff --git a/src/main/res/layout/fragment_conversation.xml b/src/main/res/layout/fragment_conversation.xml index cc35d21cc..d081b6543 100644 --- a/src/main/res/layout/fragment_conversation.xml +++ b/src/main/res/layout/fragment_conversation.xml @@ -57,6 +57,7 @@ <RelativeLayout android:id="@+id/textsend" + android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" @@ -66,13 +67,24 @@ android:paddingLeft="2dp" android:paddingTop="2dp"> + <ImageButton + android:id="@+id/recordVoiceButton" + android:layout_width="48dp" + android:layout_height="48dp" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" + android:background="?attr/color_background_secondary" + android:contentDescription="@string/attach_record_voice" + android:src="@drawable/ic_send_voice_offline" + android:visibility="gone" /> + <de.pixart.messenger.ui.widget.EditMessage android:id="@+id/textinput" style="@style/Widget.Conversations.EditText" - android:layout_width="wrap_content" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/textSendButton" + android:layout_toRightOf="@+id/recordVoiceButton" android:background="@drawable/message_bubble_sent_blue" android:ems="10" android:imeOptions="flagNoExtractUi|actionSend" diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index c96f22f3d..29a256afb 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -107,6 +107,7 @@ <string name="theme">light</string> <string name="default_font_size">small</string> <bool name="start_searching">false</bool> + <bool name="show_record_voice_btn">true</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 5b5876823..321a5f97a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -808,4 +808,6 @@ <string name="no_application_found_to_view_contact">No application found to view contact</string> <string name="welcome_server_info">We recommend the use of blabber.im as your provider.</string> <string name="no_location_permission">Pix-Art Messenger needs access to location services</string> + <string name="pref_show_record_voice_btn_summary">Show record voice button in chats as quick action</string> + <string name="pref_show_record_voice_btn">Show record voice button</string> </resources> diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 49de3cfc0..31ca6158b 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -47,6 +47,11 @@ android:summary="@string/pref_quick_action_summary" android:title="@string/pref_quick_action" /> <CheckBoxPreference + android:defaultValue="@bool/show_record_voice_btn" + android:key="show_record_voice_btn" + android:summary="@string/pref_show_record_voice_btn_summary" + android:title="@string/pref_show_record_voice_btn" /> + <CheckBoxPreference android:defaultValue="@bool/use_max_brightness" android:key="use_max_brightness" android:summary="@string/pref_use_max_brightness_summary" |