feat: 优化代码

pull/133/head
kunfei 5 years ago
parent 359b012209
commit 39b20af146
  1. 8
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  4. 24
      app/src/main/res/layout/dialog_change_source.xml
  5. 8
      app/src/main/res/menu/change_source.xml

@ -113,15 +113,16 @@ class ChangeSourceDialog : DialogFragment(),
} }
private fun initSearchView() { private fun initSearchView() {
search_view.setOnCloseListener { val searchView = tool_bar.menu.findItem(R.id.menu_screen).actionView as SearchView
searchView.setOnCloseListener {
showTitle() showTitle()
false false
} }
search_view.setOnSearchClickListener { searchView.setOnSearchClickListener {
tool_bar.title = "" tool_bar.title = ""
tool_bar.subtitle = "" tool_bar.subtitle = ""
} }
search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener { searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
return false return false
} }
@ -151,6 +152,7 @@ class ChangeSourceDialog : DialogFragment(),
putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked)
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
} }
R.id.menu_stop -> viewModel.stopSearch()
} }
return false return false
} }

@ -145,6 +145,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
} }
fun stopSearch() {
task?.cancel()
}
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
searchPool.close() searchPool.close()

@ -194,7 +194,6 @@ abstract class PageDelegate(protected val pageView: PageView) :
@CallSuper @CallSuper
open fun onTouch(event: MotionEvent) { open fun onTouch(event: MotionEvent) {
if (isStarted) return if (isStarted) return
detector.setIsLongpressEnabled(false)
if (!detector.onTouchEvent(event)) { if (!detector.onTouchEvent(event)) {
//GestureDetector.onFling小幅移动不会触发,所以要自己判断 //GestureDetector.onFling小幅移动不会触发,所以要自己判断
when (event.action) { when (event.action) {

@ -5,26 +5,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout <androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/background_menu"> android:background="@color/background_menu"
android:elevation="5dp"
<androidx.appcompat.widget.Toolbar app:displayHomeAsUp="false"
android:id="@+id/tool_bar" app:fitStatusBar="false" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_menu"
android:elevation="5dp"
app:displayHomeAsUp="false"
app:fitStatusBar="false" />
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.appbar.AppBarLayout>
<io.legado.app.ui.widget.anima.RefreshProgressBar <io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar" android:id="@+id/refresh_progress_bar"

@ -3,6 +3,14 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_screen"
android:title="@string/screen"
android:icon="@drawable/ic_screen"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item <item
android:id="@+id/menu_stop" android:id="@+id/menu_stop"
android:title="@string/stop" android:title="@string/stop"

Loading…
Cancel
Save