summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/rtt/RttTranscriptActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/rtt/RttTranscriptActivity.java')
-rw-r--r--java/com/android/dialer/rtt/RttTranscriptActivity.java122
1 files changed, 122 insertions, 0 deletions
diff --git a/java/com/android/dialer/rtt/RttTranscriptActivity.java b/java/com/android/dialer/rtt/RttTranscriptActivity.java
new file mode 100644
index 000000000..2087250b3
--- /dev/null
+++ b/java/com/android/dialer/rtt/RttTranscriptActivity.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.dialer.rtt;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.MenuItem;
+import com.android.dialer.common.Assert;
+import com.android.dialer.common.concurrent.DialerExecutorComponent;
+import com.android.dialer.common.concurrent.UiListener;
+import com.android.dialer.glidephotomanager.PhotoInfo;
+import com.android.dialer.protos.ProtoParsers;
+import com.google.common.util.concurrent.ListenableFuture;
+
+/** Activity holds RTT transcript. */
+public class RttTranscriptActivity extends AppCompatActivity {
+
+ public static final String EXTRA_TRANSCRIPT_ID = "extra_transcript_id";
+ public static final String EXTRA_PRIMARY_TEXT = "extra_primary_text";
+ public static final String EXTRA_PHOTO_INFO = "extra_photo_info";
+
+ private RttTranscriptAdapter adapter;
+ private UiListener<RttTranscript> rttTranscriptUiListener;
+
+ public static Intent getIntent(
+ Context context, String transcriptId, String primaryText, PhotoInfo photoInfo) {
+ Intent intent = new Intent(context, RttTranscriptActivity.class);
+ intent.putExtra(RttTranscriptActivity.EXTRA_TRANSCRIPT_ID, transcriptId);
+ intent.putExtra(RttTranscriptActivity.EXTRA_PRIMARY_TEXT, primaryText);
+ ProtoParsers.put(intent, RttTranscriptActivity.EXTRA_PHOTO_INFO, Assert.isNotNull(photoInfo));
+ return intent;
+ }
+
+ @Override
+ protected void onCreate(@Nullable Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.activity_rtt_transcript);
+ ActionBar actionBar = getSupportActionBar();
+ actionBar.setDisplayShowHomeEnabled(true);
+ actionBar.setDisplayHomeAsUpEnabled(true);
+
+ RecyclerView recyclerView = findViewById(R.id.rtt_recycler_view);
+ LinearLayoutManager layoutManager = new LinearLayoutManager(this);
+ layoutManager.setStackFromEnd(true);
+ recyclerView.setLayoutManager(layoutManager);
+ recyclerView.setHasFixedSize(true);
+ adapter = new RttTranscriptAdapter(this);
+ recyclerView.setAdapter(adapter);
+
+ rttTranscriptUiListener =
+ DialerExecutorComponent.get(this)
+ .createUiListener(getFragmentManager(), "Load RTT transcript");
+ handleIntent(getIntent());
+ }
+
+ private void handleIntent(Intent intent) {
+ Assert.checkArgument(intent.hasExtra(EXTRA_TRANSCRIPT_ID));
+ Assert.checkArgument(intent.hasExtra(EXTRA_PRIMARY_TEXT));
+ Assert.checkArgument(intent.hasExtra(EXTRA_PHOTO_INFO));
+
+ String id = intent.getStringExtra(EXTRA_TRANSCRIPT_ID);
+ rttTranscriptUiListener.listen(
+ this,
+ getRttTranscript(id),
+ adapter::setRttTranscript,
+ throwable -> {
+ throw new RuntimeException(throwable);
+ });
+
+ String primaryText = intent.getStringExtra(EXTRA_PRIMARY_TEXT);
+ getSupportActionBar().setTitle(primaryText);
+
+ PhotoInfo photoInfo =
+ ProtoParsers.getTrusted(intent, EXTRA_PHOTO_INFO, PhotoInfo.getDefaultInstance());
+ // Photo shown here shouldn't have video or RTT badge.
+ PhotoInfo sanitizedPhotoInfo =
+ PhotoInfo.newBuilder().mergeFrom(photoInfo).setIsRtt(false).setIsVideo(false).build();
+ adapter.setPhotoInfo(sanitizedPhotoInfo);
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ handleIntent(intent);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ final int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ onBackPressed();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private ListenableFuture<RttTranscript> getRttTranscript(String id) {
+ return DialerExecutorComponent.get(this)
+ .backgroundExecutor()
+ .submit(() -> new RttTranscriptUtil(this).getRttTranscript(id));
+ }
+}