diff options
Diffstat (limited to 'java/com/android/incallui')
3 files changed, 25 insertions, 14 deletions
diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 42bd2c60c..912314945 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -139,6 +139,18 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde lastIndexOfLocalMessage = -1; } + String computeChangeOfLocalMessage(String newMessage) { + RttChatMessage rttChatMessage = null; + if (lastIndexOfLocalMessage >= 0) { + rttChatMessage = rttMessages.get(lastIndexOfLocalMessage); + } + if (rttChatMessage == null || rttChatMessage.isFinished()) { + return newMessage; + } else { + return RttChatMessage.computeChangedString(rttChatMessage.getContent(), newMessage); + } + } + void addRemoteMessage(String message) { LogUtil.enterBlock("RttChatAdapater.addRemoteMessage"); if (TextUtils.isEmpty(message)) { diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java index 396b89e75..5094c318e 100644 --- a/java/com/android/incallui/rtt/impl/RttChatFragment.java +++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java @@ -204,7 +204,7 @@ public class RttChatFragment extends Fragment if (isClearingInput) { return; } - String messageToAppend = RttChatMessage.getChangedString(s, start, before, count); + String messageToAppend = adapter.computeChangeOfLocalMessage(s.toString()); if (!TextUtils.isEmpty(messageToAppend)) { adapter.addLocalMessage(messageToAppend); rttCallScreenDelegate.onLocalMessage(messageToAppend); diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/impl/RttChatMessage.java index fe30364b8..6c852cf92 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessage.java +++ b/java/com/android/incallui/rtt/impl/RttChatMessage.java @@ -18,7 +18,6 @@ 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; @@ -59,10 +58,7 @@ final class RttChatMessage { } /** - * Generates delta change to a text. - * - * <p>This is used to track text change of input. See more details in {@link - * TextWatcher#onTextChanged} + * Computes delta change of two string. * * <p>e.g. "hello world" -> "hello" : "\b\b\b\b\b\b" * @@ -72,16 +68,19 @@ final class RttChatMessage { * * <p>"hello world" -> "hello new world" : "\b\b\b\b\bnew world" */ - static String getChangedString(CharSequence s, int start, int before, int count) { + static String computeChangedString(String oldMessage, String newMesssage) { StringBuilder modify = new StringBuilder(); - char c = '\b'; - int oldLength = s.length() - count + before; - for (int i = 0; i < oldLength - start; i++) { - modify.append(c); + int indexChangeStart = 0; + while (indexChangeStart < oldMessage.length() + && indexChangeStart < newMesssage.length() + && oldMessage.charAt(indexChangeStart) == newMesssage.charAt(indexChangeStart)) { + indexChangeStart++; + } + for (int i = indexChangeStart; i < oldMessage.length(); i++) { + modify.append('\b'); } - modify.append(s, start, start + count); - if (start + count < s.length()) { - modify.append(s, start + count, s.length()); + for (int i = indexChangeStart; i < newMesssage.length(); i++) { + modify.append(newMesssage.charAt(i)); } return modify.toString(); } |