• 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 router from '@ohos.router';
17import pasteboard from '@ohos.pasteboard';
18import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
19import { StringUtil } from '../../../../../common/src/main/ets/util/StringUtil';
20import StringFormatUtil from '../util/StringFormatUtil';
21import { missedCallManager } from '../feature/missedCall/MissedCallManager';
22import CallRecordPresenter from './dialer/callRecord/CallRecordPresenter';
23import FavoriteListPresenter from './favorite/FavoriteListPresenter';
24
25const TAG = 'IndexPresenter  ';
26
27export default class IndexPresenter {
28  private static instance: IndexPresenter;
29
30  public static getInstance(): IndexPresenter {
31    if (!IndexPresenter.instance) {
32      IndexPresenter.instance = new IndexPresenter();
33    }
34    return IndexPresenter.instance;
35  }
36
37  onPageShow() {
38    HiLog.i(TAG, 'onPageShow !!!');
39    this.cancelMissedCallNotification()
40    if (parseInt(StringFormatUtil.judgeSysTime()) !== AppStorage.Get('sysTime')) {
41      HiLog.i(TAG, 'DO requestItem cause systemTime changed');
42      CallRecordPresenter.getInstance().requestItem();
43      AppStorage.SetOrCreate('sysTime', parseInt(StringFormatUtil.judgeSysTime()));
44    }
45  }
46
47  getCurrentUrl(){
48    let url = router.getState().path+router.getState().name;
49    HiLog.i(TAG,'getCurrentUrl:'+url)
50    return url;
51  }
52
53  goToPage(url: string, pageIndex?: number, params?) {
54    HiLog.i(TAG, 'goToPage: ' + url);
55    if (pageIndex != undefined && router.getState().index >= pageIndex) {
56      if (url == globalThis.presenterManager?.mainUrl || this.getCurrentUrl() == url) {
57        router.back({
58          url: url,
59          params: params
60        })
61        return;
62      }
63      router.replaceUrl({
64        url: url,
65        params: params
66      });
67    } else {
68      router.pushUrl({
69        url: url,
70        params: params
71      });
72    }
73  }
74
75  cancelMissedCallNotification() {
76    HiLog.i(TAG, `cancelMissedCallNotification`);
77    missedCallManager.cancelNotification()
78  }
79
80  aboutToAppear() {
81    HiLog.i(TAG, 'aboutToAppear !!!');
82    AppStorage.SetOrCreate('sysTime', parseInt(StringFormatUtil.judgeSysTime()));
83  }
84
85  aboutToDisappear() {
86    HiLog.i(TAG, 'aboutToDisappear !!!');
87  }
88
89  getCopy(phoneNumber) {
90    HiLog.i(TAG, 'Succeeded PasteData is ' + JSON.stringify(phoneNumber));
91    let pasteData = pasteboard.createPlainTextData(phoneNumber);
92    let systemPasteboard = pasteboard.getSystemPasteboard();
93    systemPasteboard.setPasteData(pasteData, (err, data) => {
94      if (err) {
95        HiLog.e(TAG, 'Failed to set PasteData. Cause: ' + JSON.stringify(err.message));
96        return;
97      }
98      HiLog.i(TAG, 'Succeeded in setting PasteData.');
99    });
100  }
101
102  getTabSrc(tabIndex: number, index: number): Resource {
103    let imgSrc = $r('app.media.ic_call_filled_normal');
104    if (index === 1) {
105      imgSrc = $r('app.media.ic_contacts_normal_filled');
106    }
107    if (index === 2) {
108      imgSrc = $r('app.media.ic_feature_normal_filled');
109    }
110    return imgSrc;
111  }
112
113  getTabText(tabIndex: number, index: number): Resource {
114    let text = $r('app.string.dialer');
115    if (index === 1) {
116      text = $r('app.string.contact');
117    }
118    if (index === 2) {
119      text = $r('app.string.favorite');
120    }
121    return text;
122  }
123
124  getTabTextColor(tabIndex: number, index: number): Resource {
125    let color = $r('sys.color.ohos_id_color_bottom_tab_text_off');
126    if (tabIndex === index) {
127      color = $r('sys.color.ohos_id_color_connected');
128    }
129    return color;
130  }
131}