pull/32/head
kunfei 5 years ago
parent 77eb21b1ad
commit f417cd6808
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  3. 27
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/readbook/config/BgTextConfigDialog.kt
  6. 2
      app/src/main/res/menu/book_source.xml

@ -1,5 +1,6 @@
package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.room.*
import io.legado.app.data.entities.BookSource
@ -13,6 +14,9 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey order by customOrder asc")
fun observeSearch(searchKey: String = ""): DataSource.Factory<Int, BookSource>
@Query("select bookSourceGroup from book_sources")
fun observeGroup(): LiveData<List<String>>
@Query("select distinct enabled from book_sources where bookSourceName like :searchKey or `bookSourceGroup` like :searchKey or bookSourceUrl like :searchKey")
fun searchIsEnable(searchKey: String = ""): List<Boolean>

@ -114,7 +114,7 @@ class AnalyzeByJSoup {
}
if (results.size > 0) {
if ("%" == elementsType) {
for (i in 0 until results[0].size) {
for (i in results[0].indices) {
for (temp in results) {
if (i < temp.size) {
textS.add(temp[i])

@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.SubMenu
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
@ -22,6 +23,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.sourceedit.SourceEditActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank
import kotlinx.android.synthetic.main.activity_book_source.*
import kotlinx.android.synthetic.main.view_search.*
import kotlinx.android.synthetic.main.view_title_bar.*
@ -36,9 +38,11 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
override val viewModel: BookSourceViewModel
get() = getViewModel(BookSourceViewModel::class.java)
private val qrRequestCode = 101
private lateinit var adapter: BookSourceAdapter
private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null
private val qrRequestCode = 101
private var groups = hashSetOf<String>()
private var groupMenu: SubMenu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
@ -52,6 +56,12 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
return super.onCompatCreateOptionsMenu(menu)
}
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
groupMenu = menu?.findItem(R.id.menu_group)?.subMenu
upGroupMenu()
return super.onPrepareOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_add_book_source -> {
@ -106,6 +116,21 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
val dataFactory = App.db.bookSourceDao().observeSearch("%$searchKey%")
bookSourceLiveDate = LivePagedListBuilder(dataFactory, 2000).build()
bookSourceLiveDate?.observe(this, Observer { adapter.submitList(it) })
App.db.bookSourceDao().observeGroup().observe(this, Observer {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(",", ";"))
}
upGroupMenu()
})
}
private fun upGroupMenu() {
groupMenu?.removeGroup(R.id.source_group)
groups.map {
groupMenu?.add(R.id.source_group, Menu.NONE, Menu.NONE, it)
}
}
override fun onQueryTextChange(newText: String?): Boolean {

@ -18,7 +18,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
var callBack: CallBack? = null
var name: String = ""
var author: String = ""
var screenKey: String = ""
private var screenKey: String = ""
private val searchBooks = linkedSetOf<SearchBook>()
fun initData() {

@ -143,7 +143,7 @@ class BgTextConfigDialog : DialogFragment() {
ImageLoader.load(context, context.assets.open("bg/$item").readBytes())
.centerCrop()
.setAsBitmap(iv_bg)
tv_name.text = item.substring(0, item.lastIndexOf("."))
tv_name.text = item.substringBeforeLast(".")
this.onClick {
ReadBookConfig.getConfig().setBg(1, item)
ReadBookConfig.upBg()

@ -11,7 +11,7 @@
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/action_group"
android:id="@+id/menu_group"
android:icon="@drawable/ic_groups"
android:title="@string/menu_action_group"
app:showAsAction="always"

Loading…
Cancel
Save