1 /*
2  * Copyright (C) 2019 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.car.dialer.ui.activecall;
18 
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 import androidx.annotation.VisibleForTesting;
27 import androidx.fragment.app.Fragment;
28 import androidx.lifecycle.MutableLiveData;
29 import androidx.lifecycle.ViewModelProviders;
30 
31 import com.android.car.apps.common.BackgroundImageView;
32 import com.android.car.dialer.R;
33 
34 /**
35  * A fragment that displays information about an on-going call with options to hang up.
36  */
37 public class OngoingCallFragment extends InCallFragment {
38     private Fragment mDialpadFragment;
39     private Fragment mOnholdCallFragment;
40     private View mUserProfileContainerView;
41     private BackgroundImageView mBackgroundImage;
42     private MutableLiveData<Boolean> mDialpadState;
43 
44     @Override
onCreateView(@onNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)45     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
46             @Nullable Bundle savedInstanceState) {
47         View fragmentView = inflater.inflate(R.layout.ongoing_call_fragment, container, false);
48 
49         mUserProfileContainerView = fragmentView.findViewById(R.id.user_profile_container);
50         mBackgroundImage = fragmentView.findViewById(R.id.background_image);
51         mOnholdCallFragment = getChildFragmentManager().findFragmentById(R.id.onhold_user_profile);
52         mDialpadFragment = getChildFragmentManager().findFragmentById(R.id.incall_dialpad_fragment);
53 
54         InCallViewModel inCallViewModel = ViewModelProviders.of(getActivity()).get(
55                 InCallViewModel.class);
56 
57         inCallViewModel.getPrimaryCallDetail().observe(this, this::bindUserProfileView);
58         inCallViewModel.getCallStateAndConnectTime().observe(this, this::updateCallDescription);
59 
60         mDialpadState = inCallViewModel.getDialpadOpenState();
61         mDialpadState.observe(this, isDialpadOpen -> {
62             if (isDialpadOpen) {
63                 onOpenDialpad();
64             } else {
65                 onCloseDialpad();
66             }
67         });
68 
69         inCallViewModel.shouldShowOnholdCall().observe(this,
70                 this::maybeShowOnholdCallFragment);
71 
72         return fragmentView;
73     }
74 
75     @VisibleForTesting
onOpenDialpad()76     void onOpenDialpad() {
77         getChildFragmentManager().beginTransaction()
78                 .show(mDialpadFragment)
79                 .commit();
80         mUserProfileContainerView.setVisibility(View.GONE);
81         mBackgroundImage.setDimmed(true);
82     }
83 
84     @VisibleForTesting
onCloseDialpad()85     void onCloseDialpad() {
86         getChildFragmentManager().beginTransaction()
87                 .hide(mDialpadFragment)
88                 .commit();
89         mUserProfileContainerView.setVisibility(View.VISIBLE);
90         mBackgroundImage.setDimmed(false);
91     }
92 
maybeShowOnholdCallFragment(Boolean showOnholdCall)93     private void maybeShowOnholdCallFragment(Boolean showOnholdCall) {
94         if (showOnholdCall) {
95             getChildFragmentManager().beginTransaction().show(mOnholdCallFragment).commit();
96         } else {
97             getChildFragmentManager().beginTransaction().hide(mOnholdCallFragment).commit();
98         }
99     }
100 }
101