Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-01-12 14:45:28 +01:00
parent de87a717ac
commit bf1f2df344
21 changed files with 137 additions and 102 deletions

View file

@ -108,12 +108,12 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.emoji:emoji-bundled:1.0.0'
implementation 'com.github.vanniktech.Emoji:emoji-twitter:182e1ff4f4'
implementation 'org.michaelevans.colorart:library:0.0.3'
implementation "android.arch.work:work-runtime:1.0.0-beta01"
implementation "android.arch.work:work-runtime:1.0.0-alpha13"
implementation "android.arch.work:work-firebase:${workVersion}"
androidTestImplementation "android.arch.work:work-testing:1.0.0-beta01"
implementation "android.arch.work:work-rxjava2:1.0.0-beta01"
androidTestImplementation "android.arch.work:work-testing:1.0.0-alpha13"
implementation "android.arch.work:work-rxjava2:1.0.0-alpha13"
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
@ -188,7 +188,7 @@ dependencies {
implementation 'com.github.wooplr:Spotlight:1.3'
implementation 'com.github.mario:chatkit:628c909ef4'
implementation 'com.github.mario:chatkit:d63d61db95'
implementation 'com.otaliastudios:autocomplete:1.1.0'

View file

@ -20,7 +20,6 @@
package com.nextcloud.talk.activities;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;

View file

@ -41,8 +41,6 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
import javax.inject.Inject;
import androidx.appcompat.widget.Toolbar;
import androidx.emoji.bundled.BundledEmojiCompatConfig;
import androidx.emoji.text.EmojiCompat;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -72,8 +70,6 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EmojiCompat.Config config = new BundledEmojiCompatConfig(this);
EmojiCompat.init(config);
setContentView(R.layout.activity_main);

View file

@ -45,6 +45,7 @@ import com.nextcloud.talk.models.json.rooms.Conversation;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.glide.GlideApp;
import com.vanniktech.emoji.EmojiTextView;
import org.apache.commons.lang3.StringUtils;
@ -287,13 +288,13 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
@BindView(R.id.dialogAvatar)
ImageView dialogAvatar;
@BindView(R.id.dialogName)
TextView dialogName;
EmojiTextView dialogName;
@BindView(R.id.dialogDate)
TextView dialogDate;
@BindView(R.id.dialogLastMessageUserAvatar)
ImageView dialogLastMessageUserAvatar;
@BindView(R.id.dialogLastMessage)
TextView dialogLastMessage;
EmojiTextView dialogLastMessage;
@BindView(R.id.dialogUnreadBubble)
TextView dialogUnreadBubble;
@BindView(R.id.passwordProtectedRoomImageView)

View file

@ -28,14 +28,12 @@ import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.RelativeSizeSpan;
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;
@ -43,6 +41,7 @@ import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.TextMatchers;
import com.nextcloud.talk.utils.database.user.UserUtils;
import com.stfalcon.chatkit.messages.MessageHolders;
import com.vanniktech.emoji.EmojiTextView;
import java.util.HashMap;
import java.util.Map;
@ -62,7 +61,7 @@ public class MagicIncomingTextMessageViewHolder
TextView messageAuthor;
@BindView(R.id.messageText)
EmoticonTextView messageText;
EmojiTextView messageText;
@BindView(R.id.messageUserAvatar)
SimpleDraweeView messageUserAvatarView;
@ -131,6 +130,8 @@ public class MagicIncomingTextMessageViewHolder
Spannable messageString = new SpannableString(message.getText());
float emojiSize = DisplayUtils.getDefaultEmojiFontSize(messageText);
if (messageParameters != null && messageParameters.size() > 0) {
for (String key : messageParameters.keySet()) {
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
@ -156,13 +157,13 @@ public class MagicIncomingTextMessageViewHolder
}
}
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(context, message.getText())) {
messageString.setSpan(new RelativeSizeSpan(2.5f), 0, messageString.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.getText())) {
emojiSize *= 2.5f;
layoutParams.setWrapBefore(true);
itemView.setSelected(true);
}
messageText.setEmojiSize((int) emojiSize, true);
messageTimeView.setLayoutParams(layoutParams);
messageText.setText(messageString);
}

View file

@ -27,12 +27,10 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.TextView;
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;
@ -40,6 +38,7 @@ import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.TextMatchers;
import com.nextcloud.talk.utils.database.user.UserUtils;
import com.stfalcon.chatkit.messages.MessageHolders;
import com.vanniktech.emoji.EmojiTextView;
import java.util.HashMap;
import java.util.Map;
@ -54,7 +53,7 @@ import butterknife.ButterKnife;
@AutoInjector(NextcloudTalkApplication.class)
public class MagicOutcomingTextMessageViewHolder extends MessageHolders.OutcomingTextMessageViewHolder<ChatMessage> {
@BindView(R.id.messageText)
EmoticonTextView messageText;
EmojiTextView messageText;
@BindView(R.id.messageTime)
TextView messageTimeView;
@ -87,6 +86,8 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) messageTimeView.getLayoutParams();
layoutParams.setWrapBefore(false);
float emojiSize = DisplayUtils.getDefaultEmojiFontSize(messageText);
if (messageParameters != null && messageParameters.size() > 0) {
for (String key : messageParameters.keySet()) {
Map<String, String> individualHashMap = message.getMessageParameters().get(key);
@ -106,9 +107,8 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
}
}
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(context, message.getText())) {
messageString.setSpan(new RelativeSizeSpan(2.5f), 0, messageString.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
} else if (TextMatchers.isMessageWithSingleEmoticonOnly(message.getText())) {
emojiSize *= 2.5f;
layoutParams.setWrapBefore(true);
messageTimeView.setTextColor(context.getResources().getColor(R.color.warm_grey_four));
itemView.setSelected(true);
@ -127,6 +127,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
ViewCompat.setBackground(bubble, bubbleDrawable);
}
messageText.setEmojiSize((int) emojiSize, true);
messageTimeView.setLayoutParams(layoutParams);
messageText.setText(messageString);
}

View file

@ -42,6 +42,8 @@ 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;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.twitter.TwitterEmojiProvider;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.voiceengine.WebRtcAudioManager;
@ -159,6 +161,8 @@ public class NextcloudTalkApplication extends MultiDexApplication implements Lif
// ExistingPeriodicWorkPolicy.REPLACE, periodicCapabilitiesUpdateWork);
WorkManager.getInstance().cancelUniqueWork("DailyCapabilitiesUpdateWork");
EmojiManager.install(new TwitterEmojiProvider());
}
@Override

View file

@ -26,6 +26,7 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -42,6 +43,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -90,6 +92,10 @@ 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.vanniktech.emoji.EmojiEditText;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.listeners.OnEmojiPopupDismissListener;
import com.vanniktech.emoji.listeners.OnEmojiPopupShownListener;
import com.webianks.library.PopupBubble;
import org.parceler.Parcels;
@ -137,6 +143,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
TextView sendHiTextView;
@BindView(R.id.progressBar)
ProgressBar loadingProgressBar;
@BindView(R.id.smileyButton)
ImageButton smileyButton;
private List<Disposable> disposableList = new ArrayList<>();
private String conversationName;
private String roomToken;
@ -165,6 +173,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private static final byte CONTENT_TYPE_SYSTEM_MESSAGE = 1;
private boolean wasDetached;
private EmojiPopup emojiPopup;
public ChatController(Bundle args) {
super(args);
@ -467,6 +476,21 @@ public class ChatController extends BaseController implements MessagesListAdapte
ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
emojiPopup = EmojiPopup.Builder.fromRootView(view).setOnEmojiPopupShownListener(new OnEmojiPopupShownListener() {
@Override
public void onEmojiPopupShown() {
smileyButton.setColorFilter(getResources().getColor(R.color.colorPrimary),
PorterDuff.Mode.SRC_IN);
}
}).setOnEmojiPopupDismissListener(new OnEmojiPopupDismissListener() {
@Override
public void onEmojiPopupDismiss() {
if (smileyButton != null) {
smileyButton.clearColorFilter();
}
}
}).build((EmojiEditText) messageInputView.getInputEditText());
if (mentionAutocomplete != null && mentionAutocomplete.isPopupShowing()) {
mentionAutocomplete.dismissPopup();
}
@ -552,6 +576,11 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
}
@OnClick(R.id.smileyButton)
void onSmileyClick() {
emojiPopup.toggle();
}
@OnClick(R.id.emptyLayout)
void sendHello() {
if (!isHelloClicked) {

View file

@ -115,7 +115,7 @@ public class ConversationInfoController extends BaseController {
private FlexibleAdapter<AbstractFlexibleItem> adapter;
private List<AbstractFlexibleItem> recyclerViewItems = new ArrayList<>();
ConversationInfoController(Bundle args) {
public ConversationInfoController(Bundle args) {
super(args);
setHasOptionsMenu(true);
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);

View file

@ -27,6 +27,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
@ -59,6 +60,7 @@ import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.vanniktech.emoji.EmojiTextView;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -119,6 +121,11 @@ public class DisplayUtils {
return new BitmapDrawable(getRoundedBitmapFromVectorDrawableResource(resources, resource));
}
public static float getDefaultEmojiFontSize(EmojiTextView emojiTextView) {
final Paint.FontMetrics fontMetrics = emojiTextView.getPaint().getFontMetrics();
return fontMetrics.descent - fontMetrics.ascent;
}
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);

View file

@ -22,18 +22,12 @@
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;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.vanniktech.emoji.EmojiInformation;
import com.vanniktech.emoji.EmojiUtils;
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;
@ -48,9 +42,7 @@ import eu.medsea.mimeutil.detector.OpendesktopMimeDetector;
public final class TextMatchers {
private static final String TAG = "EmojiDetection";
private static Pattern regexPattern;
private static final String TAG = "TextMatchers";
public static ChatMessage.MessageType getMessageTypeFromString(@NonNull final String text) {
List<String> links = new ArrayList<>();
@ -97,59 +89,8 @@ public final class TextMatchers {
return ChatMessage.MessageType.REGULAR_TEXT_MESSAGE;
}
public static boolean isMessageWithSingleEmoticonOnly(@NonNull final Context context,
@Nullable final CharSequence text) {
int startPosition = -1;
int endPosition = -1;
if (!TextUtils.isEmpty(text)) {
final Matcher matcher = getRegex(context).matcher(text);
while (matcher.find()) {
if (startPosition == -1 && endPosition == -1) {
startPosition = matcher.start();
endPosition = matcher.end();
} else {
return false;
}
}
} else {
return false;
}
return startPosition == 0 && text.length() == endPosition;
}
@NonNull
private static Pattern getRegex(@NonNull final Context context) {
if (regexPattern == null) {
String regex = readTextFile(context, R.raw.regex);
regexPattern = Pattern.compile(regex);
}
return regexPattern;
}
@NonNull
private static String readTextFile(@NonNull Context context, int rowResource) {
InputStream inputStream = context.getResources().openRawResource(rowResource);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
try {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) builder.append(sCurrentLine);
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage());
} finally {
try {
inputStream.close();
br.close();
} catch (IOException e) {
Log.e(TAG, e.getLocalizedMessage());
}
}
return builder.toString();
public static boolean isMessageWithSingleEmoticonOnly(@Nullable final String text) {
final EmojiInformation emojiInformation = EmojiUtils.emojiInformation(text);
return (emojiInformation.isOnlyEmojis && emojiInformation.emojis.size() == 1);
}
}

View file

@ -0,0 +1,44 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.viewpager.widget.ViewPager
android:id="@+id/emojis_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/emoji_divider" />
<View
android:id="@+id/emoji_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@id/emojis_tab"/>
<LinearLayout
android:id="@+id/emojis_tab"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" />
</RelativeLayout>

View file

@ -59,7 +59,7 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
<com.vanniktech.emoji.EmojiTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:textColorLink="@color/warm_grey_four"

View file

@ -54,7 +54,7 @@
android:textColor="@color/colorPrimary"
android:textSize="12sp" />
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
<androidx.emoji.widget.EmojiTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -46,7 +46,7 @@
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
<com.vanniktech.emoji.EmojiTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -38,7 +38,7 @@
app:flexWrap="wrap"
app:justifyContent="flex_end">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
<com.vanniktech.emoji.EmojiTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -64,7 +64,7 @@
android:layout_toEndOf="@id/frame_layout"
android:orientation="vertical">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
<com.vanniktech.emoji.EmojiTextView
android:id="@+id/name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -61,7 +61,7 @@
android:background="@drawable/shape_favorite_bubble" />
</FrameLayout>
<TextView
<com.vanniktech.emoji.EmojiTextView
android:id="@id/dialogName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -101,7 +101,7 @@
android:contentDescription="@null"
tools:src="@drawable/ic_call_black_24dp" />
<TextView
<com.vanniktech.emoji.EmojiTextView
android:id="@id/dialogLastMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -35,11 +35,12 @@
android:layout_height="0dp"
android:layout_toEndOf="@id/attachmentButton" />
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonEditText
<com.vanniktech.emoji.EmojiEditText
android:id="@id/messageInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:imeOptions="actionDone|flagNoFullscreen"
android:layout_toStartOf="@id/sendButtonSpace"
android:inputType="textAutoCorrect|textMultiLine|textCapSentences"/>
@ -47,7 +48,17 @@
android:id="@id/sendButtonSpace"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toStartOf="@id/messageSendButton" />
android:layout_toStartOf="@id/smileyButton"/>
<ImageButton
android:id="@+id/smileyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_smiley"
android:layout_toStartOf="@id/messageSendButton"
android:background="@color/transparent"
android:layout_marginEnd="8dp"
android:layout_centerVertical="true"/>
<ImageButton
android:id="@id/messageSendButton"

File diff suppressed because one or more lines are too long

View file

@ -17,5 +17,9 @@
<color name="nc_grey">#D5D5D5</color>
<color name="white30">#E9FFFFFF</color>
<color name="grey950">#111111</color>
<color name="emoji_background">#ECEFF1</color>
<color name="emoji_icons">#61000000</color>
<color name="emoji_divider">#15000000</color>
</resources>