Skip to content

Commit

Permalink
Merge pull request #290 from mgz0227/cat_dev
Browse files Browse the repository at this point in the history
订阅源分组切换为数据库查询、新增订阅源分组、移动分组功能
  • Loading branch information
MaoXiaoone authored Dec 9, 2024
2 parents 1f6561a + 667f3a4 commit af95621
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 33 deletions.
41 changes: 41 additions & 0 deletions entry/src/main/ets/common/utils/rssSourcesUtils.ets
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<rssSourcesGroup.length;i++){
rssSourcesGroupName.push(rssSourcesGroup[i].rssGroupName)
}
return rssSourcesGroupName
}

//新增分组
async insertRssSourceGroup(rssGroupName:string){
await rssSourceGroupDao.insert({
rssGroupName: rssGroupName,
isTop: false,
isDelete: true
})
}
}
let rssSourcesUtil = new rssSourcesUtils();
export default rssSourcesUtil as rssSourcesUtils;
55 changes: 33 additions & 22 deletions entry/src/main/ets/componets/import/SubscriptionImport.ets
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { rssGroupList, rssSources } from '../../database/entities/rssSources';
import SubscriptionDao from '../../database/dao/SubscriptionDao';
import FontConstants from '../../common/constants/FontConstants';
import CommonConstants from '../../common/constants/CommonConstants';
import programDataPreferences from '../../preferences/programDataPreferences'
import PaddingConstants from '../../common/constants/PaddingConstants';
import addBookTypeDialog from '../common/addBookTypeDialog';
import { ThemeItem } from '../../common/model/Theme';
import { ThemeStorageKey } from '../../common/constants/Theme';
import rssSourcesUtils from '../../common/utils/rssSourcesUtils';

@Component
export default struct SubscriptionImport {
Expand Down Expand Up @@ -47,8 +47,9 @@ export default struct SubscriptionImport {
})
}

getRssSourceList() {
this.sourceGroupList = programDataPreferences.getRssSourcesListData()
async getRssSourceList() {
// this.sourceGroupList = programDataPreferences.getRssSourcesListData()
this.sourceGroupList = await rssSourcesUtils.getRssSourcesGroup();
}

getGroupList() {
Expand Down Expand Up @@ -418,8 +419,14 @@ export default struct SubscriptionImport {
addNewGroupType: CustomDialogController | null = new CustomDialogController({
builder: addBookTypeDialog({
cancel: ()=> { 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
}),
Expand All @@ -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 = ''
// }
}

2 changes: 1 addition & 1 deletion entry/src/main/ets/database/dao/rssSourceGroupDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RssSourceGroupDao {

//系统初始订阅源分组数据
async initGroupData() {
let initGroup = ['小说','漫画','影视','资讯','收藏']
let initGroup = ['小说','漫画','影视','资讯','收藏夹']
try {
const groupList = await this.search()
if (groupList.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion entry/src/main/ets/database/entities/RssSourceGroup.ets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class RssSourceGroup{
//分组名称
rssGroupName:string = "";
//排序
groupSort:number = 0;
groupSort?:number;
//是否置顶
isTop:boolean = false;
//是否允许删除
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
// 主题颜色
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -89,7 +89,6 @@ export default struct RssSourceGroup {
}).ellipsisMode(EllipsisMode.END).maxLines(1)
}
.onClick(()=>{
showMessage(title)
this.moveGroup = title
})
.width(96)
Expand Down

0 comments on commit af95621

Please sign in to comment.