1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ObjectUtil } from '../../../../../common/src/main/ets/util/ObjectUtil'; 17import { HiLog } from '../../../../../common/src/main/ets/util/HiLog'; 18 19const TAG = 'CallLogSetting'; 20 21export enum MergeRule { 22 TIME = 1, 23 CONTACT = 2 24} 25 26export default class CallLogSetting { 27 private static readonly CALL_LOG_SETTING_PREFERENCE_NAME: string = 'call_log_setting'; 28 private static readonly KEY_MERGE_RULE: string = 'merge_rule'; 29 private static instance: CallLogSetting; 30 31 private constructor() { 32 } 33 34 public static getInstance(): CallLogSetting { 35 if (!CallLogSetting.instance) { 36 CallLogSetting.instance = new CallLogSetting(); 37 } 38 return CallLogSetting.instance; 39 } 40 41 setMergeRule(mergeRule: MergeRule) { 42 HiLog.i(TAG, 'MergeRule: ' + JSON.stringify(mergeRule)); 43 AppStorage.SetOrCreate(CallLogSetting.KEY_MERGE_RULE, mergeRule); 44 } 45 46 getMergeRule(): MergeRule { 47 if (!AppStorage.Has(CallLogSetting.KEY_MERGE_RULE)) { 48 return MergeRule.TIME; 49 } 50 let rst = AppStorage.Get(CallLogSetting.KEY_MERGE_RULE); 51 if (rst == MergeRule.CONTACT) { 52 return MergeRule.CONTACT; 53 } 54 return MergeRule.TIME; 55 } 56}