diff options
author | wangqi <wangqi@google.com> | 2018-03-09 10:14:47 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-09 11:10:35 -0800 |
commit | 93d27d0a5db53bc7cb7b03c58889667887d5816b (patch) | |
tree | a8fe62c062534b95caeeb29cdfe74e5c39dd686b /java/com/android/incallui/rtt/impl/RttChatAdapter.java | |
parent | 93a51cc5d641c45bcc4d8bcd47b715919935b918 (diff) |
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
Diffstat (limited to 'java/com/android/incallui/rtt/impl/RttChatAdapter.java')
-rw-r--r-- | java/com/android/incallui/rtt/impl/RttChatAdapter.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 912314945..7e2b571c1 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 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde 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 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde 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); + } } |