diff --git a/README.md b/README.md index 6062e2b534318476aa37d4364e109f5e7191b4a5..854f1119ed5df01c8fd6e6e6a9babb9adee1e090 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ ### 工程目录 ``` +├──commons +│ ├──commons/src/main/ets +│ │ └──utils +│ │ ├──FileUtils.ets // 文件工具类 +│ │ └──Logger.ets // 日志工具类 +│ └──commons/src/main/resources // 应用静态资源目录 ├──features │ ├──home/src/main/ets │ │ ├──constants @@ -34,12 +40,14 @@ │ │ └──NavigationDialog.ets // 基于Navigation弹窗组件 │ └──home/src/main/resources // 应用静态资源目录 └──products - ├──entry/src/main/ets + ├──default/src/main/ets │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 + │ ├──entrybackupability + │ │ └──EntryBackupAbility.ets // 数据备份与恢复类 │ └──pages │ └──Index.ets // 主页面 - └──entry/src/main/resources // 应用静态资源目录 + └──default/src/main/resources // 应用静态资源目录 ``` ### 具体实现 @@ -48,7 +56,7 @@ ### 相关权限 -不涉及。 +不涉及 ### 依赖 diff --git a/README_EN.md b/README_EN.md index 04719a8ab632a2bfa722c83637a2eadfe74c1d13..561adade641e692b4132bb2ca0d89b4c5257244b 100644 --- a/README_EN.md +++ b/README_EN.md @@ -21,6 +21,12 @@ Instructions: ### Project Directory ``` +├──commons +│ ├──commons/src/main/ets +│ │ └──utils +│ │ ├──FileUtils.ets // File utility class +│ │ └──Logger.ets // Log utility class +│ └──commons/src/main/resources // Static resources ├──features │ ├──home/src/main/ets │ │ ├──constants @@ -34,12 +40,14 @@ Instructions: │ │ └──NavigationDialog.ets // Navigation-based pop-up component │ └──home/src/main/resources // Static resources └──products - ├──entry/src/main/ets + ├──default/src/main/ets │ ├──entryability │ │ └──EntryAbility.ets // Entry ability + │ ├──entrybackupability + │ │ └──EntryBackupAbility.ets // Entry backup ability │ └──pages │ └──Index.ets // Index page - └──entry/src/main/resources // Static resources + └──default/src/main/resources // Static resources ``` ### How to Implement @@ -48,7 +56,7 @@ Instructions: ### Required Permissions -N/A. +N/A ### Dependency diff --git a/features/home/src/main/ets/view/CommentKeyboard.ets b/features/home/src/main/ets/view/CommentKeyboard.ets index f3899b62a6365213de059f8752b094013bbcde60..8ee0adaa1144acd8bd2ffe43044258e76eba69ad 100644 --- a/features/home/src/main/ets/view/CommentKeyboard.ets +++ b/features/home/src/main/ets/view/CommentKeyboard.ets @@ -14,6 +14,7 @@ */ import { window } from "@kit.ArkUI"; +import { BusinessError } from '@kit.BasicServicesKit'; import { NavigationDialog } from "./NavigationDialog"; import { Logger, selectImagesFromAlbum } from 'commons' @@ -44,6 +45,7 @@ export interface RichEditorSpan { type: 'text' | 'image' | 'builder' data?: User | ImageInfo } + // [End rich_editor_span] @Component @@ -69,17 +71,29 @@ export struct CommentKeyboard { aboutToAppear(): void { window.getLastWindow(this.getUIContext().getHostContext()).then(win => { this.addKeyboardHeightListener(win); + }).catch((err: BusinessError) => { + Logger.error(TAG, + `getLastWindow Failed. Code:${err.code}, message:${err.message}`); }); } aboutToDisappear(): void { window.getLastWindow(this.getUIContext().getHostContext()).then(win => { this.removeKeyboardHeightListener(win); + }).catch((err: BusinessError) => { + Logger.error(TAG, + `getLastWindow Failed. Code:${err.code}, message:${err.message}`); }); } getResourceString(resource: Resource): string { - return this.getUIContext().getHostContext()!.resourceManager.getStringSync(resource.id); + try { + return this.getUIContext().getHostContext()!.resourceManager.getStringSync(resource.id); + } catch (exception) { + Logger.error(TAG, + `getLastWindow Failed. Code:${exception.code}, message:${exception.message}`); + return ''; + } } addKeyboardHeightListener(win: window.Window) { @@ -93,7 +107,9 @@ export struct CommentKeyboard { // if close keyboard, don't set keyboardHeight, avoid EmojiKeyboard height is 0 if (!this.isEmojiKeyboardVisible) { // When the photo picker is pulled up, the soft keyboard will also be dismissed, but no need to exit the comment page - if (this.isPhotoPickerVisible) return; + if (this.isPhotoPickerVisible) { + return; + } // handle system keyboard close button click Logger.info(TAG, 'click soft keyboard close button'); this.navDialogPageInfos.pop(); @@ -105,6 +121,7 @@ export struct CommentKeyboard { removeKeyboardHeightListener(win: window.Window) { win.off('keyboardHeightChange'); } + // [End comment_keyboard1] getOperateButtons(): OperateButton[] { @@ -127,7 +144,6 @@ export struct CommentKeyboard { this.isPhotoPickerVisible = false; }); } - // [Start comment_keyboard2] // features/home/src/main/ets/view/CommentKeyboard.ets onAtButtonClick: (event?: ClickEvent) => void = event => { @@ -140,11 +156,9 @@ export struct CommentKeyboard { onEmojiButtonClick: (event: ClickEvent) => void = event => { this.isEmojiKeyboardVisible = !this.isEmojiKeyboardVisible; } - onRichEditorClick: (event: ClickEvent) => void = event => { this.isEmojiKeyboardVisible = false; } - // [Start comment_keyboard3] // features/home/src/main/ets/view/CommentKeyboard.ets onEmojiClick: (icon: Resource) => void = icon => { @@ -205,6 +219,7 @@ export struct CommentKeyboard { // [EndExclude onatfriend_click] this.setBuilderSpans(controller, friend); } + // [End onatfriend_click] @Builder @@ -214,6 +229,7 @@ export struct CommentKeyboard { .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) } + // [End comment_keyboard6] // [End comment_keyboard5] @@ -236,6 +252,7 @@ export struct CommentKeyboard { return this.isBuilderSpan(span) ? count + 1 : count; }, 0); } + // [End private] // [End comment_keyboard7] @@ -254,6 +271,7 @@ export struct CommentKeyboard { } return true; } + // [End comment_keyboard8] deleteBuilderSpan() { @@ -278,7 +296,6 @@ export struct CommentKeyboard { this.isAtFriendListVisible = false; } } - aboutToIMEInput: (value: RichEditorInsertValue) => boolean = value => { if (value.insertValue === '@') { this.onAtButtonClick(); @@ -286,7 +303,6 @@ export struct CommentKeyboard { } return true; } - onDeleteComplete: () => void = () => { const controller = this.richEditorController; const offset = controller.getCaretOffset(); @@ -351,7 +367,9 @@ export struct CommentKeyboard { GridItem() { Image(icon) .width(45) - .onClick(() => { this.onEmojiClick(icon) }) + .onClick(() => { + this.onEmojiClick(icon) + }) } }) } @@ -362,8 +380,10 @@ export struct CommentKeyboard { .rowsGap(15) .padding(10) .scrollBar(BarState.Off) + // [EndExclude comment_keyboard10] } + // [End comment_keyboard10] @Builder @@ -373,7 +393,9 @@ export struct CommentKeyboard { ListItem() { Image(icon) .width(40) - .onClick(() => { this.onEmojiClick(icon) }) + .onClick(() => { + this.onEmojiClick(icon) + }) } }) } @@ -434,5 +456,6 @@ export struct CommentKeyboard { .backgroundColor(Color.White) } } + // [End comment_keyboard11] } \ No newline at end of file diff --git a/features/home/src/main/ets/view/HomeContent.ets b/features/home/src/main/ets/view/HomeContent.ets index 20127c1706212067e09ee2d113bfd285c8222286..5298fa7c5e6929375a685859e88be9bfff48e3f6 100644 --- a/features/home/src/main/ets/view/HomeContent.ets +++ b/features/home/src/main/ets/view/HomeContent.ets @@ -13,10 +13,13 @@ * limitations under the License. */ -import { HomeConstants } from "../constants/HomeConstants"; import { display } from "@kit.ArkUI"; +import { HomeConstants } from "../constants/HomeConstants"; +import { Logger } from "commons"; -interface OperateButtonType { +const TAG = 'HomeContent'; + +interface OperateButtonType { icon: Resource count: number onClick?: (event: ClickEvent) => void @@ -26,7 +29,8 @@ interface OperateButtonType { struct OperateButton { @Require @Prop icon: Resource; @Require @Prop count: number; - handleClick: (event: ClickEvent) => void = event => {} + handleClick: (event: ClickEvent) => void = event => { + } build() { Column() { @@ -71,8 +75,13 @@ export struct HomeContent { } async setFullHeight() { - const rects = await display.getAllDisplays() - this.fullHeight = this.getUIContext().px2vp(rects[0].height) + try { + const rects = await display.getAllDisplays(); + this.fullHeight = this.getUIContext().px2vp(rects[0].height); + } catch (exception) { + Logger.error(TAG, + `getAllDisplays Failed. Code:${exception.code}, message:${exception.message}`); + } } onCommentButtonClick(event: ClickEvent) { @@ -93,6 +102,7 @@ export struct HomeContent { Text($r('app.string.video_title_time')) .videoInfoStyle() } + Text($r('app.string.video_info')) .videoInfoStyle() Row({ space: 5 }) { @@ -105,6 +115,7 @@ export struct HomeContent { .padding(16) .width('80%') .alignItems(HorizontalAlign.Start) + Column({ space: HomeConstants.MEDIUM_SPACE }) { Image($r('app.media.avatar')) .width($r('app.float.avatar_width')) diff --git a/products/default/src/main/ets/entryability/EntryAbility.ets b/products/default/src/main/ets/entryability/EntryAbility.ets index 31333cfc33395f7109359d1fe711693166b9b620..406d47d980365ce305d6a5fa672402eeb938b197 100644 --- a/products/default/src/main/ets/entryability/EntryAbility.ets +++ b/products/default/src/main/ets/entryability/EntryAbility.ets @@ -16,21 +16,28 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - const mainWindow = windowStage.getMainWindowSync(); - mainWindow.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, 'testTag', 'Succeeded in setting the window layout to full-screen mode'); - }).catch((err: BusinessError) => { - hilog.info(0x0000, 'testTag', 'Failed to set the window layout to full-screen mode. Cause: %{public}s', JSON.stringify(err) ?? ''); - }) - - const sysBarProps: window.SystemBarProperties = { - statusBarContentColor: '#ffffff' - }; - mainWindow.setWindowSystemBarProperties(sysBarProps).then(() => { - hilog.info(0x0000, 'testTag', 'Succeeded in setting the system bar properties'); - }).catch((err: BusinessError) => { - hilog.info(0x0000, 'testTag', 'Failed to set system bar properties. Cause: %{public}s', JSON.stringify(err) ?? ''); - }) + try { + const mainWindow = windowStage.getMainWindowSync(); + mainWindow.setWindowLayoutFullScreen(true).then(() => { + hilog.info(0x0000, 'testTag', 'Succeeded in setting the window layout to full-screen mode'); + }).catch((err: BusinessError) => { + hilog.info(0x0000, 'testTag', 'Failed to set the window layout to full-screen mode. Cause: %{public}s', + JSON.stringify(err) ?? ''); + }) + + const sysBarProps: window.SystemBarProperties = { + statusBarContentColor: '#ffffff' + }; + mainWindow.setWindowSystemBarProperties(sysBarProps).then(() => { + hilog.info(0x0000, 'testTag', 'Succeeded in setting the system bar properties'); + }).catch((err: BusinessError) => { + hilog.info(0x0000, 'testTag', 'Failed to set system bar properties. Cause: %{public}s', + JSON.stringify(err) ?? ''); + }) + } catch (exception) { + hilog.error(0x0000, 'testTag', + `getMainWindowSync Failed. Code:${exception.code}, message:${exception.message}`); + } windowStage.loadContent('pages/Index', (err) => { if (err.code) {