Skip to content

Commit

Permalink
Merge pull request #149 from yindushenwen/main
Browse files Browse the repository at this point in the history
阅读器 - 字体大小调节,行高调节
  • Loading branch information
MaoXiaoone authored Jul 1, 2024
2 parents 076e13a + bf8fbab commit 93bc3ed
Show file tree
Hide file tree
Showing 4 changed files with 600 additions and 495 deletions.
15 changes: 4 additions & 11 deletions entry/src/main/ets/common/utils/FileHandler.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BusinessError } from '@ohos.base';
import fs, { Options } from '@ohos.file.fs';
import { common } from '@kit.AbilityKit';
import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem';
import promptAction from '@ohos.promptAction';
import { BookList } from '../../componets/dataList/bookList';
import { addShelfBook } from '../../storage/bookListData';
import { showMessage } from '../../componets/common/promptShow';
Expand All @@ -15,22 +14,16 @@ let options: Options = {
};

export class FileHandler {
static async CopyFile(srcUrl: string) {
static CopyFile(srcUrl: string) {
let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE);
let dstPath = filePath + '/' + file.name; // file.name:《幽影之冰》.txt
addShelfBook(0,new BookList('',file.name,'会说话的肘子·未读过1','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','未分组',dstPath))
showMessage('添加到书架成功')
await fs.copyFile(file.fd, dstPath, 0).then(() => {
promptAction.showToast({
message: '导入沙箱成功',
duration: 2000
})
fs.copyFile(file.fd, dstPath, 0).then(() => {
showMessage('导入沙箱成功')
console.info("copy file success");
}).catch((err: BusinessError) => {
promptAction.showToast({
message: '导入失败',
duration: 2000
})
showMessage('导入失败')
console.error("copy file failed with error message: " + err.message + ", error code: " + err.code);
});
}
Expand Down
236 changes: 142 additions & 94 deletions entry/src/main/ets/componets/MusicPlayer.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ let seekTime: number = 15000

@Component
export struct MusicPlayer {
@StorageLink('bottomRectHeight') bottomRectHeight: number = 0
@StorageLink('topRectHeight') topRectHeight: number = 0
@StorageLink('WindowWidth') WindowWidth: number = 0
@Prop WidthMinus: number = 0
@Link isShowListen: boolean
@State hasInit: boolean = false;
@State isMusicPlaying: boolean = false; // 音乐播放状态
@State MusicPlayingTime: number = 0 // 音乐目前播放时间
Expand Down Expand Up @@ -56,128 +59,173 @@ export struct MusicPlayer {
}

build() {
Column({ space: 24 }) {
Column() {
Row() {
Stack() {
Flex() {
Text(`${this.formatMilliseconds(this.MusicPlayingTime)}/${this.formatMilliseconds(this.MusicDuration)}`)
.font({
size: 10,
weight: 400
})
}
.margin({
// 需要在模拟器查看
left: (this.WindowWidth - this.WidthMinus) * this.MusicPlayingTime / this.MusicDuration
Image($r("app.media.direction_down")).width(24)
.onClick(() => {
this.isShowListen = false
})
.borderRadius(33)
.width(70)
.zIndex(2)
.backgroundColor('#FFFFFF')
.padding({
top: 4,
bottom: 4,
left: 8,
right: 8
Blank(1)
Text("大奉打更人")
.lineHeight(24)
.fontColor("#FFFFFF")
.font({
size: 16,
weight: 500
})
Blank(1)
Image($r("app.media.more")).width(24)
}
.height(48)
.width("100%")

Line().width("100%").height(2).backgroundColor('#FFFFFF')

Blank(1)
Column() {
Row() {
Text("第1章 牢狱之灾")
}

Row() {
Text("卖报小郎君")
Button("搜作者")
}

Row() {
Text("许七安幽幽醒来,嗅到了空气中潮湿的腐臭")
}
.alignContent(Alignment.Start)
.width("100%")
}

Flex({
direction: FlexDirection.Row,
justifyContent: FlexAlign.SpaceBetween,
alignItems: ItemAlign.Center
}) {
Image($r("app.media.Backward"))
.width(24)
.onClick(() => {
avPlayer.seek(this.MusicPlayingTime - seekTime < 0 ? 0 : this.MusicPlayingTime - seekTime,
media.SeekMode.SEEK_PREV_SYNC)
})
Image($r("app.media.Previous"))
.width(24)
.onClick(() => {
})
Image($r(this.isMusicPlaying ? "app.media.stop" : "app.media.music_play"))
.fillColor(Color.White)
.width(80)
.onClick(async () => {
if (this.isMusicPlaying) {
avPlayer.pause()
avPlayer.off('timeUpdate')
} else {
avPlayer.play()
this.timeUpdateCallback()
Column({ space: 24 }) {
Row() {
Stack() {
Flex() {
Text(`${this.formatMilliseconds(this.MusicPlayingTime)}/${this.formatMilliseconds(this.MusicDuration)}`)
.font({
size: 10,
weight: 400
})
}
})
.margin({
// 需要在模拟器查看
left: (this.WindowWidth - this.WidthMinus) * this.MusicPlayingTime / this.MusicDuration
})
.borderRadius(33)
.width(70)
.zIndex(2)
.backgroundColor('#FFFFFF')
.padding({
top: 4,
bottom: 4,
left: 8,
right: 8
})

Image($r("app.media.next"))
.width(24)
.onClick(() => {
})
Image($r("app.media.forward"))
.width(24)
.onClick(() => {
avPlayer.seek(this.MusicPlayingTime + seekTime, media.SeekMode.SEEK_NEXT_SYNC)
})
}
.width("100%")
Line().width("100%").height(2).backgroundColor('#FFFFFF')
}
.alignContent(Alignment.Start)
.width("100%")
}

Flex({
direction: FlexDirection.Row,
justifyContent: FlexAlign.SpaceBetween,
alignItems: ItemAlign.Center
}) {
Column() {
Image($r("app.media.appointment_time"))
Flex({
direction: FlexDirection.Row,
justifyContent: FlexAlign.SpaceBetween,
alignItems: ItemAlign.Center
}) {
Image($r("app.media.Backward"))
.width(24)
.onClick(() => {
avPlayer.seek(this.MusicPlayingTime - seekTime < 0 ? 0 : this.MusicPlayingTime - seekTime,
media.SeekMode.SEEK_PREV_SYNC)
})
Text("定时")
}

Column() {
Image($r("app.media.speed"))
Image($r("app.media.Previous"))
.width(24)
.onClick(() => {

})
Text("语速")
}.bindSheet($$this.isShowSpeed, this.SpeedDialog(), {
height: 326,
showClose: false,
dragBar: false,
blurStyle: BlurStyle.COMPONENT_ULTRA_THIN,
})

Column() {
Image($r("app.media.add_bookshelf"))
Image($r(this.isMusicPlaying ? "app.media.stop" : "app.media.music_play"))
.fillColor(Color.White)
.width(80)
.onClick(() => {

.onClick(async () => {
if (this.isMusicPlaying) {
avPlayer.pause()
avPlayer.off('timeUpdate')
} else {
avPlayer.play()
this.timeUpdateCallback()
}
})
Text("加书架")
}

Column() {
Image($r("app.media.directory"))
Image($r("app.media.next"))
.width(24)
.onClick(() => {
})
Image($r("app.media.forward"))
.width(24)
.onClick(() => {
avPlayer.seek(this.MusicPlayingTime + seekTime, media.SeekMode.SEEK_NEXT_SYNC)
})
Text("目录")
}
}
.width("100%")
.width("100%")

Row() {
Flex({
direction: FlexDirection.Row,
justifyContent: FlexAlign.SpaceBetween,
alignItems: ItemAlign.Center
}) {
Column() {
Image($r("app.media.appointment_time"))
.width(24)
.onClick(() => {
})
Text("定时")
}

Column() {
Image($r("app.media.speed"))
.width(24)
.onClick(() => {

})
Text("语速")
}.bindSheet($$this.isShowSpeed, this.SpeedDialog(), {
height: 326,
showClose: false,
dragBar: false,
blurStyle: BlurStyle.COMPONENT_ULTRA_THIN,
})

Column() {
Image($r("app.media.add_bookshelf"))
.fillColor(Color.White)
.width(80)
.onClick(() => {

})
Text("加书架")
}

Column() {
Image($r("app.media.directory"))
.width(24)
.onClick(() => {
})
Text("目录")
}
}
.width("100%")

Row() {

}
}
}
.height("100%")
.padding({
top: this.topRectHeight,
bottom: this.bottomRectHeight,
left: 24,
right: 24
})
}

setCallback(avPlayer: media.AVPlayer) {
Expand Down
Loading

0 comments on commit 93bc3ed

Please sign in to comment.