mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
102e7bd689
commit
a4a7a63b2d
@ -25,9 +25,11 @@ import kotlinx.parcelize.Parcelize
|
||||
data class SearchBook(
|
||||
@PrimaryKey
|
||||
override var bookUrl: String = "",
|
||||
var origin: String = "", // 书源规则
|
||||
/** 书源 */
|
||||
var origin: String = "",
|
||||
var originName: String = "",
|
||||
var type: Int = BookType.text, // @BookType
|
||||
/** BookType */
|
||||
var type: Int = BookType.text,
|
||||
override var name: String = "",
|
||||
override var author: String = "",
|
||||
override var kind: String? = null,
|
||||
@ -35,7 +37,8 @@ data class SearchBook(
|
||||
var intro: String? = null,
|
||||
override var wordCount: String? = null,
|
||||
var latestChapterTitle: String? = null,
|
||||
var tocUrl: String = "", // 目录页Url (toc=table of Contents)
|
||||
/** 目录页Url (toc=table of Contents) */
|
||||
var tocUrl: String = "",
|
||||
var time: Long = System.currentTimeMillis(),
|
||||
override var variable: String? = null,
|
||||
var originOrder: Int = 0
|
||||
|
@ -10,8 +10,11 @@ import kotlinx.parcelize.Parcelize
|
||||
@Parcelize
|
||||
@Entity(tableName = "search_keywords", indices = [(Index(value = ["word"], unique = true))])
|
||||
data class SearchKeyword(
|
||||
/** 搜索关键词 */
|
||||
@PrimaryKey
|
||||
var word: String = "", // 搜索关键词
|
||||
var usage: Int = 1, // 使用次数
|
||||
var lastUseTime: Long = System.currentTimeMillis() // 最后一次使用时间
|
||||
var word: String = "",
|
||||
/** 使用次数 */
|
||||
var usage: Int = 1,
|
||||
/** 最后一次使用时间 */
|
||||
var lastUseTime: Long = System.currentTimeMillis()
|
||||
) : Parcelable
|
||||
|
@ -398,6 +398,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
}
|
||||
|
||||
override fun isInBookshelf(name: String, author: String): Boolean {
|
||||
return viewModel.bookshelf.contains("$name-$author")
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示书籍详情
|
||||
*/
|
||||
|
@ -128,6 +128,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
fun isInBookshelf(name: String, author: String): Boolean
|
||||
fun showBookInfo(name: String, author: String, bookUrl: String)
|
||||
}
|
||||
}
|
@ -10,11 +10,16 @@ import io.legado.app.data.entities.SearchKeyword
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.model.webBook.SearchModel
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
val bookshelf = hashSetOf<String>()
|
||||
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
|
||||
private val searchModel = SearchModel(viewModelScope, object : SearchModel.CallBack {
|
||||
|
||||
@ -55,6 +60,17 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}.flowOn(IO)
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
appDb.bookDao.flowAll().mapLatest { books ->
|
||||
books.map { "${it.name}-${it.author}" }
|
||||
}.collect {
|
||||
bookshelf.clear()
|
||||
bookshelf.addAll(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始搜索
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user