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

Fixes #398

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 жил өмнө
parent
commit
a71444637a
19 өөрчлөгдсөн 344 нэмэгдсэн , 135 устгасан
  1. 8 3
      app/build.gradle
  2. 4 4
      app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.java
  3. 2 2
      app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java
  4. 17 21
      app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java
  5. 22 0
      app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java
  6. 20 45
      app/src/main/java/com/nextcloud/talk/controllers/ChatController.java
  7. 1 1
      app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java
  8. 9 0
      app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java
  9. 78 0
      app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java
  10. 42 0
      app/src/main/java/com/nextcloud/talk/utils/OkHttpNetworkFetcherWithCache.java
  11. 33 1
      app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java
  12. 28 0
      app/src/main/res/drawable/incoming_corners.xml
  13. 29 0
      app/src/main/res/drawable/shape_grouped_message.xml
  14. 2 2
      app/src/main/res/drawable/shape_preview_text_incoming_message.xml
  15. 1 1
      app/src/main/res/drawable/shape_preview_text_outcoming_message.xml
  16. 19 18
      app/src/main/res/layout/item_custom_incoming_preview_message.xml
  17. 2 1
      app/src/main/res/layout/item_custom_incoming_text_message.xml
  18. 27 35
      app/src/main/res/layout/item_custom_outcoming_preview_message.xml
  19. 0 1
      app/src/main/res/layout/item_custom_outcoming_text_message.xml

+ 8 - 3
app/build.gradle

@@ -154,8 +154,8 @@ dependencies {
 
     implementation 'net.orange-box.storebox:storebox-lib:1.4.0'
 
-    compileOnly "org.projectlombok:lombok:1.18.2"
-    annotationProcessor "org.projectlombok:lombok:1.18.2"
+    compileOnly "org.projectlombok:lombok:1.18.4"
+    annotationProcessor "org.projectlombok:lombok:1.18.4"
 
     implementation 'com.jakewharton:butterknife:9.0.0-rc1'
     annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
@@ -168,6 +168,11 @@ dependencies {
     implementation 'com.github.bumptech.glide:glide:4.8.0'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
     implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0@aar'
+    implementation 'com.facebook.fresco:fresco:1.11.0'
+    implementation 'com.facebook.fresco:animated-webp:1.11.0'
+    implementation 'com.facebook.fresco:webpsupport:1.11.0'
+    implementation 'com.facebook.fresco:animated-gif:1.11.0'
+    implementation "com.facebook.fresco:imagepipeline-okhttp3:1.11.0"
     implementation 'org.webrtc:google-webrtc:1.0.23295'
     implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
 
@@ -181,7 +186,7 @@ dependencies {
 
     implementation 'com.github.wooplr:Spotlight:1.3'
 
-    implementation 'com.github.mario:Chatkit:31d75fd532'
+    implementation 'com.github.mario:chatkit:628c909ef4'
 
     implementation 'com.otaliastudios:autocomplete:1.1.0'
 

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

@@ -33,16 +33,16 @@ import android.view.View;
 import android.widget.TextView;
 
 import com.amulyakhare.textdrawable.TextDrawable;
+import com.facebook.drawee.view.SimpleDraweeView;
 import com.google.android.flexbox.FlexboxLayout;
 import com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.json.chat.ChatMessage;
 import com.nextcloud.talk.utils.DisplayUtils;
-import com.nextcloud.talk.utils.EmojiDetection;
+import com.nextcloud.talk.utils.TextMatchers;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.stfalcon.chatkit.messages.MessageHolders;
-import com.stfalcon.chatkit.utils.ShapeImageView;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -65,7 +65,7 @@ public class MagicIncomingTextMessageViewHolder
     EmoticonTextView messageText;
 
     @BindView(R.id.messageUserAvatar)
-    ShapeImageView messageUserAvatarView;
+    SimpleDraweeView messageUserAvatarView;
 
     @BindView(R.id.messageTime)
     TextView messageTimeView;
@@ -156,7 +156,7 @@ public class MagicIncomingTextMessageViewHolder
                 }
             }
 
-        } else if (EmojiDetection.isMessageWithSingleEmoticonOnly(context, message.getText())) {
+        } else if (TextMatchers.isMessageWithSingleEmoticonOnly(context, message.getText())) {
             messageString.setSpan(new RelativeSizeSpan(2.5f), 0, messageString.length(),
                     Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
             layoutParams.setWrapBefore(true);

+ 2 - 2
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.java

@@ -37,7 +37,7 @@ import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.json.chat.ChatMessage;
 import com.nextcloud.talk.utils.DisplayUtils;
-import com.nextcloud.talk.utils.EmojiDetection;
+import com.nextcloud.talk.utils.TextMatchers;
 import com.nextcloud.talk.utils.database.user.UserUtils;
 import com.stfalcon.chatkit.messages.MessageHolders;
 
@@ -106,7 +106,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
                 }
             }
 
-        } else if (EmojiDetection.isMessageWithSingleEmoticonOnly(context, message.getText())) {
+        } else if (TextMatchers.isMessageWithSingleEmoticonOnly(context, message.getText())) {
             messageString.setSpan(new RelativeSizeSpan(2.5f), 0, messageString.length(),
                     Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
             layoutParams.setWrapBefore(true);

+ 17 - 21
app/src/main/java/com/nextcloud/talk/adapters/messages/MagicPreviewMessageViewHolder.java

@@ -28,8 +28,9 @@ import android.widget.TextView;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 import com.nextcloud.talk.models.json.chat.ChatMessage;
+import com.nextcloud.talk.utils.DisplayUtils;
+import com.nextcloud.talk.utils.TextMatchers;
 import com.stfalcon.chatkit.messages.MessageHolders;
-import com.stfalcon.chatkit.utils.RoundedImageView;
 
 import butterknife.BindView;
 import butterknife.ButterKnife;
@@ -51,31 +52,26 @@ public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageM
         if (userAvatar != null) {
             if (message.isGrouped) {
                 userAvatar.setVisibility(View.INVISIBLE);
-                ((RoundedImageView) image).setCorners(R.dimen.message_bubble_corners_radius, R.dimen.message_bubble_corners_radius, 0, 0);
             } else {
                 userAvatar.setVisibility(View.VISIBLE);
             }
         }
 
-
-        if (message.getUser().getId().equals(message.activeUserId)) {
-            time.setTextColor(NextcloudTalkApplication.getSharedApplication().getResources().getColor(R.color.white60));
-            if (!message.isGrouped) {
-                ((RoundedImageView) image).setCorners(R.dimen.message_bubble_corners_radius, 0, 0, 0);
-            }
-        } else {
-            time.setTextColor(NextcloudTalkApplication.getSharedApplication().getResources().getColor(R.color.warm_grey_four));
-            if (!message.isGrouped) {
-                ((RoundedImageView) image).setCorners(0, R.dimen.message_bubble_corners_radius, 0, 0);
-            }
+        if (message.getSpecialURLType() == TextMatchers.SpecialURLType.NONE) {
+            // it's a preview for a Nextcloud share
+            messageText.setText(message.getSelectedIndividualHashMap().get("name"));
+            DisplayUtils.setClickableString(message.getSelectedIndividualHashMap().get("name"), message.getSelectedIndividualHashMap().get("link"), messageText);
+            image.setOnClickListener(v -> {
+                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message.getSelectedIndividualHashMap().get("link")));
+                browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                NextcloudTalkApplication.getSharedApplication().getApplicationContext().startActivity(browserIntent);
+            });
+        } else if (message.getSpecialURLType() == TextMatchers.SpecialURLType.GIPHY){
+            messageText.setText("GIPHY");
+            DisplayUtils.setClickableString("GIPHY", "https://giphy.com", messageText);
+        } else if (message.getSpecialURLType() == TextMatchers.SpecialURLType.TENOR) {
+            messageText.setText("Tenor");
+            DisplayUtils.setClickableString("Tenor", "https://tenor.com", messageText);
         }
-
-
-        messageText.setText(message.getSelectedIndividualHashMap().get("name"));
-        image.setOnClickListener(v -> {
-            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message.getSelectedIndividualHashMap().get("link")));
-            browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            NextcloudTalkApplication.getSharedApplication().getApplicationContext().startActivity(browserIntent);
-        });
     }
 }

+ 22 - 0
app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java

@@ -24,6 +24,10 @@ import android.content.Context;
 import android.os.Build;
 import android.util.Log;
 
+import com.facebook.cache.disk.DiskCacheConfig;
+import com.facebook.common.logging.FLog;
+import com.facebook.drawee.backends.pipeline.Fresco;
+import com.facebook.imagepipeline.core.ImagePipelineConfig;
 import com.nextcloud.talk.dagger.modules.BusModule;
 import com.nextcloud.talk.dagger.modules.ContextModule;
 import com.nextcloud.talk.dagger.modules.DatabaseModule;
@@ -35,6 +39,7 @@ import com.nextcloud.talk.jobs.SignalingSettingsJob;
 import com.nextcloud.talk.utils.ClosedInterfaceImpl;
 import com.nextcloud.talk.utils.DeviceUtils;
 import com.nextcloud.talk.utils.DisplayUtils;
+import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache;
 import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule;
 import com.nextcloud.talk.utils.database.user.UserModule;
 import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
@@ -45,6 +50,7 @@ import org.webrtc.voiceengine.WebRtcAudioUtils;
 
 import java.util.concurrent.TimeUnit;
 
+import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import androidx.lifecycle.LifecycleObserver;
@@ -55,6 +61,7 @@ import androidx.work.PeriodicWorkRequest;
 import androidx.work.WorkManager;
 import autodagger.AutoComponent;
 import autodagger.AutoInjector;
+import okhttp3.OkHttpClient;
 import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
 
 @AutoComponent(
@@ -71,6 +78,9 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
 @Singleton
 @AutoInjector(NextcloudTalkApplication.class)
 public class NextcloudTalkApplication extends MultiDexApplication implements LifecycleObserver {
+    @Inject
+    OkHttpClient okHttpClient;
+
     private static final String TAG = NextcloudTalkApplication.class.getSimpleName();
 
     //region Singleton
@@ -124,6 +134,18 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
 
         componentApplication.inject(this);
 
+        ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this)
+                .setNetworkFetcher(new OkHttpNetworkFetcherWithCache(okHttpClient))
+                .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this)
+                        .setMaxCacheSize(0)
+                        .setMaxCacheSizeOnLowDiskSpace(0)
+                        .setMaxCacheSizeOnVeryLowDiskSpace(0)
+                        .build())
+                .build();
+
+        Fresco.initialize(this, imagePipelineConfig);
+        FLog.setMinimumLoggingLevel(FLog.VERBOSE);
+
         new ClosedInterfaceImpl().providerInstallerInstallIfNeededAsync();
         DeviceUtils.ignoreSpecialBatteryFeatures();
 

+ 20 - 45
app/src/main/java/com/nextcloud/talk/controllers/ChatController.java

@@ -25,10 +25,10 @@ import android.content.ClipData;
 import android.content.ClipboardManager;
 import android.content.Context;
 import android.content.Intent;
-import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.Editable;
@@ -43,21 +43,17 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AbsListView;
-import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
-import com.amulyakhare.textdrawable.TextDrawable;
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
-import com.bumptech.glide.load.DataSource;
-import com.bumptech.glide.load.engine.DiskCacheStrategy;
-import com.bumptech.glide.load.engine.GlideException;
-import com.bumptech.glide.load.resource.bitmap.CircleCrop;
-import com.bumptech.glide.request.RequestListener;
-import com.bumptech.glide.request.RequestOptions;
-import com.bumptech.glide.request.target.Target;
+import com.facebook.drawee.backends.pipeline.Fresco;
+import com.facebook.drawee.interfaces.DraweeController;
+import com.facebook.drawee.view.SimpleDraweeView;
+import com.facebook.imagepipeline.request.ImageRequest;
+import com.facebook.imagepipeline.request.ImageRequestBuilder;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.activities.MagicCallActivity;
 import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
@@ -80,11 +76,11 @@ import com.nextcloud.talk.models.json.rooms.RoomOverall;
 import com.nextcloud.talk.models.json.rooms.RoomsOverall;
 import com.nextcloud.talk.presenters.MentionAutocompletePresenter;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.DisplayUtils;
 import com.nextcloud.talk.utils.KeyboardUtils;
 import com.nextcloud.talk.utils.NotificationUtils;
 import com.nextcloud.talk.utils.bundle.BundleKeys;
 import com.nextcloud.talk.utils.database.user.UserUtils;
-import com.nextcloud.talk.utils.glide.GlideApp;
 import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
 import com.otaliastudios.autocomplete.Autocomplete;
 import com.otaliastudios.autocomplete.AutocompleteCallback;
@@ -97,7 +93,6 @@ import com.stfalcon.chatkit.messages.MessageInput;
 import com.stfalcon.chatkit.messages.MessagesList;
 import com.stfalcon.chatkit.messages.MessagesListAdapter;
 import com.stfalcon.chatkit.utils.DateFormatter;
-import com.stfalcon.chatkit.utils.RoundedImageView;
 import com.webianks.library.PopupBubble;
 
 import org.parceler.Parcels;
@@ -113,7 +108,6 @@ import java.util.concurrent.TimeUnit;
 import javax.inject.Inject;
 
 import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import autodagger.AutoInjector;
@@ -326,38 +320,19 @@ public class ChatController extends BaseController implements MessagesListAdapte
 
             adapter = new MessagesListAdapter<>(conversationUser.getUserId(), messageHolders, new ImageLoader() {
                 @Override
-                public void loadImage(ImageView imageView, String url) {
-                    if (!(imageView instanceof RoundedImageView)) {
-                        GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
-                                .asBitmap()
-                                .diskCacheStrategy(DiskCacheStrategy.NONE)
-                                .load(url)
-                                .centerInside()
-                                .override(imageView.getMeasuredWidth(), imageView.getMeasuredHeight())
-                                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
-                                .listener(new RequestListener<Bitmap>() {
-                                    @Override
-                                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
-                                        TextDrawable drawable = TextDrawable.builder().beginConfig().bold()
-                                                .endConfig().buildRound("?", getResources().getColor(R.color.nc_grey));
-                                        imageView.setImageDrawable(drawable);
-                                        return true;
-                                    }
-
-                                    @Override
-                                    public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
-                                        return false;
-                                    }
-                                })
-                                .into(imageView);
-                    } else {
-                        GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
-                                .asBitmap()
-                                .diskCacheStrategy(DiskCacheStrategy.NONE)
-                                .override(480, 480)
-                                .load(url)
-                                .into(imageView);
-                    }
+                public void loadImage(SimpleDraweeView imageView, String url) {
+                    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
+                            .setProgressiveRenderingEnabled(true)
+                            .disableDiskCache()
+                            .build();
+
+                    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
+                            .setImageRequest(request)
+                            .setControllerListener(DisplayUtils.getImageControllerListener(imageView))
+                            .setOldController(imageView.getController())
+                            .setAutoPlayAnimations(true)
+                            .build();
+                    imageView.setController(draweeController);
                 }
             });
         } else {

+ 1 - 1
app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java

@@ -251,7 +251,7 @@ public class RestModule {
         }
     }
 
-    private class HeadersInterceptor implements Interceptor {
+    public static class HeadersInterceptor implements Interceptor {
 
         @Override
         public Response intercept(@NonNull Chain chain) throws IOException {

+ 9 - 0
app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java

@@ -25,6 +25,7 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter;
 import com.nextcloud.talk.utils.ApiUtils;
+import com.nextcloud.talk.utils.TextMatchers;
 import com.stfalcon.chatkit.commons.models.IMessage;
 import com.stfalcon.chatkit.commons.models.IUser;
 import com.stfalcon.chatkit.commons.models.MessageContentType;
@@ -44,6 +45,10 @@ import lombok.Data;
 @JsonObject
 public class ChatMessage implements IMessage, MessageContentType, MessageContentType.Image {
 
+    public TextMatchers.SpecialURLType getSpecialURLType() {
+        return TextMatchers.getSpecialUrlTypeMessage(getMessage());
+    }
+
     @Nullable
     @Override
     public String getImageUrl() {
@@ -59,6 +64,10 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent
             }
         }
 
+        if (getSpecialURLType() != TextMatchers.SpecialURLType.NONE) {
+            return getMessage().trim();
+        }
+
         return null;
     }
 

+ 78 - 0
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -22,19 +22,33 @@ package com.nextcloud.talk.utils;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.content.Intent;
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.graphics.Typeface;
+import android.graphics.drawable.Animatable;
 import android.graphics.drawable.Drawable;
+import android.net.Uri;
 import android.os.Build;
 import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.TextPaint;
 import android.text.TextUtils;
+import android.text.method.LinkMovementMethod;
 import android.text.style.AbsoluteSizeSpan;
+import android.text.style.ClickableSpan;
 import android.text.style.ForegroundColorSpan;
 import android.text.style.StyleSpan;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
 
+import com.facebook.drawee.controller.ControllerListener;
+import com.facebook.drawee.view.SimpleDraweeView;
+import com.facebook.imagepipeline.image.ImageInfo;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 
@@ -47,6 +61,8 @@ import java.util.regex.Pattern;
 import androidx.annotation.ColorInt;
 import androidx.annotation.ColorRes;
 import androidx.annotation.DrawableRes;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.appcompat.widget.AppCompatDrawableManager;
 import androidx.core.content.ContextCompat;
 import androidx.core.graphics.drawable.DrawableCompat;
@@ -55,6 +71,68 @@ public class DisplayUtils {
 
     private static final String TAG = "DisplayUtils";
 
+    public static void setClickableString(String string, String url, TextView textView){
+        SpannableString spannableString = new SpannableString(string);
+        spannableString.setSpan(new ClickableSpan() {
+            @Override
+            public void onClick(@NonNull View widget) {
+                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+                browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                NextcloudTalkApplication.getSharedApplication().getApplicationContext().startActivity(browserIntent);
+            }
+
+            @Override
+            public void updateDrawState(TextPaint ds) {
+                super.updateDrawState(ds);
+                ds.setUnderlineText(false);
+            }
+        }, 0, string.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+        textView.setText(spannableString);
+        textView.setMovementMethod(LinkMovementMethod.getInstance());
+    }
+
+    private static void updateViewSize(@Nullable ImageInfo imageInfo, SimpleDraweeView draweeView) {
+        if (imageInfo != null) {
+            draweeView.getLayoutParams().width = imageInfo.getWidth();
+            draweeView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
+            draweeView.setAspectRatio((float) imageInfo.getWidth() / imageInfo.getHeight());
+        }
+    }
+
+    public static ControllerListener getImageControllerListener(SimpleDraweeView draweeView) {
+        return new ControllerListener() {
+            @Override
+            public void onSubmit(String id, Object callerContext) {
+
+            }
+
+            @Override
+            public void onFinalImageSet(String id, @javax.annotation.Nullable Object imageInfo, @javax.annotation.Nullable Animatable animatable) {
+                updateViewSize((ImageInfo)imageInfo, draweeView);
+            }
+
+            @Override
+            public void onIntermediateImageSet(String id, @javax.annotation.Nullable Object imageInfo) {
+                updateViewSize((ImageInfo) imageInfo, draweeView);
+            }
+
+            @Override
+            public void onIntermediateImageFailed(String id, Throwable throwable) {
+
+            }
+
+            @Override
+            public void onFailure(String id, Throwable throwable) {
+
+            }
+
+            @Override
+            public void onRelease(String id) {
+
+            }
+        };
+    }
+
     public static float convertDpToPixel(float dp, Context context) {
         Resources resources = context.getResources();
         DisplayMetrics metrics = resources.getDisplayMetrics();

+ 42 - 0
app/src/main/java/com/nextcloud/talk/utils/OkHttpNetworkFetcherWithCache.java

@@ -0,0 +1,42 @@
+/*
+ * 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.utils;
+
+import com.facebook.imagepipeline.backends.okhttp3.OkHttpNetworkFetcher;
+
+import java.util.concurrent.Executor;
+
+import okhttp3.Call;
+import okhttp3.OkHttpClient;
+
+public class OkHttpNetworkFetcherWithCache extends OkHttpNetworkFetcher {
+    public OkHttpNetworkFetcherWithCache(OkHttpClient okHttpClient) {
+        super(okHttpClient);
+    }
+
+    public OkHttpNetworkFetcherWithCache(Call.Factory callFactory, Executor cancellationExecutor) {
+        super(callFactory, cancellationExecutor);
+    }
+
+    public OkHttpNetworkFetcherWithCache(Call.Factory callFactory, Executor cancellationExecutor, boolean disableOkHttpCache) {
+        super(callFactory, cancellationExecutor, true);
+    }
+}

+ 33 - 1
app/src/main/java/com/nextcloud/talk/utils/EmojiDetection.java → app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java

@@ -25,6 +25,7 @@ package com.nextcloud.talk.utils;
 import android.content.Context;
 import android.text.TextUtils;
 import android.util.Log;
+import android.util.Patterns;
 
 import com.nextcloud.talk.R;
 
@@ -32,18 +33,49 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
-public final class EmojiDetection {
+public final class TextMatchers {
 
     private static final String TAG = "EmojiDetection";
 
     private static Pattern regexPattern;
 
+    public enum SpecialURLType {
+        NONE,
+        GIPHY,
+        TENOR,
+    }
+
+    public static SpecialURLType getSpecialUrlTypeMessage(@NonNull final String text) {
+        List<String> links = new ArrayList<>();
+        Matcher m = Patterns.WEB_URL.matcher(text);
+        while (m.find()) {
+            String url = m.group();
+            links.add(url);
+        }
+
+        if (links.size() == 1 && text.trim().length() == links.get(0).length()) {
+            String specialLink = links.get(0);
+            if (specialLink.startsWith("https://media.giphy.com/") && specialLink.endsWith(".gif")) {
+                return SpecialURLType.GIPHY;
+            } else if (specialLink.contains("tenor.com/")) {
+                Pattern pattern = Pattern.compile("https://media.*\\.tenor\\.com.*\\.gif.*", Pattern.CASE_INSENSITIVE);
+                if (pattern.matcher(specialLink).matches()) {
+                    return SpecialURLType.TENOR;
+                }
+            }
+        }
+
+        return SpecialURLType.NONE;
+    }
+
     public static boolean isMessageWithSingleEmoticonOnly(@NonNull final Context context,
                                                           @Nullable final CharSequence text) {
 

+ 28 - 0
app/src/main/res/drawable/incoming_corners.xml

@@ -0,0 +1,28 @@
+<?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/>.
+  -->
+
+<shape
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+
+    <corners android:radius="@dimen/message_bubble_corners_radius" />
+    <solid android:color="@color/nc_white_color" />
+</shape>

+ 29 - 0
app/src/main/res/drawable/shape_grouped_message.xml

@@ -0,0 +1,29 @@
+<?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/>.
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+       android:shape="rectangle">
+
+    <corners
+        android:radius="@dimen/message_bubble_corners_radius" />
+
+    <solid android:color="@color/nc_white_color" />
+</shape>

+ 2 - 2
app/src/main/res/drawable/shape_preview_text_incoming_message.xml

@@ -26,7 +26,7 @@
         android:topLeftRadius="0dp"
         android:bottomRightRadius="@dimen/message_bubble_corners_radius"
         android:bottomLeftRadius="@dimen/message_bubble_corners_radius"
-        android:topRightRadius="0dp" />
+        android:topRightRadius="@dimen/message_bubble_corners_radius" />
 
-    <solid android:color="@color/white_two" />
+    <solid android:color="@color/nc_white_color" />
 </shape>

+ 1 - 1
app/src/main/res/drawable/shape_preview_text_outcoming_message.xml

@@ -28,5 +28,5 @@
         android:bottomLeftRadius="@dimen/message_bubble_corners_radius"
         android:topRightRadius="0dp" />
 
-    <solid android:color="@color/colorPrimary" />
+    <solid android:color="@color/nc_white_color" />
 </shape>

+ 19 - 18
app/src/main/res/layout/item_custom_incoming_preview_message.xml

@@ -19,6 +19,7 @@
   -->
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginStart="16dp"
@@ -26,24 +27,26 @@
     android:layout_marginEnd="16dp"
     android:layout_marginBottom="2dp">
 
-    <com.stfalcon.chatkit.utils.ShapeImageView
+    <com.facebook.drawee.view.SimpleDraweeView
         android:id="@id/messageUserAvatar"
         android:layout_width="40dp"
         android:layout_height="40dp"
+        android:layout_alignParentStart="true"
         android:layout_alignParentTop="true"
-        android:layout_marginEnd="8dp" />
+        android:layout_marginEnd="8dp"
+        app:roundAsCircle="true" />
 
     <RelativeLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_toEndOf="@id/messageUserAvatar"
-        android:background="@drawable/shape_preview_text_incoming_message">
+        android:layout_toEndOf="@id/messageUserAvatar">
 
-        <com.stfalcon.chatkit.utils.RoundedImageView
+        <com.facebook.drawee.view.SimpleDraweeView
             android:id="@id/image"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:adjustViewBounds="true" />
+            android:layout_width="480px"
+            android:layout_height="480px"
+            android:adjustViewBounds="true"
+            app:actualImageScaleType="fitCenter" />
 
         <RelativeLayout
             android:layout_width="wrap_content"
@@ -51,27 +54,25 @@
             android:layout_below="@id/image"
             android:layout_alignStart="@+id/image"
             android:layout_alignEnd="@id/image"
-            android:layout_margin="8dp">
+            android:layout_marginTop="8dp"
+            android:layout_marginBottom="8dp">
 
             <com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
                 android:id="@id/messageText"
                 android:layout_width="wrap_content"
+                android:textColorLink="@color/warm_grey_four"
                 android:layout_height="wrap_content"
-                android:textColor="@color/dark_grey_two"
+                android:autoLink="all"
+                android:textColor="@color/warm_grey_four"
                 android:textIsSelectable="true"
-                android:textSize="14sp" />
-
-            <View
-                android:id="@id/imageOverlay"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
+                android:textSize="12sp" />
 
             <TextView
                 android:id="@id/messageTime"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_below="@id/messageText"
-                android:layout_alignParentEnd="true" />
+                android:layout_alignParentEnd="true"
+                android:textColor="@color/warm_grey_four" />
 
         </RelativeLayout>
 

+ 2 - 1
app/src/main/res/layout/item_custom_incoming_text_message.xml

@@ -27,10 +27,11 @@
     android:layout_marginRight="16dp"
     android:layout_marginBottom="2dp">
 
-    <com.stfalcon.chatkit.utils.ShapeImageView
+    <com.facebook.drawee.view.SimpleDraweeView
         android:id="@id/messageUserAvatar"
         android:layout_width="40dp"
         android:layout_height="40dp"
+        app:roundAsCircle="true"
         android:layout_alignParentTop="true"
         android:layout_marginEnd="8dp" />
 

+ 27 - 35
app/src/main/res/layout/item_custom_outcoming_preview_message.xml

@@ -19,55 +19,47 @@
   -->
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginStart="16dp"
     android:layout_marginTop="2dp"
     android:layout_marginEnd="16dp"
     android:layout_marginBottom="2dp">
 
+    <com.facebook.drawee.view.SimpleDraweeView
+        android:id="@id/image"
+        android:layout_width="480px"
+        android:layout_height="480px"
+        app:actualImageScaleType="fitCenter"
+        android:adjustViewBounds="true"
+        android:layout_alignParentEnd="true"/>
+
     <RelativeLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_alignParentEnd="true"
-        android:background="@drawable/shape_preview_text_outcoming_message">
+        android:layout_below="@id/image"
+        android:layout_alignStart="@+id/image"
+        android:layout_alignEnd="@id/image"
+        android:layout_marginTop="8dp"
+        android:layout_marginBottom="8dp">
 
-        <com.stfalcon.chatkit.utils.RoundedImageView
-            android:id="@id/image"
+        <com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
+            android:id="@id/messageText"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:adjustViewBounds="true" />
+            android:autoLink="all"
+            android:textColorLink="@color/warm_grey_four"
+            android:textColor="@color/warm_grey_four"
+            android:textIsSelectable="true"
+            android:textSize="12sp" />
 
-        <RelativeLayout
+        <TextView
+            android:id="@id/messageTime"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_below="@id/image"
-            android:layout_alignStart="@+id/image"
-            android:layout_alignEnd="@id/image"
-            android:layout_margin="8dp">
-
-            <com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
-                android:id="@id/messageText"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textColor="@color/nc_outcoming_text_default"
-                android:textIsSelectable="true"
-                android:textSize="14sp" />
-
-            <View
-                android:id="@id/imageOverlay"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content" />
-
-            <TextView
-                android:id="@id/messageTime"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_below="@id/messageText"
-                android:layout_alignParentEnd="true"
-                android:textColor="@color/white60" />
-
-        </RelativeLayout>
-
+            android:layout_alignParentEnd="true"
+            android:textColor="@color/warm_grey_four" />
     </RelativeLayout>
+
 </RelativeLayout>

+ 0 - 1
app/src/main/res/layout/item_custom_outcoming_text_message.xml

@@ -44,7 +44,6 @@
             android:layout_height="wrap_content"
             android:layout_alignWithParentIfMissing="true"
             android:textColorHighlight="@color/nc_grey"
-
             android:textIsSelectable="true" />
 
         <TextView