From 445c1084506368b5468167aae1ae99402a256e45 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 16:05:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BC=80=E5=90=AF=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookmarkDao.kt | 3 +++ .../app/ui/chapterlist/BookmarkFragment.kt | 14 +++++++++++++- .../app/ui/chapterlist/ChapterListActivity.kt | 2 +- .../app/ui/chapterlist/ChapterListFragment.kt | 16 +++++++--------- .../app/ui/chapterlist/ChapterListViewModel.kt | 17 +++++++++++++---- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt index 9010aa950..568714e2f 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt @@ -17,6 +17,9 @@ interface BookmarkDao { @Query("select * from bookmarks where bookUrl = :bookUrl") fun observeByBook(bookUrl: String): DataSource.Factory + @Query("SELECT * FROM bookmarks where bookUrl = :bookUrl and chapterName like '%'||:key||'%' or content like '%'||:key||'%'") + fun liveDataSearch(bookUrl: String, key: String): DataSource.Factory + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookmark: Bookmark) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 31efa44c3..803fe2e11 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -21,7 +21,8 @@ import kotlinx.android.synthetic.main.fragment_bookmark.* class BookmarkFragment : VMBaseFragment(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(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(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) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 1aab97a4b..920b0dd24 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -54,7 +54,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi override fun onQueryTextChange(newText: String): Boolean { if (tab_layout.selectedTabPosition == 1) { - + viewModel.startBookmarkSearch(newText) } else { viewModel.startChapterListSearch(newText) } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index bc002f56e..22092493a 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -20,7 +20,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(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(R.layout.fragme override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.chapterCallBack = this initRecyclerView() initView() initData() @@ -74,19 +75,16 @@ class ChapterListFragment : VMBaseFragment(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 { - adapter.setItems(it) - mLayoutManager.scrollToPositionWithOffset(0, 0) - }) - } + App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl ?: "", newText).observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + mLayoutManager.scrollToPositionWithOffset(0, 0) + }) } } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index abbc81b01..5ac2e68d9 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -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?) } } \ No newline at end of file From e672e82c21b06a1e636f323aa5e9538af8869241 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 20:31:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=95=BF=E6=8C=89TABS?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E9=BB=98=E8=AE=A4=E9=A1=B5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../java/io/legado/app/constant/PreferKey.kt | 1 + .../app/ui/main/bookshelf/BookshelfFragment.kt | 18 ++++++++++++++---- .../ui/main/bookshelf/books/BooksFragment.kt | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 7795773e6..eb1dd14dd 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -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" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 0d8cad7cf..ac1ba5ce5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -14,6 +14,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" diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 15a494694..401685b55 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(R.layout.fragment_bookshelf), SearchView.OnQueryTextListener, GroupManageDialog.CallBack, @@ -82,7 +83,16 @@ class BookshelfFragment : VMBaseFragment(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(Bus.UP_TABS) { + tab_layout.getTabAt(it)?.select() + } } private fun initBookGroupData() { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 765c06697..bff9586ff 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -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(Bus.UP_BOOK) { booksAdapter.notification(it) } + postEvent(Bus.UP_TABS, getPrefInt(PreferKey.saveTabPosition, 0)) } private fun initRecyclerView() { From a7b055974c98b85455f5b29ab65d4adaa80bdc43 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 17 Jan 2020 21:14:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=80=BB=E6=98=AF=E7=BF=BB=E4=B8=8B=E4=B8=80=E9=A1=B5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + .../io/legado/app/ui/book/read/config/MoreConfigDialog.kt | 1 + .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 5 ++++- app/src/main/res/xml/pref_config_read.xml | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index ac1ba5ce5..b869927e6 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index c1954a4e1..899d58d63 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 3f78253b6..db1250c3d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -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 diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 4d996bd8d..b24a16a71 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -20,6 +20,12 @@ android:key="volumeKeyPage" app:iconSpaceReserved="false" /> + +