Эх сурвалжийг харах

Merge pull request #1492 from nextcloud/feature/1335/forwarding-chat-messages

Forwarding chat messages
Andy Scherzinger 4 жил өмнө
parent
commit
9fa8643494

+ 3 - 3
app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt

@@ -111,7 +111,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
         if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
             if (!router!!.hasRootController()) {
                 router!!.setRoot(
-                    RouterTransaction.with(ConversationsListController())
+                    RouterTransaction.with(ConversationsListController(Bundle()))
                         .pushChangeHandler(HorizontalChangeHandler())
                         .popChangeHandler(HorizontalChangeHandler())
                 )
@@ -121,7 +121,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
             if (hasDb) {
                 if (userUtils.anyUserExists()) {
                     router!!.setRoot(
-                        RouterTransaction.with(ConversationsListController())
+                        RouterTransaction.with(ConversationsListController(Bundle()))
                             .pushChangeHandler(HorizontalChangeHandler())
                             .popChangeHandler(HorizontalChangeHandler())
                     )
@@ -174,7 +174,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
     fun resetConversationsList() {
         if (userUtils.anyUserExists()) {
             router!!.setRoot(
-                RouterTransaction.with(ConversationsListController())
+                RouterTransaction.with(ConversationsListController(Bundle()))
                     .pushChangeHandler(HorizontalChangeHandler())
                     .popChangeHandler(HorizontalChangeHandler())
             )

+ 14 - 1
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java

@@ -69,6 +69,7 @@ import java.util.concurrent.ExecutionException;
 
 import javax.inject.Inject;
 
+import androidx.appcompat.view.ContextThemeWrapper;
 import androidx.core.content.ContextCompat;
 import androidx.core.content.FileProvider;
 import androidx.emoji.widget.EmojiTextView;
@@ -407,7 +408,19 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
             return;
         }
 
-        PopupMenu popupMenu = new PopupMenu(this.context, itemView, Gravity.START);
+        Context viewContext;
+
+        if (itemView != null && itemView.getContext() != null) {
+            viewContext = itemView.getContext();
+        } else {
+            viewContext = this.context;
+        }
+
+        PopupMenu popupMenu = new PopupMenu(
+            new ContextThemeWrapper(viewContext, R.style.appActionBarPopupMenu),
+            itemView,
+            Gravity.START
+        );
         popupMenu.inflate(R.menu.chat_preview_message_menu);
 
         popupMenu.setOnMenuItemClickListener(item -> {

+ 2 - 2
app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java

@@ -443,7 +443,7 @@ public class AccountVerificationController extends BaseController {
             getActivity().runOnUiThread(() -> {
                 if (userUtils.getUsers().size() == 1) {
                     getRouter().setRoot(RouterTransaction.with(new
-                            ConversationsListController())
+                            ConversationsListController(new Bundle()))
                             .pushChangeHandler(new HorizontalChangeHandler())
                             .popChangeHandler(new HorizontalChangeHandler()));
                 } else {
@@ -524,7 +524,7 @@ public class AccountVerificationController extends BaseController {
 
                     } else {
                         if (userUtils.anyUserExists()) {
-                            getRouter().setRoot(RouterTransaction.with(new ConversationsListController())
+                            getRouter().setRoot(RouterTransaction.with(new ConversationsListController(new Bundle()))
                                     .pushChangeHandler(new HorizontalChangeHandler())
                                     .popChangeHandler(new HorizontalChangeHandler()));
                         } else {

+ 17 - 1
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -95,6 +95,7 @@ import com.facebook.imagepipeline.image.CloseableImage
 import com.google.android.flexbox.FlexboxLayout
 import com.nextcloud.talk.R
 import com.nextcloud.talk.activities.MagicCallActivity
+import com.nextcloud.talk.activities.MainActivity
 import com.nextcloud.talk.adapters.messages.IncomingLocationMessageViewHolder
 import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder
 import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder
@@ -2061,7 +2062,7 @@ class ChatController(args: Bundle) :
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         when (item.itemId) {
             android.R.id.home -> {
-                router.popCurrentController()
+                (activity as MainActivity).resetConversationsList()
                 return true
             }
             R.id.conversation_video_call -> {
@@ -2165,6 +2166,17 @@ class ChatController(args: Bundle) :
                         clipboardManager.setPrimaryClip(clipData)
                         true
                     }
+                    R.id.action_forward_message -> {
+                        val bundle = Bundle()
+                        bundle.putBoolean(BundleKeys.KEY_FORWARD_MSG_FLAG, true)
+                        bundle.putString(BundleKeys.KEY_FORWARD_MSG_TEXT, message?.text)
+                        getRouter().pushController(
+                            RouterTransaction.with(ConversationsListController(bundle))
+                                .pushChangeHandler(HorizontalChangeHandler())
+                                .popChangeHandler(HorizontalChangeHandler())
+                        )
+                        true
+                    }
                     R.id.action_reply_to_message -> {
                         val chatMessage = message as ChatMessage?
                         replyToMessage(chatMessage, message?.jsonMessageId)
@@ -2303,6 +2315,10 @@ class ChatController(args: Bundle) :
                 (message as ChatMessage).user.id.substring(6) != currentConversation?.actorId &&
                 currentConversation?.type != Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL
             menu.findItem(R.id.action_delete_message).isVisible = isShowMessageDeletionButton(message)
+            menu.findItem(R.id.action_forward_message).isVisible = ChatMessage.MessageType.REGULAR_TEXT_MESSAGE.equals(
+                (message as ChatMessage)
+                    .getMessageType()
+            )
             if (menu.hasVisibleItems()) {
                 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
                     setForceShowIcon(true)

+ 12 - 1
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -139,6 +139,7 @@ public class ConversationsListController extends BaseController implements Searc
     public static final String TAG = "ConvListController";
     public static final int ID_DELETE_CONVERSATION_DIALOG = 0;
     private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery";
+    private final Bundle bundle;
     @Inject
     UserUtils userUtils;
 
@@ -203,9 +204,13 @@ public class ConversationsListController extends BaseController implements Searc
 
     private String textToPaste = "";
 
-    public ConversationsListController() {
+    private boolean forwardMessage = false;
+
+    public ConversationsListController(Bundle bundle) {
         super();
         setHasOptionsMenu(true);
+        forwardMessage = bundle.getBoolean(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_FLAG());
+        this.bundle = bundle;
     }
 
     @Override
@@ -340,9 +345,13 @@ public class ConversationsListController extends BaseController implements Searc
 
         showShareToScreen = !shareToScreenWasShown && hasActivityActionSendIntent();
 
+
         if (showShareToScreen) {
             hideSearchBar();
             getActionBar().setTitle(R.string.send_to_three_dots);
+        } else if (forwardMessage) {
+            hideSearchBar();
+            getActionBar().setTitle(R.string.nc_forward_to_three_dots);
         } else {
             MainActivity activity = (MainActivity) getActivity();
 
@@ -752,6 +761,8 @@ public class ConversationsListController extends BaseController implements Searc
             if (showShareToScreen) {
                 shareToScreenWasShown = true;
                 handleSharedData();
+            } else if (forwardMessage) {
+                openConversation(bundle.getString(BundleKeys.INSTANCE.getKEY_FORWARD_MSG_TEXT()));
             } else {
                 openConversation();
             }

+ 2 - 0
app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt

@@ -68,4 +68,6 @@ object BundleKeys {
     val KEY_SHARED_TEXT = "KEY_SHARED_TEXT"
     val KEY_GEOCODING_QUERY = "KEY_GEOCODING_QUERY"
     val KEY_META_DATA = "KEY_META_DATA"
+    val KEY_FORWARD_MSG_FLAG = "KEY_FORWARD_MSG_FLAG"
+    val KEY_FORWARD_MSG_TEXT = "KEY_FORWARD_MSG_TEXT"
 }

+ 27 - 0
app/src/main/res/drawable/ic_share_action.xml

@@ -0,0 +1,27 @@
+<!--
+    @author Google LLC
+    Copyright (C) 2018 Google LLC
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:autoMirrored="true"
+    android:tint="@color/medium_emphasis_text"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M21,12L14,5V9C7,10 4,15 3,20C5.5,16.5 9,14.9 14,14.9V19L21,12Z" />
+</vector>

+ 7 - 1
app/src/main/res/menu/chat_message_menu.xml

@@ -8,6 +8,12 @@
         android:title="@string/nc_copy_message"
         app:showAsAction="always" />
 
+    <item
+        android:id="@+id/action_forward_message"
+        android:icon="@drawable/ic_share_action"
+        android:title="@string/nc_forward_message"
+        app:showAsAction="always" />
+
     <item
         android:id="@+id/action_reply_to_message"
         android:icon="@drawable/ic_reply"
@@ -25,4 +31,4 @@
         android:icon="@drawable/ic_delete"
         android:title="@string/nc_delete_message"
         app:showAsAction="always" />
-</menu>
+</menu>

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -189,6 +189,8 @@
     <string name="nc_add_to_favorites">Add to favorites</string>
     <string name="nc_remove_from_favorites">Remove from favorites</string>
 
+    <string name="nc_forward_to_three_dots">Forward to …</string>
+
     <!-- Contacts -->
     <string name="nc_select_participants">Select participants</string>
     <string name="nc_add_participants">Add participants</string>
@@ -357,6 +359,7 @@
 
     <!-- Chat -->
     <string name="nc_copy_message">Copy</string>
+    <string name="nc_forward_message">Forward</string>
     <string name="nc_reply">Reply</string>
     <string name="nc_reply_privately">Reply privately</string>
     <string name="nc_delete_message">Delete</string>