diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index c61a76f3f..ddc2f3cfa 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -10,22 +10,22 @@ interface BookSourceDao { @Query("select * from book_sources order by customOrder asc") fun observeAll(): DataSource.Factory - @Query("select * from book_sources where name like :searchKey or `group` like :searchKey or origin like :searchKey order by customOrder asc") + @Query("select * from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceOrigin like :searchKey order by customOrder asc") fun observeSearch(searchKey: String = ""): DataSource.Factory - @Query("select distinct isEnabled from book_sources where name like :searchKey or `group` like :searchKey or origin like :searchKey") + @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceOrigin like :searchKey") fun searchIsEnable(searchKey: String = ""): List - @Query("UPDATE book_sources SET isEnabled = :enable where name like :searchKey or `group` like :searchKey or origin like :searchKey") + @Query("UPDATE book_sources SET enabled = :enable where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceOrigin like :searchKey") fun enableAllSearch(searchKey: String = "", enable: String = "1") - @Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc") + @Query("select * from book_sources where enabledExplore = 1 order by customOrder asc") fun observeFind(): DataSource.Factory @get:Query("select * from book_sources order by customOrder asc") val all: List - @Query("select * from book_sources where origin = :key") + @Query("select * from book_sources where bookSourceOrigin = :key") fun findByKey(key: String): BookSource? @Query("select count(*) from book_sources") diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 64d1ce1b2..552427dfb 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -4,87 +4,29 @@ import android.os.Parcelable import androidx.room.Entity import androidx.room.Index import androidx.room.PrimaryKey -import io.legado.app.constant.AppUtils.GSON_CONVERTER -import io.legado.app.data.entities.rule.* -import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.Parcelize @Parcelize @Entity( tableName = "book_sources", - indices = [(Index(value = ["origin"], unique = false))] + indices = [(Index(value = ["bookSourceOrigin"], unique = false))] ) data class BookSource( + var bookSourceName: String = "", // 名称 + var bookSourceGroup: String? = null, // 分组 @PrimaryKey - var origin: String = "", // 地址,包括 http/https - var name: String = "", // 名称 - var type: Int = 0, // 类型,0 文本,1 音频 - var group: String? = null, // 分组 + var bookSourceOrigin: String = "", // 地址,包括 http/https + var bookSourceType: Int = 0, // 类型,0 文本,1 音频 + var customOrder: Int = 0, // 手动排序编号 + var enabled: Boolean = true, // 是否启用 + var enabledExplore: Boolean = true, //启用发现 var header: String? = null, // header var loginUrl: String? = null, // 登录地址 - var isEnabled: Boolean = true, // 是否启用 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 - var customOrder: Int = 0, // 手动排序编号 var weight: Int = 0, // 智能排序的权重 - var exploreIsEnabled: Boolean = true, //启用发现 - var exploreRule: String? = null, // 发现规则 - var searchRule: String? = null, // 搜索规则 - var bookInfoRule: String? = null, // 书籍信息页规则 - var chapterRule: String? = null, // 目录页规则 - var contentRule: String? = null // 正文页规则 -) : Parcelable { - @Transient - @IgnoredOnParcel - var parsedExploreRule: ExploreRule? = null - @Transient - @IgnoredOnParcel - var parsedSearchRule: SearchRule? = null - @Transient - @IgnoredOnParcel - var parsedBookInfoRule: BookInfoRule? = null - @Transient - @IgnoredOnParcel - var parsedChapterRule: ChapterRule? = null - @Transient - @IgnoredOnParcel - var parsedContentRule: ContentRule? = null - - fun initAllRules() { - initSearchRule() - initExploreRule() - initBookInfoRule() - initChapterRule() - initContentRule() - } - - fun initSearchRule() { - if (searchRule != null) { - parsedSearchRule = GSON_CONVERTER.fromJson(searchRule, SearchRule::class.java) - } - } - - fun initExploreRule() { - if (exploreRule != null) { - parsedExploreRule = GSON_CONVERTER.fromJson(exploreRule, ExploreRule::class.java) - } - } - - fun initBookInfoRule() { - if (bookInfoRule != null) { - parsedBookInfoRule = GSON_CONVERTER.fromJson(bookInfoRule, BookInfoRule::class.java) - } - } - - fun initChapterRule() { - if (chapterRule != null) { - parsedChapterRule = GSON_CONVERTER.fromJson(chapterRule, ChapterRule::class.java) - } - } - - fun initContentRule() { - if (contentRule != null) { - parsedContentRule = GSON_CONVERTER.fromJson(contentRule, ContentRule::class.java) - } - } - -} \ No newline at end of file + var ruleExplore: String? = null, // 发现规则 + var ruleSearch: String? = null, // 搜索规则 + var ruleBookInfo: String? = null, // 书籍信息页规则 + var ruleToc: String? = null, // 目录页规则 + var ruleContent: String? = null // 正文页规则 +) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt index e66f83482..e737b02ab 100644 --- a/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt @@ -21,13 +21,13 @@ class BookSourceAdapter : PagedListAdapter() { override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean = - oldItem.origin == newItem.origin + oldItem.bookSourceOrigin == newItem.bookSourceOrigin override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean = - oldItem.origin == newItem.origin - && oldItem.name == newItem.name - && oldItem.group == newItem.group - && oldItem.isEnabled == newItem.isEnabled + oldItem.bookSourceOrigin == newItem.bookSourceOrigin + && oldItem.bookSourceName == newItem.bookSourceName + && oldItem.bookSourceGroup == newItem.bookSourceGroup + && oldItem.enabled == newItem.enabled } } @@ -76,10 +76,10 @@ class BookSourceAdapter : PagedListAdapter(Pair("data", bookSource.origin)) + context?.startActivity(Pair("data", bookSource.bookSourceOrigin)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt index da74b4020..79af1c168 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt @@ -17,11 +17,11 @@ class FindBookAdapter:PagedListAdapter companion object { var DIFF_CALLBACK = object : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean = - oldItem.origin == newItem.origin + oldItem.bookSourceOrigin == newItem.bookSourceOrigin override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean = - oldItem.origin == newItem.origin - && oldItem.name == newItem.name + oldItem.bookSourceOrigin == newItem.bookSourceOrigin + && oldItem.bookSourceName == newItem.bookSourceName } } @@ -40,7 +40,7 @@ class FindBookAdapter:PagedListAdapter fun bind(bookSource: BookSource) = with(itemView) { val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable bgShape?.setStroke(2, ColorUtils.getRandomColor()) - tv_name.text = bookSource.name + tv_name.text = bookSource.bookSourceName } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt index c8bdd0b33..941685ae3 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt @@ -10,9 +10,6 @@ import io.legado.app.base.BaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_source_edit.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.toast class SourceEditActivity : BaseActivity() { @@ -67,38 +64,38 @@ class SourceEditActivity : BaseActivity() { private fun upRecyclerView(bookSource: BookSource?) { bookSource?.let { - cb_is_enable.isChecked = it.isEnabled - cb_is_enable_find.isChecked = it.exploreIsEnabled + cb_is_enable.isChecked = it.enabled + cb_is_enable_find.isChecked = it.enabledExplore } sourceEditEntities.clear() - sourceEditEntities.add(SourceEditEntity("origin", bookSource?.origin, R.string.book_source_url)) - sourceEditEntities.add(SourceEditEntity("name", bookSource?.name, R.string.book_source_name)) - sourceEditEntities.add(SourceEditEntity("group", bookSource?.group, R.string.book_source_group)) + sourceEditEntities.add(SourceEditEntity("origin", bookSource?.bookSourceOrigin, R.string.book_source_url)) + sourceEditEntities.add(SourceEditEntity("name", bookSource?.bookSourceName, R.string.book_source_name)) + sourceEditEntities.add(SourceEditEntity("group", bookSource?.bookSourceGroup, R.string.book_source_group)) adapter.sourceEditEntities = sourceEditEntities adapter.notifyDataSetChanged() } private fun getSource(): BookSource? { val bookSource = BookSource() - bookSource.isEnabled = cb_is_enable.isChecked - bookSource.exploreIsEnabled = cb_is_enable_find.isChecked + bookSource.enabled = cb_is_enable.isChecked + bookSource.enabledExplore = cb_is_enable_find.isChecked for (entity in adapter.sourceEditEntities) { when (entity.key) { "origin" -> { if (entity.value == null) { return null } else { - bookSource.origin = entity.value!! + bookSource.bookSourceOrigin = entity.value!! } } "name" -> { if (entity.value == null) { return null } else { - bookSource.name = entity.value!! + bookSource.bookSourceName = entity.value!! } } - "group" -> bookSource.group = entity.value + "group" -> bookSource.bookSourceGroup = entity.value } } return bookSource diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt index c6e4c0ed6..19876c56b 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt @@ -5,7 +5,6 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.BookSource -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -21,7 +20,7 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application) fun save(bookSource: BookSource, finally: (() -> Unit)? = null) { launch(IO) { - val source = App.db.bookSourceDao().findByKey(bookSource.origin) + val source = App.db.bookSourceDao().findByKey(bookSource.bookSourceOrigin) if (source == null) { bookSource.customOrder = App.db.bookSourceDao().allCount() }