1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.dialer.rtt; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.support.annotation.Nullable; 23 import android.support.v7.app.AppCompatActivity; 24 import android.support.v7.widget.LinearLayoutManager; 25 import android.support.v7.widget.RecyclerView; 26 import android.view.MenuItem; 27 import com.android.dialer.common.Assert; 28 import com.android.dialer.common.concurrent.DialerExecutorComponent; 29 import com.android.dialer.common.concurrent.UiListener; 30 import com.android.dialer.glidephotomanager.PhotoInfo; 31 import com.android.dialer.protos.ProtoParsers; 32 import com.android.dialer.widget.DialerToolbar; 33 34 /** Activity holds RTT transcript. */ 35 public class RttTranscriptActivity extends AppCompatActivity { 36 37 public static final String EXTRA_TRANSCRIPT_ID = "extra_transcript_id"; 38 public static final String EXTRA_PRIMARY_TEXT = "extra_primary_text"; 39 public static final String EXTRA_PHOTO_INFO = "extra_photo_info"; 40 41 private RttTranscriptAdapter adapter; 42 private UiListener<RttTranscript> rttTranscriptUiListener; 43 private DialerToolbar toolbar; 44 getIntent( Context context, String transcriptId, String primaryText, PhotoInfo photoInfo)45 public static Intent getIntent( 46 Context context, String transcriptId, String primaryText, PhotoInfo photoInfo) { 47 Intent intent = new Intent(context, RttTranscriptActivity.class); 48 intent.putExtra(RttTranscriptActivity.EXTRA_TRANSCRIPT_ID, transcriptId); 49 intent.putExtra(RttTranscriptActivity.EXTRA_PRIMARY_TEXT, primaryText); 50 ProtoParsers.put(intent, RttTranscriptActivity.EXTRA_PHOTO_INFO, Assert.isNotNull(photoInfo)); 51 return intent; 52 } 53 54 @Override onCreate(@ullable Bundle bundle)55 protected void onCreate(@Nullable Bundle bundle) { 56 super.onCreate(bundle); 57 setContentView(R.layout.activity_rtt_transcript); 58 toolbar = findViewById(R.id.toolbar); 59 toolbar.setBackgroundColor(getColor(R.color.rtt_transcript_primary_color)); 60 getWindow().setStatusBarColor(getColor(R.color.rtt_transcript_primary_color_dark)); 61 62 RecyclerView recyclerView = findViewById(R.id.rtt_recycler_view); 63 LinearLayoutManager layoutManager = new LinearLayoutManager(this); 64 recyclerView.setLayoutManager(layoutManager); 65 recyclerView.setHasFixedSize(true); 66 adapter = new RttTranscriptAdapter(this); 67 recyclerView.setAdapter(adapter); 68 69 rttTranscriptUiListener = 70 DialerExecutorComponent.get(this) 71 .createUiListener(getFragmentManager(), "Load RTT transcript"); 72 handleIntent(getIntent()); 73 } 74 handleIntent(Intent intent)75 private void handleIntent(Intent intent) { 76 Assert.checkArgument(intent.hasExtra(EXTRA_TRANSCRIPT_ID)); 77 Assert.checkArgument(intent.hasExtra(EXTRA_PRIMARY_TEXT)); 78 Assert.checkArgument(intent.hasExtra(EXTRA_PHOTO_INFO)); 79 80 String id = intent.getStringExtra(EXTRA_TRANSCRIPT_ID); 81 rttTranscriptUiListener.listen( 82 this, 83 RttTranscriptUtil.loadRttTranscript(this, id), 84 adapter::setRttTranscript, 85 throwable -> { 86 throw new RuntimeException(throwable); 87 }); 88 89 String primaryText = intent.getStringExtra(EXTRA_PRIMARY_TEXT); 90 toolbar.setTitle(primaryText); 91 92 PhotoInfo photoInfo = 93 ProtoParsers.getTrusted(intent, EXTRA_PHOTO_INFO, PhotoInfo.getDefaultInstance()); 94 // Photo shown here shouldn't have video or RTT badge. 95 PhotoInfo sanitizedPhotoInfo = 96 PhotoInfo.newBuilder().mergeFrom(photoInfo).setIsRtt(false).setIsVideo(false).build(); 97 adapter.setPhotoInfo(sanitizedPhotoInfo); 98 } 99 100 @Override onNewIntent(Intent intent)101 protected void onNewIntent(Intent intent) { 102 super.onNewIntent(intent); 103 handleIntent(intent); 104 } 105 106 @Override onOptionsItemSelected(MenuItem item)107 public boolean onOptionsItemSelected(MenuItem item) { 108 final int itemId = item.getItemId(); 109 if (itemId == android.R.id.home) { 110 onBackPressed(); 111 return true; 112 } 113 return super.onOptionsItemSelected(item); 114 } 115 } 116