mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 14:27:24 +00:00
Remove unused method and dependency
See: commit 4c4c5839
, #1167
Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
4c4c583923
commit
8468535a1e
@ -269,10 +269,6 @@ dependencies {
|
||||
implementation 'com.github.nextcloud:PopupBubble:1.0.6'
|
||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||
|
||||
implementation('eu.medsea.mimeutil:mime-util:2.1.3', {
|
||||
exclude group: 'org.slf4j'
|
||||
})
|
||||
|
||||
implementation "com.afollestad.material-dialogs:core:${materialDialogsVersion}"
|
||||
implementation "com.afollestad.material-dialogs:datetime:${materialDialogsVersion}"
|
||||
implementation "com.afollestad.material-dialogs:bottomsheets:${materialDialogsVersion}"
|
||||
|
@ -2,6 +2,8 @@
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* @author Tim Krüger
|
||||
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@ -22,71 +24,13 @@
|
||||
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.util.PatternsCompat;
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
import com.vanniktech.emoji.EmojiInformation;
|
||||
import com.vanniktech.emoji.EmojiUtils;
|
||||
import eu.medsea.mimeutil.MimeUtil;
|
||||
import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
|
||||
import eu.medsea.mimeutil.detector.MagicMimeMimeDetector;
|
||||
import eu.medsea.mimeutil.detector.OpendesktopMimeDetector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public final class TextMatchers {
|
||||
|
||||
private static final String TAG = "TextMatchers";
|
||||
|
||||
public static ChatMessage.MessageType getMessageTypeFromString(@NonNull final String text) {
|
||||
List<String> links = new ArrayList<>();
|
||||
Matcher m = PatternsCompat.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 ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE;
|
||||
} else if (specialLink.contains("tenor.com/") &&
|
||||
Pattern.compile("https://media.*\\.tenor\\.com.*\\.gif.*",
|
||||
Pattern.CASE_INSENSITIVE).matcher(specialLink).matches()) {
|
||||
return ChatMessage.MessageType.SINGLE_LINK_TENOR_MESSAGE;
|
||||
} else {
|
||||
if (specialLink.contains("?")) {
|
||||
specialLink = specialLink.substring(0, specialLink.indexOf("?"));
|
||||
}
|
||||
MimeUtil.registerMimeDetector(MagicMimeMimeDetector.class.getName());
|
||||
MimeUtil.registerMimeDetector(ExtensionMimeDetector.class.getName());
|
||||
MimeUtil.registerMimeDetector(OpendesktopMimeDetector.class.getName());
|
||||
|
||||
String mimeType = MimeUtil.getMostSpecificMimeType(MimeUtil.getMimeTypes(specialLink)).toString();
|
||||
if (mimeType.startsWith("image/")) {
|
||||
if (mimeType.equalsIgnoreCase("image/gif")) {
|
||||
return ChatMessage.MessageType.SINGLE_LINK_GIF_MESSAGE;
|
||||
} else {
|
||||
return ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE;
|
||||
}
|
||||
} else if (mimeType.startsWith("video/")) {
|
||||
return ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE;
|
||||
} else if (mimeType.startsWith("audio/")) {
|
||||
return ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE;
|
||||
}
|
||||
|
||||
return ChatMessage.MessageType.SINGLE_LINK_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have 0 or more than 1 link, we're a regular message
|
||||
return ChatMessage.MessageType.REGULAR_TEXT_MESSAGE;
|
||||
}
|
||||
|
||||
public static boolean isMessageWithSingleEmoticonOnly(@Nullable final String text) {
|
||||
final EmojiInformation emojiInformation = EmojiUtils.emojiInformation(text);
|
||||
return (emojiInformation.isOnlyEmojis && emojiInformation.emojis.size() == 1);
|
||||
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2019 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.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TextMatchersTest {
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_regularTextGiven_regularTextMessageTypeReturned() {
|
||||
String simpleMessageText = "Hello world! Have a cookie!";
|
||||
String messageContainingLink = "Hello https://nextcloud.com! Have a good day";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleMessageText));
|
||||
assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(messageContainingLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_singleUrlTextGiven_singleLinkMessageTypeReturned() {
|
||||
String simpleUrlText = "https://nextcloud.com/";
|
||||
String complexUrlText = "https://docs.nextcloud.com/server/15/admin_manual/#target-audience";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleUrlText));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(complexUrlText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_imageLinkGiven_singleLinkImageMessageReturned() {
|
||||
String simpleImageText = "https://nextcloud.com/image.jpg";
|
||||
String complexImageUrlText = "https://nextcloud.com/wp-content/themes/next/assets/img/features/mobileDesktop.png?x22777";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleImageText));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(complexImageUrlText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_gifLinkGiven_gifMessageTypeReturned() {
|
||||
String gifImageText = "https://nextcloud.com/funny.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIF_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(gifImageText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_audioLinkGiven_audioMessageTypeReturned() {
|
||||
String wavLink = "https://nextcloud.com/message.wav";
|
||||
String mp3Link = "https://nextcloud.com/message.mp3";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(wavLink));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(mp3Link));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_videoLinkGiven_videoMessageTypeReturned() {
|
||||
String mp4Link = "https://nextcloud.com/message.mp4";
|
||||
String flvLink = "https://nextcloud.com/message.flv";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(mp4Link));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(flvLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_giphyLinkGiven_giphyMessageTypeReturned() {
|
||||
String giphyLink = "https://media.giphy.com/media/11fucLQCTOdvBS/giphy.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(giphyLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_tenorLinkGiven_tenorMessageTypeReturned() {
|
||||
String tenorLink = "https://media.tenor.com/images/d98e76e3930cf171cc39e301c9e974af/tenor.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_TENOR_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(tenorLink));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user