18779efd5Sopenharmony_ci/** 28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License. 58779efd5Sopenharmony_ci * You may obtain a copy of the License at 68779efd5Sopenharmony_ci * 78779efd5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88779efd5Sopenharmony_ci * 98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and 138779efd5Sopenharmony_ci * limitations under the License. 148779efd5Sopenharmony_ci */ 158779efd5Sopenharmony_ci 168779efd5Sopenharmony_ciimport { HiLog } from '../../../../../common/src/main/ets/util/HiLog'; 178779efd5Sopenharmony_ciimport Constants from '../../../../../common/src/main/ets/Constants'; 188779efd5Sopenharmony_ciimport ContactListPresenter from './contact/ContactListPresenter'; 198779efd5Sopenharmony_ciimport CallRecordPresenter from './dialer/callRecord/CallRecordPresenter'; 208779efd5Sopenharmony_ciimport WorkerWrapper from '../workers/base/WorkerWrapper'; 218779efd5Sopenharmony_ciimport Want from '@ohos.app.ability.Want'; 228779efd5Sopenharmony_ci 238779efd5Sopenharmony_ciconst TAG = 'PageManager' 248779efd5Sopenharmony_ci 258779efd5Sopenharmony_ciexport default class PresenterManager { 268779efd5Sopenharmony_ci mainUrl: string = 'pages/index'; 278779efd5Sopenharmony_ci context: Context; 288779efd5Sopenharmony_ci worker: WorkerWrapper; 298779efd5Sopenharmony_ci callRecordPresenter: CallRecordPresenter = CallRecordPresenter.getInstance(); 308779efd5Sopenharmony_ci contactListPresenter: ContactListPresenter = ContactListPresenter.getInstance(); 318779efd5Sopenharmony_ci 328779efd5Sopenharmony_ci constructor(context: Context, worker: WorkerWrapper) { 338779efd5Sopenharmony_ci this.context = context; 348779efd5Sopenharmony_ci this.worker = worker; 358779efd5Sopenharmony_ci } 368779efd5Sopenharmony_ci 378779efd5Sopenharmony_ci onCreate(want: Want) { 388779efd5Sopenharmony_ci HiLog.i(TAG, 'onCreate'); 398779efd5Sopenharmony_ci this.onRequest(want.parameters, true); 408779efd5Sopenharmony_ci this.callRecordPresenter.onCreate(this.context, this.worker); 418779efd5Sopenharmony_ci this.contactListPresenter.onCreate(this.context, this.worker); 428779efd5Sopenharmony_ci if (this.mainUrl == 'pages/index' && globalThis.config.needCache) { 438779efd5Sopenharmony_ci this.initDataCache(); 448779efd5Sopenharmony_ci } 458779efd5Sopenharmony_ci } 468779efd5Sopenharmony_ci 478779efd5Sopenharmony_ci onNewWant(want: Want) { 488779efd5Sopenharmony_ci HiLog.i(TAG, 'onNewWant'); 498779efd5Sopenharmony_ci this.onRequest(want.parameters, false); 508779efd5Sopenharmony_ci } 518779efd5Sopenharmony_ci 528779efd5Sopenharmony_ci initDataCache() { 538779efd5Sopenharmony_ci CallRecordPresenter.getInstance().cachePageOne(); 548779efd5Sopenharmony_ci ContactListPresenter.getInstance().cachePageOne(); 558779efd5Sopenharmony_ci } 568779efd5Sopenharmony_ci 578779efd5Sopenharmony_ci onDestroy() { 588779efd5Sopenharmony_ci HiLog.i(TAG, 'onDestroy') 598779efd5Sopenharmony_ci this.callRecordPresenter.onDestroy(); 608779efd5Sopenharmony_ci this.contactListPresenter.onDestroy(); 618779efd5Sopenharmony_ci } 628779efd5Sopenharmony_ci 638779efd5Sopenharmony_ci // Go to a specified page. 648779efd5Sopenharmony_ci onRequest(parameters: { [key: string]: Object }, isOnCreate: boolean) { 658779efd5Sopenharmony_ci HiLog.i(TAG, 'show pageRouteHandler routeMessage '); 668779efd5Sopenharmony_ci let url = 'pages/index'; 678779efd5Sopenharmony_ci let params = {}; 688779efd5Sopenharmony_ci let pageIndex = 1; 698779efd5Sopenharmony_ci if (parameters?.pageFlag) { 708779efd5Sopenharmony_ci HiLog.i(TAG, 'pageRouteHandler case is ' + parameters.pageFlag); 718779efd5Sopenharmony_ci switch (parameters.pageFlag.toString()) { 728779efd5Sopenharmony_ci // jump to index 738779efd5Sopenharmony_ci case 'page_flag_dialer': 748779efd5Sopenharmony_ci AppStorage.SetOrCreate(Constants.Storage.mainTabsIndex, 0); 758779efd5Sopenharmony_ci params = { 768779efd5Sopenharmony_ci mainTabsIndex: 0 778779efd5Sopenharmony_ci } 788779efd5Sopenharmony_ci break; 798779efd5Sopenharmony_ci case 'page_flag_choose_contacts': 808779efd5Sopenharmony_ci AppStorage.SetOrCreate(Constants.Storage.mainTabsIndex, 1); 818779efd5Sopenharmony_ci params = { 828779efd5Sopenharmony_ci mainTabsIndex: 1 838779efd5Sopenharmony_ci } 848779efd5Sopenharmony_ci break; 858779efd5Sopenharmony_ci case 'page_flag_contact_details': 868779efd5Sopenharmony_ci url = 'pages/contacts/details/ContactDetail'; 878779efd5Sopenharmony_ci pageIndex = 2; 888779efd5Sopenharmony_ci if (parameters.contactId) { 898779efd5Sopenharmony_ci params = { 908779efd5Sopenharmony_ci 'sourceHasId': true, 918779efd5Sopenharmony_ci 'contactId': parameters.contactId 928779efd5Sopenharmony_ci } 938779efd5Sopenharmony_ci } else { 948779efd5Sopenharmony_ci HiLog.i(TAG, 'SHOW pageRouteHandler and routeMessage.phoneNumber '); 958779efd5Sopenharmony_ci params = { 968779efd5Sopenharmony_ci 'sourceHasPhone': true, 978779efd5Sopenharmony_ci 'phoneNumberShow': parameters.phoneNumber, 988779efd5Sopenharmony_ci } 998779efd5Sopenharmony_ci } 1008779efd5Sopenharmony_ci break; 1018779efd5Sopenharmony_ci case 'page_flag_edit_before_calling': 1028779efd5Sopenharmony_ci AppStorage.SetOrCreate(Constants.Storage.mainTabsIndex, 0); 1038779efd5Sopenharmony_ci AppStorage.SetOrCreate(Constants.Storage.teleNumber, parameters.phoneNumber); 1048779efd5Sopenharmony_ci params = { 1058779efd5Sopenharmony_ci mainTabsIndex: 0, teleNumber: parameters.phoneNumber 1068779efd5Sopenharmony_ci } 1078779efd5Sopenharmony_ci break; 1088779efd5Sopenharmony_ci case 'page_flag_save_contact': 1098779efd5Sopenharmony_ci url = 'pages/contacts/accountants/Accountants'; 1108779efd5Sopenharmony_ci pageIndex = 3; 1118779efd5Sopenharmony_ci params = { 1128779efd5Sopenharmony_ci phoneNumbers: [ 1138779efd5Sopenharmony_ci { 1148779efd5Sopenharmony_ci 'phoneNumber': parameters.phoneNumber?.toString().replace(/[^0123456789+]*/g, ''), 1158779efd5Sopenharmony_ci } 1168779efd5Sopenharmony_ci ], 1178779efd5Sopenharmony_ci 'disPlayName': parameters.contactName 1188779efd5Sopenharmony_ci } 1198779efd5Sopenharmony_ci break; 1208779efd5Sopenharmony_ci case 'page_flag_save_exist_contact': 1218779efd5Sopenharmony_ci url = 'pages/contacts/selectContactsList/selectContactsList'; 1228779efd5Sopenharmony_ci pageIndex = 4; 1238779efd5Sopenharmony_ci params = { 1248779efd5Sopenharmony_ci type: 'saveContacts', 1258779efd5Sopenharmony_ci number: parameters.phoneNumber 1268779efd5Sopenharmony_ci } 1278779efd5Sopenharmony_ci break; 1288779efd5Sopenharmony_ci case 'page_flag_sms_forward': 1298779efd5Sopenharmony_ci url = 'pages/contacts/batchselectcontacts/BatchSelectContactsPage' 1308779efd5Sopenharmony_ci pageIndex = 4 1318779efd5Sopenharmony_ci params = { 1328779efd5Sopenharmony_ci selectType: 1 1338779efd5Sopenharmony_ci } 1348779efd5Sopenharmony_ci break; 1358779efd5Sopenharmony_ci case 'page_flag_multi_choose': 1368779efd5Sopenharmony_ci pageIndex = 4; 1378779efd5Sopenharmony_ci url = 'pages/contacts/batchselectcontacts/BatchSelectContactsPage' 1388779efd5Sopenharmony_ci params = { 1398779efd5Sopenharmony_ci selectType: 0 1408779efd5Sopenharmony_ci } 1418779efd5Sopenharmony_ci 1428779efd5Sopenharmony_ci break; 1438779efd5Sopenharmony_ci case 'page_flag_single_choose': 1448779efd5Sopenharmony_ci pageIndex = 4; 1458779efd5Sopenharmony_ci url = 'pages/contacts/batchselectcontacts/SingleSelectContactPage' 1468779efd5Sopenharmony_ci params = { 1478779efd5Sopenharmony_ci selectType: 0 1488779efd5Sopenharmony_ci } 1498779efd5Sopenharmony_ci break; 1508779efd5Sopenharmony_ci default: 1518779efd5Sopenharmony_ci HiLog.e(TAG, 'pageRouteHandler and This page is not open.'); 1528779efd5Sopenharmony_ci break; 1538779efd5Sopenharmony_ci } 1548779efd5Sopenharmony_ci } 1558779efd5Sopenharmony_ci if (isOnCreate) { 1568779efd5Sopenharmony_ci this.mainUrl = url; 1578779efd5Sopenharmony_ci AppStorage.SetOrCreate('params', params); 1588779efd5Sopenharmony_ci } else { 1598779efd5Sopenharmony_ci AppStorage.SetOrCreate(Constants.Storage.targetPage, { 1608779efd5Sopenharmony_ci url: url, 1618779efd5Sopenharmony_ci pageIndex: pageIndex, 1628779efd5Sopenharmony_ci params: params 1638779efd5Sopenharmony_ci }) 1648779efd5Sopenharmony_ci HiLog.i(TAG, 'pageRouteHandler finish!'); 1658779efd5Sopenharmony_ci } 1668779efd5Sopenharmony_ci } 1678779efd5Sopenharmony_ci}