• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 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 { AppTime, BundleStateUtil, hmsToString, getAppName, getAppIcon, getTotalTime } from 'feature-util'
17
18const TAG = 'UsageList'
19
20@Component
21export struct UsageList {
22  @State statisticals: Array<AppTime> = []
23  @State totalTime: number = 0
24
25  aboutToAppear() {
26    this.getTime()
27  }
28
29  async getTime() {
30    let bundleStateUtil = new BundleStateUtil()
31    let list = await bundleStateUtil.getTotalAppList()
32
33    this.totalTime = getTotalTime(list)
34    list.sort((a, b) => b.totalTime - a.totalTime)
35    this.statisticals = list
36  }
37
38  build() {
39    Column() {
40      Text(hmsToString(this.totalTime / 1000))
41        .width('80%')
42        .fontSize(30)
43        .textAlign(TextAlign.Start)
44        .fontWeight(FontWeight.Bold)
45        .margin({ top: 15, bottom: 15 })
46      Scroll() {
47        Column() {
48          ForEach(this.statisticals, (item) => {
49            Row() {
50              Image(getAppIcon(item.bundleName))
51                .width(80)
52                .height(80)
53                .objectFit(ImageFit.Fill)
54              Column() {
55                Row() {
56                  Text(getAppName(item.bundleName))
57                    .width('60%')
58                    .fontSize(25)
59                    .fontWeight(FontWeight.Bold)
60                  Text(hmsToString(Math.floor(item.totalTime / 1000)))
61                    .width('40%')
62                    .fontSize(22)
63                    .textAlign(TextAlign.End)
64                }
65                .width('100%')
66                .alignSelf(ItemAlign.Start)
67
68                Progress({ value: item.totalTime, total: this.totalTime, type: ProgressType.Linear })
69                  .height(20)
70                  .width('100%')
71                  .color(Color.Grey)
72                  .margin({ top: 12 })
73                  .style({ strokeWidth: 10 })
74                  .alignSelf(ItemAlign.Start)
75
76                Row() {
77                  Text($r('app.string.application_last_used')).fontSize(15)
78                  Text(hmsToString(Math.floor(item.prevAccessTime / 1000))).fontSize(15)
79                }
80              }
81              .alignItems(HorizontalAlign.Start)
82              .layoutWeight(1)
83              .padding({ left: 5, right: 5 })
84            }
85            .height(95)
86            .margin({ bottom: 50 })
87          }, item => item.bundleName)
88        }
89        .justifyContent(FlexAlign.Start)
90      }
91      .width('90%')
92      .height('80%')
93      .scrollBar(BarState.Off)
94      .backgroundColor(Color.White)
95      .scrollable(ScrollDirection.Vertical)
96      .borderRadius(10)
97      .padding(20)
98    }
99    .width('100%')
100    .height('55%')
101    .margin({ top: 40 })
102  }
103}