summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/rtt/RttTranscriptActivity.java
blob: 574cdb2e290c90832821f74be02c35c7553296d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * 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.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.android.dialer.widget.DialerToolbar;

/** 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;
  private DialerToolbar toolbar;

  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);
    toolbar = findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(getColor(R.color.rtt_transcript_primary_color));
    getWindow().setStatusBarColor(getColor(R.color.rtt_transcript_primary_color_dark));

    RecyclerView recyclerView = findViewById(R.id.rtt_recycler_view);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    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,
        RttTranscriptUtil.loadRttTranscript(this, id),
        adapter::setRttTranscript,
        throwable -> {
          throw new RuntimeException(throwable);
        });

    String primaryText = intent.getStringExtra(EXTRA_PRIMARY_TEXT);
    toolbar.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);
  }
}