• 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 { MediaName } from "../Data/Constants"
17import { TopPathInfo } from '../Data/TopPathInfo'
18import { logInfo } from './LogUtils'
19
20var TAG: string = 'Utils'
21
22const TYPE_INDEX = 0
23const NAME_INDEX = 1
24
25var strTypeArr = [
26	[MediaName.IMAGE, '图片'],
27	[MediaName.VIDEO, '视频'],
28	[MediaName.AUDIO, '音乐'],
29	[MediaName.FILE, '文档'],
30]
31
32export function changeTypeToString(mediaType: string): string {
33	logInfo(TAG, 'changeTypeToString type = ' + mediaType)
34	for (var i = 0; i < strTypeArr.length; i++) {
35		if (strTypeArr[i][0] == mediaType) {
36			return strTypeArr[i][1]
37		}
38	}
39	return ''
40}
41
42export function changeStringToType(name: string): string {
43	logInfo(TAG, 'changeStringToType type = ' + name)
44	for (var i = 0; i < strTypeArr.length; i++) {
45		if (strTypeArr[i][1] == name) {
46			return strTypeArr[i][0]
47		}
48	}
49	return ''
50}
51
52var fileSuffixAndType = [
53	['.doc', $r("app.media.ic_file_doc"), $r("app.string.file_docx")],
54	['.html', $r("app.media.ic_file_html"), $r("app.string.file_html")],
55	['.pdf', $r("app.media.ic_file_pdf"), $r("app.string.file_pdf")],
56	['.pptx', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")],
57	['.ppt', $r("app.media.ic_file_pptx"), $r("app.string.file_pptx")],
58	['.rar', $r("app.media.ic_file_rar"), $r("app.string.file_rar")],
59	['.txt', $r("app.media.ic_file_txt"), $r("app.string.file_txt")],
60	['.xls', $r("app.media.ic_file_xls"), $r("app.string.file_xls")],
61	['.xml', $r("app.media.ic_file_xml"), $r("app.string.file_xml")],
62	['.zip', $r("app.media.ic_file_zip"), $r("app.string.file_zip")],
63]
64
65export function getShowIconBySuffix(suffix: string): string | Resource {
66	logInfo(TAG, 'getShowIconBySuffix suffix = ' + suffix)
67	for (var i = 0; i < fileSuffixAndType.length; i++) {
68		if (isTwoStringEqual(fileSuffixAndType[i][0].toString(), suffix)) {
69			return fileSuffixAndType[i][1]
70		}
71	}
72	return $r("app.media.ic_file_unknown")
73}
74
75function isTwoStringEqual(src: string, tar: string) {
76	if (src.indexOf(tar) == 0 && tar.indexOf(src) == 0) {
77		return true;
78	}
79	return false;
80}
81
82export function updateTopPathInfo(currentPathInfo: Array<TopPathInfo>, name: string, path: string) {
83	currentPathInfo.forEach((item: TopPathInfo) => {
84		item.opacity = 0.4
85	})
86
87	currentPathInfo.push(new TopPathInfo(name, path))
88	AppStorage.Set('topPathInfo', currentPathInfo)
89	return currentPathInfo
90}