优化
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
package io.legado.app.data.dao
|
package io.legado.app.data.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Delete
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.OnConflictStrategy
|
||||||
|
import androidx.room.Query
|
||||||
|
import androidx.room.Transaction
|
||||||
|
import androidx.room.Update
|
||||||
import io.legado.app.constant.AppPattern
|
import io.legado.app.constant.AppPattern
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
import io.legado.app.data.entities.BookSourcePart
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
@@ -92,8 +98,12 @@ interface BookSourceDao {
|
|||||||
)
|
)
|
||||||
fun flowDisabled(): Flow<List<BookSourcePart>>
|
fun flowDisabled(): Flow<List<BookSourcePart>>
|
||||||
|
|
||||||
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
|
@Query(
|
||||||
fun flowExplore(): Flow<List<BookSource>>
|
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
|
||||||
|
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
|
||||||
|
from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc"""
|
||||||
|
)
|
||||||
|
fun flowExplore(): Flow<List<BookSourcePart>>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
|
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
|
||||||
@@ -126,17 +136,21 @@ interface BookSourceDao {
|
|||||||
fun flowDisabledExplore(): Flow<List<BookSourcePart>>
|
fun flowDisabledExplore(): Flow<List<BookSourcePart>>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""select * from book_sources
|
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
|
||||||
|
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
|
||||||
|
from book_sources
|
||||||
where enabledExplore = 1
|
where enabledExplore = 1
|
||||||
and trim(exploreUrl) <> ''
|
and trim(exploreUrl) <> ''
|
||||||
and (bookSourceGroup like '%' || :key || '%'
|
and (bookSourceGroup like '%' || :key || '%'
|
||||||
or bookSourceName like '%' || :key || '%')
|
or bookSourceName like '%' || :key || '%')
|
||||||
order by customOrder asc"""
|
order by customOrder asc"""
|
||||||
)
|
)
|
||||||
fun flowExplore(key: String): Flow<List<BookSource>>
|
fun flowExplore(key: String): Flow<List<BookSourcePart>>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""select * from book_sources
|
"""select bookSourceUrl, bookSourceName, bookSourceGroup, customOrder, enabled, enabledExplore,
|
||||||
|
trim(loginUrl) <> '' hasLoginUrl, lastUpdateTime, respondTime, weight, trim(exploreUrl) <> '' hasExploreUrl
|
||||||
|
from book_sources
|
||||||
where enabledExplore = 1
|
where enabledExplore = 1
|
||||||
and trim(exploreUrl) <> ''
|
and trim(exploreUrl) <> ''
|
||||||
and (bookSourceGroup = :key
|
and (bookSourceGroup = :key
|
||||||
@@ -145,7 +159,7 @@ interface BookSourceDao {
|
|||||||
or bookSourceGroup like '%,' || :key || ',%')
|
or bookSourceGroup like '%,' || :key || ',%')
|
||||||
order by customOrder asc"""
|
order by customOrder asc"""
|
||||||
)
|
)
|
||||||
fun flowGroupExplore(key: String): Flow<List<BookSource>>
|
fun flowGroupExplore(key: String): Flow<List<BookSourcePart>>
|
||||||
|
|
||||||
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
|
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
|
||||||
fun flowGroupsUnProcessed(): Flow<List<String>>
|
fun flowGroupsUnProcessed(): Flow<List<String>>
|
||||||
@@ -286,6 +300,10 @@ interface BookSourceDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun upOrder(bookSource: BookSourcePart) {
|
||||||
|
upOrder(bookSource.bookSourceUrl, bookSource.customOrder)
|
||||||
|
}
|
||||||
|
|
||||||
@Query("update book_sources set bookSourceGroup = :bookSourceGroup where bookSourceUrl = :bookSourceUrl")
|
@Query("update book_sources set bookSourceGroup = :bookSourceGroup where bookSourceUrl = :bookSourceUrl")
|
||||||
fun upGroup(bookSourceUrl: String, bookSourceGroup: String)
|
fun upGroup(bookSourceUrl: String, bookSourceGroup: String)
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,20 @@ package io.legado.app.data.entities
|
|||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import androidx.room.*
|
import androidx.room.ColumnInfo
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.Index
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
import androidx.room.TypeConverter
|
||||||
|
import androidx.room.TypeConverters
|
||||||
import io.legado.app.constant.AppPattern
|
import io.legado.app.constant.AppPattern
|
||||||
import io.legado.app.constant.BookSourceType
|
import io.legado.app.constant.BookSourceType
|
||||||
import io.legado.app.data.entities.rule.*
|
import io.legado.app.data.entities.rule.BookInfoRule
|
||||||
|
import io.legado.app.data.entities.rule.ContentRule
|
||||||
|
import io.legado.app.data.entities.rule.ExploreRule
|
||||||
|
import io.legado.app.data.entities.rule.ReviewRule
|
||||||
|
import io.legado.app.data.entities.rule.SearchRule
|
||||||
|
import io.legado.app.data.entities.rule.TocRule
|
||||||
import io.legado.app.utils.GSON
|
import io.legado.app.utils.GSON
|
||||||
import io.legado.app.utils.fromJsonObject
|
import io.legado.app.utils.fromJsonObject
|
||||||
import io.legado.app.utils.splitNotBlank
|
import io.legado.app.utils.splitNotBlank
|
||||||
@@ -268,12 +278,10 @@ data class BookSource(
|
|||||||
GSON.fromJsonObject<ContentRule>(json).getOrNull()
|
GSON.fromJsonObject<ContentRule>(json).getOrNull()
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringToReviewRule(json: String?) =
|
fun stringToReviewRule(json: String?): ReviewRule? = null
|
||||||
GSON.fromJsonObject<ReviewRule>(json).getOrNull()
|
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun reviewRuleToString(reviewRule: ReviewRule?): String =
|
fun reviewRuleToString(reviewRule: ReviewRule?): String = "null"
|
||||||
GSON.toJson(reviewRule)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.help.source
|
package io.legado.app.help.source
|
||||||
|
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
import io.legado.app.data.entities.rule.ExploreKind
|
import io.legado.app.data.entities.rule.ExploreKind
|
||||||
import io.legado.app.utils.ACache
|
import io.legado.app.utils.ACache
|
||||||
import io.legado.app.utils.GSON
|
import io.legado.app.utils.GSON
|
||||||
@@ -27,6 +28,14 @@ private fun BookSource.getExploreKindsKey(): String {
|
|||||||
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
|
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun BookSourcePart.getExploreKindsKey(): String {
|
||||||
|
return getBookSource()!!.getExploreKindsKey()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BookSourcePart.exploreKinds(): List<ExploreKind> {
|
||||||
|
return getBookSource()!!.exploreKinds()
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
||||||
val exploreKindsKey = getExploreKindsKey()
|
val exploreKindsKey = getExploreKindsKey()
|
||||||
exploreKindsMap[exploreKindsKey]?.let { return it }
|
exploreKindsMap[exploreKindsKey]?.let { return it }
|
||||||
@@ -75,11 +84,11 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun BookSource.clearExploreKindsCache() {
|
suspend fun BookSourcePart.clearExploreKindsCache() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val exploreKindsKey = getExploreKindsKey()
|
val exploreKindsKey = getExploreKindsKey()
|
||||||
aCache.remove(exploreKindsKey)
|
aCache.remove(exploreKindsKey)
|
||||||
exploreKindsMap.remove(getExploreKindsKey())
|
exploreKindsMap.remove(exploreKindsKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class CronetInterceptor(private val cookieJar: CookieJar) : Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
|
@Throws(IOException::class)
|
||||||
private fun proceedWithCronet(request: Request, call: Call, readTimeoutMillis: Int): Response? {
|
private fun proceedWithCronet(request: Request, call: Call, readTimeoutMillis: Int): Response? {
|
||||||
val callBack = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
val callBack = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
NewCallBack(request, call, readTimeoutMillis)
|
NewCallBack(request, call, readTimeoutMillis)
|
||||||
|
|||||||
@@ -14,13 +14,21 @@ import io.legado.app.utils.printOnDebug
|
|||||||
import org.chromium.net.CronetEngine
|
import org.chromium.net.CronetEngine
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import java.io.*
|
import java.io.BufferedReader
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
import java.io.OutputStream
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.util.*
|
import java.util.Objects
|
||||||
|
|
||||||
|
@Suppress("ConstPropertyName")
|
||||||
@Keep
|
@Keep
|
||||||
object CronetLoader : CronetEngine.Builder.LibraryLoader(), Cronet.LoaderInterface {
|
object CronetLoader : CronetEngine.Builder.LibraryLoader(), Cronet.LoaderInterface {
|
||||||
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so
|
//https://storage.googleapis.com/chromium-cronet/android/92.0.4515.159/Release/cronet/libs/arm64-v8a/libcronet.92.0.4515.159.so
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import io.legado.app.data.entities.BookSource
|
|||||||
import io.legado.app.data.entities.rule.BookInfoRule
|
import io.legado.app.data.entities.rule.BookInfoRule
|
||||||
import io.legado.app.data.entities.rule.ContentRule
|
import io.legado.app.data.entities.rule.ContentRule
|
||||||
import io.legado.app.data.entities.rule.ExploreRule
|
import io.legado.app.data.entities.rule.ExploreRule
|
||||||
import io.legado.app.data.entities.rule.ReviewRule
|
|
||||||
import io.legado.app.data.entities.rule.SearchRule
|
import io.legado.app.data.entities.rule.SearchRule
|
||||||
import io.legado.app.data.entities.rule.TocRule
|
import io.legado.app.data.entities.rule.TocRule
|
||||||
import io.legado.app.databinding.ActivityBookSourceEditBinding
|
import io.legado.app.databinding.ActivityBookSourceEditBinding
|
||||||
@@ -70,7 +69,7 @@ class BookSourceEditActivity :
|
|||||||
private val infoEntities: ArrayList<EditEntity> = ArrayList()
|
private val infoEntities: ArrayList<EditEntity> = ArrayList()
|
||||||
private val tocEntities: ArrayList<EditEntity> = ArrayList()
|
private val tocEntities: ArrayList<EditEntity> = ArrayList()
|
||||||
private val contentEntities: ArrayList<EditEntity> = ArrayList()
|
private val contentEntities: ArrayList<EditEntity> = ArrayList()
|
||||||
private val reviewEntities: ArrayList<EditEntity> = ArrayList()
|
// private val reviewEntities: ArrayList<EditEntity> = ArrayList()
|
||||||
private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
|
private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
|
||||||
it ?: return@registerForActivityResult
|
it ?: return@registerForActivityResult
|
||||||
viewModel.importSource(it) { source ->
|
viewModel.importSource(it) { source ->
|
||||||
@@ -221,14 +220,14 @@ class BookSourceEditActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setEditEntities(tabPosition: Int?) {
|
private fun setEditEntities(tabPosition: Int?) {
|
||||||
when (tabPosition) {
|
adapter.editEntities = when (tabPosition) {
|
||||||
1 -> adapter.editEntities = searchEntities
|
1 -> searchEntities
|
||||||
2 -> adapter.editEntities = exploreEntities
|
2 -> exploreEntities
|
||||||
3 -> adapter.editEntities = infoEntities
|
3 -> infoEntities
|
||||||
4 -> adapter.editEntities = tocEntities
|
4 -> tocEntities
|
||||||
5 -> adapter.editEntities = contentEntities
|
5 -> contentEntities
|
||||||
6 -> adapter.editEntities = reviewEntities
|
// 6 -> reviewEntities
|
||||||
else -> adapter.editEntities = sourceEntities
|
else -> sourceEntities
|
||||||
}
|
}
|
||||||
binding.recyclerView.scrollToPosition(0)
|
binding.recyclerView.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
@@ -342,20 +341,20 @@ class BookSourceEditActivity :
|
|||||||
add(EditEntity("payAction", cr.payAction, R.string.rule_pay_action))
|
add(EditEntity("payAction", cr.payAction, R.string.rule_pay_action))
|
||||||
}
|
}
|
||||||
// 段评
|
// 段评
|
||||||
val rr = bs.getReviewRule()
|
// val rr = bs.getReviewRule()
|
||||||
reviewEntities.clear()
|
// reviewEntities.clear()
|
||||||
reviewEntities.apply {
|
// reviewEntities.apply {
|
||||||
add(EditEntity("reviewUrl", rr.reviewUrl, R.string.rule_review_url))
|
// add(EditEntity("reviewUrl", rr.reviewUrl, R.string.rule_review_url))
|
||||||
add(EditEntity("avatarRule", rr.avatarRule, R.string.rule_avatar))
|
// add(EditEntity("avatarRule", rr.avatarRule, R.string.rule_avatar))
|
||||||
add(EditEntity("contentRule", rr.contentRule, R.string.rule_review_content))
|
// add(EditEntity("contentRule", rr.contentRule, R.string.rule_review_content))
|
||||||
add(EditEntity("postTimeRule", rr.postTimeRule, R.string.rule_post_time))
|
// add(EditEntity("postTimeRule", rr.postTimeRule, R.string.rule_post_time))
|
||||||
add(EditEntity("reviewQuoteUrl", rr.reviewQuoteUrl, R.string.rule_review_quote))
|
// add(EditEntity("reviewQuoteUrl", rr.reviewQuoteUrl, R.string.rule_review_quote))
|
||||||
add(EditEntity("voteUpUrl", rr.voteUpUrl, R.string.review_vote_up))
|
// add(EditEntity("voteUpUrl", rr.voteUpUrl, R.string.review_vote_up))
|
||||||
add(EditEntity("voteDownUrl", rr.voteDownUrl, R.string.review_vote_down))
|
// add(EditEntity("voteDownUrl", rr.voteDownUrl, R.string.review_vote_down))
|
||||||
add(EditEntity("postReviewUrl", rr.postReviewUrl, R.string.post_review_url))
|
// add(EditEntity("postReviewUrl", rr.postReviewUrl, R.string.post_review_url))
|
||||||
add(EditEntity("postQuoteUrl", rr.postQuoteUrl, R.string.post_quote_url))
|
// add(EditEntity("postQuoteUrl", rr.postQuoteUrl, R.string.post_quote_url))
|
||||||
add(EditEntity("deleteUrl", rr.deleteUrl, R.string.delete_review_url))
|
// add(EditEntity("deleteUrl", rr.deleteUrl, R.string.delete_review_url))
|
||||||
}
|
// }
|
||||||
binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0))
|
binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0))
|
||||||
setEditEntities(0)
|
setEditEntities(0)
|
||||||
}
|
}
|
||||||
@@ -376,7 +375,7 @@ class BookSourceEditActivity :
|
|||||||
val bookInfoRule = BookInfoRule()
|
val bookInfoRule = BookInfoRule()
|
||||||
val tocRule = TocRule()
|
val tocRule = TocRule()
|
||||||
val contentRule = ContentRule()
|
val contentRule = ContentRule()
|
||||||
val reviewRule = ReviewRule()
|
// val reviewRule = ReviewRule()
|
||||||
sourceEntities.forEach {
|
sourceEntities.forEach {
|
||||||
when (it.key) {
|
when (it.key) {
|
||||||
"bookSourceUrl" -> source.bookSourceUrl = it.value ?: ""
|
"bookSourceUrl" -> source.bookSourceUrl = it.value ?: ""
|
||||||
@@ -526,34 +525,34 @@ class BookSourceEditActivity :
|
|||||||
"payAction" -> contentRule.payAction = it.value
|
"payAction" -> contentRule.payAction = it.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reviewEntities.forEach {
|
// reviewEntities.forEach {
|
||||||
when (it.key) {
|
// when (it.key) {
|
||||||
"reviewUrl" -> reviewRule.reviewUrl = it.value
|
// "reviewUrl" -> reviewRule.reviewUrl = it.value
|
||||||
"avatarRule" -> reviewRule.avatarRule =
|
// "avatarRule" -> reviewRule.avatarRule =
|
||||||
viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 3)
|
// viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 3)
|
||||||
|
//
|
||||||
"contentRule" -> reviewRule.contentRule =
|
// "contentRule" -> reviewRule.contentRule =
|
||||||
viewModel.ruleComplete(it.value, reviewRule.reviewUrl)
|
// viewModel.ruleComplete(it.value, reviewRule.reviewUrl)
|
||||||
|
//
|
||||||
"postTimeRule" -> reviewRule.postTimeRule =
|
// "postTimeRule" -> reviewRule.postTimeRule =
|
||||||
viewModel.ruleComplete(it.value, reviewRule.reviewUrl)
|
// viewModel.ruleComplete(it.value, reviewRule.reviewUrl)
|
||||||
|
//
|
||||||
"reviewQuoteUrl" -> reviewRule.reviewQuoteUrl =
|
// "reviewQuoteUrl" -> reviewRule.reviewQuoteUrl =
|
||||||
viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 2)
|
// viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 2)
|
||||||
|
//
|
||||||
"voteUpUrl" -> reviewRule.voteUpUrl = it.value
|
// "voteUpUrl" -> reviewRule.voteUpUrl = it.value
|
||||||
"voteDownUrl" -> reviewRule.voteDownUrl = it.value
|
// "voteDownUrl" -> reviewRule.voteDownUrl = it.value
|
||||||
"postReviewUrl" -> reviewRule.postReviewUrl = it.value
|
// "postReviewUrl" -> reviewRule.postReviewUrl = it.value
|
||||||
"postQuoteUrl" -> reviewRule.postQuoteUrl = it.value
|
// "postQuoteUrl" -> reviewRule.postQuoteUrl = it.value
|
||||||
"deleteUrl" -> reviewRule.deleteUrl = it.value
|
// "deleteUrl" -> reviewRule.deleteUrl = it.value
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
source.ruleSearch = searchRule
|
source.ruleSearch = searchRule
|
||||||
source.ruleExplore = exploreRule
|
source.ruleExplore = exploreRule
|
||||||
source.ruleBookInfo = bookInfoRule
|
source.ruleBookInfo = bookInfoRule
|
||||||
source.ruleToc = tocRule
|
source.ruleToc = tocRule
|
||||||
source.ruleContent = contentRule
|
source.ruleContent = contentRule
|
||||||
source.ruleReview = reviewRule
|
// source.ruleReview = reviewRule
|
||||||
return source
|
return source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import com.google.android.flexbox.FlexboxLayout
|
|||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
import io.legado.app.data.entities.rule.ExploreKind
|
import io.legado.app.data.entities.rule.ExploreKind
|
||||||
import io.legado.app.databinding.ItemFilletTextBinding
|
import io.legado.app.databinding.ItemFilletTextBinding
|
||||||
import io.legado.app.databinding.ItemFindBookBinding
|
import io.legado.app.databinding.ItemFindBookBinding
|
||||||
@@ -20,12 +20,17 @@ import io.legado.app.help.source.exploreKinds
|
|||||||
import io.legado.app.lib.theme.accentColor
|
import io.legado.app.lib.theme.accentColor
|
||||||
import io.legado.app.ui.login.SourceLoginActivity
|
import io.legado.app.ui.login.SourceLoginActivity
|
||||||
import io.legado.app.ui.widget.dialog.TextDialog
|
import io.legado.app.ui.widget.dialog.TextDialog
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.activity
|
||||||
|
import io.legado.app.utils.dpToPx
|
||||||
|
import io.legado.app.utils.gone
|
||||||
|
import io.legado.app.utils.showDialogFragment
|
||||||
|
import io.legado.app.utils.startActivity
|
||||||
|
import io.legado.app.utils.visible
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import splitties.views.onLongClick
|
import splitties.views.onLongClick
|
||||||
|
|
||||||
class ExploreAdapter(context: Context, val callBack: CallBack) :
|
class ExploreAdapter(context: Context, val callBack: CallBack) :
|
||||||
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) {
|
RecyclerAdapter<BookSourcePart, ItemFindBookBinding>(context) {
|
||||||
|
|
||||||
private val recycler = arrayListOf<View>()
|
private val recycler = arrayListOf<View>()
|
||||||
private var exIndex = -1
|
private var exIndex = -1
|
||||||
@@ -38,7 +43,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
|
|||||||
override fun convert(
|
override fun convert(
|
||||||
holder: ItemViewHolder,
|
holder: ItemViewHolder,
|
||||||
binding: ItemFindBookBinding,
|
binding: ItemFindBookBinding,
|
||||||
item: BookSource,
|
item: BookSourcePart,
|
||||||
payloads: MutableList<Any>
|
payloads: MutableList<Any>
|
||||||
) {
|
) {
|
||||||
binding.run {
|
binding.run {
|
||||||
@@ -159,7 +164,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
|
|||||||
val source = getItem(position) ?: return true
|
val source = getItem(position) ?: return true
|
||||||
val popupMenu = PopupMenu(context, view)
|
val popupMenu = PopupMenu(context, view)
|
||||||
popupMenu.inflate(R.menu.explore_item)
|
popupMenu.inflate(R.menu.explore_item)
|
||||||
popupMenu.menu.findItem(R.id.menu_login).isVisible = !source.loginUrl.isNullOrBlank()
|
popupMenu.menu.findItem(R.id.menu_login).isVisible = source.hasLoginUrl
|
||||||
popupMenu.setOnMenuItemClickListener {
|
popupMenu.setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.menu_edit -> callBack.editSource(source.bookSourceUrl)
|
R.id.menu_edit -> callBack.editSource(source.bookSourceUrl)
|
||||||
@@ -187,8 +192,8 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
|
|||||||
fun scrollTo(pos: Int)
|
fun scrollTo(pos: Int)
|
||||||
fun openExplore(sourceUrl: String, title: String, exploreUrl: String?)
|
fun openExplore(sourceUrl: String, title: String, exploreUrl: String?)
|
||||||
fun editSource(sourceUrl: String)
|
fun editSource(sourceUrl: String)
|
||||||
fun toTop(source: BookSource)
|
fun toTop(source: BookSourcePart)
|
||||||
fun deleteSource(source: BookSource)
|
fun deleteSource(source: BookSourcePart)
|
||||||
fun searchBook(bookSource: BookSource)
|
fun searchBook(bookSource: BookSourcePart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package io.legado.app.ui.main.explore
|
package io.legado.app.ui.main.explore
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
|
|
||||||
|
|
||||||
class ExploreDiffItemCallBack : DiffUtil.ItemCallback<BookSource>() {
|
class ExploreDiffItemCallBack : DiffUtil.ItemCallback<BookSourcePart>() {
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
|
override fun areItemsTheSame(oldItem: BookSourcePart, newItem: BookSourcePart): Boolean {
|
||||||
return true
|
return oldItem == newItem
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: BookSource, newItem: BookSource): Boolean {
|
override fun areContentsTheSame(oldItem: BookSourcePart, newItem: BookSourcePart): Boolean {
|
||||||
return oldItem.bookSourceName == newItem.bookSourceName
|
return oldItem.bookSourceName == newItem.bookSourceName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import io.legado.app.R
|
|||||||
import io.legado.app.base.VMBaseFragment
|
import io.legado.app.base.VMBaseFragment
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
import io.legado.app.databinding.FragmentExploreBinding
|
import io.legado.app.databinding.FragmentExploreBinding
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.lib.dialogs.alert
|
import io.legado.app.lib.dialogs.alert
|
||||||
@@ -201,11 +201,11 @@ class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_exp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toTop(source: BookSource) {
|
override fun toTop(source: BookSourcePart) {
|
||||||
viewModel.topSource(source)
|
viewModel.topSource(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteSource(source: BookSource) {
|
override fun deleteSource(source: BookSourcePart) {
|
||||||
alert(R.string.draw) {
|
alert(R.string.draw) {
|
||||||
setMessage(getString(R.string.sure_del) + "\n" + source.bookSourceName)
|
setMessage(getString(R.string.sure_del) + "\n" + source.bookSourceName)
|
||||||
noButton()
|
noButton()
|
||||||
@@ -215,7 +215,7 @@ class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_exp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun searchBook(bookSource: BookSource) {
|
override fun searchBook(bookSource: BookSourcePart) {
|
||||||
startActivity<SearchActivity> {
|
startActivity<SearchActivity> {
|
||||||
putExtra("searchScope", SearchScope(bookSource).toString())
|
putExtra("searchScope", SearchScope(bookSource).toString())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ package io.legado.app.ui.main.explore
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import io.legado.app.base.BaseViewModel
|
import io.legado.app.base.BaseViewModel
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSourcePart
|
||||||
import io.legado.app.help.config.SourceConfig
|
import io.legado.app.help.config.SourceConfig
|
||||||
|
|
||||||
class ExploreViewModel(application: Application) : BaseViewModel(application) {
|
class ExploreViewModel(application: Application) : BaseViewModel(application) {
|
||||||
|
|
||||||
fun topSource(bookSource: BookSource) {
|
fun topSource(bookSource: BookSourcePart) {
|
||||||
execute {
|
execute {
|
||||||
val minXh = appDb.bookSourceDao.minOrder
|
val minXh = appDb.bookSourceDao.minOrder
|
||||||
bookSource.customOrder = minXh - 1
|
bookSource.customOrder = minXh - 1
|
||||||
appDb.bookSourceDao.insert(bookSource)
|
appDb.bookSourceDao.upOrder(bookSource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteSource(source: BookSource) {
|
fun deleteSource(source: BookSourcePart) {
|
||||||
execute {
|
execute {
|
||||||
appDb.bookSourceDao.delete(source)
|
appDb.bookSourceDao.delete(source.bookSourceUrl)
|
||||||
SourceConfig.removeSource(source.bookSourceUrl)
|
SourceConfig.removeSource(source.bookSourceUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user