-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Support post notifications after matching specific new arti…
…cles
- Loading branch information
Showing
73 changed files
with
1,005 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/skyd/anivu/model/bean/ArticleNotificationRuleBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ava/com/skyd/anivu/model/bean/FeedBean.kt → ...om/skyd/anivu/model/bean/feed/FeedBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...com/skyd/anivu/model/bean/FeedViewBean.kt → ...kyd/anivu/model/bean/feed/FeedViewBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...d/anivu/model/bean/FeedWithArticleBean.kt → ...vu/model/bean/feed/FeedWithArticleBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...va/com/skyd/anivu/model/bean/GroupBean.kt → .../skyd/anivu/model/bean/group/GroupBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...java/com/skyd/anivu/model/bean/GroupVo.kt → ...om/skyd/anivu/model/bean/group/GroupVo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...kyd/anivu/model/bean/GroupWithFeedBean.kt → ...ivu/model/bean/group/GroupWithFeedBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/skyd/anivu/model/db/converter/RequestHeadersConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/skyd/anivu/model/db/dao/ArticleNotificationRuleDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/skyd/anivu/model/db/migration/Migration13To14.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
""" | ||
) | ||
} | ||
} |
Oops, something went wrong.