diff --git a/entry/src/main/ets/common/utils/rssSourcesUtils.ets b/entry/src/main/ets/common/utils/rssSourcesUtils.ets index 527a3c45..601586e1 100644 --- a/entry/src/main/ets/common/utils/rssSourcesUtils.ets +++ b/entry/src/main/ets/common/utils/rssSourcesUtils.ets @@ -1,3 +1,5 @@ +import { showMessage } from '../../componets/common/promptShow'; +import rssSourceGroupDao from '../../database/dao/rssSourceGroupDao'; import rssSourcesHistoryDao from '../../database/dao/RssSourcesHistoryDao'; import { rssSources } from '../../database/entities/rssSources'; import { rssSourcesHistory } from '../../database/entities/rssSourcesHistory'; @@ -17,6 +19,45 @@ export class rssSourcesUtils{ } rssSourcesHistoryDao.insert(rssSourcesHistory) } + + async addGroupType(newGroupType:string){ + let isInsert = false + let group = await this.getRssSourcesGroup(); + group.map((data:string)=>{ + if(data === newGroupType){ + isInsert = true + } + }) + if (isInsert) { + showMessage('分组名称重复') + isInsert = false + return false + } else { + this.insertRssSourceGroup(newGroupType) + showMessage(`添加分组${newGroupType}成功!`) + return true + } + } + + //获取订阅分组 + async getRssSourcesGroup(){ + let rssSourcesGroup = await rssSourceGroupDao.search(); + //根据排序顺序存储到string[] + let rssSourcesGroupName:string[] = []; + for(let i=0;i { this.addNewGroupType?.close() }, - confirm: ()=> { - this.addGroupType() + confirm: async ()=> { + let insertSuccess:boolean = await rssSourcesUtils.addGroupType(this.newGroupType) + this.newGroupType = '' + if (insertSuccess) { + setTimeout(()=>{ + this.getRssSourceList() + },200) + } }, bookType: this.newGroupType }), @@ -430,22 +437,26 @@ export default struct SubscriptionImport { cornerRadius: 25 }) @State isInsert:boolean = false - addGroupType(){ - programDataPreferences.getRssSourcesListData().map((data:string)=>{ - if(data === this.newGroupType){ - this.isInsert = true - } - }) - if (this.isInsert) { - showMessage('分组名称重复') - this.isInsert = false - } else { - programDataPreferences.updateRssSourcesData(this.newGroupType) - //添加分组后再次刷新分组列表 - this.getRssSourceList() - showMessage(`添加分组${this.newGroupType}成功!`) - } - this.newGroupType = '' - } + + // async addGroupType(){ + // let group = await rssSourcesUtils.getRssSourcesGroup(); + // group.map((data:string)=>{ + // if(data === this.newGroupType){ + // this.isInsert = true + // } + // }) + // if (this.isInsert) { + // showMessage('分组名称重复') + // this.isInsert = false + // } else { + // rssSourcesUtils.insertRssSourceGroup(this.newGroupType) + // //添加分组后再次刷新分组列表 + // setTimeout(()=>{ + // this.getRssSourceList() + // },200) + // showMessage(`添加分组${this.newGroupType}成功!`) + // } + // this.newGroupType = '' + // } } diff --git a/entry/src/main/ets/database/dao/rssSourceGroupDao.ets b/entry/src/main/ets/database/dao/rssSourceGroupDao.ets index 67d2d38d..4285569b 100644 --- a/entry/src/main/ets/database/dao/rssSourceGroupDao.ets +++ b/entry/src/main/ets/database/dao/rssSourceGroupDao.ets @@ -41,7 +41,7 @@ class RssSourceGroupDao { //系统初始订阅源分组数据 async initGroupData() { - let initGroup = ['小说','漫画','影视','资讯','收藏'] + let initGroup = ['小说','漫画','影视','资讯','收藏夹'] try { const groupList = await this.search() if (groupList.length > 0) { diff --git a/entry/src/main/ets/database/entities/RssSourceGroup.ets b/entry/src/main/ets/database/entities/RssSourceGroup.ets index 8007a5c2..dcc2c4b5 100644 --- a/entry/src/main/ets/database/entities/RssSourceGroup.ets +++ b/entry/src/main/ets/database/entities/RssSourceGroup.ets @@ -10,7 +10,7 @@ export class RssSourceGroup{ //分组名称 rssGroupName:string = ""; //排序 - groupSort:number = 0; + groupSort?:number; //是否置顶 isTop:boolean = false; //是否允许删除 diff --git a/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets b/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets index d3ac6edc..c4f9e6bf 100644 --- a/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets +++ b/entry/src/main/ets/pages/view/Subscription/RssSources/newSourcesNetWork.ets @@ -12,6 +12,7 @@ import { isNetworkUrl } from '../../../../common/utils/utils' import buttonCommon from '../../../../componets/common/buttonCommon' import { showMessage } from '../../../../componets/common/promptShow' import FormItem from '../../../../componets/Form/FormItem' +import rssSourceGroupDao from '../../../../database/dao/rssSourceGroupDao' import SubscriptionDao from '../../../../database/dao/SubscriptionDao' import { rssSources, SUBSCRIPTION_GROUP_TYPE } from '../../../../database/entities/rssSources' import programDataPreferences from '../../../../preferences/programDataPreferences' @@ -97,14 +98,21 @@ export default struct newSourcesNetWork{ this.getRssSourceList() } @State sourceGroupList:SelectOption[] = [] - getRssSourceList() { - let list = programDataPreferences.getRssSourcesListData() - //将list存放到sourceGroupList - list.forEach((item) => { + + async getRssSourceList() { + let group = await rssSourceGroupDao.search(); + group.forEach(item=>{ this.sourceGroupList.push({ - value: item + value: item.rssGroupName }) }) + // let list = programDataPreferences.getRssSourcesListData() + // //将list存放到sourceGroupList + // list.forEach((item) => { + // this.sourceGroupList.push({ + // value: item + // }) + // }) } @Builder baseForm() { diff --git a/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets b/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets index b395e4d7..ccab526e 100644 --- a/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets +++ b/entry/src/main/ets/pages/view/Subscription/SubscriptionIndex.ets @@ -23,6 +23,8 @@ import { rssSourcesHistory } from '../../../database/entities/rssSourcesHistory' import { FileHandler } from 'ets/common/utils/FileHandler' import { ThemeItem } from '../../../common/model/Theme' import { ThemeStorageKey } from '../../../common/constants/Theme' +import addBookTypeDialog from '../../../componets/common/addBookTypeDialog' +import rssSourcesUtils from '../../../common/utils/rssSourcesUtils' @Component export default struct SubscriptionIndex { @@ -46,6 +48,7 @@ export default struct SubscriptionIndex { @State rssSourcesList: rssSources[] = [] @State groupList: rssGroupList[] = [] @State batchEdit: boolean = false + @State newGroupType:string = '' //全选 @Provide('batchAll') batchAll: boolean = false // 主题颜色 diff --git a/entry/src/main/ets/pages/view/Subscription/components/RssSourceGroup.ets b/entry/src/main/ets/pages/view/Subscription/components/RssSourceGroup.ets index 5319f2dd..a37fa274 100644 --- a/entry/src/main/ets/pages/view/Subscription/components/RssSourceGroup.ets +++ b/entry/src/main/ets/pages/view/Subscription/components/RssSourceGroup.ets @@ -8,9 +8,9 @@ import CommonConstants from '../../../../common/constants/CommonConstants' import PaddingConstants from '../../../../common/constants/PaddingConstants' import { ThemeStorageKey } from '../../../../common/constants/Theme' import { ThemeItem } from '../../../../common/model/Theme' +import rssSourcesUtil from '../../../../common/utils/rssSourcesUtils' import buttonCommon from '../../../../componets/common/buttonCommon' import { showMessage } from '../../../../componets/common/promptShow' -import programDataPreferences from '../../../../preferences/programDataPreferences' @Component export default struct RssSourceGroup { @@ -28,8 +28,8 @@ export default struct RssSourceGroup { this.getRssSourceList() } - getRssSourceList() { - this.sourceGroupList = programDataPreferences.getRssSourcesListData() + async getRssSourceList() { + this.sourceGroupList = await rssSourcesUtil.getRssSourcesGroup() } @Link moveGroup:string @@ -89,7 +89,6 @@ export default struct RssSourceGroup { }).ellipsisMode(EllipsisMode.END).maxLines(1) } .onClick(()=>{ - showMessage(title) this.moveGroup = title }) .width(96)