1/**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import EnvironmentProp from '../../feature/EnvironmentProp';
17import DialerPresenter from '../../presenter/dialer/DialerPresenter';
18import { MutiDialerButtonView } from '../mutisim/MutiDialerButtonView'
19import { PhoneNumber } from '../../../../../../feature/phonenumber';
20import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog';
21import promptAction from '@ohos.promptAction'
22
23const TAG = 'DialerButtonView';
24@Component
25export struct DialerButtonView {
26  emergencyNum: string;
27  @Link mPresenter: DialerPresenter;
28  @StorageLink('tele_number') tele_number: string = '';
29  @StorageLink('haveSimCard') haveSimCard: boolean = false;
30  @StorageLink('haveMultiSimCard') haveMultiSimCard: boolean = false;
31  @StorageLink('haveVoLteReg') haveVoLteReg: boolean = false;
32
33  dialClick() {
34    this.mPresenter.callBtnClick = true;
35    if (!this.haveSimCard) {
36      HiLog.i(TAG, 'No SIM card!');
37      this.emergencyNum = this.mPresenter.all_number;
38      //TODO Pop-up window for dialing without a SIM card
39      PhoneNumber.fromString(this.mPresenter.all_number).isDialEmergencyNum().then((res) => {
40        this.mPresenter.isEmergencyNum = res;
41        if (!this.mPresenter.isEmergencyNum) {
42          HiLog.i(TAG, 'Is not Emergency Phone Number!');
43          promptAction.showToast({
44            message: $r('app.string.no_simCardDailog'),
45            duration: 2000,
46            bottom:'60%'
47          });
48          return;
49        } else {
50          this.mPresenter.dialing(this.emergencyNum);
51        }
52      })
53    } else {
54      if (this.tele_number.length > 0) {
55        this.mPresenter.dialing(this.mPresenter.all_number);
56      }
57    }
58    AppStorage.SetOrCreate('tele_number', '');
59    this.mPresenter.all_number = '';
60    this.mPresenter.callBtnClick = false;
61  }
62
63  build() {
64    Row() {
65      if (!this.haveMultiSimCard) {
66        if (this.haveSimCard && this.haveVoLteReg) {
67          Button() {
68            Image($r('app.media.dial_single_button_hd'))
69              .width($r('app.float.id_item_height_large'))
70              .height($r('app.float.id_item_height_large'))
71          }
72          .width(this.mPresenter.dialerButtonHeight)
73          .height(this.mPresenter.dialerButtonHeight)
74          .backgroundColor($r('sys.color.ohos_id_color_connected'))
75          .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
76            ? 1 : $r('sys.float.ohos_id_alpha_disabled'))
77          .onClick(() => {
78            this.dialClick();
79          })
80        } else {
81          Button() {
82            Image($r('app.media.ic_public_phone_filled_white'))
83              .width($r('app.float.id_card_margin_xxxxl'))
84              .height($r('app.float.id_card_margin_xxxxl'))
85          }
86          .width(this.mPresenter.dialerButtonHeight)
87          .height(this.mPresenter.dialerButtonHeight)
88          .backgroundColor($r('sys.color.ohos_id_color_connected'))
89          .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
90            ? 1 : $r('sys.float.ohos_id_alpha_disabled'))
91          .onClick(() => {
92            this.dialClick();
93          })
94        }
95      } else {
96        MutiDialerButtonView({
97          mPresenter: $mPresenter,
98        }).height(this.mPresenter.dialerButtonHeight)
99      }
100    }.width(this.mPresenter.dialerButtonWidth)
101    .height(this.mPresenter.dialerButtonHeight)
102    .justifyContent(FlexAlign.Center)
103  }
104}