| @@ -0,0 +1,273 @@ |
| +/* |
| + * Copyright (C) 2024 HiHope Open Source Organization. |
| + * 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 LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; |
| +import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; |
| +import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent'; |
| +import SwitchComponent from '../../../../../../common/component/src/main/ets/default/switchComponent'; |
| +import OneConnectShareController from '../controller/oneconnectshare/OneConnectShareController'; |
| +import { display } from '@kit.ArkUI'; |
| + |
| +const MODULE_TAG = ConfigData.TAG + '.oneConnectShare -> '; |
| + |
| +const SHARE_OPENING_TIME_10_MIN = 10; |
| +const SHARE_OPENING_TIME_UNLIMITED = 0; |
| + |
| +let oneConnectShareController: OneConnectShareController = new OneConnectShareController(); |
| +let defaultDisplay = display.getDefaultDisplaySync(); |
| + |
| +/** |
| + * mobile Network |
| + */ |
| +@Entry |
| +@Component |
| +struct OneConnectShare { |
| + @State oneConnectShareIsOn: boolean = false; |
| + @StorageLink('shareOpenTime') @Watch('refreshText') shareOpenTime: number = SHARE_OPENING_TIME_10_MIN; |
| + @State openingTimeText: Resource = $r('app.string.endTextEmpty'); |
| + @State isVertical: boolean = defaultDisplay.height > defaultDisplay.width; |
| + |
| + private openingTimeDialogController: CustomDialogController = new CustomDialogController({ |
| + builder: OpeningTimeDialog({ |
| + openingTimeText: $openingTimeText, |
| + isVertical: $isVertical |
| + }), |
| + alignment: this.isVertical ? DialogAlignment.Bottom : DialogAlignment.Center, |
| + offset: ({ dx: 0, dy: this.isVertical ? '-54vp' : 0 }), |
| + autoCancel: false, |
| + customStyle: true |
| + }); |
| + |
| + build() { |
| + Column() { |
| + GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) { |
| + Column() { |
| + HeadComponent({ headName: $r("app.string.oneConnectShare"), isActive: true }); |
| + Column() { |
| + SwitchComponent({ |
| + title: $r("app.string.oneConnectShare"), |
| + summary: "", |
| + isOn: $oneConnectShareIsOn, |
| + controller: oneConnectShareController, |
| + switchHeight: $r("app.float.wh_value_56") |
| + }) |
| + } |
| + .borderRadius($r("app.float.radius_16")) |
| + .backgroundColor($r("app.color.white_bg_color")) |
| + .width(ConfigData.WH_100_100) |
| + .margin({ top: $r("app.float.distance_12") }) |
| + .padding({ |
| + top: $r("app.float.distance_4"), |
| + bottom: $r("app.float.distance_4") |
| + }) |
| + |
| + Column() { |
| + ShareTimeComponent({ |
| + openingTimeText: $openingTimeText, |
| + settingTitle: $r("app.string.share_opening_time"), |
| + }) |
| + } |
| + .borderRadius($r("app.float.radius_16")) |
| + .backgroundColor($r("app.color.white_bg_color")) |
| + .width(ConfigData.WH_100_100) |
| + .margin({ top: $r("app.float.distance_10") }) |
| + .padding({ |
| + top: $r("app.float.distance_4"), |
| + bottom: $r("app.float.distance_4") |
| + }) |
| + .onClick(() => { |
| + this.openingTimeDialogController?.open(); |
| + }) |
| + } |
| + .useSizeType({ |
| + sm: { span: 4, offset: 0 }, |
| + md: { span: 6, offset: 1 }, |
| + lg: { span: 8, offset: 2 } |
| + }) |
| + } |
| + .width(ConfigData.WH_100_100) |
| + .height(ConfigData.WH_100_100) |
| + } |
| + .backgroundColor($r("sys.color.ohos_id_color_sub_background")) |
| + .width(ConfigData.WH_100_100) |
| + .height(ConfigData.WH_100_100) |
| + } |
| + |
| + aboutToAppear() { |
| + LogUtil.info(MODULE_TAG + 'aboutToAppear'); |
| + this.refreshText(); |
| + } |
| + |
| + aboutToDisappear() { |
| + LogUtil.info(MODULE_TAG + 'aboutToDisappear'); |
| + } |
| + |
| + refreshText() { |
| + LogUtil.info(MODULE_TAG + 'refreshText in'); |
| + this.openingTimeText = |
| + this.shareOpenTime == SHARE_OPENING_TIME_UNLIMITED ? $r("app.string.share_opening_time_unlimited") : |
| + $r("app.string.share_opening_time_minutes", this.shareOpenTime); |
| + } |
| +} |
| + |
| +@Component |
| +export struct ShareTimeComponent { |
| + @Link openingTimeText: Resource; |
| + @State isTouched: boolean = false; |
| + private settingTitle: string | Resource = ''; |
| + |
| + build() { |
| + Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { |
| + Row() { |
| + Text(this.settingTitle) |
| + .fontSize($r("app.float.font_16")) |
| + .lineHeight($r("app.float.lineHeight_22")) |
| + .fontFamily('HarmonyHeiTi') |
| + .fontColor($r("sys.color.ohos_id_color_text_primary")) |
| + .align(Alignment.Start) |
| + .margin({ |
| + left: $r("app.float.distance_12"), |
| + top: $r("app.float.distance_17"), |
| + bottom: $r("app.float.distance_17") |
| + }) |
| + } |
| + .align(Alignment.Start) |
| + .height(ConfigData.WH_100_100) |
| + |
| + Row() { |
| + Text(this.openingTimeText) |
| + .fontSize($r("app.float.font_14")) |
| + .lineHeight($r("app.float.lineHeight_19")) |
| + .align(Alignment.End) |
| + .fontWeight(FontWeight.Regular) |
| + .fontFamily('HarmonyHeiTi') |
| + .fontColor($r('sys.color.ohos_id_color_text_secondary')) |
| + .margin({ top: $r("app.float.distance_19"), bottom: $r("app.float.distance_18") }); |
| + |
| + Image('/res/image/ic_settings_arrow.svg') |
| + .width($r("app.float.wh_value_12")) |
| + .height($r("app.float.wh_value_24")) |
| + .margin({ |
| + left: $r("app.float.distance_4"), |
| + right: $r("app.float.distance_8"), |
| + top: $r("app.float.distance_16"), |
| + bottom: $r("app.float.distance_16") |
| + }) |
| + .fillColor($r("sys.color.ohos_id_color_fourth")) |
| + } |
| + .align(Alignment.End) |
| + .height(ConfigData.WH_100_100); |
| + } |
| + .width(ConfigData.WH_100_100) |
| + .height($r("app.float.wh_value_56")) |
| + .borderRadius($r("app.float.radius_16")) |
| + .linearGradient(this.isTouched ? { |
| + angle: 90, |
| + direction: GradientDirection.Right, |
| + colors: [[$r("app.color.DCEAF9"), 0.0], [$r("app.color.FAFAFA"), 1.0]] |
| + } : { |
| + angle: 90, |
| + direction: GradientDirection.Right, |
| + colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]] |
| + }) |
| + .onTouch((event?: TouchEvent | undefined) => { |
| + if (event?.type === TouchType.Down) { |
| + this.isTouched = true; |
| + } |
| + if (event?.type === TouchType.Up) { |
| + this.isTouched = false; |
| + } |
| + }) |
| + } |
| +} |
| + |
| +@CustomDialog |
| +struct OpeningTimeDialog { |
| + controller?: CustomDialogController; |
| + private openingTime: number[] = [SHARE_OPENING_TIME_10_MIN, SHARE_OPENING_TIME_UNLIMITED]; |
| + @Link isVertical : boolean ; |
| + @Link openingTimeText: Resource; |
| + @StorageLink('shareOpenTime') shareOpenTime: number = SHARE_OPENING_TIME_10_MIN; |
| + |
| + build() { |
| + Column(){ |
| + Column() { |
| + Text($r("app.string.share_opening_time")) |
| + .fontFamily("HarmonyHeiTi") |
| + .fontSize(this.isVertical ? $r('app.float.font_24') : $r('app.float.font_16')) |
| + .fontWeight(500) |
| + .height(this.isVertical ? $r("app.float.wh_value_80") : '46vp') |
| + .alignSelf(ItemAlign.Start) |
| + .fontColor('#333333') |
| + |
| + List() { |
| + ForEach(this.openingTime, (item: number, index) => { |
| + ListItem() { |
| + Column() { |
| + Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { |
| + Text(item === SHARE_OPENING_TIME_UNLIMITED ? $r("app.string.share_opening_time_unlimited") : |
| + $r("app.string.share_opening_time_minutes", item)) |
| + .fontFamily("HarmonyHeiTi") |
| + .fontSize(this.isVertical ? $r('app.float.font_20') : '12fp') |
| + .fontWeight(FontWeight.Normal) |
| + .fontColor('#333333') |
| + |
| + Radio({ value: "", group: 'radioGroup' }) |
| + .checked(this.shareOpenTime === item ? true : false) |
| + .height(this.isVertical ? $r("app.float.wh_value_16") : $r("app.float.wh_value_18")) |
| + .width(this.isVertical ? $r("app.float.wh_value_16") : $r("app.float.wh_value_18")) |
| + .onChange((value: boolean) => { |
| + if (value) { |
| + this.controller?.close(); |
| + LogUtil.info(MODULE_TAG + `onChange, item = ${item}`); |
| + if (item === SHARE_OPENING_TIME_10_MIN) { |
| + oneConnectShareController.setShareOpenTime(10); |
| + } else { |
| + oneConnectShareController.setShareOpenTime(0); |
| + } |
| + } |
| + }) |
| + .margin({right: this.isVertical ? $r('app.float.distance_12') : $r('app.float.distance_6')}) |
| + } |
| + .height(this.isVertical ? $r("app.float.wh_value_64") : '46vp') |
| + Divider() |
| + .strokeWidth('1px') |
| + .color('#D8D8D8') |
| + } |
| + } |
| + }) |
| + } |
| + |
| + Text($r("app.string.cancel_share_time")) |
| + .fontSize(this.isVertical ? $r("app.float.font_20") : $r("app.float.font_14")) |
| + .fontColor('#0959F7') |
| + .alignSelf(ItemAlign.Center) |
| + .height(this.isVertical ? $r("app.float.wh_value_64") : '46vp') |
| + .fontWeight(600) |
| + .onClick(() => { |
| + this.controller?.close(); |
| + }) |
| + } |
| + .padding({ |
| + left: this.isVertical ? $r("app.float.padding_24") : $r("app.float.radius_16"), |
| + right: this.isVertical ? $r("app.float.padding_24") : $r("app.float.radius_16") |
| + }) |
| + .alignItems(HorizontalAlign.Center) |
| + .backgroundColor($r("app.color.white_bg_color")) |
| + .borderRadius(this.isVertical ? $r("app.float.radius_24") : $r("app.float.radius_20")) |
| + } |
| + .width(this.isVertical ? ConfigData.WH_100_100 : '342vp') |
| + .padding(this.isVertical ? { left: $r("app.float.distance_12"), right: $r("app.float.distance_12")} : {}) |
| + } |
| +} |