1/*
2 * Copyright (c) 2021-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
16@Styles
17function pressedStyles() {
18  .borderRadius($r('app.float.common_borderRadius10'))
19  .backgroundColor($r('app.color.hicloud_hmos_bg'))
20}
21
22@Styles
23function normalStyles() {
24  .borderRadius($r('app.float.common_borderRadius8'))
25  .backgroundColor($r('app.color.transparent_color'))
26}
27
28@Component
29export struct TopOperateBar {
30  public addFolder: () => void; // 点击新建的事件回调
31  // 是否可用
32  @Prop isDisabled: boolean = false;
33  // 列表或宫格
34  @Consume isList: boolean;
35
36  getUsageHabitsKey(prefix: string, suffix: string): string {
37    return prefix + suffix.charAt(0).toLocaleUpperCase() + suffix.substring(1);
38  }
39
40  build() {
41    Row() {
42      Column() {
43        Image($r('app.media.hidisk_ic_add_folder'))
44          .objectFit(ImageFit.Contain)
45          .width($r('app.float.common_size24'))
46          .height($r('app.float.common_size24'))
47      }.padding({
48        left: $r('app.float.common_padding12'),
49        right: $r('app.float.common_padding12'),
50        top: $r('app.float.common_padding10'),
51        bottom: $r('app.float.common_padding10')
52      })
53      .stateStyles({
54        pressed: pressedStyles,
55        normal: normalStyles
56      })
57      .onClick(() => {
58        if (this.isDisabled) {
59          return;
60        }
61        this.addFolder.call(this);
62      })
63
64      Column() {
65        if (this.isList) {
66          Image($r('app.media.hidisk_switch_grid'))
67            .width($r('app.float.common_size24'))
68            .height($r('app.float.common_size24'))
69        } else {
70          Image($r('app.media.hidisk_switch_list'))
71            .width($r('app.float.common_size24'))
72            .height($r('app.float.common_size24'))
73        }
74      }.padding({
75        top: $r('app.float.common_padding10'),
76        bottom: $r('app.float.common_padding10'),
77        left: $r('app.float.common_padding12'),
78        right: $r('app.float.common_padding12')
79      })
80      .onClick(() => {
81        if (this.isDisabled) {
82          return;
83        }
84        this.isList = !this.isList;
85      }).stateStyles({
86        pressed: pressedStyles,
87        normal: normalStyles
88      })
89    }
90    .width('100%')
91    .padding({
92      left: $r('app.float.common_padding4'),
93      right: $r('app.float.common_padding4'),
94      top: $r('app.float.common_padding10'),
95      bottom: $r('app.float.common_padding10')
96    })
97    .justifyContent(FlexAlign.SpaceBetween)
98    .alignItems(VerticalAlign.Center)
99    .opacity(this.isDisabled ? $r('app.float.common_opacity4') : $r('app.float.common_opacity10'))
100  }
101}