mirror of
https://github.com/openharmony/applications_contacts.git
synced 2026-07-01 19:54:30 -04:00
+2
-2
@@ -2,8 +2,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.contacts",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.4.012",
|
||||
"versionCode": 10000003,
|
||||
"versionName": "1.0.4.022",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"distributedNotificationEnabled": true
|
||||
|
||||
@@ -46,6 +46,7 @@ Contacts应用是OpenHarmony中预置的系统应用,主要的功能包含拨
|
||||
│ └── app.ets # 应用生命周期/公共方法存放
|
||||
│ ├── resources # 资源配置文件存放目录
|
||||
│ └── config.json # 全局配置文件
|
||||
├── infra # 构建脚本
|
||||
├── signs # 签名
|
||||
└── LICENSE
|
||||
~~~
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"compileSdkVersion": 10,
|
||||
"compatibleSdkVersion": 9,
|
||||
"compatibleSdkVersion": 10,
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
|
||||
@@ -28,5 +28,16 @@ export default {
|
||||
SPN_INFO_CHANGED: 3,
|
||||
VOLTE_CHANGE: 4,
|
||||
CALLS_MERGE: 5
|
||||
},
|
||||
|
||||
CONFIG: {
|
||||
useDataWorker: false,
|
||||
needCache: false
|
||||
},
|
||||
|
||||
initConfig(context: Context) {
|
||||
this.CONFIG.useDataWorker = context.resourceManager.getBoolean($r('app.boolean.use_data_worker'));
|
||||
this.CONFIG.needCache = context.resourceManager.getBoolean($r('app.boolean.cache_page_one'));
|
||||
return this.CONFIG
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import Constants from '../../../../../common/src/main/ets/Constants';
|
||||
import AbilityStage from "@ohos.app.ability.AbilityStage"
|
||||
import notification from '@ohos.notificationManager';
|
||||
|
||||
const TAG = 'ContactListItemView ';
|
||||
const TAG = 'MyAbilityStage ';
|
||||
|
||||
export default class MyAbilityStage extends AbilityStage {
|
||||
onCreate() {
|
||||
@@ -20,5 +36,6 @@ export default class MyAbilityStage extends AbilityStage {
|
||||
desc: "missedCall",
|
||||
lockscreenVisibility: 2
|
||||
})
|
||||
globalThis.config = Constants.initConfig(this.context);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import WorkFactory, { WorkerType } from "../workers/WorkFactory";
|
||||
@@ -5,8 +20,7 @@ import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import SimManager from '../feature/sim/SimManager';
|
||||
import { missedCallManager } from '../feature/missedCall/MissedCallManager';
|
||||
import CallsService from "../service/CallsService";
|
||||
import ContactsService from "../service/ContactsService";
|
||||
import PresenterManager from '../presenter/PresenterManager';
|
||||
|
||||
const TAG = 'MainAbility ';
|
||||
|
||||
@@ -14,8 +28,6 @@ export default class MainAbility extends Ability {
|
||||
storage: LocalStorage;
|
||||
simManager: SimManager;
|
||||
mDataWorker = WorkFactory.getWorker(WorkerType.DataWorker);
|
||||
mCallsService: CallsService;
|
||||
mContactsService: ContactsService;
|
||||
|
||||
updateBreakpoint(windowWidth: number) {
|
||||
let windowWidthVp: number = px2vp(windowWidth);
|
||||
@@ -51,8 +63,8 @@ export default class MainAbility extends Ability {
|
||||
this.onRequest(want, true);
|
||||
this.simManager = new SimManager();
|
||||
globalThis.DataWorker = this.mDataWorker;
|
||||
this.mCallsService = new CallsService(this.context, this.mDataWorker);
|
||||
this.mContactsService = new ContactsService(this.context, this.mDataWorker);
|
||||
globalThis.presenterManager = new PresenterManager(this.context, this.mDataWorker);
|
||||
globalThis.presenterManager.onCreate();
|
||||
}
|
||||
|
||||
onNewWant(want, launchParam) {
|
||||
@@ -64,9 +76,8 @@ export default class MainAbility extends Ability {
|
||||
|
||||
onDestroy() {
|
||||
HiLog.i(TAG, 'Ability onDestroy');
|
||||
globalThis.presenterManager.onDestroy();
|
||||
this.mDataWorker.close();
|
||||
this.mCallsService.onDestroy();
|
||||
this.mContactsService.onDestroy();
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
|
||||
export struct ItemList {
|
||||
@Link @Watch('refresh') mPresent: AccountantsPresenter;
|
||||
@State mTextInputValue: string = '';
|
||||
private index: number;
|
||||
private index: number = 0;
|
||||
private typeName: string;
|
||||
private placeholder: Resource;
|
||||
@LocalStorageProp('breakpoint') curBp: string = 'sm';
|
||||
|
||||
@@ -56,42 +56,41 @@ export struct DialerButtonView {
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Button() {
|
||||
Image($r('app.media.dial_single_button_volte'))
|
||||
.width($r("app.float.id_item_height_large"))
|
||||
.height($r("app.float.id_item_height_large"))
|
||||
if (!this.haveMultiSimCard) {
|
||||
if (this.haveSimCard && this.haveVoLteReg) {
|
||||
Button() {
|
||||
Image($r('app.media.dial_single_button_hd'))
|
||||
.width($r("app.float.id_item_height_large"))
|
||||
.height($r("app.float.id_item_height_large"))
|
||||
}
|
||||
.width(this.mPresenter.dialerButtonHeight)
|
||||
.height(this.mPresenter.dialerButtonHeight)
|
||||
.backgroundColor($r('sys.color.ohos_id_color_connected'))
|
||||
.opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
|
||||
? 1 : $r('sys.float.ohos_id_alpha_disabled'))
|
||||
.onClick(() => {
|
||||
this.dialClick();
|
||||
})
|
||||
} else {
|
||||
Button() {
|
||||
Image($r("app.media.ic_public_phone_filled_white"))
|
||||
.width($r("app.float.id_card_margin_xxxxl"))
|
||||
.height($r("app.float.id_card_margin_xxxxl"))
|
||||
}
|
||||
.width(this.mPresenter.dialerButtonHeight)
|
||||
.height(this.mPresenter.dialerButtonHeight)
|
||||
.backgroundColor($r('sys.color.ohos_id_color_connected'))
|
||||
.opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
|
||||
? 1 : $r('sys.float.ohos_id_alpha_disabled'))
|
||||
.onClick(() => {
|
||||
this.dialClick();
|
||||
})
|
||||
}
|
||||
} else {
|
||||
MutiDialerButtonView({
|
||||
mPresenter: $mPresenter,
|
||||
}).height(this.mPresenter.dialerButtonHeight)
|
||||
}
|
||||
.width(this.mPresenter.dialerButtonHeight)
|
||||
.height(this.mPresenter.dialerButtonHeight)
|
||||
.visibility(this.haveMultiSimCard ? Visibility.None : (this.haveSimCard && this.haveVoLteReg ?
|
||||
Visibility.Visible : Visibility.None))
|
||||
.backgroundColor($r('sys.color.ohos_id_color_connected'))
|
||||
.opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
|
||||
? 1 : $r('sys.float.ohos_id_alpha_disabled'))
|
||||
.onClick(() => {
|
||||
this.dialClick();
|
||||
})
|
||||
|
||||
Button() {
|
||||
Image($r("app.media.ic_public_phone_filled_white"))
|
||||
.width($r("app.float.id_card_margin_xxxxl"))
|
||||
.height($r("app.float.id_card_margin_xxxxl"))
|
||||
}
|
||||
.width(this.mPresenter.dialerButtonHeight)
|
||||
.height(this.mPresenter.dialerButtonHeight)
|
||||
.visibility(this.haveMultiSimCard ? Visibility.None : (this.haveSimCard && this.haveVoLteReg ?
|
||||
Visibility.None : Visibility.Visible))
|
||||
.backgroundColor($r('sys.color.ohos_id_color_connected'))
|
||||
.opacity(!EnvironmentProp.isTablet() || this.mPresenter.btnShow || this.haveSimCard
|
||||
? 1 : $r('sys.float.ohos_id_alpha_disabled'))
|
||||
.onClick(() => {
|
||||
this.dialClick();
|
||||
})
|
||||
|
||||
MutiDialerButtonView({
|
||||
mPresenter: $mPresenter,
|
||||
}).height(this.mPresenter.dialerButtonHeight)
|
||||
.visibility(this.haveMultiSimCard ? Visibility.Visible : Visibility.None)
|
||||
}.width(this.mPresenter.dialerButtonWidth)
|
||||
.height(this.mPresenter.dialerButtonHeight)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
|
||||
@@ -25,6 +25,7 @@ export struct MutiDialerButtonView {
|
||||
@StorageLink("spnList") simNames: Array<string | Resource> = ["", ""];
|
||||
@StorageLink("voLteRegStates") voLteRegStates: boolean[] = [false, false];
|
||||
private dailImg = [$r("app.media.ic_public_phone1_filled"), $r("app.media.ic_public_phone2_filled")]
|
||||
private dailHDImg = [$r("app.media.ic_contact_call_1_hd_dial"), $r("app.media.ic_contact_call_2_hd_dial")]
|
||||
|
||||
dialClick(slot: number) {
|
||||
this.mPresenter.callBtnClick = true;
|
||||
@@ -43,23 +44,12 @@ export struct MutiDialerButtonView {
|
||||
ForEach(this.simNames, (item, index) => {
|
||||
//DailButton for voLte
|
||||
Row() {
|
||||
Column() {
|
||||
Image(this.dailImg[index])
|
||||
.width(this.voLteRegStates[index] ? "14vp" : "18vp")
|
||||
.height(this.voLteRegStates[index] ? "14vp" : "18vp")
|
||||
.onError((event => {
|
||||
HiLog.e(TAG, "Sim:" + index + " Image onError" + JSON.stringify(event))
|
||||
}))
|
||||
Image($r('app.media.ic_dail_button_volte'))
|
||||
.onError((event => {
|
||||
HiLog.e(TAG, "ic_dail_button_volte Image onError" + JSON.stringify(event))
|
||||
}))
|
||||
.height('10vp')
|
||||
.width('16vp')
|
||||
.visibility(this.voLteRegStates[index] ? Visibility.Visible : Visibility.None)
|
||||
}.width("18vp")
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.alignItems(HorizontalAlign.Center)
|
||||
Image(this.voLteRegStates[index] ? this.dailHDImg[index] : this.dailImg[index])
|
||||
.width("18vp")
|
||||
.height("18vp")
|
||||
.onError((event => {
|
||||
HiLog.e(TAG, "Sim:" + index + " Image onError" + JSON.stringify(event))
|
||||
}))
|
||||
|
||||
Text(this.simNames[index])
|
||||
.fontColor($r("sys.color.ohos_id_color_primary_contrary"))
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import worker from '@ohos.worker';
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
|
||||
const TAG = "AudioWorker ";
|
||||
|
||||
export class AudioHepler {
|
||||
private workerName: string;
|
||||
private workerUri: string;
|
||||
private mWorker;
|
||||
constructor(name: string, workerUri: string) {
|
||||
this.workerName = name;
|
||||
this.workerUri = workerUri;
|
||||
this.initWorker();
|
||||
}
|
||||
|
||||
private initWorker(): void {
|
||||
this.mWorker = new worker.Worker(this.workerUri, { type: "classic", name: this.workerName });
|
||||
this.mWorker.onerror = this.onError.bind(this);
|
||||
this.mWorker.onmessageError = this.onMessageError.bind(this);
|
||||
this.mWorker.onexit = this.onExit.bind(this);
|
||||
this.mWorker.onmessage = this.onMessage.bind(this);
|
||||
}
|
||||
|
||||
public onError(e: any): void {
|
||||
HiLog.e(TAG, "AudioWorker is error" + JSON.stringify(e));
|
||||
}
|
||||
|
||||
public onMessageError(e: any): void {
|
||||
HiLog.e(TAG, "AudioWorker Message is error" + JSON.stringify(e));
|
||||
}
|
||||
|
||||
public onExit(e: any): void {
|
||||
HiLog.e(TAG, "AudioWorker is Exit");
|
||||
}
|
||||
|
||||
public onMessage(e: any): void {
|
||||
HiLog.e(TAG, "AudioWorker return message");
|
||||
}
|
||||
|
||||
public postMessage(message: any): void {
|
||||
HiLog.i(TAG, "AudioWorker postMessage");
|
||||
this.mWorker.postMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HiLog } from '../../../../../../common';
|
||||
import commonEvent from '@ohos.commonEventManager';
|
||||
import { PhoneNumber } from '../../../../../../feature/phonenumber';
|
||||
@@ -35,7 +36,7 @@ class MissedCallManager {
|
||||
}
|
||||
|
||||
private async autoCall(phoneNumber: string) {
|
||||
HiLog.i(TAG, 'autoCall:' + phoneNumber)
|
||||
HiLog.i(TAG, 'autoCall:')
|
||||
let readySimCount: number = 0;
|
||||
let readySim = -1;
|
||||
for (let i = 0; i < telephonySim.getMaxSimCount(); i++) {
|
||||
|
||||
@@ -818,20 +818,24 @@ export default {
|
||||
*/
|
||||
updateContact: async function (DAHelper, addParams, callBack, context?) {
|
||||
HiLog.i(TAG, 'Start to update contacts.');
|
||||
if (DAHelper == undefined || DAHelper.length == 0 || DAHelper == null) {
|
||||
DAHelper = await dataShare.createDataShareHelper(context ? context : globalThis.context, Contacts.CONTENT_URI);
|
||||
try {
|
||||
if (DAHelper == undefined || DAHelper.length == 0 || DAHelper == null) {
|
||||
DAHelper = await dataShare.createDataShareHelper(context ? context : globalThis.context, Contacts.CONTENT_URI);
|
||||
}
|
||||
let condition = new dataSharePredicates.DataSharePredicates();
|
||||
condition.equalTo('raw_contact_id', addParams.id);
|
||||
DAHelper.delete(
|
||||
Data.CONTENT_URI,
|
||||
condition,
|
||||
).then(data => {
|
||||
this.dealParam(DAHelper, addParams, false, callBack);
|
||||
}).catch(error => {
|
||||
HiLog.e(TAG, 'updateContact-update contact error: %s', JSON.stringify(error.message));
|
||||
});
|
||||
HiLog.i(TAG, 'End to update contacts.');
|
||||
} catch(err) {
|
||||
HiLog.e(TAG, 'updateContact err : ' + JSON.stringify(err));
|
||||
}
|
||||
let condition = new dataSharePredicates.DataSharePredicates();
|
||||
condition.equalTo('raw_contact_id', addParams.id);
|
||||
DAHelper.delete(
|
||||
Data.CONTENT_URI,
|
||||
condition,
|
||||
).then(data => {
|
||||
this.dealParam(DAHelper, addParams, false, callBack);
|
||||
}).catch(error => {
|
||||
HiLog.e(TAG, 'updateContact-update contact error: %s', JSON.stringify(error.message));
|
||||
});
|
||||
HiLog.i(TAG, 'End to update contacts.');
|
||||
},
|
||||
/**
|
||||
* Querying IDs by Phone Number
|
||||
|
||||
@@ -51,25 +51,25 @@ export class BasicDataSource implements IDataSource {
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataAdded(index);
|
||||
listener.onDataAdd(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataChange(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataChanged(index)
|
||||
listener.onDataChange(index)
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataDelete(index: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataDeleted(index);
|
||||
listener.onDataDelete(index);
|
||||
})
|
||||
}
|
||||
|
||||
notifyDataMove(from: number, to: number): void {
|
||||
this.listeners.forEach(listener => {
|
||||
listener.onDataMoved(from, to);
|
||||
listener.onDataMove(from, to);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil'
|
||||
const TAG = "CallRecordListDataSource";
|
||||
|
||||
export default class CallRecordListDataSource extends BasicDataSource {
|
||||
private callLogData: [] = [];
|
||||
private callLogData: any[] = [];
|
||||
private isShow: boolean;
|
||||
private isDataReload: boolean;
|
||||
|
||||
public totalCount(): number {
|
||||
return this.callLogData.length;
|
||||
@@ -34,9 +36,45 @@ export default class CallRecordListDataSource extends BasicDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(callLogData) {
|
||||
HiLog.i(TAG, ' refresh!');
|
||||
public refreshAll(callLogData) {
|
||||
HiLog.i(TAG, ' refreshAll!');
|
||||
this.callLogData = callLogData;
|
||||
this.notifyDataReload();
|
||||
this.setDataReload(true);
|
||||
}
|
||||
|
||||
public setIsShow(isShow: boolean) {
|
||||
if (this.isShow == isShow) {
|
||||
return;
|
||||
}
|
||||
this.isShow = isShow;
|
||||
HiLog.i(TAG, ' setIsShow:' + this.isShow);
|
||||
this.setDataReload(this.isDataReload);
|
||||
}
|
||||
|
||||
public refresh(start: number, count: number, callLogData: []) {
|
||||
HiLog.i(TAG, ' refresh!');
|
||||
this.callLogData.splice(start, count, ...callLogData);
|
||||
this.setDataReload(true);
|
||||
}
|
||||
|
||||
public remove(index: number, count?) {
|
||||
if (index < 0 || index >= this.totalCount()) {
|
||||
return;
|
||||
}
|
||||
HiLog.i(TAG, ' remove:' + index);
|
||||
this.callLogData.splice(index, count ? count : 1);
|
||||
this.notifyDataDelete(index);
|
||||
}
|
||||
|
||||
private setDataReload(isDataReload: boolean) {
|
||||
if (this.isShow) {
|
||||
if (isDataReload) {
|
||||
HiLog.i(TAG, 'notifyDataReload');
|
||||
this.notifyDataReload();
|
||||
}
|
||||
this.isDataReload = false;
|
||||
} else {
|
||||
this.isDataReload = isDataReload;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,8 @@ const TAG = "ContactListDataSource";
|
||||
|
||||
export default class ContactListDataSource extends BasicDataSource {
|
||||
private contactList: ContactVo[] = [];
|
||||
private contactsCount: number = 0;
|
||||
private isShow: boolean;
|
||||
private isDataReload: boolean;
|
||||
|
||||
public totalCount(): number {
|
||||
return this.contactList.length;
|
||||
@@ -56,9 +57,46 @@ export default class ContactListDataSource extends BasicDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(contactList: ContactVo[]) {
|
||||
HiLog.i(TAG, ' refresh!');
|
||||
public refreshAll(contactList: ContactVo[]) {
|
||||
HiLog.i(TAG, ' refreshAll!');
|
||||
this.contactList = contactList;
|
||||
this.setDataReload(true);
|
||||
}
|
||||
|
||||
public setIsShow(isShow: boolean) {
|
||||
if (this.isShow == isShow) {
|
||||
return;
|
||||
}
|
||||
HiLog.i(TAG, ' setIsShow:' + isShow);
|
||||
this.isShow = isShow;
|
||||
this.setDataReload(this.isDataReload)
|
||||
}
|
||||
|
||||
public refresh(start: number, count: number, contactList: ContactVo[]) {
|
||||
HiLog.i(TAG, ' refresh!');
|
||||
this.contactList.splice(start, count, ...contactList);
|
||||
this.notifyDataReload();
|
||||
this.setDataReload(true);
|
||||
}
|
||||
|
||||
public remove(index: number, count?) {
|
||||
if (index < 0 || index >= this.totalCount()) {
|
||||
return;
|
||||
}
|
||||
HiLog.i(TAG, ' remove:' + index);
|
||||
this.contactList.splice(index, count ? count : 1);
|
||||
this.notifyDataDelete(index);
|
||||
}
|
||||
|
||||
private setDataReload(isDataReload: boolean) {
|
||||
if (this.isShow) {
|
||||
if (isDataReload) {
|
||||
HiLog.i(TAG, 'notifyDataReload');
|
||||
this.notifyDataReload();
|
||||
}
|
||||
this.isDataReload = false;
|
||||
} else {
|
||||
this.isDataReload = isDataReload;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,22 +35,18 @@ export default struct ContactListPage {
|
||||
emitterId: number = 2;
|
||||
|
||||
refresh() {
|
||||
if (AppStorage.Has('contactList')) {
|
||||
let contactList: any = AppStorage.Get('contactList');
|
||||
this.contactListListLen = contactList.length;
|
||||
this.mContactPresenter.refresh(contactList);
|
||||
let contactListLen = this.mContactPresenter.contactListDataSource.totalCount();
|
||||
if (this.contactListListLen != contactListLen) {
|
||||
this.contactListListLen = contactListLen;
|
||||
this.mContactPresenter = globalThis.presenterManager.contactListPresenter;
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'Contact aboutToAppear!');
|
||||
this.mContactPresenter.aboutToAppear();
|
||||
let innerEvent = {
|
||||
eventId: Constants.Event.CONTACTS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.on(innerEvent, () => {
|
||||
this.refresh();
|
||||
this.mContactPresenter.bindUI(() => {
|
||||
this.refresh()
|
||||
})
|
||||
this.refresh();
|
||||
}
|
||||
@@ -61,14 +57,6 @@ export default struct ContactListPage {
|
||||
emitter.off(Constants.Event.CONTACTS_CHANGE);
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
this.mContactPresenter.onPageShow();
|
||||
}
|
||||
|
||||
onPageHide() {
|
||||
this.mContactPresenter.onPageHide();
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
if (this.contactListListLen == 0) {
|
||||
@@ -220,7 +208,8 @@ struct ContactContent {
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.listDirection(Axis.Vertical)
|
||||
.edgeEffect(EdgeEffect.Spring)
|
||||
.edgeEffect(EdgeEffect.None)
|
||||
.scrollBar(BarState.Off)
|
||||
}
|
||||
}
|
||||
.height('100%')
|
||||
|
||||
@@ -332,7 +332,7 @@ struct Accountants {
|
||||
, (item) => {
|
||||
ItemList({
|
||||
mPresent: $mPresenter,
|
||||
index: item.i,
|
||||
index: item?.i,
|
||||
typeName: "phone",
|
||||
placeholder: $r("app.string.phone_number")
|
||||
})
|
||||
@@ -357,7 +357,7 @@ struct Accountants {
|
||||
, (item) => {
|
||||
ItemList({
|
||||
mPresent: $mPresenter,
|
||||
index: item.i,
|
||||
index: item?.i,
|
||||
typeName: "email",
|
||||
placeholder: $r("app.string.email")
|
||||
})
|
||||
|
||||
@@ -23,58 +23,36 @@ import DialerPresenter from '../../../presenter/dialer/DialerPresenter';
|
||||
import DetailPresenter from '../../../presenter/contact/detail/DetailPresenter';
|
||||
import { PhoneNumber } from '../../../../../../../feature/phonenumber/src/main/ets/PhoneNumber';
|
||||
import IndexPresenter from '../../../presenter/IndexPresenter';
|
||||
import { HiLog, ArrayUtil } from "../../../../../../../common"
|
||||
import Constants from '../../../../../../../common/src/main/ets/Constants';
|
||||
import emitter from '@ohos.events.emitter'
|
||||
import { HiLog } from "../../../../../../../common"
|
||||
|
||||
const TAG = "AllRecord ";
|
||||
|
||||
@Component
|
||||
export default struct AllRecord {
|
||||
@Link mPresenter: CallRecordPresenter;
|
||||
@Link @Watch("onChanged") mPresenter: CallRecordPresenter;
|
||||
/*0all 1miss*/
|
||||
recordType: number = 0;
|
||||
emitterId: number = 1;
|
||||
@State callLogListEmpty: boolean = true;
|
||||
@State missedListEmpty: boolean = true;
|
||||
|
||||
refresh() {
|
||||
if (this.recordType === 0) {
|
||||
if (AppStorage.Has('callLogList')) {
|
||||
let callLogList: any = AppStorage.Get('callLogList');
|
||||
const callLogEmpty: boolean = ArrayUtil.isEmpty(callLogList)
|
||||
if (this.callLogListEmpty != callLogEmpty) {
|
||||
this.callLogListEmpty = callLogEmpty;
|
||||
}
|
||||
this.mPresenter.refreshCallLogList(callLogList);
|
||||
}
|
||||
} else {
|
||||
if (AppStorage.Has('missedList')) {
|
||||
let missedList: any = AppStorage.Get('missedList')
|
||||
const missedEmpty: boolean = ArrayUtil.isEmpty(missedList)
|
||||
if (this.missedListEmpty != missedEmpty) {
|
||||
this.missedListEmpty = missedEmpty;
|
||||
}
|
||||
this.mPresenter.refreshMissedList(missedList)
|
||||
}
|
||||
onChanged() {
|
||||
let callLogIsEmpty = this.mPresenter.mAllCallRecordListDataSource.totalCount() <= 0;
|
||||
if (this.callLogListEmpty != callLogIsEmpty) {
|
||||
this.callLogListEmpty = callLogIsEmpty
|
||||
}
|
||||
let missLogIsEmpty = this.mPresenter.mMissCallRecordListDataSource.totalCount() <= 0;
|
||||
if (this.missedListEmpty != missLogIsEmpty) {
|
||||
this.missedListEmpty = missLogIsEmpty
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'aboutToAppear,recordType:' + this.recordType)
|
||||
let innerEvent = {
|
||||
eventId: Constants.Event.CALLS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.on(innerEvent, () => {
|
||||
this.refresh();
|
||||
})
|
||||
this.refresh();
|
||||
this.onChanged();
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'aboutToDisappear,recordType:' + this.recordType)
|
||||
emitter.off(Constants.Event.CALLS_CHANGE);
|
||||
}
|
||||
|
||||
build() {
|
||||
@@ -99,7 +77,7 @@ struct RecordView {
|
||||
LazyForEach(this.recordType === 0 ? this.mPresenter.mAllCallRecordListDataSource :
|
||||
this.mPresenter.mMissCallRecordListDataSource, (item, index: number) => {
|
||||
ListItem() {
|
||||
ContactItem({ mPresenter: $mPresenter, item: item });
|
||||
ContactItem({ mPresenter: $mPresenter, item: item, index: index });
|
||||
}
|
||||
.height($r("app.float.id_item_height_max"))
|
||||
}, item => JSON.stringify(item))
|
||||
@@ -114,7 +92,8 @@ struct RecordView {
|
||||
.margin({ bottom: this.curBp === 'lg' ? '110vp' : 0 })
|
||||
.flexShrink(1)
|
||||
.listDirection(Axis.Vertical)
|
||||
.edgeEffect(EdgeEffect.Spring)
|
||||
.edgeEffect(EdgeEffect.None)
|
||||
.scrollBar(BarState.Off)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +133,7 @@ struct ContactItem {
|
||||
@State mIndexPresenter: IndexPresenter = IndexPresenter.getInstance();
|
||||
@Link mPresenter: CallRecordPresenter
|
||||
@State item: { [key: string]: any } = {};
|
||||
index: number;
|
||||
@State isEmergencyNum: boolean = false;
|
||||
@LocalStorageProp('breakpoint') curBp: string = 'sm';
|
||||
@StorageLink("haveMultiSimCard") haveMultiSimCard: boolean = false;
|
||||
@@ -165,7 +145,7 @@ struct ContactItem {
|
||||
this.deleteDialogController.close();
|
||||
},
|
||||
confirm: () => {
|
||||
this.mPresenter.deleteCallLog(this.item.ids);
|
||||
this.mPresenter.deleteCallLog(this.item.ids, this.index);
|
||||
},
|
||||
title: $r("app.string.deleteCallLog_dialog_title"),
|
||||
cancalText: $r("app.string.cancel"),
|
||||
@@ -232,7 +212,8 @@ struct ContactItem {
|
||||
.margin({
|
||||
right: $r("app.float.id_card_margin_mid"),
|
||||
top: "4vp",
|
||||
}).visibility(this.item.isHD ? Visibility.Visible : Visibility.None);
|
||||
})
|
||||
.visibility(this.item.isHD ? Visibility.Visible : Visibility.None);
|
||||
|
||||
Text(this.item.numberLocation
|
||||
? this.item.numberLocation
|
||||
@@ -261,6 +242,8 @@ struct ContactItem {
|
||||
.margin({ top: $r("app.float.id_card_margin_sm"), right: 24 })
|
||||
.onClick(() => {
|
||||
this.mPresenter.jumpToContactDetail(this.item.phoneNumber);
|
||||
DialerPresenter.getInstance().panelShow = true;
|
||||
AppStorage.SetOrCreate<boolean>("showDialBtn", true);
|
||||
})
|
||||
}
|
||||
.height($r("app.float.id_item_height_max"))
|
||||
@@ -292,6 +275,8 @@ struct ContactItem {
|
||||
this.mPresenter.dialing(this.item.phoneNumber);
|
||||
}
|
||||
}
|
||||
DialerPresenter.getInstance().panelShow = true;
|
||||
AppStorage.SetOrCreate<boolean>("showDialBtn", true);
|
||||
})
|
||||
.bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ export default struct CallRecord {
|
||||
aboutToAppear(){
|
||||
HiLog.i(TAG, 'aboutToAppear');
|
||||
this.mPresenter.aboutToAppear();
|
||||
this.mPresenter.bindUI(()=>{
|
||||
this.mPresenter = CallRecordPresenter.getInstance();
|
||||
})
|
||||
}
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'aboutToDisappear');
|
||||
@@ -56,6 +59,7 @@ export default struct CallRecord {
|
||||
}
|
||||
.onChange((index: number) => {
|
||||
this.bottomTabIndex = index
|
||||
this.mPresenter.setTabIndex(index);
|
||||
})
|
||||
.vertical(false)
|
||||
.barHeight(0)
|
||||
|
||||
@@ -43,6 +43,13 @@ struct Index {
|
||||
this.controller.changeIndex(this.mIndexPresenter.tabsIndex);
|
||||
this.bottomTabIndex = this.mIndexPresenter.tabsIndex;
|
||||
this.mDialerPresenter.editPhoneNumber(this.mIndexPresenter.editPhoneNumber);
|
||||
if (this.mIndexPresenter.tabsIndex == 0) {
|
||||
ContactListPresenter.getInstance().setPageShow(false);
|
||||
CallRecordPresenter.getInstance().setPageShow(true);
|
||||
} else {
|
||||
CallRecordPresenter.getInstance().setPageShow(false);
|
||||
ContactListPresenter.getInstance().setPageShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
pageTransition() {
|
||||
@@ -52,6 +59,18 @@ struct Index {
|
||||
|
||||
onPageShow() {
|
||||
this.mIndexPresenter.onPageShow();
|
||||
if (this.bottomTabIndex == 0) {
|
||||
ContactListPresenter.getInstance().setPageShow(false);
|
||||
CallRecordPresenter.getInstance().setPageShow(true);
|
||||
} else {
|
||||
CallRecordPresenter.getInstance().setPageShow(false);
|
||||
ContactListPresenter.getInstance().setPageShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
onPageHide() {
|
||||
ContactListPresenter.getInstance().setPageShow(false);
|
||||
CallRecordPresenter.getInstance().setPageShow(false);
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
@@ -116,7 +135,6 @@ struct Index {
|
||||
.barHeight(0)
|
||||
.scrollable(false)
|
||||
.animationDuration(0)
|
||||
|
||||
}
|
||||
.layoutWeight(this.curBp === 'lg' ? 1 : 0)
|
||||
.flexShrink(this.curBp === 'lg' ? 0 : 1)
|
||||
@@ -179,11 +197,11 @@ struct TabBars {
|
||||
this.bottomTabIndex = item;
|
||||
this.mIndexPresenter.tabsIndex = item;
|
||||
if (item == 0) {
|
||||
ContactListPresenter.getInstance().onPageHide();
|
||||
CallRecordPresenter.getInstance().onPageShow();
|
||||
ContactListPresenter.getInstance().setPageShow(false);
|
||||
CallRecordPresenter.getInstance().setPageShow(true);
|
||||
} else if (item == 1) {
|
||||
CallRecordPresenter.getInstance().onPageHide();
|
||||
ContactListPresenter.getInstance().onPageShow();
|
||||
CallRecordPresenter.getInstance().setPageShow(false);
|
||||
ContactListPresenter.getInstance().setPageShow(true);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -221,16 +221,13 @@ export default struct Call {
|
||||
}
|
||||
.height('100%')
|
||||
.zIndex(1)
|
||||
.gesture(
|
||||
SwipeGesture({ fingers: 1, direction: SwipeDirection.Vertical, speed: 150 })
|
||||
.onAction((event: GestureEvent) => {
|
||||
if (this.mPresenter.callBtnClick) {
|
||||
return;
|
||||
}
|
||||
this.mPresenter.panelShow = false;
|
||||
this.showDialBtn = false;
|
||||
})
|
||||
)
|
||||
.onTouch(() => {
|
||||
if (this.mPresenter.callBtnClick) {
|
||||
return;
|
||||
}
|
||||
this.mPresenter.panelShow = false;
|
||||
this.showDialBtn = false;
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
||||
@@ -14,16 +14,12 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { CallLogRepository } from '../../../../../feature/call';
|
||||
import { ContactRepository } from '../../../../../feature/contact/src/main/ets/repo/ContactRepository';
|
||||
import pasteboard from '@ohos.pasteboard';
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import { StringUtil } from '../../../../../common/src/main/ets/util/StringUtil';
|
||||
import StringFormatUtil from '../util/StringFormatUtil';
|
||||
import CallRecordPresenter from './dialer/callRecord/CallRecordPresenter';
|
||||
import { missedCallManager } from '../feature/missedCall/MissedCallManager';
|
||||
import emitter from '@ohos.events.emitter';
|
||||
import Constants from '../../../../../common/src/main/ets/Constants';
|
||||
import CallRecordPresenter from './dialer/callRecord/CallRecordPresenter';
|
||||
|
||||
const TAG = 'IndexPresenter ';
|
||||
|
||||
@@ -33,10 +29,6 @@ export default class IndexPresenter {
|
||||
isEditNum: boolean = false;
|
||||
editPhoneNumber: string = "";
|
||||
tabsIndex: number = 0;
|
||||
innerEvent = {
|
||||
eventId: Constants.Event.CALLS_MERGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
|
||||
public static getInstance(): IndexPresenter {
|
||||
if (!IndexPresenter.instance) {
|
||||
@@ -59,7 +51,7 @@ export default class IndexPresenter {
|
||||
this.getNewWant();
|
||||
if (parseInt(StringFormatUtil.judgeSysTime()) !== AppStorage.Get("sysTime")) {
|
||||
HiLog.i(TAG, 'DO requestItem cause systemTime changed');
|
||||
emitter.emit(this.innerEvent)
|
||||
CallRecordPresenter.getInstance().requestItem();
|
||||
AppStorage.SetOrCreate("sysTime", parseInt(StringFormatUtil.judgeSysTime()));
|
||||
}
|
||||
}
|
||||
@@ -77,10 +69,6 @@ export default class IndexPresenter {
|
||||
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'aboutToDisappear !!!');
|
||||
CallLogRepository.getInstance().unRegisterDataChangeObserver(() => {
|
||||
});
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(() => {
|
||||
});
|
||||
}
|
||||
|
||||
getNewWant() {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import ContactListPresenter from './contact/ContactListPresenter';
|
||||
import CallRecordPresenter from './dialer/callRecord/CallRecordPresenter';
|
||||
import WorkerWrapper from "../workers/base/WorkerWrapper";
|
||||
|
||||
const TAG = 'PageManager'
|
||||
|
||||
export default class PresenterManager {
|
||||
static MAIN_PAGE: string = 'pages/index'
|
||||
context: Context;
|
||||
worker: WorkerWrapper;
|
||||
callRecordPresenter: CallRecordPresenter = CallRecordPresenter.getInstance();
|
||||
contactListPresenter: ContactListPresenter = ContactListPresenter.getInstance();
|
||||
|
||||
constructor(context: Context, worker: WorkerWrapper) {
|
||||
this.context = context;
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
onCreate() {
|
||||
HiLog.i(TAG, "onCreate")
|
||||
this.callRecordPresenter.onCreate(this.context, this.worker);
|
||||
this.contactListPresenter.onCreate(this.context, this.worker);
|
||||
if (globalThis.config.needCache) {
|
||||
this.initDataCache();
|
||||
}
|
||||
}
|
||||
|
||||
initDataCache() {
|
||||
CallRecordPresenter.getInstance().cachePageOne();
|
||||
ContactListPresenter.getInstance().cachePageOne();
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
HiLog.i(TAG, "onDestroy")
|
||||
this.callRecordPresenter.onDestroy();
|
||||
this.contactListPresenter.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,11 @@ import { ContactVo } from '../../model/bean/ContactVo';
|
||||
import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil';
|
||||
import { CallLogRepository } from '../../../../../../feature/call/src/main/ets/repo/CallLogRepository';
|
||||
import { ContactRepository } from '../../../../../../feature/contact/src/main/ets/repo/ContactRepository';
|
||||
import emitter from '@ohos.events.emitter';
|
||||
import ContactListDataSource from '../../model/bean/ContactListDataSource';
|
||||
import WorkerWrapper from '../../workers/base/WorkerWrapper';
|
||||
|
||||
const TAG = 'ContactListPresenter ';
|
||||
|
||||
const DELAY_TIME: number = 1000;
|
||||
/**
|
||||
* Type of the control that is clicked in the contact list.
|
||||
*/
|
||||
@@ -40,19 +40,35 @@ export enum ContactClickType {
|
||||
export default class ContactListPresenter {
|
||||
private static sInstance: ContactListPresenter;
|
||||
indexs: string[] = ['#', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '…'];
|
||||
contactListPages: Array<number> = [];
|
||||
curItem: ContactVo = new ContactVo("", "", "", "", "", "", true, "", "");
|
||||
total: number = 0;
|
||||
page: number = 0;
|
||||
limit: number = 0;
|
||||
refreshIndex: number = 0;
|
||||
queryContactsType: string = 'all';
|
||||
isEmptyGroup: boolean = true;
|
||||
shareList: Resource[] = [$r("app.string.qr_code"), $r("app.string.v_card"), $r("app.string.text")];
|
||||
settingsMenu: Resource[] = [$r("app.string.contact_setting_type_scancard"), $r("app.string.call_setting_type_setting")];
|
||||
contactListDataSource: ContactListDataSource = new ContactListDataSource();
|
||||
isShow: boolean = false;
|
||||
context: Context;
|
||||
worker: WorkerWrapper;
|
||||
loading: boolean;
|
||||
initStarted: boolean = false;
|
||||
taskId: number = undefined;
|
||||
refreshState: () => void
|
||||
onContactChange = () => {
|
||||
HiLog.i(TAG, 'onContactChange refresh');
|
||||
this.setDelayTask();
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
public static getInstance(): ContactListPresenter {
|
||||
if (globalThis.presenterManager?.contactListPresenter) {
|
||||
return globalThis.presenterManager.contactListPresenter;
|
||||
}
|
||||
if (ContactListPresenter.sInstance == null) {
|
||||
HiLog.i(TAG, 'Contact getInstance!');
|
||||
ContactListPresenter.sInstance = new ContactListPresenter();
|
||||
@@ -60,29 +76,164 @@ export default class ContactListPresenter {
|
||||
return ContactListPresenter.sInstance;
|
||||
}
|
||||
|
||||
onCreate(context: Context, worker: WorkerWrapper) {
|
||||
this.context = context;
|
||||
this.worker = worker;
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
bindUI(refreshState?: () => void) {
|
||||
this.refreshState = refreshState;
|
||||
}
|
||||
|
||||
startInit() {
|
||||
if (this.initStarted) {
|
||||
return;
|
||||
}
|
||||
HiLog.i(TAG, "startInit");
|
||||
this.initStarted = true;
|
||||
if (this.page == 0) {
|
||||
this.page++;
|
||||
}
|
||||
this.refreshContinue();
|
||||
}
|
||||
|
||||
cachePageOne() {
|
||||
if (!this.initStarted && !this.loading) {
|
||||
HiLog.i(TAG, "cachePageOne")
|
||||
this.page = 1;
|
||||
this.refreshIndex = 0;
|
||||
this.refreshContinue();
|
||||
} else {
|
||||
HiLog.i(TAG, "no need cachePageOne");
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
this.isShow = true;
|
||||
HiLog.i(TAG, 'Contact aboutToAppear!');
|
||||
this.startInit();
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
this.isShow = false;
|
||||
HiLog.i(TAG, 'Contact aboutToDisappear!');
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
HiLog.i(TAG, 'Contact onPageShow!');
|
||||
this.isShow = true;
|
||||
setPageShow(isShow: boolean) {
|
||||
if (this.isShow == isShow) {
|
||||
return;
|
||||
}
|
||||
this.isShow = isShow;
|
||||
if (this.isShow) {
|
||||
this.startInit();
|
||||
}
|
||||
this.contactListDataSource.setIsShow(isShow);
|
||||
}
|
||||
|
||||
onPageHide() {
|
||||
HiLog.i(TAG, 'Contact onPageHide!');
|
||||
this.isShow = false;
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'Contacts requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.page++;
|
||||
this.refreshContinue();
|
||||
} else if (!this.initStarted && !this.loading) {
|
||||
this.cachePageOne();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
refresh(contactList) {
|
||||
this.contactListDataSource.refresh(contactList);
|
||||
setDelayTask() {
|
||||
if (this.taskId != undefined) {
|
||||
clearTimeout(this.taskId);
|
||||
this.taskId = undefined;
|
||||
}
|
||||
let delay: number = 0;
|
||||
if (this.page != 0) {
|
||||
delay += DELAY_TIME;
|
||||
}
|
||||
if (!this.isShow) {
|
||||
delay += DELAY_TIME;
|
||||
}
|
||||
if (delay > 0) {
|
||||
this.taskId = setTimeout(() => {
|
||||
if (this.page != 0) {
|
||||
this.setDelayTask();
|
||||
} else {
|
||||
this.requestItem();
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
this.requestItem();
|
||||
}
|
||||
}
|
||||
|
||||
refreshContinue() {
|
||||
if (this.loading) {
|
||||
HiLog.i(TAG, 'refreshContinue is loading');
|
||||
return;
|
||||
}
|
||||
if (this.page == 0) {
|
||||
HiLog.i(TAG, 'refreshContinue end');
|
||||
return;
|
||||
}
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
this.refreshPage(this.page, this.limit, () => {
|
||||
if (this.initStarted) {
|
||||
setTimeout(() => {
|
||||
this.refreshContinue();
|
||||
},!this.isShow ? 700 : 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
refreshPage(page: number, limit: number, callback?: () => void) {
|
||||
this.loading = true;
|
||||
let actionData: any = {};
|
||||
actionData.page = page;
|
||||
actionData.limit = limit;
|
||||
this.worker.sendRequest("getAllContact", {
|
||||
actionData: actionData,
|
||||
context: this.context
|
||||
}, (result) => {
|
||||
HiLog.i(TAG, `refreshPage ${page} getAllContact, length is: ` + result.length);
|
||||
if (Array.prototype.isPrototypeOf(result)) {
|
||||
this.contactListDataSource.refresh(this.refreshIndex, this.contactListPages[page -1], result);
|
||||
}
|
||||
this.contactListPages[page -1] = result.length;
|
||||
this.refreshIndex += this.contactListPages[page -1];
|
||||
if (this.refreshState) {
|
||||
this.refreshState();
|
||||
}
|
||||
let contactCount = result.length;
|
||||
if (contactCount < limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'Contacts load completed: ' + JSON.stringify(this.contactListDataSource.totalCount()));
|
||||
if (this.contactListPages.length > page) {
|
||||
this.contactListPages.splice(page, this.contactListPages.length - page);
|
||||
}
|
||||
if (this.contactListDataSource.totalCount() > this.refreshIndex) {
|
||||
this.contactListDataSource.remove(this.refreshIndex, this.contactListDataSource.totalCount() - this.refreshIndex);
|
||||
}
|
||||
this.refreshIndex = 0;
|
||||
this.loading = false;
|
||||
} else {
|
||||
this.page = page + 1;
|
||||
this.loading = false;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Touch and hold the current contact information saved by a contact item in the contact list.
|
||||
* The information can be deleted or shared later.
|
||||
@@ -108,11 +259,16 @@ export default class ContactListPresenter {
|
||||
*/
|
||||
onDeleteDialogConfirm(index, item) {
|
||||
HiLog.i(TAG, 'onDeleteDialogConfirm !!! ');
|
||||
ContactRepository.getInstance().deleteById(item.contactId, (result) => {
|
||||
HiLog.i(TAG, 'onDeleteDialogConfirm result is ' + JSON.stringify(result));
|
||||
this.worker.sendRequest("deleteContactById", {
|
||||
context: this.context,
|
||||
contactId: item.contactId
|
||||
}, (result) => {
|
||||
if (result) {
|
||||
HiLog.w(TAG, "deleteContactById error:" + JSON.stringify(result))
|
||||
}
|
||||
ContactRepository.getInstance().notifyChange();
|
||||
CallLogRepository.getInstance().notifyChange();
|
||||
});
|
||||
this.contactListDataSource.remove(index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,48 +105,52 @@ export default class AccountantsPresenter {
|
||||
}
|
||||
|
||||
isExistenceInfo(afterInfo: any) {
|
||||
let flag = false;
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.display_name);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.nickname);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.remarks);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.position);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.company);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.phones)) {
|
||||
for (let item of afterInfo.phones) {
|
||||
flag = flag || !StringUtil.isEmpty(item.num);
|
||||
if (!afterInfo) {
|
||||
return false;
|
||||
} else {
|
||||
let flag = false;
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.display_name);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.nickname);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.remarks);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.position);
|
||||
flag = flag || !StringUtil.isEmpty(afterInfo.company);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.phones)) {
|
||||
for (let item of afterInfo.phones) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.num);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.emails)) {
|
||||
for (let item of afterInfo.emails) {
|
||||
flag = flag || !StringUtil.isEmpty(item.address);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.emails)) {
|
||||
for (let item of afterInfo.emails) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.address);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.aims)) {
|
||||
for (let item of afterInfo.aims) {
|
||||
flag = flag || !StringUtil.isEmpty(item.aimName);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.aims)) {
|
||||
for (let item of afterInfo.aims) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.aimName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.houses)) {
|
||||
for (let item of afterInfo.houses) {
|
||||
flag = flag || !StringUtil.isEmpty(item.houseName);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.houses)) {
|
||||
for (let item of afterInfo.houses) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.houseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.websites)) {
|
||||
for (let item of afterInfo.websites) {
|
||||
flag = flag || !StringUtil.isEmpty(item);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.websites)) {
|
||||
for (let item of afterInfo.websites) {
|
||||
flag = flag || !StringUtil.isEmpty(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.events)) {
|
||||
for (let item of afterInfo.events) {
|
||||
flag = flag || !StringUtil.isEmpty(item.data);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.events)) {
|
||||
for (let item of afterInfo.events) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(afterInfo.relationships)) {
|
||||
for (let item of afterInfo.relationships) {
|
||||
flag = flag || !StringUtil.isEmpty(item.name);
|
||||
if (!ArrayUtil.isEmpty(afterInfo.relationships)) {
|
||||
for (let item of afterInfo.relationships) {
|
||||
flag = flag || !StringUtil.isEmpty(item?.name);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
getPageData(id: string) {
|
||||
@@ -526,45 +530,50 @@ export default class AccountantsPresenter {
|
||||
}
|
||||
|
||||
public menuChange(typeName: string, data: any, item: any) {
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.phones[data.i - 1])) {
|
||||
this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean("", "", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.phones[data.i - 1].numType = item.rawValue.toString();
|
||||
break;
|
||||
case "email":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.emails[data.i - 1])) {
|
||||
this.contactInfoAfter.emails[data.i - 1] = new EmailBean("", "", "");
|
||||
}
|
||||
this.contactInfoAfter.emails[data.i - 1].emailType = item.rawValue.toString();
|
||||
break;
|
||||
case "AIM":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.aims[data.i - 1])) {
|
||||
this.contactInfoAfter.aims[data.i - 1] = new AIMBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.aims[data.i - 1].aimType = item.rawValue.toString();
|
||||
break;
|
||||
case "house":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.houses[data.i - 1])) {
|
||||
this.contactInfoAfter.houses[data.i - 1] = new HouseBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.houses[data.i - 1].houseType = item.rawValue.toString();
|
||||
break;
|
||||
case "relationships":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.relationships[data.i - 1])) {
|
||||
this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.relationships[data.i - 1].associatedType = item.rawValue.toString();
|
||||
break;
|
||||
case "events":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.events[data.i - 1])) {
|
||||
this.contactInfoAfter.events[data.i - 1] = new EventBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.events[data.i - 1].eventType = item.rawValue.toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (data.i) {
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.phones[data.i - 1])) {
|
||||
this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean("", "", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.phones[data.i - 1].numType = item.rawValue.toString();
|
||||
break;
|
||||
case "email":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.emails[data.i - 1])) {
|
||||
this.contactInfoAfter.emails[data.i - 1] = new EmailBean("", "", "");
|
||||
}
|
||||
this.contactInfoAfter.emails[data.i - 1].emailType = item.rawValue.toString();
|
||||
break;
|
||||
case "AIM":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.aims[data.i - 1])) {
|
||||
this.contactInfoAfter.aims[data.i - 1] = new AIMBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.aims[data.i - 1].aimType = item.rawValue.toString();
|
||||
break;
|
||||
case "house":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.houses[data.i - 1])) {
|
||||
this.contactInfoAfter.houses[data.i - 1] = new HouseBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.houses[data.i - 1].houseType = item.rawValue.toString();
|
||||
break;
|
||||
case "relationships":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.relationships[data.i - 1])) {
|
||||
this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.relationships[data.i - 1].associatedType = item.rawValue.toString();
|
||||
break;
|
||||
case "events":
|
||||
if (ObjectUtil.isEmpty(this.contactInfoAfter.events[data.i - 1])) {
|
||||
this.contactInfoAfter.events[data.i - 1] = new EventBean("", "", "", "");
|
||||
}
|
||||
this.contactInfoAfter.events[data.i - 1].eventType = item.rawValue.toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
HiLog.e(TAG, "data.i is Empty!" + JSON.stringify(data));
|
||||
return;
|
||||
}
|
||||
this.addState = true;
|
||||
this.refresh();
|
||||
@@ -614,8 +623,12 @@ export default class AccountantsPresenter {
|
||||
}
|
||||
|
||||
public getAddState() {
|
||||
if (this.contactInfoAfter) {
|
||||
return this.addState && this.isExistenceInfo(this.contactInfoAfter);
|
||||
try {
|
||||
if (this.contactInfoAfter) {
|
||||
return this.addState && this.isExistenceInfo(this.contactInfoAfter);
|
||||
}
|
||||
} catch (err) {
|
||||
HiLog.i(TAG, "something err: " + JSON.stringify(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,19 +13,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
|
||||
import { ObjectUtil } from '../../../../../../../common/src/main/ets/util/ObjectUtil';
|
||||
import { HiLog, ArrayUtil } from '../../../../../../../common';
|
||||
import { PhoneNumber } from '../../../../../../../feature/phonenumber/src/main/ets/PhoneNumber';
|
||||
import { ArrayUtil } from '../../../../../../../common/src/main/ets/util/ArrayUtil';
|
||||
import router from '@ohos.router';
|
||||
import { CallLogRepository } from '../../../../../../../feature/call';
|
||||
import { ContactRepository } from '../../../../../../../feature/contact/src/main/ets/repo/ContactRepository';
|
||||
import CallRecordListDataSource from './../../../model/bean/CallRecordListDataSource';
|
||||
import CallLogSetting from '../../../../../../../feature/call/src/main/ets/CallLogSetting'
|
||||
import DialerPresenter from '../../../presenter/dialer/DialerPresenter';
|
||||
import emitter from '@ohos.events.emitter';
|
||||
import WorkerWrapper from '../../../workers/base/WorkerWrapper';
|
||||
|
||||
const TAG = 'CallRecordPresenter'
|
||||
const DELAY_TIME: number = 1000;
|
||||
|
||||
export default class CallRecordPresenter {
|
||||
private static mPresenter: CallRecordPresenter;
|
||||
@@ -33,54 +32,240 @@ export default class CallRecordPresenter {
|
||||
mMissCallRecordListDataSource: CallRecordListDataSource = new CallRecordListDataSource();
|
||||
mDialerPresent: DialerPresenter = DialerPresenter.getInstance();
|
||||
isShow: boolean = false;
|
||||
page: number = 0;
|
||||
limit: number = 0;
|
||||
context: Context;
|
||||
worker: WorkerWrapper;
|
||||
refreshState: () => void
|
||||
loading: boolean = false;
|
||||
callLogListPages: Array<number> = [];
|
||||
missedListPages: Array<number> = [];
|
||||
callLogIndex: number = 0;
|
||||
missedIndex: number = 0;
|
||||
tabIndex: number = 0;
|
||||
initStarted: boolean = false;
|
||||
taskId: number = undefined;
|
||||
onCallsChange = () => {
|
||||
HiLog.i(TAG, 'onCallsChange refresh');
|
||||
this.setDelayTask();
|
||||
}
|
||||
onContactChange = () => {
|
||||
HiLog.i(TAG, 'onContactChange refresh');
|
||||
this.setDelayTask();
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (globalThis.presenterManager?.callRecordPresenter) {
|
||||
return globalThis.presenterManager.callRecordPresenter;
|
||||
}
|
||||
if (CallRecordPresenter.mPresenter == null) {
|
||||
CallRecordPresenter.mPresenter = new CallRecordPresenter();
|
||||
}
|
||||
return CallRecordPresenter.mPresenter;
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
HiLog.i(TAG, 'onPageShow');
|
||||
this.isShow = true;
|
||||
bindUI(refreshState?: () => void) {
|
||||
this.refreshState = refreshState;
|
||||
}
|
||||
|
||||
onPageHide() {
|
||||
HiLog.i(TAG, 'onPageHide');
|
||||
this.isShow = false;
|
||||
onCreate(context: Context, worker: WorkerWrapper) {
|
||||
this.context = context;
|
||||
this.worker = worker;
|
||||
CallLogRepository.getInstance().registerDataChangeObserver(this.onCallsChange);
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
CallLogRepository.getInstance().unRegisterDataChangeObserver(this.onCallsChange);
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
startInit() {
|
||||
if (this.initStarted) {
|
||||
return;
|
||||
}
|
||||
HiLog.i(TAG, "startInit");
|
||||
this.initStarted = true;
|
||||
if (this.page == 0) {
|
||||
this.page++;
|
||||
}
|
||||
this.refreshContinue();
|
||||
}
|
||||
|
||||
cachePageOne() {
|
||||
if (!this.initStarted && !this.loading) {
|
||||
HiLog.i(TAG, "cachePageOne")
|
||||
this.page = 1;
|
||||
this.callLogIndex = 0;
|
||||
this.missedIndex = 0;
|
||||
this.refreshContinue();
|
||||
} else {
|
||||
HiLog.i(TAG, "no need cachePageOne");
|
||||
}
|
||||
}
|
||||
|
||||
setPageShow(isShow: boolean) {
|
||||
if (this.isShow == isShow) {
|
||||
return;
|
||||
}
|
||||
this.isShow = isShow;
|
||||
if (this.isShow) {
|
||||
this.startInit();
|
||||
}
|
||||
this.setTabShow();
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'aboutToAppear!');
|
||||
this.isShow = true;
|
||||
this.startInit();
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'aboutToDisappear!');
|
||||
this.isShow = false;
|
||||
}
|
||||
|
||||
refreshMissedList(missedList) {
|
||||
HiLog.i(TAG, 'refreshMissedList, length is ' + missedList.length);
|
||||
if (!ObjectUtil.isEmpty(this.mMissCallRecordListDataSource)) {
|
||||
this.mMissCallRecordListDataSource.refresh(missedList);
|
||||
setTabShow() {
|
||||
if (this.isShow) {
|
||||
HiLog.i(TAG, 'setTabShow:' + this.tabIndex);
|
||||
if (this.tabIndex == 0) {
|
||||
this.mMissCallRecordListDataSource.setIsShow(false);
|
||||
this.mAllCallRecordListDataSource.setIsShow(true);
|
||||
} else {
|
||||
this.mAllCallRecordListDataSource.setIsShow(false);
|
||||
this.mMissCallRecordListDataSource.setIsShow(true);
|
||||
}
|
||||
} else {
|
||||
this.mAllCallRecordListDataSource.setIsShow(false);
|
||||
this.mMissCallRecordListDataSource.setIsShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
refreshCallLogList(callLogList) {
|
||||
HiLog.i(TAG, 'refreshCallLogList, length is ' + callLogList.length);
|
||||
if (!ObjectUtil.isEmpty(this.mAllCallRecordListDataSource)) {
|
||||
this.mAllCallRecordListDataSource.refresh(callLogList);
|
||||
setTabIndex(index) {
|
||||
if (this.tabIndex != index) {
|
||||
this.tabIndex = index;
|
||||
this.setTabShow();
|
||||
}
|
||||
}
|
||||
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'CallLogs requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.page++;
|
||||
this.refreshContinue();
|
||||
} else if (!this.initStarted && !this.loading) {
|
||||
this.cachePageOne();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
}
|
||||
}
|
||||
|
||||
setDelayTask() {
|
||||
if (this.taskId != undefined) {
|
||||
clearTimeout(this.taskId);
|
||||
this.taskId = undefined;
|
||||
}
|
||||
let delay: number = 0;
|
||||
if (this.page != 0) {
|
||||
delay += DELAY_TIME;
|
||||
}
|
||||
if (!this.isShow) {
|
||||
delay += DELAY_TIME;
|
||||
}
|
||||
if (delay > 0) {
|
||||
this.taskId = setTimeout(() => {
|
||||
if (this.page != 0) {
|
||||
this.setDelayTask();
|
||||
} else {
|
||||
this.requestItem();
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
this.requestItem();
|
||||
}
|
||||
}
|
||||
|
||||
refreshContinue() {
|
||||
if (this.loading) {
|
||||
HiLog.i(TAG, 'refreshContinue is loading');
|
||||
return;
|
||||
}
|
||||
if (this.page == 0) {
|
||||
HiLog.i(TAG, 'refreshContinue end');
|
||||
return;
|
||||
}
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
this.refreshPage(this.page, this.limit, () => {
|
||||
if (this.initStarted) {
|
||||
setTimeout(() => {
|
||||
this.refreshContinue();
|
||||
},!this.isShow ? 700 : 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
refreshPage(page: number, limit: number, callback?: () => void) {
|
||||
this.loading = true;
|
||||
let actionData: any = {};
|
||||
actionData.page = page;
|
||||
actionData.limit = limit;
|
||||
this.worker?.sendRequest("getAllCalls", {
|
||||
context: this.context,
|
||||
mergeRule: CallLogSetting.getInstance().getMergeRule(),
|
||||
actionData: actionData
|
||||
}, (data) => {
|
||||
let dateLength = data.callLogList.length;
|
||||
HiLog.i(TAG, `refreshPage ${page} and getAllCalls, length is ` + dateLength);
|
||||
if (Array.prototype.isPrototypeOf(data.callLogList)) {
|
||||
this.mAllCallRecordListDataSource.refresh(this.callLogIndex, this.callLogListPages[page-1], data.callLogList);
|
||||
this.mDialerPresent.refresh();
|
||||
}
|
||||
if (Array.prototype.isPrototypeOf(data.missedList)) {
|
||||
this.mMissCallRecordListDataSource.refresh(this.missedIndex, this.missedListPages[page - 1], data.missedList);
|
||||
}
|
||||
this.callLogListPages[page-1] = dateLength;
|
||||
this.callLogIndex += this.callLogListPages[page-1];
|
||||
this.missedListPages[page - 1] = data.missedList.length;
|
||||
this.missedIndex += this.missedListPages[page - 1];
|
||||
if (this.refreshState) {
|
||||
this.refreshState();
|
||||
}
|
||||
if (dateLength < limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'CallLogs load completed: ' + JSON.stringify(this.mAllCallRecordListDataSource.totalCount()));
|
||||
if (this.callLogListPages.length > page) {
|
||||
this.callLogListPages.splice(page, this.callLogListPages.length - page);
|
||||
}
|
||||
if (this.missedListPages.length > page) {
|
||||
this.missedListPages.splice(page, this.missedListPages.length - page);
|
||||
}
|
||||
if (this.mAllCallRecordListDataSource.totalCount() > this.callLogIndex) {
|
||||
this.mAllCallRecordListDataSource.remove(this.callLogIndex, this.mAllCallRecordListDataSource.totalCount() - this.callLogIndex);
|
||||
}
|
||||
if (this.mMissCallRecordListDataSource.totalCount() > this.missedIndex) {
|
||||
this.mMissCallRecordListDataSource.remove(this.missedIndex, this.mMissCallRecordListDataSource.totalCount() - this.missedIndex);
|
||||
}
|
||||
this.callLogIndex = 0;
|
||||
this.missedIndex = 0;
|
||||
this.loading = false;
|
||||
} else {
|
||||
this.page = page + 1;
|
||||
this.loading = false;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
dialing(phoneNumber, options?: any) {
|
||||
PhoneNumber.fromString(phoneNumber).dial(options);
|
||||
}
|
||||
|
||||
deleteCallLog(id) {
|
||||
deleteCallLog(id, index?) {
|
||||
globalThis.DataWorker.sendRequest("deleteCallLogsById", {
|
||||
context: globalThis.context,
|
||||
ids: id
|
||||
@@ -88,6 +273,13 @@ export default class CallRecordPresenter {
|
||||
HiLog.i(TAG, 'deleteCallLog Success');
|
||||
CallLogRepository.getInstance().notifyChange()
|
||||
});
|
||||
if (index != undefined) {
|
||||
if (this.tabIndex == 0) {
|
||||
this.mAllCallRecordListDataSource.remove(index);
|
||||
} else {
|
||||
this.mMissCallRecordListDataSource.remove(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jumpToContactDetail(phoneNumber) {
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { CallLogRepository } from '../../../../../feature/call';
|
||||
import { ContactRepository } from '../../../../../feature/contact';
|
||||
import { HiLog, ArrayUtil } from '../../../../../common';
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ContactRepository } from '../../../../../feature/contact';
|
||||
import { HiLog, ArrayUtil } from '../../../../../common';
|
||||
import { ContactVo } from '../model/bean/ContactVo';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import i18n from '@ohos.i18n';
|
||||
|
||||
const YEAR_CONVERT: number = 2697;
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import worker from '@ohos.worker';
|
||||
import media from '@ohos.multimedia.media';
|
||||
import Log from "@ohos.hilog";
|
||||
|
||||
/**
|
||||
* dailpad key tone worker
|
||||
*/
|
||||
const parentPort = worker.parentPort;
|
||||
const TAG = "ContactLog";
|
||||
const DOMAIN = 0x0900;
|
||||
let audioPlayer = undefined;
|
||||
let mAudioPath = '';
|
||||
|
||||
parentPort.onmessage = function (e) {
|
||||
let data = e.data;
|
||||
switch (data.type) {
|
||||
case "audio":
|
||||
if (audioPlayer == undefined) {
|
||||
audioPlayer = media.createAudioPlayer();
|
||||
audioPlayer.on('dataLoad', () => {
|
||||
audioPlayer.play();
|
||||
});
|
||||
}
|
||||
let fileName = data.data;
|
||||
console.log(`fileName is ${JSON.stringify(fileName)}`)
|
||||
if (mAudioPath == '') {
|
||||
audioPlayer.fdSrc = fileName;
|
||||
} else if (mAudioPath == fileName) {
|
||||
audioPlayer.seek(0);
|
||||
audioPlayer.play();
|
||||
} else {
|
||||
audioPlayer.reset();
|
||||
audioPlayer.fdSrc = fileName;
|
||||
}
|
||||
mAudioPath = fileName;
|
||||
break;
|
||||
case "over":
|
||||
audioPlayer.release();
|
||||
audioPlayer = undefined;
|
||||
parentPort.close();
|
||||
break;
|
||||
default:
|
||||
Log.error(DOMAIN, TAG, 'the case is not in this category');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { HiLog } from "../../../../../common"
|
||||
import { WorkerType } from "./WorkFactory"
|
||||
import WorkerWrapper from "./base/WorkerWrapper"
|
||||
import WorkerTask from "./base/WorkerTask"
|
||||
import { ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import CallLog from '../model/calllog/CalllogModel';
|
||||
import { CallLogRepository } from '../../../../../feature/call';
|
||||
import { ContactRepository } from '../../../../../feature/contact';
|
||||
import ContactAbilityModel from '../model/ContactAbilityModel';
|
||||
|
||||
const TAG = "DataWorkerTask"
|
||||
|
||||
|
||||
export enum DataWorkerConstant {
|
||||
"deleteCallLogsById",
|
||||
"getAllCalls",
|
||||
"findByNumberIn",
|
||||
"deleteContactById",
|
||||
"addContact",
|
||||
"getAllContact",
|
||||
"getAllContactWithPhoneNumbers",
|
||||
"getContactById",
|
||||
"updateContact",
|
||||
"getIdByTelephone",
|
||||
}
|
||||
|
||||
export class DataWorkerTask extends WorkerTask {
|
||||
private static sInstance: DataWorkerTask = undefined;
|
||||
|
||||
private constructor(workerPort: ThreadWorkerGlobalScope) {
|
||||
super(workerPort)
|
||||
}
|
||||
|
||||
static getInstance(workerPort: ThreadWorkerGlobalScope) {
|
||||
HiLog.i(TAG, "getInstance in.")
|
||||
if (DataWorkerTask.sInstance == undefined || DataWorkerTask.sInstance.workerPort == undefined) {
|
||||
DataWorkerTask.sInstance = new DataWorkerTask(workerPort);
|
||||
}
|
||||
return DataWorkerTask.sInstance;
|
||||
}
|
||||
|
||||
runInWorker(request: string, callBack: (v?: any) => void, param?: any) {
|
||||
HiLog.i(TAG, `runInWorker ${request}`)
|
||||
switch (request) {
|
||||
case DataWorkerConstant[DataWorkerConstant.getAllCalls]:
|
||||
CallLog.getAllCalls(param.actionData, param.mergeRule, (data) => {
|
||||
HiLog.i(TAG, `getAllCalls result: ${JSON.stringify(data).length}`)
|
||||
callBack(data);
|
||||
}, param.context);
|
||||
break;
|
||||
case DataWorkerConstant[DataWorkerConstant.findByNumberIn]:
|
||||
CallLogRepository.getInstance().init(param.context);
|
||||
CallLogRepository.getInstance().findByNumberIn(param.numbers, (resultList) => {
|
||||
callBack(resultList);
|
||||
});
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.deleteContactById]:
|
||||
ContactRepository.getInstance().init(param.context);
|
||||
ContactRepository.getInstance().deleteById(param.contactId, (result) => {
|
||||
HiLog.i(TAG, `deleteContactById result ${result}`)
|
||||
callBack(result);
|
||||
});
|
||||
break;
|
||||
case DataWorkerConstant[DataWorkerConstant.deleteCallLogsById]:
|
||||
CallLogRepository.getInstance().init(param.context);
|
||||
CallLogRepository.getInstance().deleteByIdIn(param.ids, (result) => {
|
||||
callBack(result);
|
||||
})
|
||||
break;
|
||||
case DataWorkerConstant[DataWorkerConstant.addContact]:
|
||||
const contactInfoAfter = JSON.parse(param.contactInfoAfter)
|
||||
ContactAbilityModel.addContact(contactInfoAfter, (arg) => {
|
||||
callBack(arg);
|
||||
}, param.context)
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.getAllContact]:
|
||||
ContactAbilityModel.getAllContact(param.actionData, (result) => {
|
||||
callBack(result);
|
||||
}, param.context)
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.getAllContactWithPhoneNumbers]:
|
||||
ContactAbilityModel.getAllContactWithPhoneNumbers((resultList) => {
|
||||
callBack(resultList);
|
||||
}, param.context)
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.getContactById]:
|
||||
ContactAbilityModel.getContactById(param.contactId, result => {
|
||||
callBack(result);
|
||||
}, param.context)
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.getIdByTelephone]:
|
||||
ContactAbilityModel.getIdByTelephone(param.phoneNumber, (contactId) => {
|
||||
callBack(contactId);
|
||||
}, param.context)
|
||||
break
|
||||
case DataWorkerConstant[DataWorkerConstant.updateContact]:
|
||||
ContactAbilityModel.updateContact(null, JSON.parse(param.contactInfoAfter), (arg) => {
|
||||
callBack(arg);
|
||||
}, param.context)
|
||||
break
|
||||
default:
|
||||
HiLog.w(TAG, `${request} not allow!!!`)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
import { ThreadWorkerGlobalScope, MessageEvents } from '@ohos.worker';
|
||||
import { HiLog } from "../../../../../common"
|
||||
import DataWorkerWrapper, { DataWorkerTask } from "./DataWorkerWrapper"
|
||||
import { DataWorkerTask } from "./DataWorkerTask"
|
||||
import WorkerWrapper, { WorkerMessage } from "./base/WorkerWrapper"
|
||||
import WorkerTask from "./base/WorkerTask"
|
||||
|
||||
@@ -33,13 +33,10 @@ export default class WorkFactory {
|
||||
* @param message worker message data
|
||||
* @return WorkerTask for the message
|
||||
*/
|
||||
static getTask(workerPort: ThreadWorkerGlobalScope, message: MessageEvents): WorkerTask {
|
||||
let data = <WorkerMessage> message.data;
|
||||
let type = data.type;
|
||||
static getTask(type: WorkerType, workerPort?: ThreadWorkerGlobalScope): WorkerTask {
|
||||
HiLog.i(TAG, `getTask in ${WorkerType[type]}.`)
|
||||
let task: WorkerTask = undefined;
|
||||
if (type == WorkerType.DataWorker) {
|
||||
HiLog.w(TAG, "getTask " + type)
|
||||
task = DataWorkerTask.getInstance(workerPort);
|
||||
}
|
||||
HiLog.w(TAG, "getTask end")
|
||||
@@ -57,7 +54,7 @@ export default class WorkFactory {
|
||||
let worker: WorkerWrapper = undefined
|
||||
if (type == WorkerType.DataWorker) {
|
||||
HiLog.w(TAG, "getWorker " + type)
|
||||
worker = DataWorkerWrapper.getInstance();
|
||||
worker = new WorkerWrapper(WorkerType.DataWorker, globalThis.config.useDataWorker);
|
||||
}
|
||||
HiLog.w(TAG, "getWorker end")
|
||||
return worker;
|
||||
|
||||
@@ -28,7 +28,9 @@ const TAG = "Worker";
|
||||
workerPort.onmessage = function (e: MessageEvents) {
|
||||
HiLog.w(TAG, "onmessage");
|
||||
if (e.data) {
|
||||
let task = WorkFactory.getTask(workerPort, e)
|
||||
let data = e.data;
|
||||
let type = data.type;
|
||||
let task = WorkFactory.getTask(type, workerPort)
|
||||
task?.onmessage(e);
|
||||
} else {
|
||||
HiLog.w(TAG, `onmessage ${JSON.stringify(e)} not allow`)
|
||||
|
||||
@@ -27,7 +27,7 @@ const TAG = "WorkerTask"
|
||||
export abstract class WorkerTask {
|
||||
workerPort: ThreadWorkerGlobalScope
|
||||
|
||||
constructor(workerPort: ThreadWorkerGlobalScope) {
|
||||
constructor(workerPort?: ThreadWorkerGlobalScope) {
|
||||
HiLog.i(TAG, `WorkerTask constructor`)
|
||||
this.workerPort = workerPort;
|
||||
}
|
||||
@@ -39,20 +39,19 @@ export abstract class WorkerTask {
|
||||
* @param e message data
|
||||
*/
|
||||
public onmessage(message: MessageEvents) {
|
||||
let data = <WorkerMessage> message.data
|
||||
HiLog.i(TAG, `onmessage ${data.request}`)
|
||||
try {
|
||||
let data = <WorkerMessage> message.data
|
||||
HiLog.i(TAG, `onmessage ${data.request}`)
|
||||
this.runInWorker(data.request, (v) => {
|
||||
HiLog.i(TAG, "runInWorker callback in")
|
||||
data.param = v;
|
||||
const str = JSON.stringify(data)
|
||||
let buf = buffer.from(str).buffer;
|
||||
this.workerPort.postMessage(buf, [buf]);
|
||||
this.workerPort?.postMessage(buf, [buf]);
|
||||
}, data.param);
|
||||
} catch (err) {
|
||||
HiLog.e(TAG, 'runInWorker err = ' + JSON.stringify(err));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract runInWorker(request: string, callBack: (v?: any) => void, param?: any);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { WorkerType } from "../WorkFactory"
|
||||
import WorkFactory, { WorkerType } from "../WorkFactory"
|
||||
import worker from '@ohos.worker';
|
||||
import { HiLog } from "../../../../../../common"
|
||||
import buffer from "@ohos.buffer"
|
||||
@@ -21,10 +21,10 @@ import buffer from "@ohos.buffer"
|
||||
const TAG = "WorkerWrapper"
|
||||
|
||||
export class WorkerMessage {
|
||||
request: string;
|
||||
callBackId: number;
|
||||
type?: WorkerType;
|
||||
param?: any;
|
||||
request: string;
|
||||
callBackId: number;
|
||||
type?: WorkerType;
|
||||
param?: any;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -32,92 +32,100 @@ export class WorkerMessage {
|
||||
*
|
||||
* Processes sending tasks to workers and receiving work processing results.
|
||||
*/
|
||||
export abstract class WorkerWrapper {
|
||||
protected mWorker: worker.ThreadWorker = undefined;
|
||||
private callBacks: Map<string, (result?: any) => void> = new Map();
|
||||
private requestIndex: number = 0;
|
||||
export default class WorkerWrapper {
|
||||
protected mWorker: worker.ThreadWorker = undefined;
|
||||
private callBacks: Map<string, (result?: any) => void> = new Map();
|
||||
private requestIndex: number = 0;
|
||||
private workType: WorkerType;
|
||||
private useWorker: boolean;
|
||||
|
||||
constructor() {
|
||||
this.initWorker();
|
||||
constructor(workType: WorkerType, useWorker: boolean) {
|
||||
this.workType = workType;
|
||||
this.useWorker = useWorker;
|
||||
if (useWorker) {
|
||||
this.initWorker();
|
||||
}
|
||||
}
|
||||
|
||||
async initWorker() {
|
||||
HiLog.i(TAG, `WorkerWrapper initWorker ${WorkerType[this.getWorkerType()]}`)
|
||||
let initWorker = await new worker.ThreadWorker("entry/ets/workers/base/Worker.ts", {
|
||||
name: WorkerType[this.getWorkerType()]
|
||||
});
|
||||
let that = this;
|
||||
initWorker.onexit = function (message) {
|
||||
HiLog.w(TAG, "onexit")
|
||||
that.mWorker = undefined;
|
||||
}
|
||||
initWorker.onerror = function (e) {
|
||||
HiLog.w(TAG, "onerror:" + JSON.stringify(e))
|
||||
}
|
||||
initWorker.onmessageerror = function (e) {
|
||||
HiLog.w(TAG, "onmessageerror:" + JSON.stringify(e))
|
||||
}
|
||||
initWorker.onmessage = function (message) {
|
||||
const buff = <ArrayBuffer> message.data;
|
||||
const str = buffer.from(buff).toString();
|
||||
let data = <WorkerMessage> JSON.parse(str)
|
||||
HiLog.i(TAG, `onmessage ${data.request}`)
|
||||
const key = that.getCallBackKey(data);
|
||||
if (that.callBacks.has(key)) {
|
||||
HiLog.i(TAG, `onmessage notify result.`)
|
||||
const callback = that.callBacks.get(key);
|
||||
if (callback) {
|
||||
callback(data.param);
|
||||
}
|
||||
that.callBacks.delete(key);
|
||||
}
|
||||
}
|
||||
this.mWorker = initWorker;
|
||||
HiLog.i(TAG, `WorkerWrapper initWorker end`)
|
||||
async initWorker() {
|
||||
HiLog.i(TAG, `WorkerWrapper initWorker ${WorkerType[this.getWorkerType()]}`)
|
||||
let initWorker = await new worker.ThreadWorker("entry/ets/workers/base/Worker.ts", {
|
||||
name: WorkerType[this.getWorkerType()]
|
||||
});
|
||||
let that = this;
|
||||
initWorker.onexit = function (message) {
|
||||
HiLog.w(TAG, "onexit")
|
||||
that.mWorker = undefined;
|
||||
}
|
||||
|
||||
public abstract getWorkerType(): WorkerType;
|
||||
|
||||
/**
|
||||
* SendRequest to worker thread.
|
||||
*
|
||||
* @param {string} request the request worker to do
|
||||
* @param {Object} requestData request param Data
|
||||
* @param {Object} callBack Call back from worker
|
||||
*/
|
||||
public async sendRequest(request: string, requestData?: any, callBack?: (result?: any) => void) {
|
||||
HiLog.i(TAG, "sendRequest in " + request)
|
||||
if (this.mWorker) {
|
||||
const message = {
|
||||
request: request,
|
||||
callBackId: this.requestIndex,
|
||||
type: this.getWorkerType(),
|
||||
param: requestData
|
||||
}
|
||||
if (callBack) {
|
||||
this.callBacks.set(this.getCallBackKey(message), callBack);
|
||||
}
|
||||
this.mWorker?.postMessage(message);
|
||||
HiLog.d(TAG, `${this.getWorkerType()} ${request} send succ!`);
|
||||
this.requestIndex++;
|
||||
} else {
|
||||
HiLog.w(TAG, `${this.getWorkerType()} ${request} send fail, worker has been closed!`);
|
||||
initWorker.onerror = function (e) {
|
||||
HiLog.w(TAG, "onerror:" + JSON.stringify(e))
|
||||
}
|
||||
initWorker.onmessageerror = function (e) {
|
||||
HiLog.w(TAG, "onmessageerror:" + JSON.stringify(e))
|
||||
}
|
||||
initWorker.onmessage = function (message) {
|
||||
const buff = <ArrayBuffer> message.data;
|
||||
const str = buffer.from(buff).toString();
|
||||
let data = <WorkerMessage> JSON.parse(str)
|
||||
HiLog.i(TAG, `onmessage ${data.request}`)
|
||||
const key = that.getCallBackKey(data);
|
||||
if (that.callBacks.has(key)) {
|
||||
HiLog.i(TAG, `onmessage notify result.`)
|
||||
const callback = that.callBacks.get(key);
|
||||
if (callback) {
|
||||
callback(data.param);
|
||||
}
|
||||
that.callBacks.delete(key);
|
||||
}
|
||||
}
|
||||
this.mWorker = initWorker;
|
||||
HiLog.i(TAG, `WorkerWrapper initWorker end`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Close close worker thread.
|
||||
*/
|
||||
public close() {
|
||||
HiLog.i(TAG, `${this.getWorkerType()} worker close!`);
|
||||
this.mWorker?.terminate();
|
||||
this.mWorker = undefined;
|
||||
this.callBacks.clear();
|
||||
}
|
||||
public getWorkerType(): WorkerType {
|
||||
return this.workType;
|
||||
}
|
||||
|
||||
private getCallBackKey(message: WorkerMessage): string {
|
||||
return message.request + message.callBackId;
|
||||
/**
|
||||
* SendRequest to worker thread.
|
||||
*
|
||||
* @param {string} request the request worker to do
|
||||
* @param {Object} requestData request param Data
|
||||
* @param {Object} callBack Call back from worker
|
||||
*/
|
||||
public async sendRequest(request: string, requestData?: any, callBack?: (result?: any) => void) {
|
||||
HiLog.i(TAG, "sendRequest in " + request)
|
||||
if (!this.useWorker) {
|
||||
WorkFactory.getTask(this.getWorkerType()).runInWorker(request, callBack, requestData);
|
||||
} else if (this.mWorker) {
|
||||
const message = {
|
||||
request: request,
|
||||
callBackId: this.requestIndex,
|
||||
type: this.getWorkerType(),
|
||||
param: requestData
|
||||
}
|
||||
if (callBack) {
|
||||
this.callBacks.set(this.getCallBackKey(message), callBack);
|
||||
}
|
||||
this.mWorker?.postMessage(message);
|
||||
HiLog.d(TAG, `${this.getWorkerType()} ${request} send succ!`);
|
||||
this.requestIndex++;
|
||||
} else {
|
||||
HiLog.w(TAG, `${this.getWorkerType()} ${request} send fail, worker has been closed!`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close close worker thread.
|
||||
*/
|
||||
public close() {
|
||||
HiLog.i(TAG, `${this.getWorkerType()} worker close!`);
|
||||
this.mWorker?.terminate();
|
||||
this.mWorker = undefined;
|
||||
this.callBacks.clear();
|
||||
}
|
||||
|
||||
private getCallBackKey(message: WorkerMessage): string {
|
||||
return message.request + message.callBackId;
|
||||
}
|
||||
}
|
||||
|
||||
export default WorkerWrapper;
|
||||
@@ -25,7 +25,7 @@
|
||||
"description": "$string:mainability_description",
|
||||
"icon": "$media:ic_contact_icon",
|
||||
"label": "$string:app_name",
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowIcon": "$media:white",
|
||||
"startWindowBackground": "$color:detail_main_background",
|
||||
"minWindowWidth": 320,
|
||||
"minWindowHeight": 700,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"boolean": [
|
||||
{
|
||||
"name": "cache_page_one",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"name": "use_data_worker",
|
||||
"value": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="56px" height="56px" viewBox="0 0 56 56" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>dial_single_button_12</title>
|
||||
<g id="dial_single_button_12" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<path d="M14.8369259,16.8465451 C15.8096063,16.6601305 16.8054146,17.0439825 17.4243338,17.8129835 L17.4243338,17.8129835 L19.4276773,20.2976475 C19.5524384,20.4532632 19.6794797,20.6088789 19.8130359,20.7580106 C20.6294437,21.6774659 20.5883937,23.0697971 19.7192208,23.9400276 L19.7192208,23.9400276 L18.297987,25.280592 C17.7334029,25.8437973 17.6326187,26.7196905 18.0546541,27.3953445 C19.6472308,29.9571681 23.9461129,34.2544309 26.7266886,35.9593954 C27.4042914,36.3736647 28.2790523,36.2706409 28.8407862,35.7104102 L28.8407862,35.7104102 L30.137259,34.4505715 C30.9933157,33.6038313 32.3561618,33.5444252 33.2833228,34.3134351 C33.4347951,34.4398729 33.586593,34.5659864 33.7442547,34.6846435 L33.7442547,34.6846435 L36.5564278,36.8039347 C37.5923018,37.8408617 37.5923018,39.5157252 36.5564278,40.5526522 L36.5564278,40.5526522 L35.7420605,41.3631506 C34.4765337,42.6226653 32.6614719,43.1825576 30.906999,42.8291802 C23.3343602,41.3038222 13.1104672,30.8633054 11.3348208,23.2193323 C10.9233491,21.4281731 11.46781,19.5523789 12.7755994,18.2555156 L12.7755994,18.2555156 L13.4629254,17.5714549 C13.837546,17.198188 14.3162611,16.9456224 14.8369259,16.8465451 Z M38.6559081,12 C39.3159263,12 39.8989423,12.1566485 40.4049562,12.4699454 C40.9109701,12.7832423 41.3033142,13.2404372 41.5819885,13.8415301 C41.8606628,14.442623 42,15.1584699 42,15.989071 C42,16.8269581 41.8606628,17.5464481 41.5819885,18.147541 C41.3033142,18.7486339 40.9109701,19.2076503 40.4049562,19.5245902 C39.962194,19.8019126 39.4604771,19.9579064 38.8998055,19.9925717 L38.6559081,20 L36.2798429,20 L36.2798429,12 L38.6559081,12 Z M30.5180417,12 L30.5180417,15.1803279 L33.1911151,15.1803279 L33.1911151,12 L34.7091568,12 L34.7091568,20 L33.1911151,20 L33.1911151,16.5245902 L30.5180417,16.5245902 L30.5180417,20 L29,20 L29,12 L30.5180417,12 Z M38.4799033,13.3005464 L37.7978846,13.3005464 L37.7978846,18.6885246 L38.4799033,18.6885246 C39.1252544,18.6885246 39.6037675,18.4608379 39.9154427,18.0054645 C40.227118,17.5500911 40.3829556,16.8779599 40.3829556,15.989071 C40.3829556,15.1074681 40.2252846,14.43898 39.9099426,13.9836066 C39.5946006,13.5282332 39.1179208,13.3005464 38.4799033,13.3005464 Z" id="形状结合" fill="#FFFFFF" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ic_contact_call_1_hd_dial</title>
|
||||
<g id="ic_contact_call_1_hd_dial" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<rect id="矩形" x="0" y="0" width="24" height="24"></rect>
|
||||
<path d="M15.0769231,16 L15.2901142,16.006425 C15.7801983,16.0364085 16.21875,16.1713342 16.6057692,16.4112022 C17.0480769,16.685337 17.3910256,17.0853825 17.6346154,17.6113388 C17.8782051,18.1372951 18,18.7636612 18,19.4904372 C18,20.2235883 17.8782051,20.8531421 17.6346154,21.3790984 C17.3910256,21.9050546 17.0480769,22.306694 16.6057692,22.5840164 C16.1634615,22.8613388 15.6538462,23 15.0769231,23 L15.0769231,23 L13,23 L13,16 L15.0769231,16 Z M8.32947977,16 L8.32947977,18.7827869 L10.6705202,18.7827869 L10.6705202,16 L12,16 L12,23 L10.6705202,23 L10.6705202,19.9590164 L8.32947977,19.9590164 L8.32947977,23 L7,23 L7,16 L8.32947977,16 Z M14.9230769,17.1379781 L14.3269231,17.1379781 L14.3269231,21.852459 L14.9230769,21.852459 C15.4871795,21.852459 15.9054487,21.6532332 16.1778846,21.2547814 C16.4503205,20.8563297 16.5865385,20.2682149 16.5865385,19.4904372 C16.5865385,18.7190346 16.4487179,18.1341075 16.1730769,17.7356557 C15.8974359,17.337204 15.4807692,17.1379781 14.9230769,17.1379781 L14.9230769,17.1379781 Z M6.94835318,1.02493489 C7.46943192,0.925069898 8.00290068,1.13070493 8.33446451,1.54266972 L8.33446451,1.54266972 L9.40768429,2.87373974 C9.47452058,2.9571053 9.54257842,3.04047085 9.6141264,3.12036284 C10.0514877,3.61292816 10.0294966,4.35881985 9.5638683,4.82501476 L9.5638683,4.82501476 L8.80249304,5.54317428 C8.50003727,5.84489135 8.44604572,6.31411995 8.6721361,6.67607744 C9.52530219,8.04848289 11.8282748,10.350588 13.3178689,11.2639618 C13.6808704,11.4858918 14.1494923,11.4307005 14.4504212,11.1305769 L14.4504212,11.1305769 L15.1449602,10.4556633 C15.603562,10.0020525 16.3336581,9.97022779 16.8303515,10.3821974 C16.9114974,10.4499319 16.9928177,10.5174927 17.0772793,10.581059 L17.0772793,10.581059 L18.5838006,11.7163936 C19.1387331,12.2718902 19.1387331,13.1691385 18.5838006,13.7246351 L18.5838006,13.7246351 L18.1475324,14.1588307 C17.4695716,14.8335707 16.4972171,15.133513 15.5573209,14.9442037 C11.5005501,14.1270476 6.02346459,8.53391357 5.07222541,4.43892804 C4.85179416,3.47937846 5.14346966,2.47448869 5.84407111,1.77974051 L5.84407111,1.77974051 L6.21228147,1.41327943 C6.41297107,1.21331498 6.66942558,1.07801198 6.94835318,1.02493489 Z M17.5,1 L17.5,7 L16.4283019,7 L16.4283019,2.45081967 L15.5,3.18032787 L15.5,1.8852459 L16.6169811,1 L17.5,1 Z" id="形状结合" fill="#ffffff"></path>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>ic_contact_call_2_hd_dial</title>
|
||||
<g id="ic_contact_call_2_hd_dial" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<rect id="矩形" x="0" y="0" width="24" height="24"></rect>
|
||||
<path d="M14.663146,16 C15.2723935,16 15.8105621,16.1370674 16.2776519,16.4112022 C16.7447416,16.685337 17.1069054,17.0853825 17.3641432,17.6113388 C17.6213811,18.1372951 17.75,18.7636612 17.75,19.4904372 C17.75,20.2235883 17.6213811,20.8531421 17.3641432,21.3790984 C17.1069054,21.9050546 16.7447416,22.306694 16.2776519,22.5840164 C15.8689483,22.8266735 15.405825,22.9631681 14.888282,22.9935003 L14.663146,23 L12.4698549,23 L12.4698549,16 L14.663146,16 Z M7.65126927,16 L7.65126927,18.7827869 L10.1187217,18.7827869 L10.1187217,16 L11.5199909,16 L11.5199909,23 L10.1187217,23 L10.1187217,19.9590164 L7.65126927,19.9590164 L7.65126927,23 L6.25,23 L6.25,16 L7.65126927,16 Z M14.50068,17.1379781 L13.8711242,17.1379781 L13.8711242,21.852459 L14.50068,21.852459 C15.0963886,21.852459 15.5380931,21.6532332 15.8257933,21.2547814 C16.1134935,20.8563297 16.2573436,20.2682149 16.2573436,19.4904372 C16.2573436,18.7190346 16.1118011,18.1341075 15.8207162,17.7356557 C15.5296313,17.337204 15.0896192,17.1379781 14.50068,17.1379781 Z M8.23919311,1.43550581 L8.33446451,1.54266972 L9.40768429,2.87373974 C9.47452058,2.9571053 9.54257842,3.04047085 9.6141264,3.12036284 C10.0202476,3.57774493 10.0302946,4.25355638 9.65684971,4.72102903 L9.5638683,4.82501476 L8.80249304,5.54317428 C8.50003727,5.84489135 8.44604572,6.31411995 8.6721361,6.67607744 C9.52530219,8.04848289 11.8282748,10.350588 13.3178689,11.2639618 C13.6445703,11.4636988 14.0568241,11.4389676 14.355385,11.2132338 L14.4504212,11.1305769 L15.1449602,10.4556633 C15.603562,10.0020525 16.3336581,9.97022779 16.8303515,10.3821974 L16.952572,10.4831913 L16.952572,10.4831913 L17.0772793,10.581059 L18.5838006,11.7163936 C19.1040498,12.2371717 19.1365654,13.0583174 18.6813474,13.6166415 L18.5838006,13.7246351 L18.1475324,14.1588307 C17.4695716,14.8335707 16.4972171,15.133513 15.5573209,14.9442037 C11.5005501,14.1270476 6.02346459,8.53391357 5.07222541,4.43892804 C4.86648958,3.54334843 5.10685562,2.60827248 5.70943374,1.92272004 L5.84407111,1.77974051 L6.21228147,1.41327943 C6.41297107,1.21331498 6.66942558,1.07801198 6.94835318,1.02493489 C7.42206113,0.934148533 7.90600876,1.09584154 8.23919311,1.43550581 Z M16.5694823,1 C17.0161541,1 17.3501362,1.12598878 17.5708447,1.37825399 C17.7915531,1.63080685 17.9019074,1.9690781 17.9019074,2.39306774 C17.9019074,2.68847979 17.8432269,2.98935711 17.726158,3.29512441 C17.6087972,3.60146699 17.3977228,4.04703006 17.0926431,4.6323889 L16.3896458,5.9690781 L18,5.9690781 L18,7 L15,7 L15,6.13821372 L16.0953678,4.14885661 C16.3295056,3.7194017 16.4877384,3.3972386 16.5694823,3.18236732 C16.6512262,2.96749604 16.6920981,2.75291241 16.6920981,2.53804113 C16.6920981,2.37724723 16.6728299,2.25902488 16.6348774,2.18366173 C16.5966329,2.10858622 16.5367847,2.07090465 16.4550409,2.07090465 C16.3405995,2.07090465 16.2477618,2.14741838 16.1768198,2.30044585 C16.1061697,2.45347332 16.0407746,2.70199914 15.9809264,3.04544801 L15.0245232,2.52222062 C15.2040677,1.50711923 15.719346,1 16.5694823,1 Z" id="形状结合" fill="#ffffff"></path>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 123 B |
@@ -15,7 +15,6 @@
|
||||
import Notification from "@ohos.notificationManager"
|
||||
import WantAgent from '@ohos.app.ability.wantAgent';
|
||||
import { HiLog, sharedPreferencesUtils } from '../../../../../../common';
|
||||
var notificationManager = globalThis.requireNapi("notificationManager");
|
||||
|
||||
const TAG = "MissedCallNotifier";
|
||||
|
||||
@@ -112,6 +111,16 @@ export class MissedCallNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* get Missed Call BadgeNumber
|
||||
*/
|
||||
public async getMissedBadgeNumber() {
|
||||
if (this.missedBadgeNumber == -1) {
|
||||
this.missedBadgeNumber = <number> await sharedPreferencesUtils.getFromPreferences(KEY_MISSED_BADGE_NUM, -1);
|
||||
}
|
||||
return this.missedBadgeNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* cancel Missed Call Notification By NotificationId
|
||||
*
|
||||
@@ -122,12 +131,10 @@ export class MissedCallNotifier {
|
||||
Notification.cancel(id, this.label).catch(error => {
|
||||
HiLog.e(TAG, `cancelNotificationById,err ${JSON.stringify(error)}}`)
|
||||
});
|
||||
if (this.missedBadgeNumber == -1) {
|
||||
let badgeNumber: number = <number> await sharedPreferencesUtils.getFromPreferences(KEY_MISSED_BADGE_NUM, -1);
|
||||
badgeNumber -= count;
|
||||
if (badgeNumber >= 0) {
|
||||
this.setMissedBadgeNumber(badgeNumber);
|
||||
}
|
||||
let badgeNumber = await this.getMissedBadgeNumber();
|
||||
badgeNumber -= count;
|
||||
if (badgeNumber >= 0) {
|
||||
this.setMissedBadgeNumber(badgeNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +195,7 @@ export class MissedCallNotifier {
|
||||
wantAgent: wantAgent
|
||||
});
|
||||
}
|
||||
notificationRequest.removalWantAgent = await this.createWantAgentForCommonEvent(missedCallData, "contact.event.CANCEL_MISSED");
|
||||
Notification.publish(notificationRequest).then(() => {
|
||||
HiLog.i(TAG, '===>publish promise success req.id : ' + notificationRequest.id);
|
||||
}).catch((err) => {
|
||||
@@ -199,10 +207,26 @@ export class MissedCallNotifier {
|
||||
private setMissedBadgeNumber(newBadgeNum: number) {
|
||||
HiLog.i(TAG, 'setMissedBadgeNumber :' + newBadgeNum);
|
||||
this.missedBadgeNumber = newBadgeNum;
|
||||
notificationManager.setBadgeNumber(newBadgeNum);
|
||||
Notification.setBadgeNumber(newBadgeNum);
|
||||
sharedPreferencesUtils.saveToPreferences(KEY_MISSED_BADGE_NUM, newBadgeNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* create wantAgent for common event
|
||||
*
|
||||
* @param mAction
|
||||
* @return return the created WantAgent object.
|
||||
*/
|
||||
private async createWantAgentForCommonEvent(missedCallData, action: string) {
|
||||
return await WantAgent.getWantAgent({
|
||||
wants: [{ action: action, parameters: {
|
||||
missedCallData: missedCallData
|
||||
}, }],
|
||||
operationType: WantAgent.OperationType.SEND_COMMON_EVENT,
|
||||
requestCode: 0 // requestCode是WantAgentInfo的请求码,是使用者定义的一个私有值
|
||||
})
|
||||
}
|
||||
|
||||
private getWantAgent(missedCallData: MissedCallNotifyData, action: string) {
|
||||
let data: any = {}
|
||||
data.action = action,
|
||||
|
||||
@@ -81,7 +81,7 @@ export class MissedCallService {
|
||||
* @param data MissedCallNotifyData need cancel notify
|
||||
*/
|
||||
public async cancelMissedNotificationAction(data: MissedCallNotifyData) {
|
||||
HiLog.i(TAG, `updateMissedCallNotifications, ${JSON.stringify(data)}`);
|
||||
HiLog.i(TAG, `cancelMissedNotificationAction, ${JSON.stringify(data)}`);
|
||||
MissedCallNotifier.getInstance().cancelNotificationById(data.id, data.count);
|
||||
CallLogRepository.getInstance().markMissedCallLogAsRead(data.phoneNumber);
|
||||
}
|
||||
@@ -90,9 +90,12 @@ export class MissedCallService {
|
||||
* cancelAllMissedNotificationAction
|
||||
*/
|
||||
public async cancelAllMissedNotificationAction() {
|
||||
HiLog.i(TAG, `cancelAllMissedNotificationAction cancel all`);
|
||||
MissedCallNotifier.getInstance().cancelAllNotification();
|
||||
CallLogRepository.getInstance().markMissedCallLogAsRead();
|
||||
let unreadMissed = await MissedCallNotifier.getInstance().getMissedBadgeNumber()
|
||||
if (unreadMissed > 0) {
|
||||
HiLog.i(TAG, `cancelAllMissedNotificationAction cancel all`);
|
||||
MissedCallNotifier.getInstance().cancelAllNotification();
|
||||
CallLogRepository.getInstance().markMissedCallLogAsRead();
|
||||
}
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
|
||||
@@ -39,10 +39,10 @@ export class PhoneNumber {
|
||||
return new Promise<boolean>(function (resolve, reject) {
|
||||
call.isEmergencyPhoneNumber(phoneNumber, (err, data) => {
|
||||
if (err) {
|
||||
HiLog.e(TAG, 'isEmergencyPhoneNumber error: ' + JSON.stringify(phoneNumber));
|
||||
HiLog.e(TAG, 'isEmergencyPhoneNumber error: ' + JSON.stringify(err));
|
||||
reject(err);
|
||||
} else {
|
||||
HiLog.e(TAG, 'isEmergencyPhoneNumber data: ' + JSON.stringify(data));
|
||||
HiLog.i(TAG, 'isEmergencyPhoneNumber data: ' + JSON.stringify(data));
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import data_preferences from '@ohos.data.preferences';
|
||||
|
||||
const NAME: string = "CONTACT_PREFERENCE";
|
||||
type ValueType = number | string | boolean | Array<number> | Array<string> | Array<boolean>;
|
||||
|
||||
class SharedPreferencesUtils {
|
||||
private mPreferences: data_preferences.Preferences;
|
||||
|
||||
constructor() {
|
||||
this.getPreferences().then((data) => {
|
||||
this.mPreferences = data;
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* getFromPreferences
|
||||
*
|
||||
* @return the value get from Preferences
|
||||
*/
|
||||
public async getFromPreferences(key: string, defValue) {
|
||||
let preferences: data_preferences.Preferences = await this.getPreferences();
|
||||
return await preferences.get(key, defValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* saveToPreferences
|
||||
*
|
||||
* @param key save to Preferences
|
||||
* @param value save to Preferences
|
||||
*/
|
||||
public async saveToPreferences(key: string, value: ValueType) {
|
||||
let preferences: data_preferences.Preferences = await this.getPreferences();
|
||||
await preferences.put(key, value);
|
||||
preferences.flush()
|
||||
}
|
||||
|
||||
private async getPreferences() {
|
||||
if (this.mPreferences) {
|
||||
return this.mPreferences;
|
||||
}
|
||||
return await data_preferences.getPreferences(globalThis.context, NAME);
|
||||
}
|
||||
}
|
||||
|
||||
export default new SharedPreferencesUtils();
|
||||
@@ -1,196 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import observer from '@ohos.telephony.observer';
|
||||
import telephonySim from '@ohos.telephony.sim';
|
||||
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import SharedPreferencesUtils from "./SharedPreferencesUtils";
|
||||
|
||||
export const simId_NONE: number = -1;
|
||||
|
||||
export const simId_ONE: number = 0;
|
||||
|
||||
export const simId_TWO: number = 1;
|
||||
|
||||
const INTERVAL = 1000;
|
||||
|
||||
const TIME_OUT = 10;
|
||||
|
||||
const KEY_LAST_ID: string = "last_used_sim_key"
|
||||
|
||||
const TAG = 'SimUtil';
|
||||
|
||||
interface Observer {
|
||||
(): void;
|
||||
}
|
||||
|
||||
class SimCardState {
|
||||
mSimStateArray: Array<telephonySim.SimState> =
|
||||
[telephonySim.SimState.SIM_STATE_UNKNOWN, telephonySim.SimState.SIM_STATE_UNKNOWN];
|
||||
haveSimCard: boolean = false;
|
||||
haveMultiSimCard: boolean = false;
|
||||
private observers: Observer[] = [];
|
||||
|
||||
constructor() {
|
||||
try {
|
||||
this.addSimChangeListener();
|
||||
this.getSimCardState();
|
||||
} catch (error) {
|
||||
HiLog.w(TAG, "SimCardState, get sim state error.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* attachObserver The subscription management methods.
|
||||
*
|
||||
* @param Observer the Observer need attach
|
||||
*/
|
||||
public attachObserver(observer: Observer): void {
|
||||
const isExist = this.observers.includes(observer);
|
||||
if (isExist) {
|
||||
return console.log('Subject: Observer has been attached already.');
|
||||
}
|
||||
HiLog.d(TAG, 'Subject: Attached an observer.');
|
||||
this.observers.push(observer);
|
||||
if (observer) {
|
||||
observer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* detachObserver
|
||||
*
|
||||
* @param Observer the Observer need detach
|
||||
*/
|
||||
public detachObserver(observer: Observer): void {
|
||||
const observerIndex = this.observers.indexOf(observer);
|
||||
if (observerIndex === -1) {
|
||||
return console.log('Subject: Nonexistent observer.');
|
||||
}
|
||||
|
||||
this.observers.splice(observerIndex, 1);
|
||||
HiLog.d(TAG, 'Subject: Detached an observer.');
|
||||
}
|
||||
|
||||
/**
|
||||
* isSimReady
|
||||
*
|
||||
* @param slotId the sim slot id number
|
||||
* @return boolean the sim is ready or not
|
||||
*/
|
||||
public isSimReady(slotId: number) {
|
||||
return this.mSimStateArray[slotId] == telephonySim.SimState.SIM_STATE_READY || this.mSimStateArray[slotId]
|
||||
== telephonySim.SimState.SIM_STATE_LOADED;
|
||||
}
|
||||
|
||||
private notify(): void {
|
||||
HiLog.d(TAG, 'sim state changed: Notifying observers...');
|
||||
for (const observer of this.observers) {
|
||||
observer();
|
||||
}
|
||||
}
|
||||
|
||||
private addSimChangeListener() {
|
||||
HiLog.i(TAG, 'addSimChangeListener start ! ');
|
||||
for (let i = 0; i < telephonySim.getMaxSimCount(); i++) {
|
||||
observer.on('simStateChange', {
|
||||
slotId: i
|
||||
}, value => {
|
||||
let simState = value?.state;
|
||||
HiLog.i(TAG, 'simStateChange for simId_ONE, SIM value: ' + simState);
|
||||
this.parseSimCardStateForSlot(i, simState);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private getSimCardState() {
|
||||
HiLog.i(TAG, '-----getSimCardState-----');
|
||||
for (let i = 0; i < telephonySim.getMaxSimCount(); i++) {
|
||||
telephonySim.getSimState(i, (err, value) => {
|
||||
if (err) {
|
||||
HiLog.e(TAG, `getSimCardState, ${i} error: ${JSON.stringify(err.message)}`);
|
||||
} else {
|
||||
this.parseSimCardStateForSlot(i, value)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private parseSimCardStateForSlot(slotId: number, value) {
|
||||
HiLog.i(TAG, 'parseSimCardStateForSlot, slotId: ' + slotId + ', SimCardState value: ' + value);
|
||||
let changed: boolean = (value != this.mSimStateArray[slotId]);
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
this.mSimStateArray[slotId] = value;
|
||||
this.haveSimCard = this.isSimReady(simId_ONE) || this.isSimReady(simId_TWO);
|
||||
this.haveMultiSimCard = this.isSimReady(simId_ONE) && this.isSimReady(simId_TWO);
|
||||
HiLog.i(TAG, 'parseSimCardStateForSlot sim state changed, haveSimCard: ' + this.haveSimCard +
|
||||
', haveMultiSimCard: ' + this.haveMultiSimCard);
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
|
||||
export const simCardState: SimCardState = new SimCardState();
|
||||
|
||||
/**
|
||||
* getLastUsedSlotId
|
||||
*
|
||||
* @return the last sim id number used to dail
|
||||
*/
|
||||
export function getLastUsedSlotId(): Promise<number> {
|
||||
return new Promise<number>(async (resolve) => {
|
||||
const value = <number> await SharedPreferencesUtils.getFromPreferences(KEY_LAST_ID, simId_NONE)
|
||||
HiLog.i(TAG, "getLastUsedSlotId:" + value);
|
||||
resolve(value)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* setLastUsedSlotId
|
||||
*
|
||||
* @param simId the sim id number
|
||||
*/
|
||||
export function setLastUsedSlotId(simId: number) {
|
||||
HiLog.i(TAG, "setLastUsedSlotId:" + simId)
|
||||
SharedPreferencesUtils.getFromPreferences(KEY_LAST_ID, simId);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSimName
|
||||
*
|
||||
* @param simId the sim id number
|
||||
* @return the sim name to show
|
||||
*/
|
||||
export function getSimName(simId: number): Promise<string> {
|
||||
return new Promise((resolveInner) => {
|
||||
telephonySim.getSimSpn(simId, (error, data) => {
|
||||
if (error || !data) {
|
||||
HiLog.i(TAG, "getSimSpn error" + JSON.stringify(error))
|
||||
telephonySim.getSimOperatorNumeric(simId, (error, opNum) => {
|
||||
if (error) {
|
||||
HiLog.i(TAG, "getSimOperatorNumeric error" + JSON.stringify(error))
|
||||
} else {
|
||||
HiLog.i(TAG, "getSimSpn error, opNum:" + opNum)
|
||||
resolveInner(opNum);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
resolveInner(data);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user