add auto subscribe (#768)
* add auto subscribe * [优化] 优化代码 --------- Co-authored-by: HapeLee <1321903405@qq.com>
This commit is contained in:
@@ -3,13 +3,23 @@ package io.legado.app.data.entities
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/**
|
||||
* 类型常量
|
||||
*/
|
||||
object RuleSubType {
|
||||
const val BOOK_SOURCE = 0 // 书源
|
||||
const val RSS_SOURCE = 1 // 订阅源
|
||||
const val REPLACE_RULE = 2 // 替换规则
|
||||
const val AUTO = 3 // 自动识别
|
||||
}
|
||||
|
||||
@Entity(tableName = "ruleSubs")
|
||||
data class RuleSub(
|
||||
@PrimaryKey
|
||||
val id: Long = System.currentTimeMillis(),
|
||||
var name: String = "",
|
||||
var url: String = "",
|
||||
var type: Int = 0,
|
||||
var type: Int = RuleSubType.BOOK_SOURCE,
|
||||
var customOrder: Int = 0,
|
||||
var autoUpdate: Boolean = false,
|
||||
var update: Long = System.currentTimeMillis()
|
||||
|
||||
@@ -46,9 +46,11 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringArrayResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import io.legado.app.R
|
||||
import io.legado.app.data.entities.RuleSub
|
||||
import io.legado.app.data.entities.RuleSubType
|
||||
import io.legado.app.ui.association.ImportBookSourceDialog
|
||||
import io.legado.app.ui.association.ImportReplaceRuleDialog
|
||||
import io.legado.app.ui.association.ImportRssSourceDialog
|
||||
@@ -153,17 +155,26 @@ fun RuleSubScreen(
|
||||
viewModel.toggleSelection(ruleSub)
|
||||
} else {
|
||||
when (ruleSub.type) {
|
||||
0 -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
RuleSubType.BOOK_SOURCE -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
ImportBookSourceDialog(ruleSub.url)
|
||||
)
|
||||
|
||||
1 -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
RuleSubType.RSS_SOURCE -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
ImportRssSourceDialog(ruleSub.url)
|
||||
)
|
||||
|
||||
2 -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
RuleSubType.REPLACE_RULE -> (context as? AppCompatActivity)?.showDialogFragment(
|
||||
ImportReplaceRuleDialog(ruleSub.url)
|
||||
)
|
||||
|
||||
RuleSubType.AUTO -> {
|
||||
val encodedUrl = java.net.URLEncoder.encode(ruleSub.url, "UTF-8")
|
||||
val intent = android.content.Intent(
|
||||
android.content.Intent.ACTION_VIEW,
|
||||
"legado://import/importonline?src=$encodedUrl".toUri()
|
||||
)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user