• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Logger from '../util/Logger'
17import { updateData } from '../mock/DialogData'
18import { dialogFeature } from '../feature/DialogFeature'
19import { AbilityContext } from '../model/DialogDataModel'
20import { RequestResponseContent } from '../net/RequestResponse'
21
22const TAG: string = 'UpdateDialog'
23
24// 按钮共同样式
25@Styles function commonButtonStyle () {
26  .width('45%')
27  .height(50)
28  .alignSelf(ItemAlign.Center)
29  .borderRadius(20)
30}
31
32@CustomDialog
33export struct UpdateDialog {
34  @State currentVersion: string = ''
35  @State richTextData: string = ''
36  @State lastVersion: string = ''
37  @State updateContent: string = ''
38  private context?: AbilityContext
39  private customDialogController?: CustomDialogController
40
41  async aboutToAppear() {
42    this.context = getContext(this) as AbilityContext
43    this.richTextData = await dialogFeature.getRichTextData(this.context)
44    Logger.info(TAG, `this.richTextData = ${this.richTextData}`)
45    await this.getData()
46  }
47
48  async getData() {
49    try {
50      this.currentVersion = await dialogFeature.getCurrentVersion()
51      let requestResponseContent: RequestResponseContent = await dialogFeature.getLastVersion()
52      if (requestResponseContent.content === null || requestResponseContent.content === undefined) {
53        return
54      }
55      this.updateContent = requestResponseContent.content
56      if (requestResponseContent.versionName === null || requestResponseContent.versionName === undefined) {
57        return
58      }
59      this.lastVersion = requestResponseContent.versionName
60    } catch (err) {
61      Logger.info(TAG, `getApplicationVersion is fail`)
62    }
63  }
64
65  build() {
66    Stack() {
67      // mask 遮罩层
68      Column()
69        .width('100%')
70        .height('100%')
71        .backgroundColor('#000000')
72        .opacity(.4)
73      Column() {
74        Stack({ alignContent: Alignment.TopStart }) {
75          Text($r('app.string.update_title'))
76            .fontSize(30)
77            .fontColor('#FFFFFF')
78            .fontWeight(500)
79            .margin({ top: 70, left: 76 })
80
81          Text(`V${(this.lastVersion || updateData.versionName)}`)
82            .fontSize(16)
83            .backgroundColor('#FFFFFF')
84            .textAlign(TextAlign.Center)
85            .fontColor('#E9304E')
86            .borderRadius(20)
87            .width(80)
88            .aspectRatio(2.8)
89            .margin({ top: 110, left: 76 })
90
91          Column() {
92            // 富文本容器
93            Scroll() {
94              Column() {
95                if (this.richTextData) {
96                  RichText((this.updateContent || this.richTextData))
97                    .width('100%')
98                    .height('100%')
99                }
100              }
101              .width('100%')
102            }
103            .height(200)
104
105            Row() {
106              Button($r('app.string.cancel'))
107                .commonButtonStyle()
108                .fontSize(20)
109                .margin({ left: 10 })
110                .fontColor('#E92F4F')
111                .backgroundColor('rgba(0,0,0,0.05)')
112                .margin({ right: 10 })
113                .onClick(() => {
114                  this.customDialogController.close()
115                })
116                .key("cancel")
117
118              Button($r('app.string.update_now'))
119                .commonButtonStyle()
120                .fontSize(20)
121                .margin({ right: 10 })
122                .fontColor('#FFFFFF')
123                .backgroundColor('#E92F4F')
124                .margin({ left: 10 })
125                .onClick(() => {
126                  this.customDialogController.close()
127                })
128                .key("Now")
129            }
130            .margin({ top: 30 })
131          }
132          .width('100%')
133          .padding({ left: 25, right: 25 })
134          .margin({ top: 230 })
135        }
136        .height(600)
137        .width('100%')
138        .backgroundImage($r('app.media.update'), ImageRepeat.NoRepeat)
139        .backgroundImageSize(ImageSize.Contain)
140      }
141      .width(480)
142      .padding({ left: 16, right: 16 })
143    }
144    .width('100%')
145    .height('100%')
146  }
147}
148
149
150