feat: 优化代码

pull/379/head
kunfei 5 years ago
parent 0c3d9f5f1e
commit 4457ee2519
  1. 5
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  3. 16
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  5. 2
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt
  6. 11
      app/src/main/res/layout/activity_audio_play.xml
  7. 9
      app/src/main/res/layout/activity_book_info.xml
  8. 27
      app/src/main/res/layout/dialog_change_cover.xml
  9. 36
      app/src/main/res/layout/dialog_change_source.xml
  10. 6
      app/src/main/res/menu/change_source.xml
  11. 1
      app/src/main/res/values/styles.xml

@ -46,8 +46,9 @@ class AudioPlayActivity :
private var adjustProgress = false
override fun onActivityCreated(savedInstanceState: Bundle?) {
title_bar.background.alpha = 0
AudioPlay.titleData.observe(this, Observer { title_bar.title = it })
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
AudioPlay.titleData.observe(this, Observer { toolbar.title = it })
AudioPlay.coverData.observe(this, Observer { upCover(it) })
viewModel.initData(intent)
initView()

@ -52,12 +52,12 @@ class ChangeCoverDialog : DialogFragment(),
callBack = activity as? CallBack
viewModel = getViewModel(ChangeCoverViewModel::class.java)
viewModel.callBack = this
return inflater.inflate(R.layout.dialog_change_source, container)
return inflater.inflate(R.layout.dialog_change_cover, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.searchStateData.observe(this, Observer {
viewModel.searchStateData.observe(viewLifecycleOwner, Observer {
refresh_progress_bar.isAutoLoading = it
})
tool_bar.setTitle(R.string.change_cover_source)

@ -16,9 +16,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.constant.Theme
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getViewModel
import io.legado.app.utils.putPrefBoolean
@ -69,10 +71,8 @@ class ChangeSourceDialog : DialogFragment(),
super.onViewCreated(view, savedInstanceState)
viewModel.initData(arguments)
showTitle()
tool_bar.inflateMenu(R.menu.change_source)
tool_bar.setOnMenuItemClickListener(this)
initRecyclerView()
initMenu()
initRecyclerView()
initSearchView()
initLiveData()
viewModel.loadDbSearchBook()
@ -85,6 +85,9 @@ class ChangeSourceDialog : DialogFragment(),
}
private fun initMenu() {
tool_bar.inflateMenu(R.menu.change_source)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
tool_bar.menu.findItem(R.id.menu_load_toc)?.isChecked =
getPrefBoolean(PreferKey.changeSourceLoadToc)
}
@ -110,16 +113,15 @@ class ChangeSourceDialog : DialogFragment(),
}
private fun initSearchView() {
val searchView = tool_bar.menu.findItem(R.id.menu_search).actionView as SearchView
searchView.setOnCloseListener {
search_view.setOnCloseListener {
showTitle()
false
}
searchView.setOnSearchClickListener {
search_view.setOnSearchClickListener {
tool_bar.title = ""
tool_bar.subtitle = ""
}
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
search_view.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}

@ -24,13 +24,13 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton
import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.chapterlist.ChapterListActivity
import io.legado.app.ui.book.group.GroupSelectDialog
import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.chapterlist.ChapterListActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import io.legado.app.utils.visible
@ -55,7 +55,8 @@ class BookInfoActivity :
get() = getViewModel(BookInfoViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
title_bar.background.alpha = 0
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
tv_intro.movementMethod = ScrollingMovementMethod.getInstance()
viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.chapterListData.observe(this, Observer { upLoading(false, it) })

@ -1,5 +1,6 @@
package io.legado.app.utils
import android.annotation.SuppressLint
import android.content.Context
import android.view.Menu
import android.view.MenuItem
@ -13,6 +14,7 @@ import io.legado.app.lib.theme.primaryTextColor
import java.lang.reflect.Method
import java.util.*
@SuppressLint("RestrictedApi")
fun Menu.applyTint(context: Context, theme: Theme = Theme.Auto): Menu = this.let { menu ->
if (menu is MenuBuilder) {
menu.setOptionalIconsVisible(true)

@ -21,10 +21,13 @@
android:layout_height="match_parent"
android:background="#50000000" />
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_constraintTop_toTopOf="parent" />
<TextView
@ -37,7 +40,7 @@
android:paddingStart="3dp"
android:paddingEnd="3dp"
android:visibility="invisible"
app:layout_constraintTop_toBottomOf="@id/title_bar"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintRight_toRightOf="parent" />
<io.legado.app.ui.widget.image.CircleImageView
@ -51,7 +54,7 @@
app:layout_constraintBottom_toTopOf="@+id/ll_player_progress"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<TextView
android:id="@+id/tv_sub_title"

@ -23,10 +23,13 @@
app:layout_constraintBottom_toTopOf="@+id/view_info"
app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="?attr/actionBarStyle"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/book_info" />
@ -38,7 +41,7 @@
android:scaleType="centerCrop"
android:src="@drawable/image_cover_default"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" />
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<LinearLayout
android:id="@+id/ll_book_info"

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_menu"
android:elevation="5dp"
app:displayHomeAsUp="false"
app:fitStatusBar="false" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

@ -1,31 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_menu"
android:elevation="5dp"
app:displayHomeAsUp="false"
app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent" />
android:background="@color/background_menu">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
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
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
app:layout_constraintTop_toBottomOf="@+id/tool_bar" />
android:layout_height="2dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar"
app:layout_constraintBottom_toBottomOf="parent" />
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

@ -4,9 +4,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:id="@+id/menu_stop"
android:title="@string/stop"
android:icon="@drawable/ic_stop_black_24dp"
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />

@ -33,7 +33,6 @@
<item name="android:popupMenuStyle">@style/Style.PopupMenu</item>
<item name="android:statusBarColor">@color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="elevation">0dp</item>
</style>
<style name="AppTheme.AppBarOverlay.Light" parent="ThemeOverlay.AppCompat.Light">

Loading…
Cancel
Save