Save RTT chat history during the call.
Thus putting call into background won't lose the history.
This is only stored in memory by making RttChatMessage Parcelable and saved
along with fragment's life cycle.
Bug: 67596257
Test: manual
PiperOrigin-RevId: 188500104
Change-Id: I11e8e55f0475defd9c3b9a8cc10db4186392ddd8
diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java
index 9123149..7e2b571 100644
--- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java
+++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java
@@ -17,6 +17,9 @@
package com.android.incallui.rtt.impl;
import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -33,15 +36,26 @@
void newMessageAdded();
}
+ private static final String KEY_MESSAGE_DATA = "key_message_data";
+ private static final String KEY_LAST_REMOTE_MESSAGE = "key_last_remote_message";
+ private static final String KEY_LAST_LOCAL_MESSAGE = "key_last_local_message";
+
private final Context context;
- private final List<RttChatMessage> rttMessages = new ArrayList<>();
+ private final List<RttChatMessage> rttMessages;
private int lastIndexOfLocalMessage = -1;
private int lastIndexOfRemoteMessage = -1;
private final MessageListener messageListener;
- RttChatAdapter(Context context, MessageListener listener) {
+ RttChatAdapter(Context context, MessageListener listener, @Nullable Bundle savedInstanceState) {
this.context = context;
this.messageListener = listener;
+ if (savedInstanceState == null) {
+ rttMessages = new ArrayList<>();
+ } else {
+ rttMessages = savedInstanceState.getParcelableArrayList(KEY_MESSAGE_DATA);
+ lastIndexOfRemoteMessage = savedInstanceState.getInt(KEY_LAST_REMOTE_MESSAGE);
+ lastIndexOfLocalMessage = savedInstanceState.getInt(KEY_LAST_LOCAL_MESSAGE);
+ }
}
@Override
@@ -161,4 +175,10 @@
messageListener.newMessageAdded();
}
}
+
+ void onSaveInstanceState(@NonNull Bundle bundle) {
+ bundle.putParcelableArrayList(KEY_MESSAGE_DATA, (ArrayList<RttChatMessage>) rttMessages);
+ bundle.putInt(KEY_LAST_REMOTE_MESSAGE, lastIndexOfRemoteMessage);
+ bundle.putInt(KEY_LAST_LOCAL_MESSAGE, lastIndexOfLocalMessage);
+ }
}
diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java
index f9c91e5..9e8a24a 100644
--- a/java/com/android/incallui/rtt/impl/RttChatFragment.java
+++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java
@@ -124,6 +124,8 @@
if (savedInstanceState != null) {
inCallButtonUiDelegate.onRestoreInstanceState(savedInstanceState);
}
+ // Prevent updating local message until UI is ready.
+ isClearingInput = true;
}
@Override
@@ -158,7 +160,7 @@
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(false);
- adapter = new RttChatAdapter(getContext(), this);
+ adapter = new RttChatAdapter(getContext(), this, savedInstanceState);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(onScrollListener);
submitButton = view.findViewById(R.id.rtt_chat_submit_button);
@@ -242,13 +244,21 @@
public void onStart() {
LogUtil.enterBlock("RttChatFragment.onStart");
super.onStart();
+ isClearingInput = false;
onRttScreenStart();
}
@Override
+ public void onSaveInstanceState(@NonNull Bundle bundle) {
+ super.onSaveInstanceState(bundle);
+ adapter.onSaveInstanceState(bundle);
+ }
+
+ @Override
public void onStop() {
LogUtil.enterBlock("RttChatFragment.onStop");
super.onStop();
+ isClearingInput = true;
if (overflowMenu.isShowing()) {
overflowMenu.dismiss();
}
diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/impl/RttChatMessage.java
index 6c852cf..fd83fb8 100644
--- a/java/com/android/incallui/rtt/impl/RttChatMessage.java
+++ b/java/com/android/incallui/rtt/impl/RttChatMessage.java
@@ -16,6 +16,8 @@
package com.android.incallui.rtt.impl;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.android.incallui.rtt.protocol.Constants;
@@ -25,7 +27,7 @@
import java.util.List;
/** Message class that holds one RTT chat content. */
-final class RttChatMessage {
+final class RttChatMessage implements Parcelable {
private static final Splitter SPLITTER = Splitter.on(Constants.BUBBLE_BREAKER);
@@ -119,4 +121,41 @@
return messageList;
}
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(getContent());
+ boolean[] values = new boolean[2];
+ values[0] = isRemote;
+ values[1] = isFinished;
+ dest.writeBooleanArray(values);
+ }
+
+ public static final Parcelable.Creator<RttChatMessage> CREATOR =
+ new Parcelable.Creator<RttChatMessage>() {
+ @Override
+ public RttChatMessage createFromParcel(Parcel in) {
+ return new RttChatMessage(in);
+ }
+
+ @Override
+ public RttChatMessage[] newArray(int size) {
+ return new RttChatMessage[size];
+ }
+ };
+
+ private RttChatMessage(Parcel in) {
+ content.append(in.readString());
+ boolean[] values = new boolean[2];
+ in.readBooleanArray(values);
+ isRemote = values[0];
+ isFinished = values[1];
+ }
+
+ RttChatMessage() {}
}