Skip to content

Commit

Permalink
Merge pull request #199 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
刚导入或更新24小时内订阅源红点进行标记
  • Loading branch information
MaoXiaoone authored Jul 19, 2024
2 parents a5af6e0 + 0d923b8 commit 0f1e4d1
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 40 deletions.
20 changes: 19 additions & 1 deletion entry/src/main/ets/database/AppDatabase/index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ export default {
},
{
"tableName": "rssSources",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourceType` INTEGER NOT NULL ,`sourceUrl` TEXT NOT NULL, `sourceName` TEXT NOT NULL, `sourceIcon` TEXT NOT NULL, `sourceGroup` TEXT, `sourceComment` TEXT, `enabled` INTEGER NOT NULL, `variableComment` TEXT, `jsLib` TEXT, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `loginCheckJs` TEXT, `coverDecodeJs` TEXT, `sortUrl` TEXT, `singleUrl` INTEGER NOT NULL, `articleStyle` INTEGER NOT NULL DEFAULT 0, `ruleArticles` TEXT, `ruleNextPage` TEXT, `ruleTitle` TEXT, `rulePubDate` TEXT, `ruleDescription` TEXT, `ruleImage` TEXT, `ruleLink` TEXT, `ruleContent` TEXT, `contentWhitelist` TEXT, `contentBlacklist` TEXT, `shouldOverrideUrlLoading` TEXT, `style` TEXT, `enableJs` INTEGER NOT NULL DEFAULT 1, `loadWithBaseUrl` INTEGER NOT NULL DEFAULT 1, `injectJs` TEXT, `lastUpdateTime` INTEGER NOT NULL DEFAULT 0, `customOrder` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`sourceUrl`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`sourceType` INTEGER NOT NULL ,`sourceUrl` TEXT NOT NULL, `sourceName` TEXT NOT NULL, `sourceIcon` TEXT NOT NULL, `sourceGroup` TEXT, `sourceComment` TEXT, `enabled` INTEGER NOT NULL, `variableComment` TEXT, `jsLib` TEXT, `enabledCookieJar` INTEGER DEFAULT 0, `concurrentRate` TEXT, `header` TEXT, `loginUrl` TEXT, `loginUi` TEXT, `loginCheckJs` TEXT, `coverDecodeJs` TEXT, `sortUrl` TEXT, `singleUrl` INTEGER NOT NULL, `articleStyle` INTEGER NOT NULL DEFAULT 0, `ruleArticles` TEXT, `ruleNextPage` TEXT, `ruleTitle` TEXT, `rulePubDate` TEXT, `ruleDescription` TEXT, `ruleImage` TEXT, `ruleLink` TEXT, `ruleContent` TEXT, `contentWhitelist` TEXT, `contentBlacklist` TEXT, `shouldOverrideUrlLoading` TEXT, `style` TEXT, `enableJs` INTEGER NOT NULL DEFAULT 1, `loadWithBaseUrl` INTEGER NOT NULL DEFAULT 1, `injectJs` TEXT, `lastUpdateTime` INTEGER NOT NULL DEFAULT 0,`variable` TEXT, `sourceIconIsUrl` INTEGER ,`showRecentIcon` INTEGER NOT NULL DEFAULT 1, `customOrder` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`sourceUrl`))",
"fields": [
{
"fieldPath": "sourceType",
Expand Down Expand Up @@ -1212,6 +1212,24 @@ export default {
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "sourceIconIsUrl",
"columnName": "sourceIconIsUrl",
"affinity": "INTEGER"
},
{
"fieldPath": "variable",
"columnName": "variable",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "showRecentIcon",
"columnName": "showRecentIcon",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "1"
},
{
"fieldPath": "lastUpdateTime",
"columnName": "lastUpdateTime",
Expand Down
21 changes: 20 additions & 1 deletion entry/src/main/ets/database/dao/SubscriptionDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ class SubscriptionDao {
if (rssSource instanceof rssSources) {
const rssSourceDb = ToRssSourcesDb(rssSource)
rssSourceDb.lastUpdateTime = Date.now()
rssSourceDb.showRecentIcon = true
await DbUtil.update(predicates, rssSourceDb, column)
return true
}
rssSource.lastUpdateTime = Date.now()
rssSource.showRecentIcon = true
const columnPart: ColumnInfo[] = this.getFlowColumn().slice(0, -2)
await DbUtil.update(predicates, rssSource, columnPart)
return true
Expand All @@ -132,6 +134,23 @@ class SubscriptionDao {

}

async updateRecentIcon(rssSource: rssSources) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
const predicates = DbUtil.getPredicates(this.TABLE_NAME);
predicates.equalTo('sourceUrl', rssSource.sourceUrl)
const rssSourceDb = ToRssSourcesDb(rssSource)
rssSourceDb.showRecentIcon = false
await DbUtil.update(predicates, rssSourceDb, column)
return true
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
return false
}

}


async getRssSources(key: string): Promise<rssSources | null> {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
Expand All @@ -152,7 +171,7 @@ class SubscriptionDao {
getFlowColumn() {
const column: ColumnInfo[] = AppDatabaseUtil.getAssignColumn(this.TABLE_NAME,
['sourceName', 'sourceUrl', 'sourceGroup', 'sourceGroup', 'enabled', 'variableComment',
'sortUrl', 'singleUrl', 'lastUpdateTime','customOrder','variable','sourceType']);
'sortUrl', 'singleUrl', 'lastUpdateTime','customOrder','variable','sourceType','showRecentIcon',]);
return column;
}
}
Expand Down
58 changes: 31 additions & 27 deletions entry/src/main/ets/database/entities/rssSources.ets
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class rssSources{
customOrder:number = 0
//设置源变量
variable?:string
//是否新增或则更新点击过
showRecentIcon:boolean = true
//自动补全
autoComplete:boolean = true
//列表
Expand Down Expand Up @@ -155,41 +157,43 @@ export const ToRssSources = (rssSourceDb: rssSourceDb) => {
customOrder: rssSourceDb.customOrder,
variable: rssSourceDb.variable,
autoComplete: rssSourceDb.autoComplete,
showRecentIcon:rssSourceDb.showRecentIcon,
rssListRule,
rssWebViewRule
}
return rssSources
}


export const ToRssSourcesDb = (rssSourceDb: rssSources) => {
const rssListRule = GSON.toString(rssSourceDb.rssListRule);
const rssWebViewRule = GSON.toString(rssSourceDb.rssWebViewRule);
export const ToRssSourcesDb = (rssSource: rssSources) => {
const rssListRule = GSON.toString(rssSource.rssListRule);
const rssWebViewRule = GSON.toString(rssSource.rssWebViewRule);
const rssSourcesDb: rssSourceDb = {
sourceType: rssSourceDb.sourceType,
sourceName: rssSourceDb.sourceName,
sourceUrl: rssSourceDb.sourceUrl,
sourceIcon: rssSourceDb.sourceIcon,
sourceIconIsUrl: rssSourceDb.sourceIconIsUrl,
sourceGroup: rssSourceDb.sourceGroup,
sourceComment: rssSourceDb.sourceComment,
enabled: rssSourceDb.enabled,
variableComment: rssSourceDb.variableComment,
jsLib: rssSourceDb.jsLib,
enabledCookieJar: rssSourceDb.enabledCookieJar,
concurrentRate: rssSourceDb.concurrentRate,
header: rssSourceDb.header,
loginUrl: rssSourceDb.loginUrl,
loginUi: rssSourceDb.loginUi,
loginCheckJs: rssSourceDb.loginCheckJs,
coverDecodeJs: rssSourceDb.coverDecodeJs,
sortUrl: rssSourceDb.sortUrl,
singleUrl: rssSourceDb.singleUrl,
articleStyle: rssSourceDb.articleStyle,
lastUpdateTime: rssSourceDb.lastUpdateTime,
customOrder: rssSourceDb.customOrder,
variable: rssSourceDb.variable,
autoComplete: rssSourceDb.autoComplete,
sourceType: rssSource.sourceType,
sourceName: rssSource.sourceName,
sourceUrl: rssSource.sourceUrl,
sourceIcon: rssSource.sourceIcon,
sourceIconIsUrl: rssSource.sourceIconIsUrl,
sourceGroup: rssSource.sourceGroup,
sourceComment: rssSource.sourceComment,
enabled: rssSource.enabled,
variableComment: rssSource.variableComment,
jsLib: rssSource.jsLib,
enabledCookieJar: rssSource.enabledCookieJar,
concurrentRate: rssSource.concurrentRate,
header: rssSource.header,
loginUrl: rssSource.loginUrl,
loginUi: rssSource.loginUi,
loginCheckJs: rssSource.loginCheckJs,
coverDecodeJs: rssSource.coverDecodeJs,
sortUrl: rssSource.sortUrl,
singleUrl: rssSource.singleUrl,
articleStyle: rssSource.articleStyle,
lastUpdateTime: rssSource.lastUpdateTime,
customOrder: rssSource.customOrder,
variable: rssSource.variable,
autoComplete: rssSource.autoComplete,
showRecentIcon: rssSource.showRecentIcon,
rssListRule,
rssWebViewRule
}
Expand Down
2 changes: 2 additions & 0 deletions entry/src/main/ets/database/entities/rssSourcesPart.ets
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export class rssSourcesPart {
variable?:string
//订阅源类型0.常规网站 1.订阅源
sourceType?: number = 1

showRecentIcon:boolean = true
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { showMessage } from '../../../../componets/common/promptShow'
import FormItem from '../../../../componets/Form/FormItem'
import SubscriptionDao from '../../../../database/dao/SubscriptionDao'
import { rssSources, SUBSCRIPTION_GROUP_TYPE } from '../../../../database/entities/rssSources'
import { rssListRule } from '../../../../database/entities/rule/rssListRule'
import { rssWebViewRule } from '../../../../database/entities/rule/rssWebViewRule'
import programDataPreferences from '../../../../preferences/programDataPreferences'

@Component
Expand Down Expand Up @@ -122,7 +124,8 @@ export default struct newSources{
autoComplete: false,
sourceGroup: SUBSCRIPTION_GROUP_TYPE[0],
enabled: true,
singleUrl: true
singleUrl: true,
showRecentIcon: true
}

@State sourceGroupList:SelectOption[] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export default struct newSourcesNetWork{
autoComplete: false,
sourceGroup: SUBSCRIPTION_GROUP_TYPE[0],
enabled: true,
singleUrl: true
singleUrl: true,
showRecentIcon: true
}
@Builder
baseForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { showMessage } from '../../../../componets/common/promptShow'
import newSourcesNetWork from '../RssSources/newSourcesNetWork'
import newSources from '../RssSources/newSources'
import { router } from '@kit.ArkUI'
import SubscriptionDao from '../../../../database/dao/SubscriptionDao'

@Component
export default struct SubscriptionContent{
Expand Down Expand Up @@ -107,12 +108,14 @@ export default struct SubscriptionContent{
this.contentCoverBuilder(item)
}
.onClick(()=>{
SubscriptionDao.updateRecentIcon(item)
router.pushUrl({
url: 'pages/view/Subscription/rssWebView',
params: {
url: item.sourceUrl
}
})
this.refresh()
})
.gesture(
LongPressGesture({ repeat: true,duration:1000 })
Expand Down Expand Up @@ -142,12 +145,14 @@ export default struct SubscriptionContent{
this.contentListBuilder(item)
}
.onClick(()=>{
SubscriptionDao.updateRecentIcon(item)
router.pushUrl({
url: 'pages/view/Subscription/rssWebView',
params: {
url: item.sourceUrl
}
})
this.refresh()
})
.gesture(
LongPressGesture({ repeat: true,duration:500 })
Expand Down Expand Up @@ -261,10 +266,21 @@ export default struct SubscriptionContent{
// .width(ImageConstants.IMG_WIDTH_24)
// .height(ImageConstants.IMG_HEIGHT_24)
// .borderRadius(4)
Image($r('app.media.icon'))
.width(ImageConstants.IMG_WIDTH_40)
.height(ImageConstants.IMG_HEIGHT_40)
.borderRadius(4)
Stack(){
Image($r('app.media.icon'))
.width(ImageConstants.IMG_WIDTH_40)
.height(ImageConstants.IMG_HEIGHT_40)
.borderRadius(4)

if (this.isShowRecentIcon(item.lastUpdateTime) && item.showRecentIcon)
Row().width(8).height(8)
.borderRadius(8)
.backgroundColor('#EF4444')
.position({
right: -2,
top:-2
})
}.alignContent(Alignment.TopEnd)
Text(item.sourceName)
.font({
size:14,
Expand All @@ -281,6 +297,10 @@ export default struct SubscriptionContent{
.padding(PaddingConstants.PADDING_12)

}
//刚导入的24小时内以红点进行标记,24小时后消失,或者手动点击该订阅查看后也会消失
isShowRecentIcon(lastTime:number){
return (new Date().getTime() - lastTime)/(1000 * 60 * 60) <= 24
}

@Builder
contentListBuilder(item:rssSources){
Expand All @@ -291,10 +311,21 @@ export default struct SubscriptionContent{
// .width(ImageConstants.IMG_WIDTH_40)
// .height(ImageConstants.IMG_HEIGHT_40)
// .borderRadius(8)
Image($r('app.media.icon'))
.width(ImageConstants.IMG_WIDTH_40)
.height(ImageConstants.IMG_HEIGHT_40)
.borderRadius(4)
Stack(){
Image($r('app.media.icon'))
.width(ImageConstants.IMG_WIDTH_40)
.height(ImageConstants.IMG_HEIGHT_40)
.borderRadius(4)

if (this.isShowRecentIcon(item.lastUpdateTime) && item.showRecentIcon)
Row().width(8).height(8)
.borderRadius(8)
.backgroundColor('#EF4444')
.position({
right: -2,
top:-2
})
}.alignContent(Alignment.TopEnd)

Text(`${item.sourceName}`).fontSize(10)
.fontColor($r('app.string.color_black_88'))
Expand Down
1 change: 0 additions & 1 deletion entry/src/main/ets/pages/view/Subscription/rssWebView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct RssWebView {
aboutToAppear(): void {
const params = router.getParams() as RouteParams;
this.sourcesUrl = params.url
showMessage(this.sourcesUrl)
}

build() {
Expand Down

0 comments on commit 0f1e4d1

Please sign in to comment.