Merge pull request #75 from KKL369/master

开启书籍标签搜索
pull/78/head
kunfei 5 years ago committed by GitHub
commit 57aafe2965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 3
      app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  5. 5
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  6. 14
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt
  7. 2
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  8. 10
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt
  9. 17
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt
  10. 18
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  11. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  12. 6
      app/src/main/res/xml/pref_config_read.xml

@ -20,4 +20,5 @@ object Bus {
const val SHOW_RSS = "showRss"
const val WEB_SERVICE_STOP = "webServiceStop"
const val UP_DOWNLOAD = "upDownload"
const val UP_TABS = "upTabs"
}

@ -4,6 +4,7 @@ object PreferKey {
const val downloadPath = "downloadPath"
const val hideStatusBar = "hideStatusBar"
const val clickAllNext = "clickAllNext"
const val hideNavigationBar = "hideNavigationBar"
const val precisionSearch = "precisionSearch"
const val prevKey = "prevKeyCode"
@ -14,6 +15,7 @@ object PreferKey {
const val processText = "process_text"
const val cleanCache = "cleanCache"
const val lastGroup = "lastGroup"
const val saveTabPosition = "saveTabPosition"
const val pageAnim = "pageAnim"
const val readBookFont = "readBookFont"
const val fontFolder = "fontFolder"

@ -17,6 +17,9 @@ interface BookmarkDao {
@Query("select * from bookmarks where bookUrl = :bookUrl")
fun observeByBook(bookUrl: String): DataSource.Factory<Int, Bookmark>
@Query("SELECT * FROM bookmarks where bookUrl = :bookUrl and chapterName like '%'||:key||'%' or content like '%'||:key||'%'")
fun liveDataSearch(bookUrl: String, key: String): DataSource.Factory<Int, Bookmark>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookmark: Bookmark)

@ -94,6 +94,7 @@ class MoreConfigDialog : DialogFragment() {
when (key) {
PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true)
PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true)
PreferKey.clickAllNext -> postEvent(Bus.UP_CONFIG, true)
}
}

@ -9,8 +9,10 @@ import android.widget.Scroller
import androidx.annotation.CallSuper
import androidx.interpolator.view.animation.FastOutLinearInInterpolator
import com.google.android.material.snackbar.Snackbar
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.read.page.ContentView
import io.legado.app.ui.book.read.page.PageView
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.screenshot
import io.legado.app.utils.snackbar
import kotlin.math.abs
@ -256,7 +258,8 @@ abstract class PageDelegate(protected val pageView: PageView) {
pageView.callBack?.clickCenter()
setTouchPoint(x, y)
} else {
bitmap = if (x > viewWidth / 2) {
bitmap = if (x > viewWidth / 2 ||
pageView.context.getPrefBoolean(PreferKey.clickAllNext, false)) {
//设置动画方向
if (!hasNext()) {
return true

@ -21,7 +21,8 @@ import kotlinx.android.synthetic.main.fragment_bookmark.*
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark),
BookmarkAdapter.Callback {
BookmarkAdapter.Callback,
ChapterListViewModel.BookmarkCallBack {
override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
@ -30,6 +31,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.bookMarkCallBack = this
initRecyclerView()
initData()
}
@ -53,6 +55,16 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
override fun startBookmarkSearch(newText: String?) {
if (newText.isNullOrBlank()) {
initData()
} else {
bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder(App.db.bookmarkDao().liveDataSearch(viewModel.bookUrl ?: "", newText), 20).build()
bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
}
override fun open(bookmark: Bookmark) {
val bookmarkData = Intent()
bookmarkData.putExtra("index", bookmark.chapterIndex)

@ -54,7 +54,7 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activi
override fun onQueryTextChange(newText: String): Boolean {
if (tab_layout.selectedTabPosition == 1) {
viewModel.startBookmarkSearch(newText)
} else {
viewModel.startChapterListSearch(newText)
}

@ -20,7 +20,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list),
ChapterListAdapter.Callback,
ChapterListViewModel.CallBack {
ChapterListViewModel.ChapterListCallBack{
override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
@ -30,6 +30,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.chapterCallBack = this
initRecyclerView()
initView()
initData()
@ -74,21 +75,18 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
mLayoutManager.scrollToPositionWithOffset(it.durChapterIndex, 0)
}
}
viewModel.callBack = this
}
override fun startSearch(newText: String?) {
override fun startChapterListSearch(newText: String?) {
if (newText.isNullOrBlank()) {
initData()
} else {
viewModel.bookUrl?.let { bookUrl ->
App.db.bookChapterDao().liveDataSearch(bookUrl, newText).observe(viewLifecycleOwner, Observer {
App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl ?: "", newText).observe(viewLifecycleOwner, Observer {
adapter.setItems(it)
mLayoutManager.scrollToPositionWithOffset(0, 0)
})
}
}
}
override fun durChapterIndex(): Int {
return durChapterIndex

@ -9,7 +9,8 @@ import io.legado.app.data.entities.Book
class ChapterListViewModel(application: Application) : BaseViewModel(application) {
var bookUrl: String? = null
var book: Book? = null
var callBack: CallBack? = null
var chapterCallBack: ChapterListCallBack? = null
var bookMarkCallBack: BookmarkCallBack? = null
fun loadBook(success: () -> Unit) {
execute {
@ -22,10 +23,18 @@ class ChapterListViewModel(application: Application) : BaseViewModel(application
}
fun startChapterListSearch(newText: String?) {
callBack?.startSearch(newText)
chapterCallBack?.startChapterListSearch(newText)
}
interface CallBack {
fun startSearch(newText: String?)
fun startBookmarkSearch(newText: String?) {
bookMarkCallBack?.startBookmarkSearch(newText)
}
interface ChapterListCallBack {
fun startChapterListSearch(newText: String?)
}
interface BookmarkCallBack {
fun startBookmarkSearch(newText: String?)
}
}

@ -13,22 +13,23 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey
import io.legado.app.constant.PreferKey.saveTabPosition
import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.download.DownloadActivity
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getViewModel
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.startActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_tab_layout.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onLongClick
import org.jetbrains.anko.startActivity
class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_bookshelf),
SearchView.OnQueryTextListener,
GroupManageDialog.CallBack,
@ -82,7 +83,16 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
view_pager_bookshelf.adapter = BookshelfAdapter(this, this)
TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position ->
tab.text = bookGroups[position].groupName
tab.view?.onLongClick {
tab.select()
putPrefInt(saveTabPosition, position)
toast("该分组<" + bookGroups[position].groupName + ">已成为默认页。")
true
}
}.attach()
observeEvent<Int>(Bus.UP_TABS) {
tab_layout.getTabAt(it)?.select()
}
}
private fun initBookGroupData() {

@ -24,6 +24,7 @@ import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.observeEvent
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.fragment_books.*
import org.jetbrains.anko.startActivity
@ -56,6 +57,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
observeEvent<String>(Bus.UP_BOOK) {
booksAdapter.notification(it)
}
postEvent(Bus.UP_TABS, getPrefInt(PreferKey.saveTabPosition, 0))
}
private fun initRecyclerView() {

@ -20,6 +20,12 @@
android:key="volumeKeyPage"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:title="@string/click_all_next_page"
android:key="clickAllNext"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:title="@string/volume_key_page_on_play"

Loading…
Cancel
Save