diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-03-09 19:38:40 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-09 19:38:40 +0000 |
commit | 187363d7823242f87cc64f04bbe86ed150e1e1b2 (patch) | |
tree | a8fe62c062534b95caeeb29cdfe74e5c39dd686b /java/com/android/incallui/rtt/impl/RttChatAdapter.java | |
parent | 93a51cc5d641c45bcc4d8bcd47b715919935b918 (diff) | |
parent | 93d27d0a5db53bc7cb7b03c58889667887d5816b (diff) |
Merge "Save RTT chat history during the call."
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); + } } |