diff options
Diffstat (limited to 'java/com/android/incallui/rtt/impl')
-rw-r--r-- | java/com/android/incallui/rtt/impl/RttChatAdapter.java | 76 | ||||
-rw-r--r-- | java/com/android/incallui/rtt/impl/RttChatMessage.java | 6 |
2 files changed, 3 insertions, 79 deletions
diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 1db4c6bad..1ea7f31b1 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -17,19 +17,15 @@ package com.android.incallui.rtt.impl; import android.content.Context; -import android.support.annotation.MainThread; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.ThreadUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Random; /** Adapter class for holding RTT chat data. */ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolder> { @@ -42,13 +38,11 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde private final List<RttChatMessage> rttMessages = new ArrayList<>(); private int lastIndexOfLocalMessage = -1; private int lastIndexOfRemoteMessage = -1; - private final TypeBot typeBot; private final MessageListener messageListener; RttChatAdapter(Context context, MessageListener listener) { this.context = context; this.messageListener = listener; - typeBot = new TypeBot(text -> ThreadUtil.postOnUiThread(() -> addRemoteMessage(text))); } @Override @@ -133,7 +127,6 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde rttMessages.get(lastIndexOfLocalMessage).finish(); notifyItemChanged(lastIndexOfLocalMessage); lastIndexOfLocalMessage = -1; - startChatBot(); } void addRemoteMessage(String message) { @@ -146,73 +139,4 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde messageListener.newMessageAdded(); } } - - private void startChatBot() { - typeBot.scheduleMessage(); - } - - // TODO(wangqi): Move this out of this class once a bug is fixed. - private static class TypeBot { - interface Callback { - void type(String text); - } - - private static final String[] CANDIDATE_MESSAGES = - new String[] { - "To RTT or not to RTT, that is the question...", - "Making TTY great again!", - "I would be more comfortable with real \"Thyme\" chatting." - + " I don't know how to end this pun", - "お疲れ様でした", - "The FCC has mandated that I respond... I will do so begrudgingly", - "😂😂😂💯" - }; - private final Random random = new Random(); - private final Callback callback; - private final List<String> messageQueue = new ArrayList<>(); - private int currentTypingPosition = -1; - private String currentTypingMessage = null; - - TypeBot(Callback callback) { - this.callback = callback; - } - - @MainThread - public void scheduleMessage() { - Assert.isMainThread(); - if (random.nextDouble() < 0.5) { - return; - } - - String text = CANDIDATE_MESSAGES[random.nextInt(CANDIDATE_MESSAGES.length)]; - messageQueue.add(text); - typeMessage(); - } - - @MainThread - private void typeMessage() { - Assert.isMainThread(); - if (currentTypingPosition < 0 || currentTypingMessage == null) { - if (messageQueue.size() <= 0) { - return; - } - currentTypingMessage = messageQueue.remove(0); - currentTypingPosition = 0; - } - if (currentTypingPosition < currentTypingMessage.length()) { - int size = random.nextInt(currentTypingMessage.length() - currentTypingPosition + 1); - callback.type( - currentTypingMessage.substring(currentTypingPosition, currentTypingPosition + size)); - currentTypingPosition = currentTypingPosition + size; - // Wait up to 2s between typing. - ThreadUtil.postDelayedOnUiThread(this::typeMessage, 200 * random.nextInt(10)); - } else { - callback.type(RttChatMessage.BUBBLE_BREAKER); - currentTypingPosition = -1; - currentTypingMessage = null; - // Wait 1-11s between two messages. - ThreadUtil.postDelayedOnUiThread(this::typeMessage, 1000 * (1 + random.nextInt(10))); - } - } - } } diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/impl/RttChatMessage.java index 85b045183..b36da77cc 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessage.java +++ b/java/com/android/incallui/rtt/impl/RttChatMessage.java @@ -19,6 +19,7 @@ package com.android.incallui.rtt.impl; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextWatcher; +import com.android.incallui.rtt.protocol.Constants; import com.google.common.base.Splitter; import java.util.ArrayList; import java.util.Iterator; @@ -27,8 +28,7 @@ import java.util.List; /** Message class that holds one RTT chat content. */ final class RttChatMessage { - static final String BUBBLE_BREAKER = "\n\n"; - private static final Splitter SPLITTER = Splitter.on(BUBBLE_BREAKER); + private static final Splitter SPLITTER = Splitter.on(Constants.BUBBLE_BREAKER); boolean isRemote; public boolean hasAvatar; @@ -108,7 +108,7 @@ final class RttChatMessage { firstMessage.isRemote = true; } firstMessage.append(firstMessageContent); - if (splitText.hasNext() || text.endsWith(BUBBLE_BREAKER)) { + if (splitText.hasNext() || text.endsWith(Constants.BUBBLE_BREAKER)) { firstMessage.finish(); } messageList.add(firstMessage); |