mirror of
https://github.com/openharmony/applications_contacts.git
synced 2026-07-01 19:54:30 -04:00
!52 0330 update contact
Merge pull request !52 from jiangbinghan/master
This commit is contained in:
@@ -22,10 +22,11 @@ export default {
|
||||
UNICOM: "China Unicom",
|
||||
},
|
||||
Event: {
|
||||
CALLS_CANGE: 0,
|
||||
CALLS_CHANGE: 0,
|
||||
CONTACTS_CHANGE: 1,
|
||||
SLOT_CHANGE: 2,
|
||||
SPN_INFO_CHANGED: 3,
|
||||
VOLTE_CHANGE: 4
|
||||
VOLTE_CHANGE: 4,
|
||||
CALLS_MERGE: 5
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,21 @@
|
||||
import Ability from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import WorkFactory, { WorkerType } from "../workers/WorkFactory";
|
||||
import { MissedCallService } from '../../../../../feature/call';
|
||||
import { PhoneNumber } from '../../../../../feature/phonenumber';
|
||||
import { HiLog } from '../../../../../common/src/main/ets/util/HiLog';
|
||||
import Constants from '../../../../../common/src/main/ets/Constants';
|
||||
import Want from '@ohos.application.Want';
|
||||
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";
|
||||
|
||||
const TAG = 'MainAbility ';
|
||||
|
||||
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);
|
||||
@@ -28,43 +31,28 @@ export default class MainAbility extends Ability {
|
||||
}
|
||||
|
||||
onRequest(want: Want, isOnCreate: boolean) {
|
||||
HiLog.i(TAG, "onRequest Contact notification");
|
||||
if (!want || !want.parameters) {
|
||||
return;
|
||||
}
|
||||
const data = want.parameters["missedCallData"];
|
||||
const data: any = want.parameters["missedCallData"];
|
||||
const action = want.parameters["action"];
|
||||
HiLog.i(TAG, `onRequest action: ${action}`);
|
||||
MissedCallService.getInstance().init(this.context);
|
||||
switch (action) {
|
||||
case 'notification.event.click':
|
||||
case 'notification.event.dial_back':
|
||||
HiLog.i(TAG, "action to dialBack.");
|
||||
if (data) {
|
||||
MissedCallService.getInstance().cancelMissedNotificationAction(data);
|
||||
}
|
||||
break;
|
||||
case 'notification.event.message':
|
||||
if (data && data.phoneNumber) {
|
||||
PhoneNumber.fromString(data.phoneNumber).sendMessage()
|
||||
MissedCallService.getInstance().cancelMissedNotificationAction(data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
HiLog.i(TAG, "onRequest, no action!")
|
||||
break;
|
||||
if (action != undefined && data != undefined) {
|
||||
missedCallManager.requestMissedCallAction(action, data);
|
||||
}
|
||||
}
|
||||
|
||||
onCreate(want, launchParam) {
|
||||
HiLog.i(TAG, 'Application onCreate start');
|
||||
globalThis.DataWorker = WorkFactory.getWorker(WorkerType.DataWorker);
|
||||
globalThis.isFromOnCreate = true;
|
||||
globalThis.context = this.context;
|
||||
globalThis.abilityWant = want;
|
||||
this.storage = new LocalStorage()
|
||||
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);
|
||||
}
|
||||
|
||||
onNewWant(want, launchParam) {
|
||||
@@ -76,7 +64,9 @@ export default class MainAbility extends Ability {
|
||||
|
||||
onDestroy() {
|
||||
HiLog.i(TAG, 'Ability onDestroy');
|
||||
globalThis.DataWorker?.close()
|
||||
this.mDataWorker.close();
|
||||
this.mCallsService.onDestroy();
|
||||
this.mContactsService.onDestroy();
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: Window.WindowStage) {
|
||||
|
||||
@@ -23,6 +23,12 @@ export default class StaticSubscriber extends StaticSubscriberExtensionAbility {
|
||||
MissedCallService.getInstance().init(this.context);
|
||||
if ("usual.event.INCOMING_CALL_MISSED" == event.event) {
|
||||
MissedCallService.getInstance().updateMissedCallNotifications();
|
||||
} else if ( "contact.event.CANCEL_MISSED" == event.event) {
|
||||
if (event.parameters?.missedCallData) {
|
||||
MissedCallService.getInstance().cancelMissedNotificationAction(event.parameters?.missedCallData)
|
||||
} else {
|
||||
MissedCallService.getInstance().cancelAllMissedNotificationAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil';
|
||||
import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
|
||||
import { StringUtil, HiLog } from '../../../../../../../common';
|
||||
import AccountantsPresenter from '../../../presenter/contact/accountants/AccountantsPresenter';
|
||||
import StringFormatUtil from "../../../util/StringFormatUtil";
|
||||
import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
|
||||
|
||||
const TAG = "ItemEvent"
|
||||
|
||||
@Component
|
||||
export struct ItemEvent {
|
||||
@Link mPresent: { [key: string]: any };
|
||||
@Link mPresent: AccountantsPresenter;
|
||||
@Link itemIndex: number;
|
||||
@Link eventType: number;
|
||||
private controller: { [key: string]: any };
|
||||
private index: number;
|
||||
private typeName: string;
|
||||
@@ -58,7 +62,8 @@ export struct ItemEvent {
|
||||
Text(
|
||||
StringUtil.isEmpty(this.mPresent.getTextDisplay(this.typeName, this.mPresent.getData(this.typeName, this.index - 1)))
|
||||
? $r("app.string.date")
|
||||
: StringFormatUtil.stringFormatDateResource(this.mPresent.getData(this.typeName, this.index - 1).item.data)
|
||||
: StringFormatUtil.stringFormatDateResource(this.mPresent.getData(this.typeName, this.index - 1).item.data,
|
||||
this.mPresent.getData(this.typeName, this.index - 1)?.item?.eventType == Birthday.TYPE_LUNARBIRTHDAY)
|
||||
)
|
||||
.margin({ left: $r("app.float.id_card_margin_xxl") })
|
||||
.height($r("app.float.id_item_height_large"))
|
||||
@@ -72,6 +77,10 @@ export struct ItemEvent {
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.flexGrow(1)
|
||||
.onClick(() => {
|
||||
let data = this.mPresent.getData(this.typeName, this.index - 1)
|
||||
if (data.item && data.item.hasOwnProperty("eventType")) {
|
||||
this.eventType = Number(data.item.eventType)
|
||||
}
|
||||
this.itemIndex = this.index - 1;
|
||||
this.controller.open()
|
||||
})
|
||||
|
||||
@@ -17,12 +17,14 @@ import { StringUtil } from '../../../../../../../common/src/main/ets/util/String
|
||||
import { EventBean } from "../../../model/bean/EventBean";
|
||||
import AccountantsPresenter from '../../../presenter/contact/accountants/AccountantsPresenter';
|
||||
import StringFormatUtil from "../../../util/StringFormatUtil"
|
||||
import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
|
||||
|
||||
@CustomDialog
|
||||
export struct ShowDayTime {
|
||||
private date = new Date(2000, 0, 1);
|
||||
@Link mPresent: AccountantsPresenter;
|
||||
@Prop itemIndex: number;
|
||||
@Prop itemType: number;
|
||||
@State showTime: Resource = $r("app.string.yearMonthDay", this.date.getFullYear(),
|
||||
(this.date.getMonth() + 1), this.date.getDate());
|
||||
controller: CustomDialogController
|
||||
@@ -45,6 +47,7 @@ export struct ShowDayTime {
|
||||
.width("85%")
|
||||
.height("200vp")
|
||||
.margin({ bottom: 8 })
|
||||
.lunar(this.itemType == Birthday.TYPE_LUNARBIRTHDAY)
|
||||
.onChange((value: DatePickerResult) => {
|
||||
this.date = new Date(value.year, value.month, value.day);
|
||||
this.showTime = $r("app.string.yearMonthDay", value.year, (value.month + 1), value.day);
|
||||
|
||||
@@ -128,14 +128,14 @@ export default struct CallLogListItem {
|
||||
//TODO Pop-up window for dialing without a SIM card
|
||||
PhoneNumber.fromString(this.message.formatNumber).isDialEmergencyNum().then((res) => {
|
||||
this.isEmergencyNum = res;
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
PhoneNumber.fromString(this.message.formatNumber).dial();
|
||||
}
|
||||
})
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
PhoneNumber.fromString(this.message.formatNumber).dial();
|
||||
}
|
||||
} else {
|
||||
PhoneNumber.fromString(this.message.formatNumber).dial();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import { ArrayUtil } from '../../../../../../common/src/main/ets/util/ArrayUtil';
|
||||
import { DataItemType } from '../../../../../../feature/contact/src/main/ets/contract/DataType';
|
||||
import StringFormatUtil from '../../util/StringFormatUtil'
|
||||
import { Birthday } from '../../../../../../feature/contact/src/main/ets/contract/Birthday';
|
||||
|
||||
@Component
|
||||
export default struct DetailInfoList {
|
||||
@@ -32,7 +33,7 @@ export default struct DetailInfoList {
|
||||
ForEach(JSON.parse(this.List), (item, index) => {
|
||||
ListItem() {
|
||||
DetailInfoListItem({
|
||||
title: this.dataType == DataItemType.EVENT ? StringFormatUtil.stringFormatDateResource(item.data) : item.data,
|
||||
title: this.dataType == DataItemType.EVENT ? StringFormatUtil.stringFormatDateResource(item.data, item?.type == Birthday.TYPE_LUNARBIRTHDAY) : item.data,
|
||||
content: item.labelName,
|
||||
hasArrow: this.hasArrow,
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ export default struct DetailInfoListView {
|
||||
TelList({
|
||||
List: JSON.stringify(this.mPresenter.contactForm.phones),
|
||||
mPresenter: $mPresenter,
|
||||
selectSimBuilder:$selectSimBuilder
|
||||
selectSimBuilder: $selectSimBuilder
|
||||
});
|
||||
|
||||
// email list
|
||||
@@ -118,7 +118,11 @@ struct TelList {
|
||||
List() {
|
||||
ForEach(JSON.parse(this.List), item => {
|
||||
ListItem() {
|
||||
TelListItem({ message: JSON.stringify(item), mPresenter: $mPresenter, selectSimBuilder:$selectSimBuilder });
|
||||
TelListItem({
|
||||
message: JSON.stringify(item),
|
||||
mPresenter: $mPresenter,
|
||||
selectSimBuilder: $selectSimBuilder
|
||||
});
|
||||
}
|
||||
}, item => JSON.stringify(item))
|
||||
}
|
||||
@@ -280,25 +284,25 @@ struct TelListItem {
|
||||
//TODO Pop-up window for dialing without a SIM card
|
||||
PhoneNumber.fromString(phoneNum).isDialEmergencyNum().then((res) => {
|
||||
this.isEmergencyNum = res;
|
||||
})
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
PhoneNumber.fromString(phoneNum).dial();
|
||||
}
|
||||
} else if (this.haveMultiSimCard) {
|
||||
this.selectSimBuilder.title = $r("app.string.contacts_call_number", phoneNum);
|
||||
this.selectSimBuilder.callback = (value) => {
|
||||
PhoneNumber.fromString(phoneNum).dial({
|
||||
accountId: value,
|
||||
});
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
PhoneNumber.fromString(phoneNum).dial();
|
||||
}
|
||||
})
|
||||
} else if (this.haveMultiSimCard) {
|
||||
this.selectSimBuilder.title = $r("app.string.contacts_call_number", phoneNum);
|
||||
this.selectSimBuilder.callback = (value) => {
|
||||
PhoneNumber.fromString(phoneNum).dial({
|
||||
accountId: value,
|
||||
});
|
||||
}
|
||||
this.selectSimBuilder.lastSimId = this.mPresenter.lastUsedSlotId;
|
||||
let spnList = AppStorage.Get<Array<string|Resource>>('spnList');
|
||||
let spnList = AppStorage.Get<Array<string | Resource>>('spnList');
|
||||
for (var index = 0; index < spnList.length; index++) {
|
||||
this.selectSimBuilder.multiSimCardItems[index].name = spnList[index];
|
||||
this.selectSimBuilder.multiSimCardItems[index].name = spnList[index];
|
||||
}
|
||||
this.selectSimBuilder.controller?.open();
|
||||
} else {
|
||||
|
||||
@@ -22,6 +22,7 @@ import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog';
|
||||
const TAG = 'DialerButtonView';
|
||||
@Component
|
||||
export struct DialerButtonView {
|
||||
emergencyNum: string;
|
||||
@Link mPresenter: DialerPresenter;
|
||||
@StorageLink("tele_number") tele_number: string = "";
|
||||
@StorageLink("haveSimCard") haveSimCard: boolean = false;
|
||||
@@ -32,17 +33,17 @@ export struct DialerButtonView {
|
||||
this.mPresenter.callBtnClick = true;
|
||||
if (!this.haveSimCard) {
|
||||
HiLog.i(TAG, "No SIM card!");
|
||||
this.emergencyNum = this.mPresenter.all_number;
|
||||
//TODO Pop-up window for dialing without a SIM card
|
||||
PhoneNumber.fromString(this.mPresenter.all_number).isDialEmergencyNum().then((res) => {
|
||||
this.mPresenter.isEmergencyNum = res;
|
||||
if (!this.mPresenter.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
this.mPresenter.dialing(this.emergencyNum);
|
||||
}
|
||||
})
|
||||
if (!this.mPresenter.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
this.mPresenter.dialing(this.mPresenter.all_number);
|
||||
}
|
||||
} else {
|
||||
if (this.tele_number.length > 0) {
|
||||
this.mPresenter.dialing(this.mPresenter.all_number);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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 { HiLog } from '../../../../../../common';
|
||||
import commonEvent from '@ohos.commonEventManager';
|
||||
import { PhoneNumber } from '../../../../../../feature/phonenumber';
|
||||
import telephonySim from '@ohos.telephony.sim';
|
||||
|
||||
const TAG = 'MissedCallManager'
|
||||
|
||||
class MissedCallManager {
|
||||
requestMissedCallAction(action, data: any) {
|
||||
if ('notification.event.message' == action) {
|
||||
if (data && data.phoneNumber) {
|
||||
PhoneNumber.fromString(data.phoneNumber).sendMessage();
|
||||
}
|
||||
} else if ('notification.event.dialBack' == action) {
|
||||
if (data && data.phoneNumber) {
|
||||
this.autoCall(data.phoneNumber)
|
||||
}
|
||||
}
|
||||
HiLog.i(TAG, `requestMissedCallAction action: ${action}`);
|
||||
this.cancelNotification(data);
|
||||
}
|
||||
|
||||
private async autoCall(phoneNumber: string) {
|
||||
HiLog.i(TAG, 'autoCall:' + phoneNumber)
|
||||
let readySimCount: number = 0;
|
||||
let readySim = -1;
|
||||
for (let i = 0; i < telephonySim.getMaxSimCount(); i++) {
|
||||
try {
|
||||
const state = await telephonySim.getSimState(i);
|
||||
if (state) {
|
||||
if (this.isSimReady(state)) {
|
||||
readySimCount++;
|
||||
readySim = i;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
HiLog.e(TAG, `autoCall, ${i} error: ${JSON.stringify(err.message)}`);
|
||||
}
|
||||
}
|
||||
if (readySimCount == 1 && readySim != -1) {
|
||||
PhoneNumber.fromString(phoneNumber).dial({
|
||||
accountId: readySim,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private isSimReady(state) {
|
||||
return state == telephonySim.SimState.SIM_STATE_READY || state == telephonySim.SimState.SIM_STATE_LOADED;
|
||||
}
|
||||
|
||||
cancelNotification(data?: any) {
|
||||
commonEvent.publish("contact.event.CANCEL_MISSED", {
|
||||
bundleName: 'com.ohos.contacts',
|
||||
parameters: {
|
||||
missedCallData: data
|
||||
}
|
||||
}, (err) => {
|
||||
HiLog.w(TAG, JSON.stringify(err))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const missedCallManager: MissedCallManager = new MissedCallManager();
|
||||
@@ -12,16 +12,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import CommonEvent from '@ohos.commonEventManager';
|
||||
import telephonySim from '@ohos.telephony.sim';
|
||||
import Constants from "../../../../../../common/src/main/ets/Constants"
|
||||
import { HiLog } from '../../../../../../common';
|
||||
import radio from '@ohos.telephony.radio';
|
||||
import observer from '@ohos.telephony.observer';
|
||||
|
||||
const TAG = "SimOpName"
|
||||
|
||||
class SimOpName {
|
||||
spnList: Array<string | Resource> = [];
|
||||
spnEventSubscriber: any;
|
||||
|
||||
constructor() {
|
||||
for (let index = 0; index < telephonySim.getMaxSimCount(); index++) {
|
||||
@@ -33,47 +32,37 @@ class SimOpName {
|
||||
* recycle
|
||||
*/
|
||||
public unsubscribeSpnObserver() {
|
||||
if (this.spnEventSubscriber) {
|
||||
CommonEvent.unsubscribe(this.spnEventSubscriber);
|
||||
}
|
||||
observer.off('networkStateChange');
|
||||
}
|
||||
|
||||
public initSpnObserver() {
|
||||
let subscribeInfo = {
|
||||
events: ['usual.event.SPN_INFO_CHANGED']
|
||||
};
|
||||
CommonEvent.createSubscriber(subscribeInfo, (err, data) => {
|
||||
if (err) {
|
||||
HiLog.e(TAG, JSON.stringify(err))
|
||||
return
|
||||
}
|
||||
this.spnEventSubscriber = data;
|
||||
CommonEvent.subscribe(data, (err, data) => {
|
||||
if (data && data.parameters) {
|
||||
let spn = data.parameters.CUR_SPN ? data.parameters.CUR_SPN : data.parameters.CUR_PLMN;
|
||||
if (spn) {
|
||||
HiLog.i(TAG, `SPN_INFO_CHANGED notify Sim${data.parameters.CUR_SLOT_ID} Name:${spn}`);
|
||||
this.notifySimName(data.parameters.CUR_SLOT_ID, spn);
|
||||
try {
|
||||
for (let index = 0; index < telephonySim.getMaxSimCount(); index++) {
|
||||
observer.on('networkStateChange', { slotId: index }, data => {
|
||||
if (!data) {
|
||||
HiLog.e(TAG, "there is something wrong with networkState");
|
||||
return
|
||||
} else {
|
||||
HiLog.i(TAG, "observer ON data : " + JSON.stringify(data));
|
||||
let spn = data.longOperatorName ? data.longOperatorName : data.plmnNumeric;
|
||||
if (spn) {
|
||||
HiLog.i(TAG, `networkStateChange notify Sim${index} Name:${spn}`);
|
||||
this.notifySimName(index, spn);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
HiLog.e(TAG, "get error: " + JSON.stringify(err));
|
||||
}
|
||||
}
|
||||
|
||||
public initSimName(simId: number) {
|
||||
telephonySim.getSimSpn(simId, (error, data) => {
|
||||
radio.getNetworkState(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)
|
||||
this.notifySimName(simId, opNum);
|
||||
}
|
||||
})
|
||||
HiLog.e(TAG, "getNetworkState error: " + JSON.stringify(error));
|
||||
} else {
|
||||
this.notifySimName(simId, data);
|
||||
this.notifySimName(simId, data.longOperatorName);
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -81,13 +70,6 @@ class SimOpName {
|
||||
public notifySimName(slot: number, spn: string) {
|
||||
HiLog.i(TAG, `notify Sim${slot} Name:${spn}`);
|
||||
this.spnList[slot] = spn;
|
||||
if (Constants.SPN_CHINA.MOBILE == spn) {
|
||||
this.spnList[slot] = $r('app.string.china_mobile')
|
||||
} else if (Constants.SPN_CHINA.TELECOM == spn) {
|
||||
this.spnList[slot] = $r('app.string.china_telecom')
|
||||
} else if (Constants.SPN_CHINA.UNICOM == spn) {
|
||||
this.spnList[slot] = $r('app.string.china_unicom')
|
||||
}
|
||||
AppStorage.SetOrCreate<Array<string | Resource>>("spnList", this.spnList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
|
||||
import ContactListItemView from '../../component/contact/ContactListItemView';
|
||||
import ContactListPresenter from '../../presenter/contact/ContactListPresenter';
|
||||
import { HiLog } from '../../../../../../common/src/main/ets/util/HiLog';
|
||||
import { HiLog, ArrayUtil } from '../../../../../../common';
|
||||
import emitter from '@ohos.events.emitter';
|
||||
import { StringUtil } from '../../../../../../common/src/main/ets/util/StringUtil';
|
||||
import Constants from '../../../../../../common/src/main/ets/Constants';
|
||||
|
||||
const TAG = 'ContactList ';
|
||||
let storage = LocalStorage.GetShared();
|
||||
@@ -33,22 +34,31 @@ export default struct ContactListPage {
|
||||
@State contactListListLen: number = 0;
|
||||
emitterId: number = 2;
|
||||
|
||||
refresh() {
|
||||
if (AppStorage.Has('contactList')) {
|
||||
let contactList: any = AppStorage.Get('contactList');
|
||||
this.contactListListLen = contactList.length;
|
||||
this.mContactPresenter.refresh(contactList);
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'Contact aboutToAppear!');
|
||||
this.mContactPresenter.aboutToAppear();
|
||||
let innerEvent = {
|
||||
eventId: this.emitterId,
|
||||
eventId: Constants.Event.CONTACTS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.on(innerEvent, (data) => {
|
||||
this.contactListListLen = data.data['contactListListLen'];
|
||||
emitter.on(innerEvent, () => {
|
||||
this.refresh();
|
||||
})
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'Contact aboutToDisappear!');
|
||||
this.mContactPresenter.aboutToDisappear();
|
||||
emitter.off(this.emitterId);
|
||||
emitter.off(Constants.Event.CONTACTS_CHANGE);
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
@@ -61,7 +71,7 @@ export default struct ContactListPage {
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
if (this.mContactPresenter.contactList.length == 0 && this.contactListListLen == 0) {
|
||||
if (this.contactListListLen == 0) {
|
||||
ContactEmptyPage({ presenter: $mContactPresenter })
|
||||
} else {
|
||||
ContactContent({ presenter: $mContactPresenter, contactListListLen: $contactListListLen })
|
||||
|
||||
@@ -51,6 +51,7 @@ let storage = LocalStorage.GetShared();
|
||||
struct Accountants {
|
||||
@State mPresenter: AccountantsPresenter = AccountantsPresenter.getInstance();
|
||||
@State eventItemId: number = 0;
|
||||
@State eventType: number = 1;
|
||||
@LocalStorageProp('breakpoint') curBp: string = 'sm';
|
||||
@State updataShow: boolean = false;
|
||||
private pageTitle: Resource = $r("app.string.create_contact");
|
||||
@@ -58,7 +59,8 @@ struct Accountants {
|
||||
builder: ShowDayTime({ mPresent: $mPresenter,
|
||||
cancel: this.onCancel,
|
||||
confirm: this.onAccept,
|
||||
itemIndex: this.eventItemId }),
|
||||
itemIndex: this.eventItemId,
|
||||
itemType: this.eventType}),
|
||||
cancel: this.existApp,
|
||||
autoCancel: true,
|
||||
alignment: (EnvironmentProp.isTablet() ? DialogAlignment.Center : DialogAlignment.Bottom),
|
||||
@@ -87,6 +89,11 @@ struct Accountants {
|
||||
gridCount: 4
|
||||
});
|
||||
|
||||
pageTransition() {
|
||||
PageTransitionEnter({ duration: 100 })
|
||||
PageTransitionExit({ duration: 100 })
|
||||
}
|
||||
|
||||
onCancel() {
|
||||
HiLog.i(TAG, 'Callback when the first button is clicked');
|
||||
}
|
||||
@@ -576,6 +583,7 @@ struct Accountants {
|
||||
controller: this.dialogController,
|
||||
index: item.i,
|
||||
itemIndex: $eventItemId,
|
||||
eventType: $eventType,
|
||||
typeName: "events"
|
||||
});
|
||||
}, item => item.i.toString())
|
||||
|
||||
@@ -23,7 +23,8 @@ 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 } from "../../../../../../../common"
|
||||
import { HiLog, ArrayUtil } from "../../../../../../../common"
|
||||
import Constants from '../../../../../../../common/src/main/ets/Constants';
|
||||
import emitter from '@ohos.events.emitter'
|
||||
|
||||
const TAG = "AllRecord ";
|
||||
@@ -34,28 +35,51 @@ export default struct AllRecord {
|
||||
/*0all 1miss*/
|
||||
recordType: number = 0;
|
||||
emitterId: number = 1;
|
||||
@State callLogListLen: number = 0;
|
||||
@State missedListListLen: number = 0;
|
||||
@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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'aboutToAppear,recordType:' + this.recordType)
|
||||
let innerEvent = {
|
||||
eventId: this.emitterId,
|
||||
eventId: Constants.Event.CALLS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.on(innerEvent, (data) => {
|
||||
this.callLogListLen = data.data['callLogListLen'];
|
||||
this.missedListListLen = data.data['missedListListLen'];
|
||||
emitter.on(innerEvent, () => {
|
||||
this.refresh();
|
||||
})
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
emitter.off(this.emitterId);
|
||||
HiLog.i(TAG, 'aboutToDisappear,recordType:' + this.recordType)
|
||||
emitter.off(Constants.Event.CALLS_CHANGE);
|
||||
}
|
||||
|
||||
build() {
|
||||
Stack() {
|
||||
if ((this.recordType === 0 ? this.mPresenter.callLogList.length === 0 && this.callLogListLen == 0:
|
||||
this.mPresenter.missedList.length === 0 && this.missedListListLen == 0 )) {
|
||||
if ((this.recordType === 0 ? this.callLogListEmpty : this.missedListEmpty)) {
|
||||
EmptyView({ recordType: this.recordType })
|
||||
} else {
|
||||
RecordView({ mPresenter: $mPresenter, recordType: this.recordType });
|
||||
@@ -75,7 +99,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 });
|
||||
}
|
||||
.height($r("app.float.id_item_height_max"))
|
||||
}, item => JSON.stringify(item))
|
||||
@@ -133,7 +157,7 @@ struct ContactItem {
|
||||
@State isEmergencyNum: boolean = false;
|
||||
@LocalStorageProp('breakpoint') curBp: string = 'sm';
|
||||
@StorageLink("haveMultiSimCard") haveMultiSimCard: boolean = false;
|
||||
@StorageLink('haveSimCard') haveSimCard:boolean = false;
|
||||
@StorageLink('haveSimCard') haveSimCard: boolean = false;
|
||||
deleteDialogController: CustomDialogController = new CustomDialogController({
|
||||
//Components shared by the TIP for creating or updating a contact by mistake and the TIP for deleting a contact
|
||||
builder: DeleteDialogEx({
|
||||
@@ -252,14 +276,14 @@ struct ContactItem {
|
||||
//TODO Pop-up window for dialing without a SIM card
|
||||
PhoneNumber.fromString(this.item.phoneNumber).isDialEmergencyNum().then((res) => {
|
||||
this.isEmergencyNum = res;
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
this.mPresenter.dialing(this.item.phoneNumber);
|
||||
}
|
||||
})
|
||||
if (!this.isEmergencyNum) {
|
||||
HiLog.i(TAG, "Is not Emergency Phone Number!");
|
||||
return;
|
||||
} else {
|
||||
HiLog.i(TAG, "No SIM card, but is Emergency Phone Number");
|
||||
this.mPresenter.dialing(this.item.phoneNumber);
|
||||
}
|
||||
} else {
|
||||
if (this.haveMultiSimCard) {
|
||||
DialerPresenter.getInstance().editPhoneNumber(this.item.phoneNumber);
|
||||
|
||||
@@ -45,6 +45,11 @@ struct Index {
|
||||
this.mDialerPresenter.editPhoneNumber(this.mIndexPresenter.editPhoneNumber);
|
||||
}
|
||||
|
||||
pageTransition() {
|
||||
PageTransitionEnter({ duration: 100 })
|
||||
PageTransitionExit({ duration: 100 })
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
this.mIndexPresenter.onPageShow();
|
||||
}
|
||||
|
||||
@@ -14,13 +14,16 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { CallLogRepository, MissedCallService } from '../../../../../feature/call';
|
||||
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';
|
||||
|
||||
const TAG = 'IndexPresenter ';
|
||||
|
||||
@@ -30,6 +33,10 @@ 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) {
|
||||
@@ -52,15 +59,14 @@ export default class IndexPresenter {
|
||||
this.getNewWant();
|
||||
if (parseInt(StringFormatUtil.judgeSysTime()) !== AppStorage.Get("sysTime")) {
|
||||
HiLog.i(TAG, 'DO requestItem cause systemTime changed');
|
||||
CallRecordPresenter.getInstance().requestItem();
|
||||
emitter.emit(this.innerEvent)
|
||||
AppStorage.SetOrCreate("sysTime", parseInt(StringFormatUtil.judgeSysTime()));
|
||||
}
|
||||
}
|
||||
|
||||
cancelMissedCallNotification() {
|
||||
HiLog.i(TAG, `cancelMissedCallNotification`);
|
||||
MissedCallService.getInstance().init(globalThis.context)
|
||||
MissedCallService.getInstance().cancelAllMissedNotificationAction()
|
||||
missedCallManager.cancelNotification()
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
|
||||
@@ -40,22 +40,14 @@ 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', '…'];
|
||||
contactList: ContactVo[] = [];
|
||||
curItem: ContactVo = new ContactVo("", "", "", "", "", "", true, "", "");
|
||||
page: number = 0;
|
||||
limit: number = 0;
|
||||
total: number = 0;
|
||||
queryContactsType: string = 'all';
|
||||
contactCount: number = 0;
|
||||
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;
|
||||
onContactChange = () => {
|
||||
HiLog.i(TAG, 'onContactChange refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
|
||||
private constructor() {
|
||||
}
|
||||
@@ -70,13 +62,10 @@ export default class ContactListPresenter {
|
||||
|
||||
aboutToAppear() {
|
||||
this.isShow = true;
|
||||
this.requestItem();
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
this.isShow = false;
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
onPageShow() {
|
||||
@@ -89,55 +78,9 @@ export default class ContactListPresenter {
|
||||
this.isShow = false;
|
||||
}
|
||||
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'Contacts requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.contactList = [];
|
||||
this.page++;
|
||||
this.refresh();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
let actionData: any = {};
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
actionData.page = this.page;
|
||||
actionData.limit = this.limit;
|
||||
globalThis.DataWorker.sendRequest("getAllContact", {
|
||||
actionData: actionData,
|
||||
context: globalThis.context
|
||||
}, (result) => {
|
||||
HiLog.i(TAG, 'getAllContact and refresh, length is: ' + JSON.stringify(result.length));
|
||||
if (!ArrayUtil.isEmpty(result)) {
|
||||
this.contactList = this.contactList.concat(result);
|
||||
}
|
||||
this.contactCount = result.length;
|
||||
this.contactListDataSource.refresh(this.contactList);
|
||||
if (this.contactCount < this.limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'Contacts load completed: ' + JSON.stringify(this.contactList.length));
|
||||
} else {
|
||||
this.page++;
|
||||
setTimeout(() => {
|
||||
this.refresh();
|
||||
}, this.page == 2 ? 700 : 1);
|
||||
}
|
||||
let innerEvent = {
|
||||
eventId: 2,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.emit(innerEvent, {
|
||||
data: {
|
||||
'contactListListLen': this.contactList.length
|
||||
}
|
||||
});
|
||||
})
|
||||
refresh(contactList) {
|
||||
this.contactListDataSource.refresh(contactList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -312,18 +312,22 @@ export default class AccountantsPresenter {
|
||||
HiLog.i(TAG, `deleteItem ${typeName} ${startIndex}`);
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (this.contactInfoAfter.phones.length > 1) {
|
||||
this.contactInfoAfter.phones.splice(startIndex, 1);
|
||||
} else {
|
||||
this.contactInfoAfter.phones[0].num = "";
|
||||
if (this.contactInfoAfter.phones.length > startIndex) {
|
||||
if (this.contactInfoAfter.phones.length > 0) {
|
||||
this.contactInfoAfter.phones.splice(startIndex, 1);
|
||||
} else {
|
||||
this.contactInfoAfter.phones[0].num = "";
|
||||
}
|
||||
}
|
||||
this.getPhones = this.getArray(this.contactInfoAfter.phones);
|
||||
break;
|
||||
case "email":
|
||||
if (this.contactInfoAfter.emails.length > 1) {
|
||||
this.contactInfoAfter.emails.splice(startIndex, 1);
|
||||
} else {
|
||||
this.contactInfoAfter.emails[0].address = "";
|
||||
if (this.contactInfoAfter.phones.length > startIndex) {
|
||||
if (this.contactInfoAfter.emails.length > 0) {
|
||||
this.contactInfoAfter.emails.splice(startIndex, 1);
|
||||
} else {
|
||||
this.contactInfoAfter.emails[0].address = "";
|
||||
}
|
||||
}
|
||||
this.getEmails = this.getArray(this.contactInfoAfter.emails);
|
||||
break;
|
||||
@@ -333,6 +337,7 @@ export default class AccountantsPresenter {
|
||||
} else {
|
||||
this.contactInfoAfter.aims[0].aimName = "";
|
||||
}
|
||||
break;
|
||||
case "house":
|
||||
if (this.contactInfoAfter.houses.length > 1) {
|
||||
this.contactInfoAfter.houses.splice(startIndex, 1);
|
||||
@@ -363,77 +368,83 @@ export default class AccountantsPresenter {
|
||||
|
||||
public getTextDisplay(typeName: string, data: any) {
|
||||
let display: string = "";
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (data.item.hasOwnProperty("num")) {
|
||||
display = data.item.num;
|
||||
}
|
||||
break;
|
||||
case "email":
|
||||
if (data.item.hasOwnProperty("address")) {
|
||||
display = data.item.address;
|
||||
}
|
||||
break;
|
||||
case "AIM":
|
||||
if (data.item.hasOwnProperty("aimName")) {
|
||||
display = data.item.aimName;
|
||||
}
|
||||
break;
|
||||
case "house":
|
||||
if (data.item.hasOwnProperty("houseName")) {
|
||||
display = data.item.houseName;
|
||||
}
|
||||
break;
|
||||
case "relationships":
|
||||
if (data.item.hasOwnProperty("name")) {
|
||||
display = data.item.name;
|
||||
}
|
||||
break;
|
||||
case "events":
|
||||
if (data.item.hasOwnProperty("data")) {
|
||||
display = data.item.data;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (data && data.item) {
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (data.item.hasOwnProperty("num")) {
|
||||
display = data.item.num;
|
||||
}
|
||||
break;
|
||||
case "email":
|
||||
if (data.item.hasOwnProperty("address")) {
|
||||
display = data.item.address;
|
||||
}
|
||||
break;
|
||||
case "AIM":
|
||||
if (data.item.hasOwnProperty("aimName")) {
|
||||
display = data.item.aimName;
|
||||
}
|
||||
break;
|
||||
case "house":
|
||||
if (data.item.hasOwnProperty("houseName")) {
|
||||
display = data.item.houseName;
|
||||
}
|
||||
break;
|
||||
case "relationships":
|
||||
if (data?.item.hasOwnProperty("name")) {
|
||||
display = data.item.name;
|
||||
}
|
||||
break;
|
||||
case "events":
|
||||
if (data.item.hasOwnProperty("data")) {
|
||||
display = data.item.data;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public listItemChange(typeName: string, data: any, arg: string) {
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.phones[data?.i - 1]?.numType)) {
|
||||
this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean("", "", "1", "", "");
|
||||
}
|
||||
this.contactInfoAfter.phones[data.i - 1].num = arg.toString();
|
||||
break;
|
||||
case "email":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.emails[data?.i - 1]?.emailType)) {
|
||||
this.contactInfoAfter.emails[data.i - 1] = new EmailBean("", "", "1");
|
||||
}
|
||||
this.contactInfoAfter.emails[data.i - 1].address = arg.toString();
|
||||
break;
|
||||
case "AIM":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.aims[data?.i - 1]?.aimType)) {
|
||||
this.contactInfoAfter.aims[data.i - 1] = new AIMBean("", "", "1", "");
|
||||
}
|
||||
this.contactInfoAfter.aims[data.i - 1].aimName = arg.toString();
|
||||
break;
|
||||
case "house":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.houses[data?.i - 1]?.houseType)) {
|
||||
this.contactInfoAfter.houses[data.i - 1] = new HouseBean("", "", "1", "");
|
||||
}
|
||||
this.contactInfoAfter.houses[data.i - 1].houseName = arg.toString();
|
||||
break;
|
||||
case "relationships":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.relationships[data?.i - 1]?.associatedType)) {
|
||||
this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean("", "", "", "1");
|
||||
}
|
||||
this.contactInfoAfter.relationships[data.i - 1].name = arg.toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
try {
|
||||
switch (typeName) {
|
||||
case "phone":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.phones[data?.i - 1]?.numType)) {
|
||||
this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean("", "", "1", "", "");
|
||||
}
|
||||
this.contactInfoAfter.phones[data.i - 1].num = arg.toString();
|
||||
break;
|
||||
case "email":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.emails[data?.i - 1]?.emailType)) {
|
||||
this.contactInfoAfter.emails[data.i - 1] = new EmailBean("", "", "1");
|
||||
}
|
||||
this.contactInfoAfter.emails[data.i - 1].address = arg.toString();
|
||||
break;
|
||||
case "AIM":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.aims[data?.i - 1]?.aimType)) {
|
||||
this.contactInfoAfter.aims[data.i - 1] = new AIMBean("", "", "1", "");
|
||||
}
|
||||
this.contactInfoAfter.aims[data.i - 1].aimName = arg.toString();
|
||||
break;
|
||||
case "house":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.houses[data?.i - 1]?.houseType)) {
|
||||
this.contactInfoAfter.houses[data.i - 1] = new HouseBean("", "", "1", "");
|
||||
}
|
||||
this.contactInfoAfter.houses[data.i - 1].houseName = arg.toString();
|
||||
break;
|
||||
case "relationships":
|
||||
if (StringUtil.isEmpty(this.contactInfoAfter?.relationships[data?.i - 1]?.associatedType)) {
|
||||
this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean("", "", "", "1");
|
||||
}
|
||||
this.contactInfoAfter.relationships[data.i - 1].name = arg.toString();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
HiLog.e(TAG, "something error happened: " + JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -643,8 +643,6 @@ export default class DetailPresenter {
|
||||
}, (result) => {
|
||||
if (result == 0 || result == undefined) {
|
||||
ContactRepository.getInstance().notifyChange()
|
||||
CallLogRepository.getInstance().notifyChange()
|
||||
router.back();
|
||||
} else {
|
||||
HiLog.i(TAG, `doDeleteContact Failed ${JSON.stringify(result)}`);
|
||||
prompt.showToast({
|
||||
@@ -652,6 +650,7 @@ export default class DetailPresenter {
|
||||
});
|
||||
}
|
||||
});
|
||||
router.back();
|
||||
}
|
||||
|
||||
// Sending Messages
|
||||
|
||||
@@ -29,16 +29,10 @@ const TAG = 'CallRecordPresenter'
|
||||
|
||||
export default class CallRecordPresenter {
|
||||
private static mPresenter: CallRecordPresenter;
|
||||
callLogList = [];
|
||||
missedList = [];
|
||||
mAllCallRecordListDataSource: CallRecordListDataSource = new CallRecordListDataSource();
|
||||
mMissCallRecordListDataSource: CallRecordListDataSource = new CallRecordListDataSource();
|
||||
mDialerPresent: DialerPresenter = DialerPresenter.getInstance();
|
||||
isShow: boolean = false;
|
||||
page: number = 0;
|
||||
limit: number = 0;
|
||||
dateLength: number = 0;
|
||||
missedLogDateLength: number = 0;
|
||||
|
||||
static getInstance() {
|
||||
if (CallRecordPresenter.mPresenter == null) {
|
||||
@@ -57,92 +51,29 @@ export default class CallRecordPresenter {
|
||||
this.isShow = false;
|
||||
}
|
||||
|
||||
onCallsChange = () => {
|
||||
HiLog.i(TAG, 'onCallsChange refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
onContactChange = () => {
|
||||
HiLog.i(TAG, 'onContactChange refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
|
||||
aboutToAppear() {
|
||||
HiLog.i(TAG, 'aboutToAppear!');
|
||||
this.isShow = true;
|
||||
this.requestItem();
|
||||
CallLogRepository.getInstance().registerDataChangeObserver(this.onCallsChange);
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
HiLog.i(TAG, 'aboutToDisappear!');
|
||||
this.isShow = false;
|
||||
CallLogRepository.getInstance().unRegisterDataChangeObserver(this.onCallsChange)
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactChange);
|
||||
}
|
||||
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'CallLogs requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.callLogList = [];
|
||||
this.missedList = [];
|
||||
this.page++;
|
||||
this.refresh();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
refreshMissedList(missedList) {
|
||||
HiLog.i(TAG, 'refreshMissedList, length is ' + missedList.length);
|
||||
if (!ObjectUtil.isEmpty(this.mMissCallRecordListDataSource)) {
|
||||
this.mMissCallRecordListDataSource.refresh(missedList);
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
let actionData: any = {};
|
||||
actionData.page = this.page;
|
||||
actionData.limit = this.limit;
|
||||
globalThis.DataWorker?.sendRequest("getAllCalls", {
|
||||
context: globalThis.context,
|
||||
mergeRule: CallLogSetting.getInstance().getMergeRule(),
|
||||
actionData: actionData
|
||||
}, (data) => {
|
||||
HiLog.i(TAG, 'getAllCalls and refresh, length is ' + JSON.stringify(data.callLogList.length));
|
||||
this.dateLength = data.callLogList.length;
|
||||
this.missedLogDateLength = data.missedList.length;
|
||||
let innerEvent = {
|
||||
eventId: 1,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
emitter.emit(innerEvent, {
|
||||
data: {
|
||||
'callLogListLen': this.dateLength,
|
||||
'missedListListLen': this.missedLogDateLength
|
||||
}
|
||||
});
|
||||
if (!ArrayUtil.isEmpty(data.callLogList)) {
|
||||
this.callLogList = this.callLogList.concat(data.callLogList);
|
||||
refreshCallLogList(callLogList) {
|
||||
HiLog.i(TAG, 'refreshCallLogList, length is ' + callLogList.length);
|
||||
if (!ObjectUtil.isEmpty(this.mAllCallRecordListDataSource)) {
|
||||
this.mAllCallRecordListDataSource.refresh(callLogList);
|
||||
this.mDialerPresent.refresh();
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(data.missedList)) {
|
||||
this.missedList = this.missedList.concat(data.missedList);
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(this.mAllCallRecordListDataSource)) {
|
||||
this.mAllCallRecordListDataSource.refresh(this.callLogList);
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(this.mMissCallRecordListDataSource)) {
|
||||
this.mMissCallRecordListDataSource.refresh(this.missedList);
|
||||
}
|
||||
if (this.dateLength < this.limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'CallLogs load completed: ' + JSON.stringify(this.callLogList.length));
|
||||
} else {
|
||||
this.page++;
|
||||
setTimeout(() => {
|
||||
this.refresh();
|
||||
}, this.page == 2 ? 700 : 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
dialing(phoneNumber, options?: any) {
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* 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';
|
||||
import CallLogSetting from '../../../../../feature/call/src/main/ets/CallLogSetting'
|
||||
import WorkerWrapper from "../workers/base/WorkerWrapper";
|
||||
import { DataWorkerConstant } from "../workers/DataWorkerWrapper";
|
||||
import emitter from '@ohos.events.emitter'
|
||||
import Constants from '../../../../../common/src/main/ets/Constants';
|
||||
|
||||
const TAG = "CallsService"
|
||||
|
||||
export default class CallsService {
|
||||
page: number = 0;
|
||||
limit: number = 50;
|
||||
callLogList: Array<any> = [];
|
||||
missedList: Array<any> = [];
|
||||
context: Context;
|
||||
worker: WorkerWrapper;
|
||||
innerEvent = {
|
||||
eventId: Constants.Event.CALLS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
onContactsChange = () => {
|
||||
HiLog.i(TAG, 'onContactsChange refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
onCallLogsChange = () => {
|
||||
HiLog.i(TAG, 'refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
|
||||
constructor(context: Context, worker: WorkerWrapper) {
|
||||
this.context = context;
|
||||
this.worker = worker;
|
||||
this.requestItem();
|
||||
CallLogRepository.getInstance().registerDataChangeObserver(this.onCallLogsChange);
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactsChange);
|
||||
emitter.on({
|
||||
eventId: Constants.Event.CALLS_MERGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
}, () => {
|
||||
this.requestItem();
|
||||
})
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactsChange);
|
||||
CallLogRepository.getInstance().unRegisterDataChangeObserver(this.onCallLogsChange);
|
||||
emitter.off(Constants.Event.CALLS_MERGE);
|
||||
}
|
||||
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'CallLogs requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.callLogList = [];
|
||||
this.missedList = [];
|
||||
this.page++;
|
||||
this.refresh();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
let actionData: any = {};
|
||||
actionData.page = this.page;
|
||||
actionData.limit = this.limit;
|
||||
this.worker.sendRequest(DataWorkerConstant[DataWorkerConstant.getAllCalls], {
|
||||
context: this.context,
|
||||
mergeRule: CallLogSetting.getInstance().getMergeRule(),
|
||||
actionData: actionData
|
||||
}, (data) => {
|
||||
HiLog.i(TAG, 'getAllCalls and refresh, length is ' + JSON.stringify(data.callLogList.length));
|
||||
const dateLength = data.callLogList.length;
|
||||
if (!ArrayUtil.isEmpty(data.callLogList)) {
|
||||
this.callLogList = this.callLogList.concat(data.callLogList);
|
||||
}
|
||||
if (!ArrayUtil.isEmpty(data.missedList)) {
|
||||
this.missedList = this.missedList.concat(data.missedList);
|
||||
}
|
||||
HiLog.i(TAG, 'getAllCalls and refresh end, length is ' + JSON.stringify(this.callLogList.length));
|
||||
|
||||
AppStorage.SetOrCreate("callLogList", this.callLogList)
|
||||
AppStorage.SetOrCreate("missedList", this.missedList)
|
||||
emitter.emit(this.innerEvent);
|
||||
if (dateLength < this.limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'CallLogs load completed: ' + JSON.stringify(this.callLogList.length));
|
||||
} else {
|
||||
this.page++;
|
||||
setTimeout(() => {
|
||||
this.refresh();
|
||||
}, this.page == 2 ? 700 : 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 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';
|
||||
import WorkerWrapper from "../workers/base/WorkerWrapper";
|
||||
import { DataWorkerConstant } from "../workers/DataWorkerWrapper";
|
||||
import emitter from '@ohos.events.emitter'
|
||||
import Constants from '../../../../../common/src/main/ets/Constants';
|
||||
|
||||
const TAG = "ContactsService"
|
||||
|
||||
export default class ContactsService {
|
||||
page: number = 0;
|
||||
limit: number = 50;
|
||||
contactList: ContactVo[] = [];
|
||||
context: Context;
|
||||
worker: WorkerWrapper;
|
||||
innerEvent = {
|
||||
eventId: Constants.Event.CONTACTS_CHANGE,
|
||||
priority: emitter.EventPriority.HIGH
|
||||
};
|
||||
onContactsChange = () => {
|
||||
HiLog.i(TAG, 'onContactsChange refresh');
|
||||
this.requestItem();
|
||||
}
|
||||
|
||||
constructor(context: Context, worker: WorkerWrapper) {
|
||||
this.context = context;
|
||||
this.worker = worker;
|
||||
this.requestItem();
|
||||
ContactRepository.getInstance().registerDataChangeObserver(this.onContactsChange);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
ContactRepository.getInstance().unRegisterDataChangeObserver(this.onContactsChange);
|
||||
}
|
||||
|
||||
requestItem() {
|
||||
HiLog.i(TAG, 'Contacts requestItem!');
|
||||
if (this.page == 0) {
|
||||
this.contactList = [];
|
||||
this.page++;
|
||||
this.refresh();
|
||||
} else {
|
||||
HiLog.i(TAG, 'isLoading');
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
let actionData: any = {};
|
||||
if (this.page == 1) {
|
||||
this.limit = 50;
|
||||
} else {
|
||||
this.limit = 500;
|
||||
}
|
||||
actionData.page = this.page;
|
||||
actionData.limit = this.limit;
|
||||
this.worker.sendRequest(DataWorkerConstant[DataWorkerConstant.getAllContact], {
|
||||
actionData: actionData,
|
||||
context: this.context
|
||||
}, (result) => {
|
||||
HiLog.i(TAG, 'getAllContact and refresh, length is: ' + JSON.stringify(result.length));
|
||||
if (!ArrayUtil.isEmpty(result)) {
|
||||
this.contactList = this.contactList.concat(result);
|
||||
}
|
||||
const contactCount = result.length;
|
||||
AppStorage.SetOrCreate<ContactVo[]>('contactList', this.contactList);
|
||||
emitter.emit(this.innerEvent);
|
||||
if (contactCount < this.limit) {
|
||||
this.page = 0;
|
||||
HiLog.i(TAG, 'Contacts load completed: ' + JSON.stringify(this.contactList.length));
|
||||
} else {
|
||||
this.page++;
|
||||
setTimeout(() => {
|
||||
this.refresh();
|
||||
}, this.page == 2 ? 700 : 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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 i18n from '@ohos.i18n';
|
||||
|
||||
const YEAR_CONVERT: number = 2697;
|
||||
const YEAR_CYCLE: number = 60;
|
||||
const LUNAR_MONTH = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊"];
|
||||
const LUNAR_DAY = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四",
|
||||
"十五", "十六", "十七", "十八", "十九", "廿十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十",
|
||||
"三一"];
|
||||
const NUM_CHAR = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
|
||||
|
||||
class CalendarUtil {
|
||||
//公历转农历
|
||||
getLunarDate(date: Date) {
|
||||
let calendar = i18n.getCalendar("zh-CN", "chinese");
|
||||
calendar.setTime(date);
|
||||
const lunarMonth = calendar.get('month');
|
||||
const lunarDay = calendar.get('date');
|
||||
let lunarYear = calendar.get('era') * YEAR_CYCLE + calendar.get('year') - YEAR_CONVERT;
|
||||
return {
|
||||
year: lunarYear,
|
||||
month: lunarMonth,
|
||||
day: lunarDay
|
||||
}
|
||||
}
|
||||
|
||||
formatLunarDate(lunar: any) {
|
||||
if (!lunar) {
|
||||
return "";
|
||||
}
|
||||
let result: string = '';
|
||||
if (lunar.year) {
|
||||
result += `${lunar.year}年`
|
||||
}
|
||||
if (lunar.month != undefined) {
|
||||
result += `${LUNAR_MONTH[lunar.month]}月`
|
||||
}
|
||||
if (lunar.day) {
|
||||
result += ` ${LUNAR_DAY[lunar.day - 1]}`
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default new CalendarUtil();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,16 +13,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import settings from '@ohos.settings';
|
||||
import CalendarUtil from './CalendarUtil'
|
||||
|
||||
export default {
|
||||
numberFormatDateString(year : number, month : number, day : number) : string {
|
||||
return year + "-" + month + "-" + day;
|
||||
},
|
||||
|
||||
stringFormatDateResource(data: string): Resource{
|
||||
stringFormatDateResource(data: string, lunar: boolean): Resource|string{
|
||||
let year: number = parseInt(data.substr(0, data.indexOf("-")));
|
||||
let month: number = parseInt(data.substr(data.indexOf("-") + 1, data.lastIndexOf("-")));
|
||||
let day: number = parseInt(data.substr(data.lastIndexOf("-") + 1, data.length));
|
||||
if (lunar) {
|
||||
return CalendarUtil.formatLunarDate(CalendarUtil.getLunarDate(new Date(year,month-1,day)))
|
||||
}
|
||||
return $r("app.string.yearMonthDay", year, month, day);
|
||||
},
|
||||
|
||||
|
||||
@@ -98,6 +98,9 @@
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user