• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 { MenuLevel } from '../../../../../../common/src/main/ets/components/Data/Constants'
17import { FileInfo } from '../../../../../../common/src/main/ets/components/Data/FileInfo'
18import { getListFile } from '../../../../../../common/src/main/ets/components/Utils/FileManagerServiceUtils'
19import { logDebug, logInfo } from '../../../../../../common/src/main/ets/components/Utils/LogUtils'
20import { changeTypeToString, updateTopPathInfo } from '../../../../../../common/src/main/ets/components/Utils/Utils'
21
22let TAG: string = 'SecondLevelByFold'
23
24@Component
25export struct SecondLevelByFold {
26  private mWorker
27  @Link mFileList: FileInfo[]
28  @Link @Watch('fileTypeChange') mType: string
29  @Link mMenuLevel: number
30  @Link mCurrentPath: string
31
32  aboutToAppear(): void{
33    logInfo(TAG, 'aboutToAppear')
34    if (globalThis.debugMode) {
35      this.mFileList = getListFile('local', this.mType, this.mCurrentPath)
36      logDebug(TAG, 'mFileList length = ' + this.mFileList.length)
37    } else {
38      this.mWorker.postMessage({
39        request_data: 'listFile',
40        device_name: 'local',
41        menu_level: this.mMenuLevel,
42        MediaType: this.mType,
43        path: this.mCurrentPath,
44        context: globalThis.context,
45      })
46    }
47
48    updateTopPathInfo([], '文件类型', '')
49    updateTopPathInfo(AppStorage.Get('topPathInfo'), changeTypeToString(this.mType), this.mCurrentPath)
50  }
51
52  fileTypeChange() {
53    logInfo(TAG, 'fileTypeChange ' + this.mType)
54    if (globalThis.debugMode) {
55      this.mFileList = getListFile('local', this.mType, this.mCurrentPath)
56    } else {
57      this.mWorker.postMessage({
58        request_data: 'listFile',
59        device_name: 'local',
60        menu_level: this.mMenuLevel,
61        MediaType: this.mType,
62        path: this.mCurrentPath,
63        context: globalThis.context,
64      })
65    }
66  }
67
68  build() {
69    Column() {
70      ForEach(this.mFileList, (item: FileInfo, index: number) => {
71        Column() {
72          SecondRowView({
73            item: item,
74            mMenuLevel: $mMenuLevel,
75            mCurrentPath: $mCurrentPath,
76            isType: $mType
77          })
78
79          Divider()
80            .color('#000000')
81            .opacity(0.05)
82            .visibility(this.mFileList.length == index + 1 ? Visibility.Hidden : Visibility.Visible)
83            .margin({ left: 40 * 1.3 })
84        }
85        .width('100%')
86        .height(56 * 1.3)
87      }, item => item.name.toString())
88    }
89    .padding({ top: 4 * 1.3, bottom: 4 * 1.3, left: 12 * 1.3, right: 12 * 1.3 })
90    .width('100%')
91    .alignItems(HorizontalAlign.Start)
92    .border({ radius: 24 })
93    .opacity(0.9)
94    .backgroundColor(Color.White)
95  }
96}
97
98@Component
99struct SecondRowView {
100  private item: FileInfo = new FileInfo('')
101  @Link mMenuLevel: number
102  @Link mCurrentPath: string
103  @Link isType: string
104
105  build() {
106    Row() {
107      Image($r("app.media.ic_type_smallfile"))
108        .width(24 * 1.3)
109        .height(24 * 1.3)
110      Text(this.item.name)
111        .fontSize(16 * 1.3)
112        .fontColor('#182431')
113        .fontWeight(FontWeight.Medium)
114        .margin({ left: 17 * 1.3 })
115      Blank()
116      Image($r("app.media.ic_right"))
117        .width(12 * 1.3)
118        .height(24 * 1.3)
119    }
120    .height(56 * 1.3)
121    .width('100%') // TODO
122    .backgroundColor(this.item.listBackground)
123    .onClick(() => {
124      logInfo(TAG, 'onClick this.mCurrentPath = ' + this.mCurrentPath)
125      this.mCurrentPath = this.item.path
126      updateTopPathInfo(AppStorage.Get('topPathInfo'), this.item.name, this.mCurrentPath)
127
128      if (this.item.path.includes('datashare:///media/root') == false) {
129        if (this.isType != 'file') {
130          logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_PIC - onClick')
131          this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_PIC
132        } else {
133          this.mMenuLevel = MenuLevel.MENU_THIRD_LEVEL_HAS_DETAIL
134          logInfo(TAG, 'MENU_THIRD_LEVEL_HAS_DETAIL - onClick')
135        }
136      }
137    })
138  }
139}