18779efd5Sopenharmony_ci/** 28779efd5Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License. 58779efd5Sopenharmony_ci * You may obtain a copy of the License at 68779efd5Sopenharmony_ci * 78779efd5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88779efd5Sopenharmony_ci * 98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and 138779efd5Sopenharmony_ci * limitations under the License. 148779efd5Sopenharmony_ci */ 158779efd5Sopenharmony_ci 168779efd5Sopenharmony_ciimport { ObjectUtil } from '../../../../../common/src/main/ets/util/ObjectUtil'; 178779efd5Sopenharmony_ciimport { HiLog } from '../../../../../common/src/main/ets/util/HiLog'; 188779efd5Sopenharmony_ci 198779efd5Sopenharmony_ciconst TAG = 'CallLogSetting'; 208779efd5Sopenharmony_ci 218779efd5Sopenharmony_ciexport enum MergeRule { 228779efd5Sopenharmony_ci TIME = 1, 238779efd5Sopenharmony_ci CONTACT = 2 248779efd5Sopenharmony_ci} 258779efd5Sopenharmony_ci 268779efd5Sopenharmony_ciexport default class CallLogSetting { 278779efd5Sopenharmony_ci private static readonly CALL_LOG_SETTING_PREFERENCE_NAME: string = 'call_log_setting'; 288779efd5Sopenharmony_ci private static readonly KEY_MERGE_RULE: string = 'merge_rule'; 298779efd5Sopenharmony_ci private static instance: CallLogSetting; 308779efd5Sopenharmony_ci 318779efd5Sopenharmony_ci private constructor() { 328779efd5Sopenharmony_ci } 338779efd5Sopenharmony_ci 348779efd5Sopenharmony_ci public static getInstance(): CallLogSetting { 358779efd5Sopenharmony_ci if (!CallLogSetting.instance) { 368779efd5Sopenharmony_ci CallLogSetting.instance = new CallLogSetting(); 378779efd5Sopenharmony_ci } 388779efd5Sopenharmony_ci return CallLogSetting.instance; 398779efd5Sopenharmony_ci } 408779efd5Sopenharmony_ci 418779efd5Sopenharmony_ci setMergeRule(mergeRule: MergeRule) { 428779efd5Sopenharmony_ci HiLog.i(TAG, 'MergeRule: ' + JSON.stringify(mergeRule)); 438779efd5Sopenharmony_ci AppStorage.SetOrCreate(CallLogSetting.KEY_MERGE_RULE, mergeRule); 448779efd5Sopenharmony_ci } 458779efd5Sopenharmony_ci 468779efd5Sopenharmony_ci getMergeRule(): MergeRule { 478779efd5Sopenharmony_ci if (!AppStorage.Has(CallLogSetting.KEY_MERGE_RULE)) { 488779efd5Sopenharmony_ci return MergeRule.TIME; 498779efd5Sopenharmony_ci } 508779efd5Sopenharmony_ci let rst = AppStorage.Get(CallLogSetting.KEY_MERGE_RULE); 518779efd5Sopenharmony_ci if (rst == MergeRule.CONTACT) { 528779efd5Sopenharmony_ci return MergeRule.CONTACT; 538779efd5Sopenharmony_ci } 548779efd5Sopenharmony_ci return MergeRule.TIME; 558779efd5Sopenharmony_ci } 568779efd5Sopenharmony_ci}