Skip to content

Commit

Permalink
Merge pull request #211 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
订阅源图标没有设置或则未找到资源默认用预设图标
  • Loading branch information
MaoXiaoone authored Jul 20, 2024
2 parents ebe9462 + 5de57ff commit 29280bf
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 31 deletions.
2 changes: 1 addition & 1 deletion entry/src/main/ets/common/utils/rssSourcesUtils.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class rssSourcesUtils{
sourceType: item.sourceType,
sourceName: item.sourceName,
sourceUrl: item.sourceUrl,
sourceIcon: item.sourceIcon,
sourceIcon: item.sourceIcon||'',
sourceIconIsUrl: item.sourceIconIsUrl,
sourceGroup: item.sourceGroup,
lastUpdateTime: Date.now(),
Expand Down
10 changes: 6 additions & 4 deletions entry/src/main/ets/database/dao/RssSourcesHistoryDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ class RssSourcesHistoryDao {
}
}

async search() {
async search(sourceUrl?:string) {
try {
const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME);
let sql = `SELECT * FROM ${this.TABLE_NAME}`;
// 动态添加 WHERE 子句
let whereClause: string[] = [];
if (sourceUrl) {
whereClause.push(`(
sourceUrl LIKE '%${sourceUrl}%'
)`);

}
// 如果有 where 子句,添加 WHERE 关键字
if (whereClause.length > 0) {
sql += ` WHERE ${whereClause.join(' AND ')}`;
Expand Down Expand Up @@ -74,9 +79,6 @@ class RssSourcesHistoryDao {
this.update(rssHistory)
return true
}
if(rssHistory.sourceIcon === '' && !rssHistory.sourceIconIsUrl){
rssHistory.sourceIcon = 'app.media.icon'
}
rssHistory.lastUpdateTime = Date.now()
await DbUtil.insert(this.TABLE_NAME, rssHistory, column)
console.log('TagInfo', '创建成功')
Expand Down
9 changes: 5 additions & 4 deletions entry/src/main/ets/database/dao/SubscriptionDao.ets
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class SubscriptionDao {
this.update(rssSource)
return true
}
if(rssSource.sourceIcon === '' && !rssSource.sourceIconIsUrl){
rssSource.sourceIcon = 'app.media.icon'
}
const rssSourceDb = ToRssSourcesDb(rssSource)
rssSourceDb.lastUpdateTime = Date.now()
await DbUtil.insert(this.TABLE_NAME, rssSourceDb, column)
Expand All @@ -123,7 +120,11 @@ class SubscriptionDao {
rssSourceDb.lastUpdateTime = Date.now()
rssSourceDb.showRecentIcon = true
await DbUtil.update(predicates, rssSourceDb, column)
await rssSourcesUtils.pushRssSourcesHistory(rssSource)
rssSourcesHistoryDao.search(rssSource.sourceUrl).then(async (value) => {
if (value.length > 0) {
await rssSourcesUtils.pushRssSourcesHistory(rssSource)
}
})
return true
} catch (err) {
console.log('TagInfo, Error, ', JSON.stringify(err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ export default struct newSources{
return
}
}
if(this.formModel.sourceIcon === '' && !this.formModel.sourceIconIsUrl){
this.formModel.sourceIcon = 'app.media.icon'
}
let isInsert = await SubscriptionDao.insert(this.formModel)
if (isInsert) {
showMessage('保存成功')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export default struct newSourcesNetWork{
return
}
}
if(this.formModel.sourceIcon === '' && !this.formModel.sourceIconIsUrl){
this.formModel.sourceIcon = 'app.media.icon'
}
let isInsert = await SubscriptionDao.insert(this.formModel)
if (isInsert) {
showMessage('保存成功')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import CommonConstants from '../../../../common/constants/CommonConstants'
import FontConstants from '../../../../common/constants/FontConstants'
import { showMessage } from '../../../../componets/common/promptShow'

@Component
export default struct PreviewEffectImage{
Expand All @@ -16,6 +17,8 @@ export default struct PreviewEffectImage{
@Prop PreviewHeight:number = 60
@Prop isShowTitle:boolean = true
@Prop ImageRadius:number = 4
@Prop sourceName:string = ''
@State isError:boolean = false
build() {
Column(){
if (this.isShowTitle){
Expand All @@ -30,25 +33,54 @@ export default struct PreviewEffectImage{
.fontColor($r('app.string.color_black_45'))
}
}
Stack(){
if (this.customizeTitle && !this.sourceIconIsUrl){
Text(this.customizeTitle.slice(0,1)).font({
size:FontConstants.FONT_SIZE_16,
weight:FontConstants.FONT_WEIGHT_700,
family:CommonConstants.FAMILY_PingFANG
})
.zIndex(9)
.fontColor(Color.White)
if (this.isError){
this.ImageStack(true)
} else {
Stack(){
this.ImageStack(this.customizeTitle.length > 0 && !this.sourceIconIsUrl)
Column(){
LoadingProgress().color("#FF6600").height(30)
Text('图片加载中...').fontSize(5).fontColor($r('app.color.theme_color'))
}.zIndex(-1)
}
}
}
}


initialImage:string[] = ['one','two','three','four','five','six','seven','eight','nine','ten']
@Builder ImageStack(isShow:boolean){
Stack(){
if (isShow || this.isError){
Text(this.isError?this.sourceName.slice(0,1):this.customizeTitle.slice(0,1)).font({
size:FontConstants.FONT_SIZE_16,
weight:FontConstants.FONT_WEIGHT_700,
family:CommonConstants.FAMILY_PingFANG
})
.zIndex(9)
.fontColor(Color.White)
}
if (this.isError){
Image($r(`app.media.icon_check_image_${this.initialImage[this.sourceName.slice(0,9).length]}`))
.width(this.PreviewWidth)
.height(this.PreviewHeight)
.animation(({
duration:1000
}))
.borderRadius(this.ImageRadius)
} else {
Image(this.sourceIcon.indexOf('app.media.')>-1?$r(this.sourceIcon):this.sourceIcon)
.alt($r('app.media.icon'))
.width(this.PreviewWidth)
.height(this.PreviewHeight)
.animation(({
duration:1000
}))
.borderRadius(this.ImageRadius)
.onError(()=>{
this.isError = true
})
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export default struct RssSourcesHistory{
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
sourceIconIsUrl:item.sourceIconIsUrl,
isShowTitle:false
isShowTitle:false,
sourceName:item.sourceName
})

Text(`${item.sourceName}`).fontSize(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ export default struct SubscriptionContent{
customizeTitle:item.customizeTitle,
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
isShowTitle:false
isShowTitle:false,
sourceName:item.sourceName
})
.borderRadius(8)

Expand Down Expand Up @@ -481,7 +482,8 @@ export default struct SubscriptionContent{
customizeTitle:item.customizeTitle,
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
isShowTitle:false
isShowTitle:false,
sourceName:item.sourceName
})
.borderRadius(8)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct SubscriptionSearch {
}

changeSearchValue(){
showMessage('模糊匹配中')
if(this.searchValue.length > 0){
this.searchSources()
} else {
Expand Down Expand Up @@ -124,11 +123,11 @@ struct SubscriptionSearch {
PreviewEffectImage({
customizeTitle:item.customizeTitle,
sourceIcon:item.sourceIcon,

sourceIconIsUrl:item.sourceIconIsUrl,
isShowTitle:false,
PreviewWidth:ImageConstants.IMG_WIDTH_40,
PreviewHeight:ImageConstants.IMG_HEIGHT_40
PreviewHeight:ImageConstants.IMG_HEIGHT_40,
sourceName:item.sourceName
}).borderRadius(50)

Text(`${item.sourceName}`).fontSize(10)
Expand Down

0 comments on commit 29280bf

Please sign in to comment.