1/** 2 * Copyright (c) 2021-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 */ 15import ConfigData from '../../common/constants'; 16import Log from '../../../../../../../../../common/src/main/ets/default/Log'; 17import NotificationListener from '../../model/notificationListener'; 18import Router from '@system.router' 19 20const TAG = 'ManagementComponent-AppItemComponent'; 21 22@Component 23export default struct AppItemComponent { 24 @State canNotice: boolean= false; 25 @State appIcon: string =''; 26 @State appTitle: string =''; 27 @State appSummary: string =''; 28 @State appValue: string =''; 29 @State appArrow: string =''; 30 @State appArrowStyle: string =''; 31 @State appUri: string =''; 32 @State appSwitch: number = 0; 33 @State appBundleName: string =''; 34 @State appUid: number = 0; 35 36 build() { 37 Flex({ justifyContent: FlexAlign.SpaceBetween }) { 38 Row() { 39 if ('' !== this.appIcon) { 40 if (this.appSwitch === 2 || this.appSwitch === 3) { 41 Image(this.appIcon) 42 .width($r('app.float.appitem_notice_info_icon_width_l')) 43 .height($r('app.float.appitem_notice_info_icon_height_l')) 44 .margin({ right: $r('app.float.appitem_icon_info_margin_r') }) 45 .objectFit(ImageFit.Contain); 46 } else { 47 Image(this.appIcon) 48 .width($r('app.float.appitem_notice_info_icon_width')) 49 .height($r('app.float.appitem_notice_info_icon_height')) 50 .margin({ right: $r('app.float.appitem_icon_info_list_margin_r') }) 51 .objectFit(ImageFit.Contain); 52 } 53 } 54 Column() { 55 Text(this.appTitle) 56 .fontColor($r('sys.color.ohos_id_color_text_primary')) 57 .fontSize($r('sys.float.ohos_id_text_size_body1')) 58 .fontWeight(FontWeight.Medium) 59 .textAlign(TextAlign.Start) 60 .maxLines(ConfigData.MAX_LINES_3) 61 .textOverflow({ overflow: TextOverflow.Ellipsis }) 62 .margin({ 63 top: $r('app.float.appitem_label_margin_t'), 64 bottom: $r('app.float.appitem_label_margin_b'), 65 left: $r('app.float.page_notice_info_label_margin') 66 }); 67 Row() { 68 if (this.appSwitch === 3) { 69 if (parseInt(this.appValue) == 0) { 70 Text($r('app.string.slot_unknown')) 71 .fontColor($r('sys.color.ohos_id_color_text_primary')) 72 .fontSize($r('sys.float.ohos_id_text_size_body2')) 73 .textAlign(TextAlign.Start) 74 .maxLines(ConfigData.MAX_LINES_1) 75 .textOverflow({ overflow: TextOverflow.Ellipsis }) 76 .visibility(Visibility.Visible) 77 .margin({ 78 bottom: $r('app.float.appitem_version_margin_b'), 79 left: $r('app.float.page_notice_info_label_margin') 80 }); 81 } else if (parseInt(this.appValue) == 1) { 82 Text($r('app.string.slot_social_communication')) 83 .fontColor($r('sys.color.ohos_id_color_text_primary')) 84 .fontSize($r('sys.float.ohos_id_text_size_body2')) 85 .textAlign(TextAlign.Start) 86 .maxLines(ConfigData.MAX_LINES_1) 87 .textOverflow({ overflow: TextOverflow.Ellipsis }) 88 .visibility(Visibility.Visible) 89 .margin({ 90 bottom: $r('app.float.appitem_version_margin_b'), 91 left: $r('app.float.page_notice_info_label_margin') 92 }); 93 } else if (parseInt(this.appValue) == 2) { 94 Text($r('app.string.slot_service_information')) 95 .fontColor($r('sys.color.ohos_id_color_text_primary')) 96 .fontSize($r('sys.float.ohos_id_text_size_body2')) 97 .textAlign(TextAlign.Start) 98 .maxLines(ConfigData.MAX_LINES_1) 99 .textOverflow({ overflow: TextOverflow.Ellipsis }) 100 .visibility(Visibility.Visible) 101 .margin({ 102 bottom: $r('app.float.appitem_version_margin_b'), 103 left: $r('app.float.page_notice_info_label_margin') 104 }); 105 } else if (parseInt(this.appValue) == 3) { 106 Text($r('app.string.slot_content_information')) 107 .fontColor($r('sys.color.ohos_id_color_text_primary')) 108 .fontSize($r('sys.float.ohos_id_text_size_body2')) 109 .textAlign(TextAlign.Start) 110 .maxLines(ConfigData.MAX_LINES_1) 111 .textOverflow({ overflow: TextOverflow.Ellipsis }) 112 .visibility(Visibility.Visible) 113 .margin({ 114 bottom: $r('app.float.appitem_version_margin_b'), 115 left: $r('app.float.page_notice_info_label_margin') 116 }); 117 } else if (parseInt(this.appValue) == 0xFFFF) { 118 Text($r('app.string.slot_other')) 119 .fontColor($r('sys.color.ohos_id_color_text_primary')) 120 .fontSize($r('sys.float.ohos_id_text_size_body2')) 121 .textAlign(TextAlign.Start) 122 .maxLines(ConfigData.MAX_LINES_1) 123 .textOverflow({ overflow: TextOverflow.Ellipsis }) 124 .visibility(Visibility.Visible) 125 .margin({ 126 bottom: $r('app.float.appitem_version_margin_b'), 127 left: $r('app.float.page_notice_info_label_margin') 128 }); 129 } else { 130 Text('') 131 .fontColor($r('sys.color.ohos_id_color_text_primary')) 132 .fontSize($r('sys.float.ohos_id_text_size_body2')) 133 .textAlign(TextAlign.Start) 134 .maxLines(ConfigData.MAX_LINES_1) 135 .textOverflow({ overflow: TextOverflow.Ellipsis }) 136 .visibility(Visibility.Visible) 137 .margin({ 138 bottom: $r('app.float.appitem_version_margin_b'), 139 left: $r('app.float.page_notice_info_label_margin') 140 }); 141 } 142 } else { 143 Text($r('app.string.version')) 144 .fontColor($r('sys.color.ohos_id_color_text_primary')) 145 .fontSize($r('sys.float.ohos_id_text_size_body2')) 146 .textAlign(TextAlign.Start) 147 .maxLines(ConfigData.MAX_LINES_1) 148 .textOverflow({ overflow: TextOverflow.Ellipsis }) 149 .visibility(Visibility.Visible) 150 .margin({ 151 bottom: $r('app.float.appitem_version_margin_b'), 152 left: $r('app.float.page_notice_info_label_margin') 153 }); 154 Text(this.appSummary) 155 .fontColor($r('sys.color.ohos_id_color_text_primary')) 156 .fontSize($r('sys.float.ohos_id_text_size_body2')) 157 .textAlign(TextAlign.Start) 158 .maxLines(ConfigData.MAX_LINES_1) 159 .textOverflow({ overflow: TextOverflow.Ellipsis }) 160 .visibility(Visibility.Visible) 161 .margin({ bottom: $r('app.float.appitem_version_margin_b') }); 162 } 163 } 164 } 165 .alignItems(HorizontalAlign.Start); 166 } 167 .flexShrink(0) 168 .height(ConfigData.WH_100_100) 169 .alignItems(VerticalAlign.Center) 170 .align(Alignment.Start) 171 172 Row() { 173 if (this.appSwitch === 0) { 174 Text(this.appValue) 175 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 176 .fontSize($r('sys.float.ohos_id_text_size_body2')) 177 .margin({ right: $r('app.float.appitem_version_margin_r') }) 178 .align(Alignment.End); 179 Image(this.appArrow) 180 .width($r('app.float.itemComp_image_width')) 181 .height($r('app.float.itemComp_image_height')) 182 .visibility(Visibility.Visible); 183 } else if (this.appSwitch === 2) { 184 Text(this.appValue) 185 .width($r('app.float.itemComp_image_width')) 186 .height($r('app.float.itemComp_image_height')) 187 .margin({ right: $r('app.float.appitem_version_margin_r') }) 188 .align(Alignment.End); 189 Image($r('app.media.ic_settings_arrow')) 190 .width($r('app.float.appitem_notice_infopop_icon_width')) 191 .height($r('app.float.appitem_notice_infopop_icon_height')) 192 .margin({ right: $r('app.float.appitem_notice_info_icon_margin_r') }) 193 .visibility(Visibility.None); 194 } else if (this.appSwitch === 3) { 195 Text('') 196 .fontSize($r('app.float.appitem_version_font')) 197 .fontColor($r('app.color.appitem_version_fontcolor')) 198 .margin({ right: $r('app.float.appitem_version_margin_r') }) 199 .align(Alignment.End); 200 Image($r('app.media.ic_settings_arrow')) 201 .width($r('app.float.appitem_notice_infopop_icon_width')) 202 .height($r('app.float.appitem_notice_infopop_icon_height')) 203 .margin({ right: $r('app.float.appitem_notice_infopop_icon_margin_r') }) 204 .visibility(Visibility.None); 205 } else { 206 Toggle({ type: ToggleType.Switch, isOn: this.canNotice }) 207 .align(Alignment.End) 208 .selectedColor($r("app.color.font_color_007DFF")) 209 .width($r('app.float.toggle_comp_width')) 210 .height($r('app.float.toggle_comp_height')) 211 .onChange((flag) => { 212 Log.showInfo(TAG, `Toggle onChange param: data:${flag} `); 213 NotificationListener.enableNotification({ bundle: this.appBundleName, uid: this.appUid }, flag); 214 }) 215 } 216 } 217 .height(ConfigData.WH_100_100) 218 .alignItems(VerticalAlign.Center) 219 .align(Alignment.End); 220 } 221 .height($r('app.float.page_notice_app_item_row_height')) 222 .width(ConfigData.WH_100_100) 223 } 224 225 aboutToAppear(): void{ 226 Log.showInfo(TAG, `aboutToAppear`); 227 if (this.appSwitch === 1) { 228 NotificationListener.subscribeEnableChanged(); 229 NotificationListener.register({ bundle: this.appBundleName, 230 onEnableChanged: (stateValue: boolean) => { 231 Log.showDebug(TAG, `aboutToAppear listener call`); 232 this.canNotice = stateValue; 233 } }); 234 235 NotificationListener.isNotificationEnabled({ bundle: this.appBundleName, uid: this.appUid }) 236 .then((stateValue) => { 237 Log.showInfo(TAG, `NotificationListener.isNotificationEnabled data:${JSON.stringify(stateValue)}`); 238 this.canNotice = stateValue; 239 }) 240 .catch((error) => { 241 Log.showError(TAG, `NotificationListener.isNotificationEnabled error:${JSON.stringify(error)}`); 242 }); 243 } 244 } 245 246 aboutToDisappear(): void{ 247 Log.showInfo(TAG, `aboutToDisappear`); 248 if (this.appSwitch === 1) { 249 NotificationListener.unsubscribeEnableChanged(); 250 } 251 } 252 253 onBackPress() { 254 Log.showDebug(TAG, `onBackPress`); 255 Router.back(); 256 } 257}