Bladeren bron

Styling the chat

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 jaren geleden
bovenliggende
commit
a351925141

+ 56 - 0
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java

@@ -0,0 +1,56 @@
+/*
+ * Nextcloud Talk application
+ *
+ * @author Mario Danic
+ * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.talk.adapters.messages;
+
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.TextView;
+
+import com.nextcloud.talk.R;
+import com.nextcloud.talk.models.json.chat.ChatMessage;
+import com.stfalcon.chatkit.messages.MessageHolders;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+public class MagicIncomingTextMessageViewHolder
+        extends MessageHolders.IncomingTextMessageViewHolder<ChatMessage> {
+
+    @BindView(R.id.messageAuthor)
+    TextView messageAuthor;
+
+    public MagicIncomingTextMessageViewHolder(View itemView) {
+        super(itemView);
+        ButterKnife.bind(this, itemView);
+    }
+
+
+    @Override
+    public void onBind(ChatMessage message) {
+        super.onBind(message);
+        String author;
+        if (TextUtils.isEmpty(author = message.getActorDisplayName())) {
+            messageAuthor.setText(author);
+        } else {
+            messageAuthor.setText(R.string.nc_nick_guest);
+        }
+    }
+}

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

@@ -36,6 +36,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
 import com.bumptech.glide.load.resource.bitmap.CircleCrop;
 import com.bumptech.glide.request.RequestOptions;
 import com.nextcloud.talk.R;
+import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
 import com.nextcloud.talk.api.NcApi;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.controllers.base.BaseController;
@@ -117,7 +118,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
 
         if (adapter == null) {
             adapterWasNull = true;
-            adapter = new MessagesListAdapter<>(currentUser.getUserId(), new ImageLoader() {
+
+            MessagesListAdapter.HoldersConfig holdersConfig = new MessagesListAdapter.HoldersConfig();
+            holdersConfig.setIncoming(MagicIncomingTextMessageViewHolder.class,
+                    R.layout.item_custom_incoming_text_message);
+
+            adapter = new MessagesListAdapter<>(currentUser.getUserId(), holdersConfig, new ImageLoader() {
                 @Override
                 public void loadImage(ImageView imageView, String url) {
                     GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())

+ 9 - 1
app/src/main/res/layout/controller_chat.xml

@@ -29,8 +29,16 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_above="@+id/input"
+        app:incomingDefaultBubbleColor="@color/white_two"
+        app:incomingDefaultBubblePressedColor="@color/white_two"
+        app:incomingDefaultBubbleSelectedColor="@color/colorPrimaryDark"
+        app:incomingTextSize="14sp"
+        app:incomingTimeTextSize="12sp"
         app:outcomingDefaultBubbleColor="@color/colorPrimary"
+        app:outcomingDefaultBubblePressedColor="@color/colorPrimary"
         app:outcomingDefaultBubbleSelectedColor="@color/colorPrimaryDark"
+        app:outcomingTextSize="14sp"
+        app:outcomingTimeTextSize="12sp"
         app:textAutoLink="all"/>
 
     <View
@@ -54,6 +62,6 @@
         app:inputButtonWidth="30dp"
         app:inputHint="@string/nc_hint_enter_a_message"
         app:inputTextColor="@color/black"
-        app:inputTextSize="18sp"/>
+        app:inputTextSize="16sp"/>
 
 </RelativeLayout>

+ 76 - 0
app/src/main/res/layout/item_custom_incoming_text_message.xml

@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ This program is free software: you can redistribute it and/or modify
+  ~ it under the terms of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ at your option) any later version.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  ~ GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+  -->
+
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_marginBottom="8dp"
+    android:layout_marginLeft="16dp"
+    android:layout_marginRight="16dp"
+    android:layout_marginTop="8dp">
+
+    <com.stfalcon.chatkit.utils.ShapeImageView
+        android:id="@id/messageUserAvatar"
+        android:layout_width="40dp"
+        android:layout_height="40dp"
+        android:layout_alignParentBottom="true"
+        android:layout_marginEnd="8dp"/>
+
+    <com.google.android.flexbox.FlexboxLayout
+        android:id="@id/bubble"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="@dimen/message_incoming_bubble_margin_right"
+        android:layout_toEndOf="@id/messageUserAvatar"
+        android:orientation="vertical"
+        app:alignContent="stretch"
+        app:alignItems="stretch"
+        app:flexWrap="wrap"
+        app:justifyContent="flex_end">
+
+        <TextView
+            android:id="@+id/messageAuthor"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:textColor="@color/colorPrimaryDark"
+            android:textSize="12sp"
+            app:layout_alignSelf="flex_start"/>
+
+        <TextView
+            android:id="@id/messageText"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            app:layout_alignSelf="flex_start"
+            app:layout_wrapBefore="true"/>
+
+        <TextView
+            android:id="@id/messageTime"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/messageText"
+            android:layout_marginStart="8dp"
+            app:layout_alignSelf="center"/>
+
+    </com.google.android.flexbox.FlexboxLayout>
+
+</RelativeLayout>