Skip to content

Commit

Permalink
Merge pull request #229 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
书架长按底部弹窗、置顶、移动分组、新建分组、同步刷新书架分组
  • Loading branch information
MaoXiaoone authored Jul 25, 2024
2 parents 9bf3f77 + 16d4893 commit 50cbfa0
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 19 deletions.
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 @@ -234,6 +234,7 @@ export default class CommonConstants {
static readonly SHELF_LIST_DATA:string = 'SHELF_LIST_DATA'
static readonly HAS_EXPLORE_URL:string = 'HAS_EXPLORE_URL'
static readonly BOOK_IS_BOOK_REFRESHING:string = 'BOOK_IS_BOOK_REFRESHING'
static readonly BOOK_IS_BOOK_GROUPS_REFRESHING:string = 'BOOK_IS_BOOK_GROUPS_REFRESHING'
// 订阅源分组数据
//分组是否初始化key
static readonly RSS_SOURCES_GROUP_INIT:string = 'RSS_SOURCES_GROUP_INIT'
Expand Down
3 changes: 3 additions & 0 deletions entry/src/main/ets/common/utils/booksUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import BooksDao from '../../database/dao/BooksDao'
import { Books } from '../../database/entities/Books'

class booksUtils{
async isTopBook(id: number): Promise<boolean> {
return BooksDao.isUpdateBookTop(id)
}
async addBooks(books: Books){
BooksDao.insert(books)
}
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/componets/common/InsideCircleIcon.ets
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { buttonList } from '../dataList/buttonList'

@Component
export default struct InsideCircleIcon{
export default struct InsideCircleIcon{
@Prop item:buttonList
build() {
Column({
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/componets/group/GroupType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default struct groupTypeComponent {
@State groupList:BookGroups[] = []
@Link bookTypeNumber:number
// initGroup:string[] = ['分组','全部','未分组','本地','书单']

@StorageLink('BOOK_IS_BOOK_GROUPS_REFRESHING') @Watch('changeRefresh')BOOK_IS_BOOK_GROUPS_REFRESHING: number = 0
aboutToAppear(): void {
this.getGroupList()
}
Expand Down
57 changes: 54 additions & 3 deletions entry/src/main/ets/database/dao/BooksDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BooksDao {
if (type !== undefined) {
whereClause.push(`bookType = ${type}`);
}
if (bookGroup !== undefined) {
if (bookGroup !== undefined && bookGroup !== 2) {
whereClause.push(`bookGroup = ${bookGroup}`);
}
if (searchKey) {
Expand Down Expand Up @@ -110,7 +110,6 @@ class BooksDao {
predicates.equalTo('id', books.id)
const count = await DbUtil.queryForCount(predicates, column)
if (count === 0 && books instanceof Books) {
// books.createTime = Date.now()
this.insert(books)
return true
}
Expand All @@ -120,7 +119,59 @@ class BooksDao {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}

}
//置顶
async isUpdateBookTop(id: number) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('id', id)
const count = await DbUtil.queryForList<Books>(predicates, column)
if (column.length > 0) {
count.forEach((item) => {
item.isTop = !item.isTop
item.updateTime = Date.now()
this.update(item)
})
return true
}
return false
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}
}
//批量更新书籍分组
async batchUpdateBookGroup(id: number[],groupId:number) {
try {
for (let index = 0; index < id.length; index++) {
this.updateBookGroup(id[index],groupId)
}
return true
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}
}
//更新书籍分组
async updateBookGroup(id: number,groupId:number) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('id', id)
const count = await DbUtil.queryForList<Books>(predicates, column)
if (column.length > 0) {
count.forEach((item) => {
item.bookGroup = groupId
this.update(item)
})
return true
}
return false
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}
}

//批量删除订阅源历史记录
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default struct IndexShelf {
titleArray: Array<string> = ['小说', '漫画', '有声书']

@State bookType:string = '全部'
@State bookTypeNumber:number = 1
@State bookTypeNumber:number = 2
@State EXHIBIT: string = '列表'
@State GROUP: string = '标签'
@State searchValue: string = '最近阅读'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { showMessage } from '../../../../../componets/common/promptShow'
import confirmDialogExample from '../../../../../componets/common/confirmDialog'
import { sleep } from '../../../../../common/utils/utils'
import booksUtil from '../../../../../common/utils/booksUtils'
import BookSelectGroupDialog from './BookSelectGroupDialog'

@CustomDialog
/**
Expand All @@ -14,10 +15,10 @@ import booksUtil from '../../../../../common/utils/booksUtils'
export default struct BookInfoDialogs{
controller?: CustomDialogController
//推送提醒
@Link bookData:Books
@Prop bookData:Books
@State pushReminder:boolean = false
@State buttonListInfo:buttonList[] = [
new buttonList(1,'置顶',$r('app.media.top')),
new buttonList(1,this.bookData.isTop?'取消置顶':'置顶',$r('app.media.top')),
new buttonList(2,'移动至',$r('app.media.folder')),
new buttonList(3,'加入书单',$r('app.media.shelf')),
new buttonList(4,'删除',$r('app.media.ic_public_delete'))
Expand Down Expand Up @@ -90,25 +91,16 @@ export default struct BookInfoDialogs{
bookInfoButton(id:number){
switch (id){
case 1 :
showMessage(!this.bookData.isTop?'置顶':'取消置顶');
this.isFolderTop(); break;
this.isTopBook(); break;
case 2 :
showMessage('移动至'); break;
this.bookMoveGroup?.open(); break;
case 3 :
showMessage('加入书单'); break;
case 4 :
this.bookDelDialog?.open(); break;
}
}

isFolderTop(){
this.bookData.isTop = !this.bookData.isTop
this.buttonListInfo[0].title = this.bookData.isTop?'取消置顶':'置顶'
//刷新数组buttonListInfo
this.buttonListInfo = this.buttonListInfo.slice(0)
this.bookData.updateTime = Date.now()
}

@State delCache:boolean = false
//弹窗
bookDelDialog: CustomDialogController | null = new CustomDialogController({
Expand Down Expand Up @@ -142,4 +134,36 @@ export default struct BookInfoDialogs{
showMessage('删除成功')
}

async isTopBook(){
booksUtil.isTopBook(this.bookData.id || 0).then((val)=>{
val?showMessage(this.bookData.isTop?'置顶成功':'取消置顶成功'):showMessage('数据更新失败')
})
setTimeout(()=>{
this.controller?.close()
this.isBookRefreshing++
},500)
}

//移动分组
//弹窗
bookMoveGroup: CustomDialogController | null = new CustomDialogController({
builder: BookSelectGroupDialog({
moveGroup: ()=> {
this.bookMoveGroup?.close()
setTimeout(()=>{
this.isBookRefreshing++
},500)
},
currentIndex:this.bookData.bookType,
booId:this.bookData.id
}),
height: 400,
cancel: this.exitApp,
autoCancel: true,
alignment: DialogAlignment.Center,
gridCount: 4,
customStyle: false,
cornerRadius: 25,
})

}
Loading

0 comments on commit 50cbfa0

Please sign in to comment.