Skip to content

Commit

Permalink
[feature] Support post notifications after matching specific new arti…
Browse files Browse the repository at this point in the history
…cles
  • Loading branch information
SkyD666 committed Oct 22, 2024
1 parent a9d746e commit 6617411
Show file tree
Hide file tree
Showing 73 changed files with 1,005 additions and 136 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 24
versionName = "2.1-beta07"
versionName = "2.1-beta08"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="article.screen"
android:scheme="anivu" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="magnet" />
</intent-filter>
<intent-filter>
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/skyd/anivu/config/SearchConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.skyd.anivu.config

import com.skyd.anivu.model.bean.article.ARTICLE_TABLE_NAME
import com.skyd.anivu.model.bean.article.ArticleBean
import com.skyd.anivu.model.bean.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.FEED_VIEW_NAME
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.feed.FEED_VIEW_NAME
import com.skyd.anivu.model.bean.feed.FeedBean

val allSearchDomain: Map<String, List<String>> = mutableMapOf(
FEED_TABLE_NAME to listOf(
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/skyd/anivu/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.skyd.anivu.model.db.AppDatabase
import com.skyd.anivu.model.db.SearchDomainDatabase
import com.skyd.anivu.model.db.dao.ArticleDao
import com.skyd.anivu.model.db.dao.ArticleNotificationRuleDao
import com.skyd.anivu.model.db.dao.DownloadInfoDao
import com.skyd.anivu.model.db.dao.EnclosureDao
import com.skyd.anivu.model.db.dao.FeedDao
Expand Down Expand Up @@ -67,6 +68,10 @@ object DatabaseModule {
@Singleton
fun provideRssModuleDao(database: AppDatabase): RssModuleDao = database.rssModuleDao()

@Provides
@Singleton
fun provideArticleNotificationRuleDao(database: AppDatabase): ArticleNotificationRuleDao =
database.articleNotificationRuleDao()

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.skyd.anivu.model.bean

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.skyd.anivu.base.BaseBean
import com.skyd.anivu.model.bean.article.ArticleWithEnclosureBean
import kotlinx.serialization.Serializable

const val ARTICLE_NOTIFICATION_RULE_TABLE_NAME = "ArticleNotificationRule"

@Serializable
@Entity(tableName = ARTICLE_NOTIFICATION_RULE_TABLE_NAME)
data class ArticleNotificationRuleBean(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = ID_COLUMN)
val id: Int = 0,
@ColumnInfo(name = NAME_COLUMN)
var name: String,
@ColumnInfo(name = REGEX_COLUMN)
var regex: String,
) : BaseBean {
companion object {
const val ID_COLUMN = "id"
const val NAME_COLUMN = "name"
const val REGEX_COLUMN = "regex"
}

private fun isValid() = regex.isNotBlank() && runCatching { Regex(regex) }.getOrNull() != null

fun match(data: ArticleWithEnclosureBean): Boolean {
if (!isValid()) return false
return Regex(regex).run {
matches(data.article.title.orEmpty()) ||
matches(data.article.description.orEmpty()) ||
matches(data.article.content.orEmpty()) ||
matches(data.article.content.orEmpty())
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import com.skyd.anivu.base.BaseBean
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FeedBean
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.skyd.anivu.model.bean.article
import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Relation
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FeedBean
import kotlinx.parcelize.Parcelize
import java.io.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.feed

import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.skyd.anivu.base.BaseBean
import com.skyd.anivu.model.bean.group.GroupVo
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.feed

import android.os.Parcelable
import androidx.room.ColumnInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.feed

import androidx.room.Embedded
import androidx.room.Relation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.group

import android.os.Parcelable
import androidx.room.ColumnInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.group

import android.os.Parcelable
import com.skyd.anivu.R
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.skyd.anivu.model.bean
package com.skyd.anivu.model.bean.group

import androidx.room.Embedded
import androidx.room.Relation
import com.skyd.anivu.model.bean.feed.FeedBean
import com.skyd.anivu.model.bean.feed.FeedViewBean

/**
* A [group] contains many [feeds].
Expand Down
17 changes: 11 additions & 6 deletions app/src/main/java/com/skyd/anivu/model/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.FeedViewBean
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.model.bean.ArticleNotificationRuleBean
import com.skyd.anivu.model.bean.MediaPlayHistoryBean
import com.skyd.anivu.model.bean.article.ArticleBean
import com.skyd.anivu.model.bean.article.EnclosureBean
Expand All @@ -16,9 +14,13 @@ import com.skyd.anivu.model.bean.download.DownloadInfoBean
import com.skyd.anivu.model.bean.download.DownloadLinkUuidMapBean
import com.skyd.anivu.model.bean.download.SessionParamsBean
import com.skyd.anivu.model.bean.download.TorrentFileBean
import com.skyd.anivu.model.bean.feed.FeedBean
import com.skyd.anivu.model.bean.feed.FeedViewBean
import com.skyd.anivu.model.bean.group.GroupBean
import com.skyd.anivu.model.db.converter.CategoriesConverter
import com.skyd.anivu.model.db.converter.RequestHeadersConverter
import com.skyd.anivu.model.db.dao.ArticleDao
import com.skyd.anivu.model.db.dao.ArticleNotificationRuleDao
import com.skyd.anivu.model.db.dao.DownloadInfoDao
import com.skyd.anivu.model.db.dao.EnclosureDao
import com.skyd.anivu.model.db.dao.FeedDao
Expand All @@ -30,6 +32,7 @@ import com.skyd.anivu.model.db.dao.TorrentFileDao
import com.skyd.anivu.model.db.migration.Migration10To11
import com.skyd.anivu.model.db.migration.Migration11To12
import com.skyd.anivu.model.db.migration.Migration12To13
import com.skyd.anivu.model.db.migration.Migration13To14
import com.skyd.anivu.model.db.migration.Migration1To2
import com.skyd.anivu.model.db.migration.Migration2To3
import com.skyd.anivu.model.db.migration.Migration3To4
Expand All @@ -53,11 +56,11 @@ const val APP_DATA_BASE_FILE_NAME = "app.db"
TorrentFileBean::class,
GroupBean::class,
MediaPlayHistoryBean::class,

ArticleNotificationRuleBean::class,
RssMediaBean::class,
],
views = [FeedViewBean::class],
version = 13,
version = 14,
)
@TypeConverters(
value = [CategoriesConverter::class, RequestHeadersConverter::class]
Expand All @@ -72,6 +75,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun sessionParamsDao(): SessionParamsDao
abstract fun mediaPlayHistoryDao(): MediaPlayHistoryDao
abstract fun rssModuleDao(): RssModuleDao
abstract fun articleNotificationRuleDao(): ArticleNotificationRuleDao

companion object {
@Volatile
Expand All @@ -80,7 +84,8 @@ abstract class AppDatabase : RoomDatabase() {
private val migrations = arrayOf(
Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5(),
Migration5To6(), Migration6To7(), Migration7To8(), Migration8To9(),
Migration9To10(), Migration10To11(), Migration11To12(), Migration12To13()
Migration9To10(), Migration10To11(), Migration11To12(), Migration12To13(),
Migration13To14(),
)

fun getInstance(context: Context): AppDatabase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.skyd.anivu.model.db.converter

import androidx.room.TypeConverter
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FeedBean
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/skyd/anivu/model/db/dao/ArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import androidx.room.RewriteQueriesToDropUnusedColumns
import androidx.room.Transaction
import androidx.sqlite.db.SupportSQLiteQuery
import com.skyd.anivu.appContext
import com.skyd.anivu.model.bean.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.feed.FeedBean
import com.skyd.anivu.model.bean.article.ARTICLE_TABLE_NAME
import com.skyd.anivu.model.bean.article.ArticleBean
import com.skyd.anivu.model.bean.article.ArticleWithEnclosureBean
import com.skyd.anivu.model.bean.article.ArticleWithFeed
import com.skyd.anivu.model.bean.article.EnclosureBean
import com.skyd.anivu.ui.notification.ArticleNotificationManager
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
Expand Down Expand Up @@ -95,12 +96,13 @@ interface ArticleDao {
// Update all fields except articleId
newArticle = article.copy(articleId = newArticle.articleId)
innerUpdateArticle(newArticle)
articleWithEnclosure.article = newArticle
}

// Update modules
val media = articleWithEnclosure.media
if (media != null) {
hiltEntryPoint.rssModuleDao.insertIfNotExistITunesRssBean(media)
hiltEntryPoint.rssModuleDao.insertIfNotExistRssMediaBean(media)
}

hiltEntryPoint.enclosureDao.insertListIfNotExist(
Expand All @@ -109,6 +111,7 @@ interface ArticleDao {
}
)
}
ArticleNotificationManager.onNewData(articleWithEnclosureList)
}

@Transaction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.skyd.anivu.model.bean.ARTICLE_NOTIFICATION_RULE_TABLE_NAME
import com.skyd.anivu.model.bean.ArticleNotificationRuleBean
import com.skyd.anivu.model.bean.ArticleNotificationRuleBean.Companion.ID_COLUMN
import kotlinx.coroutines.flow.Flow

@Dao
interface ArticleNotificationRuleDao {
@Transaction
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun setArticleNotificationRule(bean: ArticleNotificationRuleBean)

@Transaction
@Query(value = "DELETE FROM $ARTICLE_NOTIFICATION_RULE_TABLE_NAME WHERE $ID_COLUMN = :id")
fun removeArticleNotificationRule(id: Int): Int

@Transaction
@Query(value = "SELECT * FROM $ARTICLE_NOTIFICATION_RULE_TABLE_NAME")
fun getAllArticleNotificationRules(): Flow<List<ArticleNotificationRuleBean>>
}
14 changes: 7 additions & 7 deletions app/src/main/java/com/skyd/anivu/model/db/dao/FeedDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import androidx.room.Transaction
import androidx.room.Update
import androidx.sqlite.db.SupportSQLiteQuery
import com.skyd.anivu.appContext
import com.skyd.anivu.model.bean.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.FEED_VIEW_NAME
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.FeedViewBean
import com.skyd.anivu.model.bean.FeedWithArticleBean
import com.skyd.anivu.model.bean.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.feed.FEED_VIEW_NAME
import com.skyd.anivu.model.bean.feed.FeedBean
import com.skyd.anivu.model.bean.feed.FeedViewBean
import com.skyd.anivu.model.bean.feed.FeedWithArticleBean
import com.skyd.anivu.model.bean.group.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.group.GroupBean
import com.skyd.anivu.model.bean.article.ArticleBean
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/skyd/anivu/model/db/dao/GroupDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.skyd.anivu.appContext
import com.skyd.anivu.model.bean.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.model.bean.GroupWithFeedBean
import com.skyd.anivu.model.bean.group.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.group.GroupBean
import com.skyd.anivu.model.bean.group.GroupWithFeedBean
import com.skyd.anivu.model.repository.feed.tryDeleteFeedIconFile
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.skyd.anivu.model.bean.article.RssMediaBean
interface RssModuleDao {
@Transaction
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insertIfNotExistITunesRssBean(rssMediaBean: RssMediaBean)
fun insertIfNotExistRssMediaBean(rssMediaBean: RssMediaBean)

@Transaction
@Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.skyd.anivu.model.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.skyd.anivu.model.bean.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.GroupBean
import com.skyd.anivu.model.bean.group.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.group.GroupBean
import com.skyd.anivu.model.bean.MEDIA_PLAY_HISTORY_TABLE_NAME
import com.skyd.anivu.model.bean.MediaPlayHistoryBean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.skyd.anivu.model.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.skyd.anivu.model.bean.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.FeedBean
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.feed.FeedBean

class Migration12To13 : Migration(12, 13) {
override fun migrate(db: SupportSQLiteDatabase) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.skyd.anivu.model.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.skyd.anivu.model.bean.ARTICLE_NOTIFICATION_RULE_TABLE_NAME
import com.skyd.anivu.model.bean.ArticleNotificationRuleBean
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
import com.skyd.anivu.model.bean.feed.FeedBean
import com.skyd.anivu.model.bean.group.GROUP_TABLE_NAME
import com.skyd.anivu.model.bean.group.GroupBean

class Migration13To14 : Migration(13, 14) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"""
CREATE TABLE `$ARTICLE_NOTIFICATION_RULE_TABLE_NAME` (
${ArticleNotificationRuleBean.ID_COLUMN} INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
${ArticleNotificationRuleBean.NAME_COLUMN} TEXT NOT NULL,
${ArticleNotificationRuleBean.REGEX_COLUMN} TEXT NOT NULL
)
"""
)
}
}
Loading

0 comments on commit 6617411

Please sign in to comment.