• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
21
22const TAG = 'DialerButtonView';
23@Component
24export struct DialerButtonView {
25  emergencyNum: string;
26  @Link mPresenter: DialerPresenter;
27  @StorageLink("tele_number") tele_number: string = "";
28  @StorageLink("haveSimCard") haveSimCard: boolean = false;
29  @StorageLink("haveMultiSimCard") haveMultiSimCard: boolean = false;
30  @StorageLink("haveVoLteReg") haveVoLteReg: boolean = false;
31
32  dialClick() {
33    this.mPresenter.callBtnClick = true;
34    if (!this.haveSimCard) {
35      HiLog.i(TAG, "No SIM card!");
36      this.emergencyNum = this.mPresenter.all_number;
37      //TODO Pop-up window for dialing without a SIM card
38      PhoneNumber.fromString(this.mPresenter.all_number).isDialEmergencyNum().then((res) => {
39        this.mPresenter.isEmergencyNum = res;
40        if (!this.mPresenter.isEmergencyNum) {
41          HiLog.i(TAG, "Is not Emergency Phone Number!");
42          return;
43        } else {
44          this.mPresenter.dialing(this.emergencyNum);
45        }
46      })
47    } else {
48      if (this.tele_number.length > 0) {
49        this.mPresenter.dialing(this.mPresenter.all_number);
50      }
51    }
52    AppStorage.SetOrCreate("tele_number", '');
53    this.mPresenter.all_number = '';
54    this.mPresenter.callBtnClick = false;
55  }
56
57  build() {
58    Row() {
59      Button() {
60        Image($r('app.media.dial_single_button_volte'))
61          .width($r("app.float.id_item_height_large"))
62          .height($r("app.float.id_item_height_large"))
63      }
64      .width(this.mPresenter.dialerButtonHeight)
65      .height(this.mPresenter.dialerButtonHeight)
66      .visibility(this.haveMultiSimCard ? Visibility.None : (this.haveSimCard && this.haveVoLteReg ?
67          Visibility.Visible : Visibility.None))
68      .backgroundColor($r('sys.color.ohos_id_color_connected'))
69      .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
70        ? 1 : $r('sys.float.ohos_id_alpha_disabled'))
71      .onClick(() => {
72        this.dialClick();
73      })
74
75      Button() {
76        Image($r("app.media.ic_public_phone_filled_white"))
77          .width($r("app.float.id_card_margin_xxxxl"))
78          .height($r("app.float.id_card_margin_xxxxl"))
79      }
80      .width(this.mPresenter.dialerButtonHeight)
81      .height(this.mPresenter.dialerButtonHeight)
82      .visibility(this.haveMultiSimCard ? Visibility.None : (this.haveSimCard && this.haveVoLteReg ?
83          Visibility.None : Visibility.Visible))
84      .backgroundColor($r('sys.color.ohos_id_color_connected'))
85      .opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
86        ? 1 : $r('sys.float.ohos_id_alpha_disabled'))
87      .onClick(() => {
88        this.dialClick();
89      })
90
91      MutiDialerButtonView({
92        mPresenter: $mPresenter,
93      }).height(this.mPresenter.dialerButtonHeight)
94        .visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None)
95    }.width(this.mPresenter.dialerButtonWidth)
96    .height(this.mPresenter.dialerButtonHeight)
97    .justifyContent(FlexAlign.Center)
98  }
99}