1048147e0Sopenharmony_ci/** 2048147e0Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License. 5048147e0Sopenharmony_ci * You may obtain a copy of the License at 6048147e0Sopenharmony_ci * 7048147e0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8048147e0Sopenharmony_ci * 9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and 13048147e0Sopenharmony_ci * limitations under the License. 14048147e0Sopenharmony_ci */ 15048147e0Sopenharmony_ciimport mediaquery from '@ohos.mediaquery'; 16048147e0Sopenharmony_ciimport IndexController from './indexController' 17048147e0Sopenharmony_ciimport ConversationList from './conversationlist/conversationList' 18048147e0Sopenharmony_ciimport ConListController from './conversationlist/conversationListController'; 19048147e0Sopenharmony_ciimport DeviceUtil from '../utils/DeviceUtil'; 20048147e0Sopenharmony_ciimport MmsPreferences from '../utils/MmsPreferences'; 21048147e0Sopenharmony_ciimport HiLog from '../utils/HiLog' 22048147e0Sopenharmony_ciimport WantUtil from '../utils/WantUtil'; 23048147e0Sopenharmony_ci 24048147e0Sopenharmony_ciconst TAG = 'Index'; 25048147e0Sopenharmony_ci 26048147e0Sopenharmony_ci@Entry 27048147e0Sopenharmony_ci@Component 28048147e0Sopenharmony_cistruct Index { 29048147e0Sopenharmony_ci @State mIndexCtrl: IndexController = IndexController.getInstance(); 30048147e0Sopenharmony_ci @State mConListCtrl: ConListController = ConListController.getInstance(); 31048147e0Sopenharmony_ci private gridColumns: GridRowColumnOption = { sm: 4, md: 8, lg: 12 }; 32048147e0Sopenharmony_ci private girdSpan: GridColColumnOption = { sm: 4, md: 8, lg: 12 }; 33048147e0Sopenharmony_ci private gridGutter: string = '24vp'; 34048147e0Sopenharmony_ci private gridMargin: string = '24vp'; 35048147e0Sopenharmony_ci private smListener: mediaquery.MediaQueryListener; 36048147e0Sopenharmony_ci private mdListener: mediaquery.MediaQueryListener; 37048147e0Sopenharmony_ci private lgListener: mediaquery.MediaQueryListener; 38048147e0Sopenharmony_ci 39048147e0Sopenharmony_ci isBreakpointSM = (mediaQueryResult) => { 40048147e0Sopenharmony_ci if (mediaQueryResult.matches) { 41048147e0Sopenharmony_ci AppStorage.SetOrCreate('curBp', 'sm') 42048147e0Sopenharmony_ci } 43048147e0Sopenharmony_ci } 44048147e0Sopenharmony_ci isBreakpointMD = (mediaQueryResult) => { 45048147e0Sopenharmony_ci if (mediaQueryResult.matches) { 46048147e0Sopenharmony_ci AppStorage.SetOrCreate('curBp', 'md') 47048147e0Sopenharmony_ci } 48048147e0Sopenharmony_ci } 49048147e0Sopenharmony_ci isBreakpointLG = (mediaQueryResult) => { 50048147e0Sopenharmony_ci if (mediaQueryResult.matches) { 51048147e0Sopenharmony_ci AppStorage.SetOrCreate('curBp', 'lg') 52048147e0Sopenharmony_ci } 53048147e0Sopenharmony_ci } 54048147e0Sopenharmony_ci 55048147e0Sopenharmony_ci /** 56048147e0Sopenharmony_ci * The function executes after a new instance of the custom component is created and before its build function 57048147e0Sopenharmony_ci * is executed. 58048147e0Sopenharmony_ci * Allows state variables to be changed in the aboutToAppear function, and these changes will take effect in 59048147e0Sopenharmony_ci * subsequent executions of the build function. 60048147e0Sopenharmony_ci */ 61048147e0Sopenharmony_ci aboutToAppear() { 62048147e0Sopenharmony_ci this.mIndexCtrl.onInit(); 63048147e0Sopenharmony_ci this.mConListCtrl.onInit(); 64048147e0Sopenharmony_ci this.smListener = mediaquery.matchMediaSync('(320vp<width<=520vp)'); 65048147e0Sopenharmony_ci this.smListener.on('change', this.isBreakpointSM); 66048147e0Sopenharmony_ci this.mdListener = mediaquery.matchMediaSync('(520vp<width<=840vp)'); 67048147e0Sopenharmony_ci this.mdListener.on('change', this.isBreakpointMD); 68048147e0Sopenharmony_ci this.lgListener = mediaquery.matchMediaSync('(840vp<width)'); 69048147e0Sopenharmony_ci this.lgListener.on('change', this.isBreakpointLG); 70048147e0Sopenharmony_ci } 71048147e0Sopenharmony_ci 72048147e0Sopenharmony_ci /** 73048147e0Sopenharmony_ci * Function executes before custom component destructor consumption. 74048147e0Sopenharmony_ci * Changing state variables in the aboutToDisappear function is not allowed, especially changes to the @Link 75048147e0Sopenharmony_ci * variable may cause unstable application behavior. 76048147e0Sopenharmony_ci */ 77048147e0Sopenharmony_ci aboutToDisappear() { 78048147e0Sopenharmony_ci this.mConListCtrl.onDestroy(); 79048147e0Sopenharmony_ci this.mIndexCtrl.onDestroy(); 80048147e0Sopenharmony_ci this.smListener.off('change', this.isBreakpointSM); 81048147e0Sopenharmony_ci this.mdListener.off('change', this.isBreakpointMD); 82048147e0Sopenharmony_ci this.lgListener.off('change', this.isBreakpointLG); 83048147e0Sopenharmony_ci } 84048147e0Sopenharmony_ci 85048147e0Sopenharmony_ci /** 86048147e0Sopenharmony_ci * Triggers once when this page is displayed. In scenarios such as routing and application access to the foreground 87048147e0Sopenharmony_ci * and background, only customized components modified by @Entry take effect. 88048147e0Sopenharmony_ci */ 89048147e0Sopenharmony_ci async onPageShow() { 90048147e0Sopenharmony_ci WantUtil.getWant(); 91048147e0Sopenharmony_ci await MmsPreferences.getInstance().initPreferences(); 92048147e0Sopenharmony_ci this.mIndexCtrl.onShow(); 93048147e0Sopenharmony_ci this.mConListCtrl.onShow(); 94048147e0Sopenharmony_ci } 95048147e0Sopenharmony_ci 96048147e0Sopenharmony_ci /** 97048147e0Sopenharmony_ci * Triggers once when this page disappears. In scenarios such as routing and application access to the foreground 98048147e0Sopenharmony_ci * and background, only customized components modified by @Entry take effect. 99048147e0Sopenharmony_ci */ 100048147e0Sopenharmony_ci onPageHide() { 101048147e0Sopenharmony_ci this.mConListCtrl.onHide(); 102048147e0Sopenharmony_ci this.mIndexCtrl.onHide(); 103048147e0Sopenharmony_ci } 104048147e0Sopenharmony_ci 105048147e0Sopenharmony_ci /** 106048147e0Sopenharmony_ci * Triggered when a user clicks the back button. Only the customized component modified by @Entry takes effect. 107048147e0Sopenharmony_ci * If true is returned, the page processes the return logic and does not route the page. 108048147e0Sopenharmony_ci * If false is returned, the default return logic is used. 109048147e0Sopenharmony_ci * If no value is returned, the value is treated as false. 110048147e0Sopenharmony_ci */ 111048147e0Sopenharmony_ci onBackPress() { 112048147e0Sopenharmony_ci if (this.mIndexCtrl.showConList) { 113048147e0Sopenharmony_ci return this.mConListCtrl.onBackPress(); 114048147e0Sopenharmony_ci } 115048147e0Sopenharmony_ci return false; 116048147e0Sopenharmony_ci } 117048147e0Sopenharmony_ci 118048147e0Sopenharmony_ci build() { 119048147e0Sopenharmony_ci Column() { 120048147e0Sopenharmony_ci GridRow({ columns: this.gridColumns, gutter: this.gridGutter }) { 121048147e0Sopenharmony_ci GridCol({ span: this.girdSpan }) { 122048147e0Sopenharmony_ci if (this.mIndexCtrl.showConList) { 123048147e0Sopenharmony_ci Flex() { 124048147e0Sopenharmony_ci ConversationList({ 125048147e0Sopenharmony_ci mConListCtrl: $mConListCtrl 126048147e0Sopenharmony_ci }) 127048147e0Sopenharmony_ci } 128048147e0Sopenharmony_ci .width('100%') 129048147e0Sopenharmony_ci .height('100%') 130048147e0Sopenharmony_ci } 131048147e0Sopenharmony_ci } 132048147e0Sopenharmony_ci } 133048147e0Sopenharmony_ci .height('100%') 134048147e0Sopenharmony_ci } 135048147e0Sopenharmony_ci .padding({ left: this.gridMargin, right: this.gridMargin }) 136048147e0Sopenharmony_ci .width('100%') 137048147e0Sopenharmony_ci .height('100%') 138048147e0Sopenharmony_ci } 139048147e0Sopenharmony_ci}