Переглянути джерело

Merge pull request #419 from nextcloud/fix-413

First steps towards fixing german
Mario Đanić 6 роки тому
батько
коміт
a6f635966a

+ 15 - 23
app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java

@@ -21,12 +21,8 @@
 package com.nextcloud.talk.adapters.items;
 
 import android.content.Context;
-import android.graphics.Typeface;
-import android.text.Spannable;
-import android.text.SpannableString;
 import android.text.TextUtils;
 import android.text.format.DateUtils;
-import android.text.style.StyleSpan;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
@@ -128,7 +124,6 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
             holder.dialogUnreadBubble.setVisibility(View.GONE);
         }
 
-        String authorDisplayName;
 
         if (conversation.isHasPassword()) {
             holder.passwordProtectedRoomImageView.setVisibility(View.VISIBLE);
@@ -151,29 +146,26 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
                 holder.dialogLastMessageUserAvatar.setVisibility(View.GONE);
                 holder.dialogLastMessage.setText(conversation.getLastMessage().getText());
             } else {
-                if (conversation.getLastMessage().getActorId().equals(userEntity.getUserId())) {
-                    authorDisplayName = context.getString(R.string.nc_chat_you);
-                } else {
-                    if (!TextUtils.isEmpty(conversation.getLastMessage().getActorDisplayName())) {
-                        authorDisplayName = conversation.getLastMessage().getActorDisplayName();
+                String authorDisplayName = "";
+                conversation.getLastMessage().setActiveUserId(userEntity.getUserId());
+                String text;
+                if (conversation.getLastMessage().getMessageType().equals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE)) {
+                    if (conversation.getLastMessage().getActorId().equals(conversation.getLastMessage().getActiveUserId())) {
+                        text = String.format(context.getString(R.string.nc_formatted_message_you), conversation.getLastMessage().getLastMessageDisplayText();
                     } else {
-                        authorDisplayName = context.getString(R.string.nc_nick_guest);
+                        authorDisplayName = !TextUtils.isEmpty(conversation.getLastMessage().getActorDisplayName()) ?
+                                conversation.getLastMessage().getActorDisplayName() :
+                                "guests".equals(conversation.getLastMessage().getActorType()) ?
+                                        NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest) : "";
+                        text = String.format(context.getString(R.string.nc_formatted_message),
+                                authorDisplayName,
+                                conversation.getLastMessage().getLastMessageDisplayText());
                     }
-                }
-
-                if (conversation.getLastMessage().getMessageType().equals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE)) {
-                    authorDisplayName += ": ";
                 } else {
-                    authorDisplayName += " ";
+                    text = conversation.getLastMessage().getLastMessageDisplayText();
                 }
 
-                String fullString = authorDisplayName + conversation.getLastMessage().getLastMessageDisplayText();
-                Spannable spannableString = new SpannableString(fullString);
-                final StyleSpan boldStyleSpan = new StyleSpan(Typeface.BOLD);
-                spannableString.setSpan(boldStyleSpan, 0, authorDisplayName.length(), Spannable
-                        .SPAN_INCLUSIVE_INCLUSIVE);
-
-                holder.dialogLastMessage.setText(spannableString);
+                holder.dialogLastMessage.setText(text);
 
                 int smallAvatarSize = Math.round(context.getResources().getDimension(R.dimen.small_item_height));
 

+ 37 - 6
app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java

@@ -20,6 +20,7 @@
 package com.nextcloud.talk.models.json.chat;
 
 import android.text.TextUtils;
+import android.util.Log;
 
 import com.bluelinelabs.logansquare.annotation.JsonField;
 import com.bluelinelabs.logansquare.annotation.JsonIgnore;
@@ -197,17 +198,47 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
             if (getMessageType().equals(MessageType.SINGLE_LINK_GIPHY_MESSAGE)
                     || getMessageType().equals(MessageType.SINGLE_LINK_TENOR_MESSAGE)
                     || getMessageType().equals(MessageType.SINGLE_LINK_GIF_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_gif));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_gif_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_gif),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             } else if (getMessageType().equals(MessageType.SINGLE_NC_ATTACHMENT_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_attachment));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_attachment_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_attachment),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             } else if (getMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_link));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_link_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_link),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             } else if (getMessageType().equals(MessageType.SINGLE_LINK_AUDIO_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_audio));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_audio_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_audio),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             } else if (getMessageType().equals(MessageType.SINGLE_LINK_VIDEO_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_video));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_a_video_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_a_video),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             } else if (getMessageType().equals(MessageType.SINGLE_LINK_IMAGE_MESSAGE)) {
-                return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_image));
+                if (getActorId().equals(getActiveUserId())) {
+                    return (NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_sent_an_image_you));
+                } else {
+                    return (String.format(NextcloudTalkApplication.getSharedApplication().getResources().getString(R.string.nc_sent_an_image),
+                            !TextUtils.isEmpty(getActorDisplayName()) ? getActorDisplayName() : NextcloudTalkApplication.getSharedApplication().getString(R.string.nc_guest)));
+                }
             }
         }
 

+ 16 - 9
app/src/main/res/values/strings.xml

@@ -18,7 +18,7 @@
   ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
   -->
 
-<resources>
+<resources xmlns:tools="http://schemas.android.com/tools">
     <!-- Bottom Navigation -->
     <string name="nc_settings">Settings</string>
 
@@ -179,14 +179,21 @@
     <string name="nc_conversation_menu_conversation_info">Conversation info</string>
     <string name="nc_new_messages">New messages</string>
     <string name="nc_no_messages_yet">No messages yet</string>
-    <string name="nc_chat_you">You</string>
-    <string name="nc_sent_a_link">sent a link.</string>
-    <string name="nc_sent_a_gif">sent a GIF.</string>
-    <string name="nc_sent_an_attachment">sent an attachment.</string>
-    <string name="nc_sent_an_audio">sent an audio.</string>
-    <string name="nc_sent_a_video">sent a video.</string>
-    <string name="nc_sent_an_image">sent an image.</string>
-
+    <string name="nc_sent_a_link" formatted="true">%1$s sent a link.</string>
+    <string name="nc_sent_a_gif" formatted="true">%1$s sent a GIF.</string>
+    <string name="nc_sent_an_attachment" formatted="true">%1$s sent an attachment.</string>
+    <string name="nc_sent_an_audio" formatted="true">%1$s sent an audio.</string>
+    <string name="nc_sent_a_video" formatted="true">%1$s sent a video.</string>
+    <string name="nc_sent_an_image" formatted="true">%1$s sent an image.</string>
+    <string name="nc_sent_a_link_you" tools:ignore="ExtraTranslation">You sent a link.</string>
+    <string name="nc_sent_a_gif_you">You sent a GIF.</string>
+    <string name="nc_sent_an_attachment_you">You sent an attachment.</string>
+    <string name="nc_sent_an_audio_you">You sent an audio.</string>
+    <string name="nc_sent_a_video_you">You sent a video.</string>
+    <string name="nc_sent_an_image_you">You sent an image.</string>
+    <string name="nc_formatted_message" translatable="false">%1$s: %2$s</string>
+    <!-- When translating to German, please use non-formal variant -->
+    <string name="nc_formatted_message_you">You: %1$s</string>
 
     <!-- Contacts endless loading -->
     <string name="nc_no_more_load_retry">No more items to load. Refresh to retry.</string>