Skip to content

Commit

Permalink
Merge pull request #253 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
fix:分组自定义封面功能,发现页面跳转阅读界面是否加入书单和加入书单功能;修改分组、书籍组件样式;
  • Loading branch information
MaoXiaoone authored Aug 9, 2024
2 parents 66223f9 + 1b81728 commit 320fe17
Show file tree
Hide file tree
Showing 28 changed files with 427 additions and 197 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 @@ -215,6 +215,7 @@ export default class CommonConstants {
/**
* space间距
*/
static readonly SPACE_2: number = 2;
static readonly SPACE_6: number = 6;
static readonly SPACE_10: number = 10;
static readonly SPACE_12: number = 12;
Expand Down
9 changes: 9 additions & 0 deletions entry/src/main/ets/common/utils/BookHistoryUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
import bookHistoryDao from '../../database/dao/BookHistoryDao';
import { BookHistory } from '../../database/entities/BookHistory';
import { Books } from '../../database/entities/Books';
import booksUtils from './booksUtils';

export class BookHistoryUtils {
async deleteBookHistory(id: number) {
Expand All @@ -16,6 +18,13 @@ export class BookHistoryUtils {
}
async addBooks(books: BookHistory){
bookHistoryDao.insert(books)
let book = new Books()
book.id = books.id
book.latestChapterTitle = books.durChapterTitle
book.lastCheckTime = books.durChapterTime
book.durChapterIndex = books.durChapterIndex
book.durChapterTime = Date.now()
booksUtils.partialUpdate(book)
}
}

Expand Down
5 changes: 5 additions & 0 deletions entry/src/main/ets/common/utils/bookGroupUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ class bookGroupUtils{
let Ids:number[] = toolsUtils.numberArrays(groupId)
return await BookGroupsDao.queryBookByGroup(Ids)
}

//更新分组部分数据
async updatePartialGroup(data:BookGroups){
BookGroupsDao.updatePartialGroup(data)
}
}
let bookGroupUtil = new bookGroupUtils();
export default bookGroupUtil as bookGroupUtils;
11 changes: 11 additions & 0 deletions entry/src/main/ets/common/utils/booksUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ class booksUtils{
}
}
async addBooks(books: Books){
books.isJoin = true
books.bookGroup = 3 //默认未分组
BooksDao.insert(books)
}
//校验当前书籍是否存在书架中
async isExistBooks(bookUrl?:string,bookName?:string): Promise<boolean>{
let books: Books[] = await BooksDao.isExistBooks(bookUrl, bookName)
return books.length > 0
}
//更新部分书籍信息
async partialUpdate(books: Books){
BooksDao.partialUpdate(books)
}
/**
* @author 2008
* @param id 需要移动的书籍Id
Expand Down
20 changes: 11 additions & 9 deletions entry/src/main/ets/componets/bookDetail/BookOverlay.ets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default struct BookOverlay {
@Prop bookImage:Resource|string
@Prop isTop:boolean
@Prop isShow:boolean = false
@Prop coverType:number = 0
build() {

Stack(){
Expand All @@ -30,17 +31,18 @@ export default struct BookOverlay {
}
.zIndex(2)
.alignContent(Alignment.BottomStart)
if (this.coverType !== 2){
Row(){
Image($r('app.media.occlusion1')).draggable(false)
}
.zIndex(1)
.width(CommonConstants.NOVEL_IMG_WIDTH + 5).height(CommonConstants.NOVEL_IMG_HEIGHT - 5)

Row(){
Image($r('app.media.occlusion1')).draggable(false)
Row(){
Image($r('app.media.occlusion2')).draggable(false)
}.zIndex(0)
.width(CommonConstants.NOVEL_IMG_WIDTH + 10).height(CommonConstants.NOVEL_IMG_HEIGHT - 10)
}
.zIndex(1)
.width(CommonConstants.NOVEL_IMG_WIDTH + 5).height(CommonConstants.NOVEL_IMG_HEIGHT - 5)

Row(){
Image($r('app.media.occlusion2')).draggable(false)
}.zIndex(0)
.width(CommonConstants.NOVEL_IMG_WIDTH + 10).height(CommonConstants.NOVEL_IMG_HEIGHT - 10)
}
.align(Alignment.BottomStart)
}
Expand Down
6 changes: 3 additions & 3 deletions entry/src/main/ets/database/AppDatabase/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
"entities": [
{
"tableName": "books",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ( `id` INTEGER NOT NULL, `bookUrl` TEXT, `toUrl` TEXT, `origin` TEXT, `originName` TEXT, `bookName` TEXT NOT NULL, `author` TEXT, `cover` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `bookGroup` INTEGER NOT NULL DEFAULT 0, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `sort` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `syncTime` INTEGER NOT NULL DEFAULT 0, `bookType` INTEGER NOT NULL DEFAULT 0, `isTop` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0,`updateTime` INTEGER NOT NULL DEFAULT 0,`isJoin` INTEGER NOT NULL DEFAULT 1,isSystem INTEGER NOT NULL DEFAULT 0,bookIds TEXT,PRIMARY KEY ( `id` ))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ( `id` INTEGER NOT NULL, `bookUrl` TEXT, `toUrl` TEXT, `origin` TEXT, `originName` TEXT, `bookName` TEXT NOT NULL, `author` TEXT, `cover` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `bookGroup` INTEGER NOT NULL DEFAULT 3, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `sort` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `syncTime` INTEGER NOT NULL DEFAULT 0, `bookType` INTEGER NOT NULL DEFAULT 0, `isTop` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0,`updateTime` INTEGER NOT NULL DEFAULT 0,`isJoin` INTEGER NOT NULL DEFAULT 1,PRIMARY KEY ( `id` ))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -101,7 +101,7 @@ export default {
"columnName": "bookGroup",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
"defaultValue": "3"
},
{
"fieldPath": "latestChapterTitle",
Expand Down Expand Up @@ -257,7 +257,7 @@ export default {
},
{
"tableName": "book_groups",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` INTEGER NOT NULL, `groupName` TEXT NOT NULL, `coverUrl` TEXT, `groupDescribe` TEXT, `sort` INTEGER NOT NULL, `enableRefresh` INTEGER NOT NULL DEFAULT 1, `show` INTEGER NOT NULL DEFAULT 1, `groupType` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0, `updateTime` INTEGER NOT NULL DEFAULT 0, `bookSort` INTEGER NOT NULL DEFAULT -1, `canUpdate` INTEGER NOT NULL DEFAULT 0, `coverOnly` INTEGER NOT NULL DEFAULT 0, `coverType` INTEGER NOT NULL DEFAULT 0, `canDelete` INTEGER NOT NULL DEFAULT 1, `isTop` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`groupId`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`groupId` INTEGER NOT NULL, `groupName` TEXT NOT NULL, `coverUrl` TEXT, `groupDescribe` TEXT, `sort` INTEGER NOT NULL, `enableRefresh` INTEGER NOT NULL DEFAULT 1, `show` INTEGER NOT NULL DEFAULT 1, `groupType` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0, `updateTime` INTEGER NOT NULL DEFAULT 0, `bookSort` INTEGER NOT NULL DEFAULT -1, `canUpdate` INTEGER NOT NULL DEFAULT 0, `coverOnly` INTEGER NOT NULL DEFAULT 0, `coverType` INTEGER NOT NULL DEFAULT 0, `canDelete` INTEGER NOT NULL DEFAULT 1, `isTop` INTEGER NOT NULL DEFAULT 0,`isSystem` INTEGER NOT NULL DEFAULT 0,`bookIds` TEXT,PRIMARY KEY(`groupId`))",
"fields": [
{
"fieldPath": "groupId",
Expand Down
29 changes: 29 additions & 0 deletions entry/src/main/ets/database/dao/BookGroupsDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,35 @@ class BookGroupsDao{
}
}

async updatePartialGroup(group: BookGroups) {
// if (!(group instanceof BookGroups)) {
// console.warn('Invalid group instance.');
// return;
// }

const column = this.getPartialColumn();
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('groupId', group.groupId);

try {
const count = await DbUtil.queryForCount(predicates, column);
if (count > 0) {
await DbUtil.update(predicates, ToBookGroupsDb(group), column);
} else {
console.warn('No records found for update.');
}
} catch (err) {
console.error('Error in partialUpdate:', err);
}
}

getPartialColumn(): ColumnInfo[] {
return AppDatabaseUtil.getAssignColumn(this.TABLE_NAME, ['groupId',
'groupName', 'coverOnly', 'coverType','coverUrl','groupDescribe',
'enableRefresh','canUpdate'
]);
}

}

const bookGroupsDao = new BookGroupsDao()
Expand Down
54 changes: 54 additions & 0 deletions entry/src/main/ets/database/dao/BooksDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,28 @@ class BooksDao {
}
}

// 校验当前书籍是否存在书架中
async isExistBooks(bookUrl?: string, bookName?: string): Promise<Books[]> {
if (!bookUrl || !bookName) {
console.warn('bookUrl or bookName is missing.');
return [];
}

const column = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('bookUrl', bookUrl);
predicates.equalTo('bookName', bookName);

try {
const books = await DbUtil.queryForList<Books>(predicates, column);
return books || [];
} catch (err) {
console.error('isExistBooks, Error:', err);
return [];
}
}


//根据书籍Id获取书籍
async getBookByIds(ids: number[]) {

Expand All @@ -316,6 +338,38 @@ class BooksDao {
return [];
}
}
//部分更新
async partialUpdate(books: Books) {
if (!(books instanceof Books)) {
console.warn('Invalid Books instance.');
return;
}

const column = this.getPartialColumn();
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('id', books.id);

try {
const count = await DbUtil.queryForCount(predicates, column);

if (count > 0) {
await DbUtil.update(predicates, books, column);
} else {
console.warn('No records found for update.');
}
} catch (err) {
console.error('Error in partialUpdate:', err);
}
}

getPartialColumn(): ColumnInfo[] {
return AppDatabaseUtil.getAssignColumn(this.TABLE_NAME, ['id',
'latestChapterTitle', 'latestChapterTime', 'lastCheckTime',
'lastCheckCount', 'totalChapterNum', 'durChapterTitle',
'durChapterIndex', 'durChapterPos', 'durChapterTime',
'wordCount', 'syncTime', 'updateTime'
]);
}
}


Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/database/entities/Books.ets
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Books {
//自定义字符集名称(仅适用于本地书籍)
charset?:string
//在导入的情况下或则未分组默认为2 未分组
bookGroup:number = 2;
bookGroup:number = 3;
// 最新章节标题
latestChapterTitle?:string
// 最新章节标题更新时间
Expand Down
26 changes: 19 additions & 7 deletions entry/src/main/ets/pages/view/BookDetailPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import ChaptersDataSource from '../../common/LazyIDataSource/ChaptersDataSource'
import { Books } from '../../database/entities/Books'
import { BookHistory } from '../../database/entities/BookHistory'
import bookHistoryUtils from '../../common/utils/BookHistoryUtils'
import booksUtil from '../../common/utils/booksUtils'
import { showMessage } from '../../componets/common/promptShow'

/**
* 标题图片样式
Expand Down Expand Up @@ -80,7 +82,9 @@ struct BookDetailPage {
dialogController: CustomDialogController = new CustomDialogController({
builder: AddBookShelfDialog(),
cornerRadius: 8,
offset: { dx: 0, dy: -100 }
offset: { dx: 0, dy: -100 },
gridCount: 4,
customStyle: false,
})
@State txtFiles: chaptersItem[] = [];
@State txtFile: ChaptersDataSource = new ChaptersDataSource()
Expand All @@ -92,6 +96,10 @@ struct BookDetailPage {
console.log('router BookDetailPage:' + JSON.stringify(router.getParams()))
if (router.getParams() as Books) {
this.bookData = router.getParams() as Books
//校验是否加入书架
if (!this.bookData.isJoin) {
this.bookData.isJoin = await booksUtil.isExistBooks(this.bookData.bookUrl, this.bookData.bookName)
}
let temp = await FileHandler.readFile(this.bookData?.bookUrl||'') //txt小说
this.txtFile.pushAllData(temp)
this.txtFiles = this.txtFile.getListData()
Expand All @@ -100,13 +108,13 @@ struct BookDetailPage {

// 加入书架函数
addBookShelf() {
booksUtil.addBooks(this.bookData)
this.dialogController.open();
this.isAddBookShelf = true;
// 1s后关闭dialog
let timeoutID = setTimeout(() => {
setTimeout(() => {
this.dialogController.close();
}, 1000);
clearTimeout(timeoutID);
}

/**
Expand Down Expand Up @@ -199,7 +207,7 @@ struct BookDetailPage {
})

Row({ space: 20 }) {
Button(this.isAddBookShelf ? '已加书架' : '加入书架')
Button(this.bookData.isJoin ? '已加书架' : '加入书架')
.padding({
left: 32,
right: 32,
Expand All @@ -212,7 +220,7 @@ struct BookDetailPage {
.backgroundColor('#1fff6600')
.fontColor('#FF6600')
.onClick(() => {
this.addBookShelf();
!this.bookData.isJoin?this.addBookShelf():''
})
Button('立即阅读')
.padding({
Expand Down Expand Up @@ -337,12 +345,16 @@ struct BookDetailPage {

// 小说标题
Row({ space: CommonConstants.SPACE_20 }) {
Image(this.bookData.coverUrl ?? $r('app.media.cover_list'))
Image(this.bookData.coverUrl)
.alt($r('app.media.icon_book_default_cover_ten'))
.width(CommonConstants.NOVEL_IMG_WIDTH)
.height(CommonConstants.NOVEL_IMG_HEIGHT)
.borderRadius(5)
Column({ space: 8 }) {
Text(this.bookData.bookName.replace(new RegExp('\\..*', 'g'), ''))
.width('75%')
.maxLines(2)
.textOverflow({overflow:TextOverflow.Ellipsis})
.fontColor(Color.White)
.fontSize(20)
Blank()
Expand Down Expand Up @@ -457,6 +469,6 @@ struct BookDetailPage {
bookHistory.originBookId = this.bookData.id
bookHistory.durChapterTitle = durChapterTitle
bookHistory.durChapterIndex = durChapterIndex
await bookHistoryUtils.addBooks(bookHistory)
bookHistoryUtils.addBooks(bookHistory)
}
}
6 changes: 4 additions & 2 deletions entry/src/main/ets/pages/view/Find/CategoryList/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { CardItem } from '../components/CardItem';
interface RouteParams {
bookSourceUrl: string,
exploreItem: ExploreItem,
exploreRule: ExploreRule
exploreRule: ExploreRule,
currentIndex: number
}

@Entry
Expand All @@ -30,10 +31,11 @@ struct CateGoryListPage {
@State loading: boolean = false
@State isRefreshing: boolean = false
@State RefreshingTitle: string = '松开刷新'

@State currentIndex:number = 0
async aboutToAppear() {
this.startLoading = true
const params = router.getParams() as RouteParams;
this.currentIndex = params.currentIndex
console.log('TagInfo', JSON.stringify(params))
this.bookSourceUrl = params.bookSourceUrl
this.exploreItem = params.exploreItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default struct BookFindContent {
} else {
Column() {
ForEach(this.bookList, (item: ExploreRule, index) => {
CardItem({ item: item })
CardItem({ item: item ,currentIndex:this.currentIndex})
})
if (this.bookList.length === 3) {
Column() {
Expand All @@ -116,7 +116,8 @@ export default struct BookFindContent {
params: {
bookSourceUrl: this.bookSourceUrl,
exploreItem: this.exploreItem,
exploreRule: this.exploreRule
exploreRule: this.exploreRule,
currentIndex: this.currentIndex
}
})
})
Expand Down
Loading

0 comments on commit 320fe17

Please sign in to comment.