Skip to content

Commit

Permalink
Merge branch 'mgz0227:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yindushenwen authored Jul 2, 2024
2 parents 54a515b + 1aa66cc commit 5982e75
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 170 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CodeQL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
name: "CodeQL"

on:
push:
branches: [ "main" ]
# push:
# branches: [ "main" ]
# pull_request:
# branches: [ "main" ]
schedule:
Expand Down
1 change: 1 addition & 0 deletions entry/src/main/ets/common/constants/CommonConstants.ets
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default class CommonConstants {
/**
* 小说AppStorage存储key
*/
static readonly PREFERENCES_BOOK_TYPE_NUMBER:string = 'PREFERENCES_BOOK_TYPE_NUMBER'
static readonly PREFERENCES_BOOK_INIT_KEY:string = 'PREFERENCES_BOOK_INIT_KEY'
static readonly PREFERENCES_BOOK_DATA_KEY:string = 'PREFERENCES_BOOK_DATA_KEY'
static readonly KEY_NOVEL_BOOK_DATA:string = 'KEY_NOVEL_BOOK_DATA'
Expand Down
47 changes: 47 additions & 0 deletions entry/src/main/ets/common/utils/DataPreferencesUtils.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import CommonConstants from '../constants/CommonConstants';
import dataPreferences from '@ohos.data.preferences';

// 获取context
let context = getContext(this);
export default class bookDataPreferences {

static shared = new bookDataPreferences();
preferences?: dataPreferences.Preferences;
preferencesName: string = CommonConstants.PREFERENCES_BOOK_DATA_KEY;

// 初始化preferences实例
initPreferences() {
this.preferences = dataPreferences.getPreferencesSync(context, { name: this.preferencesName });
}

// 设置数据
set(key: string, value: dataPreferences.ValueType) {
if (!this.preferences) {
this.initPreferences();
}
console.log('setinitPreferences', key, value)
this.preferences?.putSync(key, value);
this.preferences?.flush();
}

// 获取数据
get(key: string): dataPreferences.ValueType | null | undefined {
if (!this.preferences) {
this.initPreferences();
}
let value = this.preferences?.getSync(key, null);;
return value;
}

// 删除数据
delete(key: string) {
if (!this.preferences) {
this.initPreferences();
}
if (this.preferences?.hasSync(key)) {
this.preferences.deleteSync(key);
this.preferences.flush();
}
}
}

5 changes: 3 additions & 2 deletions entry/src/main/ets/common/utils/FileHandler.ets
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export class FileHandler {
let chapterNumber = 0
const chapters: chaptersItem[] = [];
console.info('readFileUrl:' + readFileUrl)
const regex = /===第(.*?)章 (.*?)===/g;
//const regex = /===第(.*?)章 (.*?)===/g;
const regex = /^[=|<]{0,4}((?:序章|楔子|番外|第\s{0,4})([\d〇零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\s{0,4})(?:章|回(?!合)|话(?!说)|节(?!课)|卷|篇(?!张)))(.{0,30})/g;
await fs.readLines(readFileUrl, options).then((readerIterator: fs.ReaderIterator) => {
for (let it = readerIterator.next();!it.done; it = readerIterator.next()) {
const match = regex.exec(it.value);
if (match) {
const chapterTitleNumber = match[1]; // 书源内部章节
const chapterTitle = match[2];
const chapterTitle = match[3];
chapterNumber++
chapters.push(new chaptersItem(chapterNumber, chapterTitle, chapterTitleNumber, ''))
} else {
Expand Down
1 change: 1 addition & 0 deletions entry/src/main/ets/componets/common/ReadShow.ets
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default struct ReadShow {
}
.alignItems(HorizontalAlign.Start)
}
.layoutWeight(1)
.alignItems(HorizontalAlign.Start)
.padding({left:15})
Column(){
Expand Down
57 changes: 50 additions & 7 deletions entry/src/main/ets/pages/view/BookDetailPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import TagIndex from '../../componets/bookDetail/TagIndex'
import { router, SwipeRefresher } from '@kit.ArkUI'
import NoteIndex from '../../componets/bookDetail/note/NoteIndex'
import { BookList } from 'ets/componets/dataList/bookList'
import { chaptersItem } from '../../componets/dataList/ReaderChaptersItem'
import { FileHandler } from '../../common/utils/FileHandler'

/**
* 标题图片样式
Expand Down Expand Up @@ -78,10 +80,13 @@ struct BookDetailPage {
offset: { dx: 0, dy: -100 }
})

onPageShow(): void {
@State txtFile: chaptersItem[] = [];

async onPageShow() {
console.log('router BookDetailPage:' + JSON.stringify(router.getParams()))
if (router.getParams() as BookList) {
this.bookData = router.getParams() as BookList
this.txtFile = await FileHandler.readFile(this.bookData.fileLink) //txt小说
}
}

Expand All @@ -108,18 +113,56 @@ struct BookDetailPage {
Tabs({ barPosition: BarPosition.Start }) {
TabContent() {
Column() {
SwipeRefresher({
content: '目录加载中...',
isLoading: true
})
if (this.txtFile.length === 0 || undefined) {
SwipeRefresher({
content: '目录加载中...',
isLoading: true
})
} else {
List() {
ForEach(this.txtFile, (item: chaptersItem, index: number) => {
ListItem() {
Button({ type: ButtonType.Normal }) {
Row() {
Text(`${item.chapterTitleNumber} ${item.title}`.replace(new RegExp('\\s{1,}','g'),' ').replaceAll('=', '')).layoutWeight(1)
}
.width('100%')
.padding({
left: 20,
right: 20,
top: 12,
bottom: 12
})
}
.borderRadius(10)
.width('100%')
.backgroundColor(Color.White)
.onClick(() => {
// 跳转到阅读器
router.pushUrl({
url: 'pages/view/Reader/ReaderPage',
//跳转到对应的章节,额,不会传这个参。。。只知道传index过去,对面TotalChapters接收
params: this.bookData
})
})
}
})
}
.divider({
strokeWidth: 0.8,
color: '#cccccc',
startMargin: 12,
endMargin: 12
})
}
}
}
.tabBar(this.catalogTab(0, '目录', 548))
.tabBar(this.catalogTab(0, '目录', this.txtFile.length))

TabContent() {
Column() {
SwipeRefresher({
content: '目录加载中...',
content: '书源加载中...',
isLoading: true
})
}
Expand Down
12 changes: 7 additions & 5 deletions entry/src/main/ets/pages/view/Reader/ReaderPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ struct ReaderPage {
.onClick(() => {
router.back()
})
Text(`第${this.txtFile[this.CurrentChapters]?.chapterTitleNumber}章 ${this.txtFile[this.CurrentChapters]?.title}`)
Blank(1)
Text(`${this.txtFile[this.CurrentChapters]?.chapterTitleNumber} ${this.txtFile[this.CurrentChapters]?.title}`.replace(new RegExp('\\s{1,}','g'),' ').replaceAll('=',''))
.layoutWeight(1)
.maxLines(1)
.textOverflow({overflow:TextOverflow.Ellipsis})
Row({ space: 16 }) {
Image($r("app.media.refresh"))
.width(24)
Expand Down Expand Up @@ -392,11 +394,11 @@ struct ReaderPage {
Scroll() {
Column() {
Row() {
Text(this.txtFile[this.CurrentChapters]?.title)
Text(`${this.txtFile[this.CurrentChapters]?.chapterTitleNumber} ${this.txtFile[this.CurrentChapters]?.title}`.replace(new RegExp('\\s{1,}','g'),' ').replaceAll('=',''))
.lineHeight(20)
.font({
size: 12,
weight: 400
size: 15,
weight: 700
})
.fontColor("rgba(0, 0, 0, 0.88)")
}
Expand Down
1 change: 1 addition & 0 deletions entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ShelfBookList from './Shelf/ShelfBookList'
import picker from '@ohos.file.picker'
import { FileHandler } from 'ets/common/utils/FileHandler'
import RefreshComponent from '../../../componets/common/RefreshComponent'
import CommonConstants from '../../../common/constants/CommonConstants'

@Component
export default struct IndexShelf {
Expand Down
11 changes: 6 additions & 5 deletions entry/src/main/ets/pages/view/bookShelf/cartoonPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import BookInfo from './BookInfo'
import { promptAction } from '@kit.ArkUI'
import BookInfoGrid from './BookInfoGrid'
import CommonConstants from '../../../common/constants/CommonConstants'
import { delBookListAll, delBookListByBookId, getBookData } from '../../../storage/bookListData'
import { delBookListAll, delBookListByBookId} from '../../../storage/bookListData'
import { updateShelfBookData } from '../../../preferences/bookDataPreferences'

/**
* 漫画
Expand All @@ -15,11 +16,11 @@ export default struct cartoonPage{
@Prop currentIndex:number
@State lastIndex:string = '9999'
@Prop @Watch('onIsEXHIBITChange') EXHIBIT:string
@StorageLink(CommonConstants.KEY_CARTOON_BOOK_DATA)
@Watch('updatePreferences')cartoonList:BookList[] = []

@State cartoonList:BookList[] = []

aboutToAppear(): void {
this.cartoonList = getBookData(1) as BookList[] //初始化数据
updatePreferences(){
updateShelfBookData(this.cartoonList, 0)
}

onIsClearChange() {
Expand Down
32 changes: 6 additions & 26 deletions entry/src/main/ets/pages/view/bookShelf/novelPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import BookInfo from './BookInfo'
import { promptAction } from '@kit.ArkUI'
import BookInfoGrid from './BookInfoGrid'
import CommonConstants from '../../../common/constants/CommonConstants'
import { delBookListAll, delBookListByBookId, getBookData } from '../../../storage/bookListData'
import { delBookListAll, delBookListByBookId } from '../../../storage/bookListData'
import { updateShelfBookData } from '../../../preferences/bookDataPreferences'


@Component
Expand All @@ -15,12 +16,10 @@ export default struct novelPage{
@Prop bookType:string
@Prop @Watch('onIsEXHIBITChange') EXHIBIT:string

@State bookList:BookList[] = []

aboutToAppear(): void {
this.bookList = getBookData(0) as BookList[] //初始化数据
console.log('test----------')
console.log(JSON.stringify(this.bookList))
@StorageLink(CommonConstants.KEY_NOVEL_BOOK_DATA)
@Watch('updatePreferences')bookList:BookList[] = []
updatePreferences(){
updateShelfBookData(this.bookList, 0)
}

//监听isClear变化
Expand All @@ -35,25 +34,6 @@ export default struct novelPage{
}
}

// isChangeManageDelete() {
// if (this.manageDelete) {
// if (this.checkBookList === null || this.checkBookList.length === 0) {
// promptAction.showToast({
// message: '请选择要删除的内容',
// duration: 1000,
// })
// this.manageDelete = false
// return
// }
// this.bookList = []
// console.log('删除')
// this.manageDelete = false
// }
// }
// isChangeBookList() {
// console.log(this.checkBookList + '')
// }

//监听EXHIBIT变化
onIsEXHIBITChange() {
console.log(this.EXHIBIT)
Expand Down
11 changes: 7 additions & 4 deletions entry/src/main/ets/pages/view/bookShelf/soundPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import BookInfo from './BookInfo'
import { promptAction } from '@kit.ArkUI'
import BookInfoGrid from './BookInfoGrid'
import CommonConstants from '../../../common/constants/CommonConstants'
import { delBookListAll, delBookListByBookId, getBookData } from '../../../storage/bookListData'
import { delBookListAll, delBookListByBookId } from '../../../storage/bookListData'
import { updateShelfBookData } from '../../../preferences/bookDataPreferences'

/**
* 有声书
Expand All @@ -16,11 +17,13 @@ export default struct soundPage{
@State lastIndex:string = '9999'
@Prop @Watch('onIsEXHIBITChange') EXHIBIT:string

soundList:BookList[] = []
@StorageLink(CommonConstants.KEY_SOUND_BOOK_DATA)
@Watch('updatePreferences')soundList:BookList[] = []

aboutToAppear(): void {
this.soundList = getBookData(2) as BookList[] //初始化数据
updatePreferences(){
updateShelfBookData(this.soundList, 0)
}

//监听isClear变化
onIsClearChange() {
if (this.currentIndex === 2 && this.isClear) {
Expand Down
8 changes: 4 additions & 4 deletions entry/src/main/ets/pages/view/myCenter/MyCenter.ets
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default struct MyCenter {
Text("夏目友人").fontSize(16).fontWeight(600).lineHeight(24)
Text("今日阅读"+this.reading_time+"分钟").fontSize(12).fontColor(TextConstants.TEXT_FONT_COLOR)
.lineHeight(20)
}.alignItems(HorizontalAlign.Start).width("45%").height("100%")
}.alignItems(HorizontalAlign.Start).width("45%").height("100%").layoutWeight(1)

.justifyContent(FlexAlign.SpaceBetween)
//云盘登录
Expand Down Expand Up @@ -120,12 +120,12 @@ export default struct MyCenter {
ForEach(this.end_list,(item:dataItem)=>{
Row({space:10}){
Image(item.icon).size({width:20,height:20}).interpolation(ImageInterpolation.High)
Text(item.title).fontSize(14).width("75%" )
Text(item.title).fontSize(14).width("75%" ).layoutWeight(1)
Image($r("app.media.right")).size({width:24,height:24})
}.width(300)
}.width("100%")
.height(48)
.justifyContent(FlexAlign.SpaceBetween)
.padding({top:12,bottom:12})
.padding({top:12,bottom:12,left:20,right:20})
.onClick(()=>this.endOnclick(item.value))
})
}.padding({top:5,bottom:5})
Expand Down
Loading

0 comments on commit 5982e75

Please sign in to comment.