Skip to content

Commit

Permalink
add bot import/export, support xml action
Browse files Browse the repository at this point in the history
  • Loading branch information
aj3423 committed Oct 10, 2024
1 parent 74e6159 commit 7d3d76d
Show file tree
Hide file tree
Showing 40 changed files with 1,045 additions and 422 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/spam/blocker/GlobalEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package spam.blocker

import android.content.Context
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.mutableIntStateOf
import androidx.lifecycle.MutableLiveData
import androidx.work.WorkManager
import spam.blocker.db.BotTable
Expand All @@ -12,6 +13,12 @@ import spam.blocker.ui.setting.quick.reScheduleSpamDBCleanup
@Immutable
object Events {

// An event triggered when spam db is updated, maybe triggered by Workflow
val spamDbUpdated = mutableIntStateOf(0)

// An event triggered when regex rule list is updated, maybe triggered by Workflow
val regexRuleUpdated = mutableIntStateOf(0)

// An event for notifying the configuration has changed,
// observers should restart, such as:
// - history cleanup schedule
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/spam/blocker/GlobalVariables.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package spam.blocker
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.MutableIntState
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.MutableLiveData
import spam.blocker.ui.history.CallViewModel
import spam.blocker.ui.history.SmsViewModel
import spam.blocker.ui.setting.TestingViewModel
Expand All @@ -30,7 +27,7 @@ object G {
val NumberRuleVM : NumberRuleViewModel = NumberRuleViewModel()
val ContentRuleVM : ContentRuleViewModel = ContentRuleViewModel()
val QuickCopyRuleVM : QuickCopyRuleViewModel = QuickCopyRuleViewModel()
val BotVM : BotViewModel = BotViewModel()
val botVM : BotViewModel = BotViewModel()

lateinit var bottomBarVM : BottomBarViewModel

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/spam/blocker/db/RuleTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ data class RegexRule(
var patternExtra: String = "",

@Serializable(with = CompatibleIntSerializer::class)
var patternFlags: Int = Def.FLAG_REGEX_IGNORE_CASE or Def.FLAG_REGEX_DOT_MATCH_ALL,
var patternFlags: Int = Def.DefaultRegexFlags,
@Serializable(with = CompatibleIntSerializer::class)
var patternExtraFlags: Int = Def.FLAG_REGEX_IGNORE_CASE or Def.FLAG_REGEX_DOT_MATCH_ALL,
var patternExtraFlags: Int = Def.DefaultRegexFlags,

var description: String = "",
var priority: Int = 1,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/spam/blocker/db/SpamTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.database.getIntOrNull
import androidx.core.database.getStringOrNull
import kotlinx.serialization.Serializable
import spam.blocker.def.Def
import spam.blocker.util.Util
import spam.blocker.util.hasFlag
import spam.blocker.util.loge

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/spam/blocker/def/Def.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ object Def {
const val FLAG_REGEX_FOR_CONTACT_GROUP = 1 shl 11
const val FLAG_REGEX_FOR_CONTACT = 1 shl 12

const val DefaultRegexFlags = FLAG_REGEX_IGNORE_CASE or FLAG_REGEX_DOT_MATCH_ALL

val MAP_REGEX_FLAGS = mapOf(
FLAG_REGEX_IGNORE_CASE to "i",
FLAG_REGEX_MULTILINE to "m",
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/spam/blocker/service/bot/Action.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package spam.blocker.service.bot
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.net.Uri
import android.os.Build
import android.os.Environment
Expand All @@ -25,7 +24,7 @@ import java.lang.Exception

// When adding a new IAction type, follow all the steps:
// - add to `ActionType`
// - implement it
// - implement it in Actions.kt
// - add to `defaultActions`
// - add to `botModule` in BotSerializersModule.kt

Expand All @@ -41,19 +40,23 @@ enum class ActionType {
ParseCSV,
ImportToSpamDB,
ImportAsRegexRule,
ConvertNumber,
ParseXML,
}

val defaultActions = listOf(
HttpDownload(),
ImportToSpamDB(),
ImportAsRegexRule(),
ReadFile(),
WriteFile(),
ParseCSV(),
ParseXML(),
ConvertNumber(),
CleanupSpamDB(),
CleanupHistory(),
BackupExport(),
BackupImport(),
ReadFile(),
WriteFile(),
ParseCSV(),
ImportToSpamDB(),
ImportAsRegexRule(),
)


Expand All @@ -62,7 +65,7 @@ enum class ParamType {
None,
String,
ByteArray,
RuleList
RuleList,
}

interface IAction {
Expand Down
Loading

0 comments on commit 7d3d76d

Please sign in to comment.