删除kotlin-android-extensions插件,使用viewBinding替代

master
Z 4 years ago
parent b5a59fd8fd
commit af217ea769
  1. 14
      app/build.gradle
  2. 12
      app/src/main/java/com/novel/read/base/BaseActivity.kt
  3. 41
      app/src/main/java/com/novel/read/base/BaseBindingAdapter.kt
  4. 2
      app/src/main/java/com/novel/read/base/BaseFragment.kt
  5. 6
      app/src/main/java/com/novel/read/base/VMBaseActivity.kt
  6. 43
      app/src/main/java/com/novel/read/lib/ATH.kt
  7. 15
      app/src/main/java/com/novel/read/service/help/ReadBook.kt
  8. 54
      app/src/main/java/com/novel/read/ui/MainActivity.kt
  9. 15
      app/src/main/java/com/novel/read/ui/MainViewModel.kt
  10. 7
      app/src/main/java/com/novel/read/ui/about/AboutActivity.kt
  11. 20
      app/src/main/java/com/novel/read/ui/channel/ChannelActivity.kt
  12. 31
      app/src/main/java/com/novel/read/ui/channel/ChannelAdapter.kt
  13. 21
      app/src/main/java/com/novel/read/ui/channel/ChannelInfoActivity.kt
  14. 31
      app/src/main/java/com/novel/read/ui/channel/ChannelInfoAdapter.kt
  15. 25
      app/src/main/java/com/novel/read/ui/chapter/BookMarkAdapter.kt
  16. 17
      app/src/main/java/com/novel/read/ui/chapter/BookmarkFragment.kt
  17. 30
      app/src/main/java/com/novel/read/ui/chapter/ChapterListActivity.kt
  18. 53
      app/src/main/java/com/novel/read/ui/chapter/ChapterListAdapter.kt
  19. 29
      app/src/main/java/com/novel/read/ui/chapter/ChapterListFragment.kt
  20. 16
      app/src/main/java/com/novel/read/ui/daily/DailyActivity.kt
  21. 37
      app/src/main/java/com/novel/read/ui/daily/DailyAdapter.kt
  22. 17
      app/src/main/java/com/novel/read/ui/end/EndActivity.kt
  23. 35
      app/src/main/java/com/novel/read/ui/end/EndAdapter.kt
  24. 14
      app/src/main/java/com/novel/read/ui/feedback/FeedBackActivity.kt
  25. 50
      app/src/main/java/com/novel/read/ui/info/BookInfoActivity.kt
  26. 23
      app/src/main/java/com/novel/read/ui/info/BookInfoAdapter.kt
  27. 73
      app/src/main/java/com/novel/read/ui/main/bookshelf/BookShelfAdapter.kt
  28. 50
      app/src/main/java/com/novel/read/ui/main/bookshelf/BooksAdapterGrid.kt
  29. 50
      app/src/main/java/com/novel/read/ui/main/bookshelf/BookshelfFragment.kt
  30. 16
      app/src/main/java/com/novel/read/ui/main/bookshelf/arrange/ArrangeBookActivity.kt
  31. 38
      app/src/main/java/com/novel/read/ui/main/bookshelf/arrange/ArrangeBookAdapter.kt
  32. 15
      app/src/main/java/com/novel/read/ui/main/mail/MailFragment.kt
  33. 29
      app/src/main/java/com/novel/read/ui/main/mail/pick/ClickAdapter.kt
  34. 23
      app/src/main/java/com/novel/read/ui/main/mail/pick/EndAdapter.kt
  35. 23
      app/src/main/java/com/novel/read/ui/main/mail/pick/HotAdapter.kt
  36. 99
      app/src/main/java/com/novel/read/ui/main/mail/pick/PickAdapter.kt
  37. 28
      app/src/main/java/com/novel/read/ui/main/mail/pick/RecommendAdapter.kt
  38. 46
      app/src/main/java/com/novel/read/ui/main/my/MyFragment.kt
  39. 19
      app/src/main/java/com/novel/read/ui/main/my/ToolsAdapter.kt
  40. 24
      app/src/main/java/com/novel/read/ui/rank/RankActivity.kt
  41. 38
      app/src/main/java/com/novel/read/ui/rank/RankAdapter.kt
  42. 28
      app/src/main/java/com/novel/read/ui/rank/TypeAdapter.kt
  43. 243
      app/src/main/java/com/novel/read/ui/read/ReadBookActivity.kt
  44. 143
      app/src/main/java/com/novel/read/ui/read/ReadBookBaseActivity.kt
  45. 124
      app/src/main/java/com/novel/read/ui/read/ReadMenu.kt
  46. 55
      app/src/main/java/com/novel/read/ui/read/TextActionMenu.kt
  47. 30
      app/src/main/java/com/novel/read/ui/read/config/ReadAdjustDialog.kt
  48. 110
      app/src/main/java/com/novel/read/ui/read/config/ReadAloudDialog.kt
  49. 76
      app/src/main/java/com/novel/read/ui/read/config/ReadStyleDialog.kt
  50. 193
      app/src/main/java/com/novel/read/ui/read/page/ContentView.kt
  51. 12
      app/src/main/java/com/novel/read/ui/read/page/PageView.kt
  52. 39
      app/src/main/java/com/novel/read/ui/record/ReadRecordActivity.kt
  53. 21
      app/src/main/java/com/novel/read/ui/search/HistoryAdapter.kt
  54. 20
      app/src/main/java/com/novel/read/ui/search/HotAdapter.kt
  55. 89
      app/src/main/java/com/novel/read/ui/search/SearchActivity.kt
  56. 40
      app/src/main/java/com/novel/read/ui/search/SearchAdapter.kt
  57. 9
      app/src/main/java/com/novel/read/ui/setting/SettingActivity.kt
  58. 9
      app/src/main/java/com/novel/read/ui/theme/ThemeActivity.kt
  59. 12
      app/src/main/java/com/novel/read/ui/welcome/WelcomeActivity.kt
  60. 11
      app/src/main/java/com/novel/read/ui/widget/AutoCompleteTextView.kt
  61. 55
      app/src/main/java/com/novel/read/ui/widget/dialog/AppraiseDialog.kt
  62. 45
      app/src/main/java/com/novel/read/ui/widget/dialog/AutoReadDialog.kt
  63. 7
      app/src/main/java/com/novel/read/ui/widget/dialog/PhotoDialog.kt
  64. 16
      app/src/main/java/com/novel/read/ui/widget/dialog/TextDialog.kt
  65. 60
      app/src/main/java/com/novel/read/utils/viewbindingdelegate/ActivityViewBindings.kt
  66. 54
      app/src/main/java/com/novel/read/utils/viewbindingdelegate/FragmentViewBindings.kt
  67. 57
      app/src/main/java/com/novel/read/utils/viewbindingdelegate/ViewBindingProperty.kt
  68. 4
      app/src/main/res/layout/activity_rank.xml
  69. 10
      app/src/main/res/layout/dialog_go_appraise.xml
  70. 55
      app/src/main/res/layout/item_tools.xml
  71. 9
      app/src/main/res/values/themes.xml
  72. 2
      build.gradle

@ -1,7 +1,7 @@
plugins { plugins {
id 'com.android.application' id 'com.android.application'
id 'kotlin-android' id 'kotlin-android'
id 'kotlin-android-extensions' id 'kotlin-parcelize'
} }
def name = "reader" def name = "reader"
@ -22,7 +22,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk { ndk {
abiFilters "armeabi", "arm64-v8a"// "armeabi-v7a", abiFilters "armeabi"
} }
multiDexEnabled true multiDexEnabled true
resConfigs "zh", "zh-rCN" resConfigs "zh", "zh-rCN"
@ -38,7 +38,9 @@ android {
storePassword '1qaz@WSX' storePassword '1qaz@WSX'
} }
} }
buildFeatures {
viewBinding true
}
buildTypes { buildTypes {
debug { debug {
minifyEnabled true minifyEnabled true
@ -68,11 +70,6 @@ android {
dimension "mode" dimension "mode"
manifestPlaceholders = [APP_CHANNEL_VALUE: "app"] manifestPlaceholders = [APP_CHANNEL_VALUE: "app"]
} }
google {
dimension "mode"
applicationId "com.novel.read"
manifestPlaceholders = [APP_CHANNEL_VALUE: "google"]
}
} }
compileOptions { compileOptions {
@ -161,5 +158,4 @@ dependencies {
implementation 'com.allenliu.versionchecklib:library:2.2.0' implementation 'com.allenliu.versionchecklib:library:2.2.0'
implementation 'com.permissionx.guolindev:permissionx:1.4.0' implementation 'com.permissionx.guolindev:permissionx:1.4.0'
} }

@ -10,6 +10,7 @@ import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.novel.read.R import com.novel.read.R
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.constant.Theme import com.novel.read.constant.Theme
@ -23,8 +24,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
abstract class BaseActivity( abstract class BaseActivity<VB : ViewBinding>(
private val layoutID: Int,
val fullScreen: Boolean = true, val fullScreen: Boolean = true,
private val theme: Theme = Theme.Auto, private val theme: Theme = Theme.Auto,
private val toolBarTheme: Theme = Theme.Auto, private val toolBarTheme: Theme = Theme.Auto,
@ -32,6 +32,8 @@ abstract class BaseActivity(
) : AppCompatActivity(), ) : AppCompatActivity(),
CoroutineScope by MainScope() { CoroutineScope by MainScope() {
protected val binding: VB by lazy { getViewBinding() }
val isInMultiWindow: Boolean val isInMultiWindow: Boolean
get() { get() {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
@ -45,6 +47,8 @@ abstract class BaseActivity(
super.attachBaseContext(LanguageUtils.setConfiguration(newBase)) super.attachBaseContext(LanguageUtils.setConfiguration(newBase))
} }
protected abstract fun getViewBinding(): VB
override fun onCreateView( override fun onCreateView(
parent: View?, parent: View?,
name: String, name: String,
@ -60,9 +64,9 @@ abstract class BaseActivity(
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
window.decorView.disableAutoFill() window.decorView.disableAutoFill()
initTheme() initTheme()
setupSystemBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(layoutID) setContentView(binding.root)
setupSystemBar()
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
findViewById<TitleBar>(R.id.title_bar) findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen) ?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen)

@ -0,0 +1,41 @@
package com.novel.read.base
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.entity.SectionEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder
abstract class BaseBindingAdapter<T, VB : ViewBinding>(data: MutableList<T>? = null) :
BaseQuickAdapter<T, VBViewHolder<VB>>(0, data) {
abstract fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): VB
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): VBViewHolder<VB> {
val viewBinding = createViewBinding(LayoutInflater.from(parent.context), parent)
return VBViewHolder(viewBinding, viewBinding.root)
}
}
class VBViewHolder<VB : ViewBinding>(val vb: VB, view: View) : BaseViewHolder(view)
@JvmName("bind")
fun <VB : ViewBinding> BaseViewHolder.withBinding(bind: (View) -> VB): BaseViewHolder =
BaseViewHolderWithBinding(bind(itemView))
@JvmName("getBinding")
@Suppress("UNCHECKED_CAST")
fun <VB : ViewBinding> BaseViewHolder.getViewBinding(): VB {
if (this is BaseViewHolderWithBinding<*>) {
return binding as VB
} else {
throw IllegalStateException("The binding could not be found.")
}
}
class BaseViewHolderWithBinding<VB : ViewBinding>(val binding: VB) : BaseViewHolder(binding.root)

@ -58,7 +58,7 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID),
} }
private fun onMultiWindowModeChanged() { private fun onMultiWindowModeChanged() {
(activity as? BaseActivity)?.let { (activity as? BaseActivity<*>)?.let {
view?.findViewById<TitleBar>(R.id.title_bar) view?.findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(it.isInMultiWindow, it.fullScreen) ?.onMultiWindowModeChanged(it.isInMultiWindow, it.fullScreen)
} }

@ -1,14 +1,14 @@
package com.novel.read.base package com.novel.read.base
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.viewbinding.ViewBinding
import com.novel.read.constant.Theme import com.novel.read.constant.Theme
abstract class VMBaseActivity<VM : ViewModel>( abstract class VMBaseActivity<VB : ViewBinding,VM : ViewModel>(
layoutID: Int,
fullScreen: Boolean = true, fullScreen: Boolean = true,
theme: Theme = Theme.Auto, theme: Theme = Theme.Auto,
toolBarTheme: Theme = Theme.Auto toolBarTheme: Theme = Theme.Auto
) : BaseActivity(layoutID, fullScreen, theme, toolBarTheme) { ) : BaseActivity<VB>(fullScreen, theme, toolBarTheme) {
protected abstract val viewModel: VM protected abstract val viewModel: VM

@ -10,6 +10,7 @@ import android.os.Build
import android.view.View import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.Window import android.view.Window
import android.view.WindowInsetsController
import android.widget.EdgeEffect import android.widget.EdgeEffect
import android.widget.ScrollView import android.widget.ScrollView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
@ -23,7 +24,6 @@ import com.novel.read.help.AppConfig
import com.novel.read.help.TintHelper import com.novel.read.help.TintHelper
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_main.view.*
import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.backgroundColor
@ -86,6 +86,45 @@ object ATH {
} }
} }
fun setLightStatusBarAuto(activity: Activity, bgColor: Int) {
setLightStatusBar(activity, ColorUtils.isColorLight(bgColor))
}
fun setLightStatusBar(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.window.insetsController?.let {
if (enabled) {
it.setSystemBarsAppearance(
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
} else {
it.setSystemBarsAppearance(
0,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
)
}
}
}
setLightStatusBarO(activity, enabled)
}
@Suppress("DEPRECATION")
private fun setLightStatusBarO(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val decorView = activity.window.decorView
val systemUiVisibility = decorView.systemUiVisibility
if (enabled) {
decorView.systemUiVisibility =
systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility =
systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
}
}
}
fun setLightNavigationBar(activity: Activity, enabled: Boolean) { fun setLightNavigationBar(activity: Activity, enabled: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val decorView = activity.window.decorView val decorView = activity.window.decorView
@ -207,7 +246,7 @@ object ATH {
val textColor = context.getSecondaryTextColor(textIsDark) val textColor = context.getSecondaryTextColor(textIsDark)
val colorStateList = Selector.colorBuild() val colorStateList = Selector.colorBuild()
.setDefaultColor(textColor) .setDefaultColor(textColor)
.setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() .setSelectedColor(ThemeStore.accentColor(context)).create()
itemIconTintList = colorStateList itemIconTintList = colorStateList
itemTextColor = colorStateList itemTextColor = colorStateList
} }

@ -98,8 +98,8 @@ object ReadBook {
} }
loadContent(durChapterIndex.plus(1), upContent, false) loadContent(durChapterIndex.plus(1), upContent, false)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
for (i in 2..10) { for (i in 2..9) {
delay(100) delay(1000)
download(durChapterIndex + i) download(durChapterIndex + i)
} }
} }
@ -128,8 +128,8 @@ object ReadBook {
} }
loadContent(durChapterIndex.minus(1), upContent, false) loadContent(durChapterIndex.minus(1), upContent, false)
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
for (i in -5..-2) { for (i in 2..9) {
delay(100) delay(1000)
download(durChapterIndex + i) download(durChapterIndex + i)
} }
} }
@ -410,12 +410,6 @@ object ReadBook {
} }
fun pageAnim(): Int { fun pageAnim(): Int {
// book?.let {
// return if (it.getPageAnim() < 0)
// ReadBookConfig.pageAnim
// else
// it.getPageAnim()
// }
return ReadBookConfig.pageAnim return ReadBookConfig.pageAnim
} }
@ -439,6 +433,7 @@ object ReadBook {
fun upView() fun upView()
fun pageChanged() fun pageChanged()
fun contentLoadFinish() fun contentLoadFinish()
fun upPageAnim()
} }
} }

@ -16,18 +16,17 @@ import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.data.model.AppUpdateResp import com.novel.read.data.model.AppUpdateResp
import com.novel.read.databinding.ActivityMainBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.service.BaseReadAloudService import com.novel.read.service.BaseReadAloudService
import com.novel.read.ui.main.bookshelf.BookshelfFragment import com.novel.read.ui.main.bookshelf.BookshelfFragment
import com.novel.read.ui.main.mail.MailFragment import com.novel.read.ui.main.mail.MailFragment
import com.novel.read.ui.main.my.MyFragment import com.novel.read.ui.main.my.MyFragment
import com.novel.read.ui.widget.dialog.AppraiseDialog
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_main.*
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main), class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
BottomNavigationView.OnNavigationItemSelectedListener, BottomNavigationView.OnNavigationItemSelectedListener,
BottomNavigationView.OnNavigationItemReselectedListener, BottomNavigationView.OnNavigationItemReselectedListener,
ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() {
@ -35,31 +34,34 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
override val viewModel: MainViewModel override val viewModel: MainViewModel
get() = getViewModel(MainViewModel::class.java) get() = getViewModel(MainViewModel::class.java)
override fun getViewBinding(): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater)
}
private var bookshelfReselected: Long = 0 private var bookshelfReselected: Long = 0
private var exitTime: Long = 0 private var exitTime: Long = 0
private var pagePosition = 0 private var pagePosition = 0
private val fragmentMap = hashMapOf<Int, Fragment>() private val fragmentMap = hashMapOf<Int, Fragment>()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) = with(binding) {
ATH.applyEdgeEffectColor(view_pager_main) ATH.applyEdgeEffectColor(viewPagerMain)
ATH.applyBottomNavigationColor(bottom_navigation_view) ATH.applyBottomNavigationColor(bottomNavigationView)
view_pager_main.offscreenPageLimit = 3 viewPagerMain.offscreenPageLimit = 3
view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager)
view_pager_main.addOnPageChangeListener(this) viewPagerMain.addOnPageChangeListener(this@MainActivity)
bottom_navigation_view.elevation = bottomNavigationView.elevation =
if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat() if (AppConfig.elevation < 0) elevation else AppConfig.elevation.toFloat()
bottom_navigation_view.setOnNavigationItemSelectedListener(this) bottomNavigationView.setOnNavigationItemSelectedListener(this@MainActivity)
bottom_navigation_view.setOnNavigationItemReselectedListener(this) bottomNavigationView.setOnNavigationItemReselectedListener(this@MainActivity)
initData() initData()
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState) super.onPostCreate(savedInstanceState)
viewModel.appUpdate() viewModel.appUpdate()
viewModel.checkCount()
//自动更新书籍 //自动更新书籍
view_pager_main.postDelayed({ binding.viewPagerMain.postDelayed({
viewModel.upAllBookToc() viewModel.upAllBookToc()
}, 1000) }, 1000)
} }
@ -69,21 +71,13 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
viewModel.appResp.observe(this) { viewModel.appResp.observe(this) {
updateApk(it) updateApk(it)
} }
viewModel.showEvaluate.observe(this) {
val dialog = AppraiseDialog(this)
dialog.appraiseDialog {
goShop()
dialog.dismiss()
}
dialog.show()
}
} }
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) = with(binding) {
view_pager_main.hideSoftInput() viewPagerMain.hideSoftInput()
pagePosition = position pagePosition = position
when (position) { when (position) {
0, 1, 2 -> bottom_navigation_view.menu.getItem(position).isChecked = true 0, 1, 2 -> bottomNavigationView.menu.getItem(position).isChecked = true
} }
} }
@ -92,7 +86,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled) { KeyEvent.KEYCODE_BACK -> if (event.isTracking && !event.isCanceled) {
if (pagePosition != 0) { if (pagePosition != 0) {
view_pager_main.currentItem = 0 binding.viewPagerMain.currentItem = 0
return true return true
} }
if (System.currentTimeMillis() - exitTime > 2000) { if (System.currentTimeMillis() - exitTime > 2000) {
@ -112,11 +106,11 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
return super.onKeyUp(keyCode, event) return super.onKeyUp(keyCode, event)
} }
override fun onNavigationItemSelected(item: MenuItem): Boolean { override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) {
when (item.itemId) { when (item.itemId) {
R.id.menu_mail -> view_pager_main.setCurrentItem(0, false) R.id.menu_mail -> viewPagerMain.setCurrentItem(0, false)
R.id.menu_bookshelf -> view_pager_main.setCurrentItem(1, false) R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(1, false)
R.id.menu_my_config -> view_pager_main.setCurrentItem(2, false) R.id.menu_my_config -> viewPagerMain.setCurrentItem(2, false)
} }
return false return false
} }

@ -26,7 +26,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
private val homeRepository by lazy { HomeRepository() } private val homeRepository by lazy { HomeRepository() }
private val bookRepository by lazy { BookRepository() } private val bookRepository by lazy { BookRepository() }
var appResp = MutableLiveData<AppUpdateResp>() var appResp = MutableLiveData<AppUpdateResp>()
val showEvaluate = MutableLiveData<Boolean>()
fun appUpdate() { fun appUpdate() {
launch({ launch({
@ -126,18 +125,4 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun checkCount() {
val count = App.INSTANCE.getPrefInt(PreferKey.installCount, 0)
App.INSTANCE.putPrefInt(PreferKey.installCount, count + 1)
if (App.INSTANCE.getPrefLong(PreferKey.installTime) == 0L) {
App.INSTANCE.putPrefLong(PreferKey.installTime, System.currentTimeMillis())
} else {
if (StringUtils.checkInstallTime() && !App.INSTANCE.getPrefBoolean(PreferKey.appraiseShow)) {
showEvaluate.postValue(true)
App.INSTANCE.putPrefBoolean(PreferKey.appraiseShow, true)
}
}
}
} }

@ -3,9 +3,14 @@ package com.novel.read.ui.about
import android.os.Bundle import android.os.Bundle
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.databinding.ActivityAboutBinding
class AboutActivity : BaseActivity(R.layout.activity_about) { class AboutActivity : BaseActivity<ActivityAboutBinding>() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
} }
override fun getViewBinding(): ActivityAboutBinding {
return ActivityAboutBinding.inflate(layoutInflater)
}
} }

@ -8,29 +8,33 @@ import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.data.model.ChannelSection import com.novel.read.data.model.ChannelSection
import com.novel.read.databinding.ActivityChannelBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_channel.*
import java.util.ArrayList import java.util.ArrayList
class ChannelActivity : VMBaseActivity<ChannelViewModel>(R.layout.activity_channel) { class ChannelActivity : VMBaseActivity<ActivityChannelBinding, ChannelViewModel>() {
override val viewModel: ChannelViewModel override val viewModel: ChannelViewModel
get() = getViewModel(ChannelViewModel::class.java) get() = getViewModel(ChannelViewModel::class.java)
override fun getViewBinding(): ActivityChannelBinding {
return ActivityChannelBinding.inflate(layoutInflater)
}
private lateinit var adapter: ChannelAdapter private lateinit var adapter: ChannelAdapter
private val data: MutableList<ChannelSection> = ArrayList() private val data: MutableList<ChannelSection> = ArrayList()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_channel) ATH.applyEdgeEffectColor(binding.rlvChannel)
initRecyclerView() initRecyclerView()
upRecyclerData() upRecyclerData()
} }
private fun initRecyclerView() { private fun initRecyclerView() = with(binding) {
rlv_channel.layoutManager = GridLayoutManager(this, 2) rlvChannel.layoutManager = GridLayoutManager(this@ChannelActivity, 2)
adapter = ChannelAdapter() adapter = ChannelAdapter()
rlv_channel.adapter = adapter rlvChannel.adapter = adapter
} }
private fun upRecyclerData() { private fun upRecyclerData() {
@ -69,9 +73,11 @@ class ChannelActivity : VMBaseActivity<ChannelViewModel>(R.layout.activity_chann
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_channel, false) val errorView: View =
layoutInflater.inflate(R.layout.view_net_error, binding.rlvChannel, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }
} }

@ -1,14 +1,18 @@
package com.novel.read.ui.channel package com.novel.read.ui.channel
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseSectionQuickAdapter import com.chad.library.adapter.base.BaseSectionQuickAdapter
import com.chad.library.adapter.base.entity.SectionEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.getViewBinding
import com.novel.read.base.withBinding
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.data.model.AllType import com.novel.read.data.model.AllType
import com.novel.read.data.model.ChannelSection import com.novel.read.data.model.ChannelSection
import kotlinx.android.synthetic.main.item_channel.view.* import com.novel.read.databinding.ItemChannelBinding
import kotlinx.android.synthetic.main.item_channel_head.view.* import com.novel.read.databinding.ItemChannelHeadBinding
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -17,26 +21,35 @@ class ChannelAdapter : BaseSectionQuickAdapter<ChannelSection, BaseViewHolder>(
R.layout.item_channel R.layout.item_channel
) { ) {
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewHolder = super.onCreateDefViewHolder(parent, viewType)
return when (viewType) {
SectionEntity.HEADER_TYPE -> viewHolder.withBinding(ItemChannelHeadBinding::bind)
SectionEntity.NORMAL_TYPE -> viewHolder.withBinding(ItemChannelBinding::bind)
else -> throw IllegalStateException()
}
}
override fun convertHeader(helper: BaseViewHolder, item: ChannelSection) { override fun convertHeader(helper: BaseViewHolder, item: ChannelSection) {
val value = item.obj as String val value = item.obj as String
helper.itemView.run { helper.getViewBinding<ItemChannelHeadBinding>().apply {
tv_sex.text = value tvSex.text = value
} }
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun convert(holder: BaseViewHolder, item: ChannelSection) { override fun convert(holder: BaseViewHolder, item: ChannelSection) {
val value = item.obj as AllType val value = item.obj as AllType
holder.itemView.run { holder.itemView.onClick {
tv_name.text = value.getBChannel()
iv_cover.load(value.typeImageUrl, "", "")
tv_count.text= "${value.bookCount}"
onClick {
context.startActivity<ChannelInfoActivity>( context.startActivity<ChannelInfoActivity>(
Pair(IntentAction.bookTypeId, value.bookTypeId), Pair(IntentAction.bookTypeId, value.bookTypeId),
Pair(IntentAction.channelName, value.getBChannel()), Pair(IntentAction.channelName, value.getBChannel()),
) )
} }
holder.getViewBinding<ItemChannelBinding>().apply {
tvName.text = value.getBChannel()
ivCover.load(value.typeImageUrl, "", "")
tvCount.text = "${value.bookCount}"
} }
} }

@ -9,17 +9,23 @@ import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.databinding.ActivityChannelInfoBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_channel_info.*
class ChannelInfoActivity : VMBaseActivity<ChannelInfoViewModel>(R.layout.activity_channel_info) { class ChannelInfoActivity : VMBaseActivity<ActivityChannelInfoBinding,ChannelInfoViewModel>() {
override val viewModel: ChannelInfoViewModel override val viewModel: ChannelInfoViewModel
get() = getViewModel(ChannelInfoViewModel::class.java) get() = getViewModel(ChannelInfoViewModel::class.java)
override fun getViewBinding(): ActivityChannelInfoBinding {
return ActivityChannelInfoBinding.inflate(layoutInflater)
}
private lateinit var adapter: ChannelInfoAdapter private lateinit var adapter: ChannelInfoAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_book) ATH.applyEdgeEffectColor(binding.rlvBook)
initRecyclerView() initRecyclerView()
viewModel.initData(intent) viewModel.initData(intent)
upRecyclerData() upRecyclerData()
@ -27,14 +33,14 @@ class ChannelInfoActivity : VMBaseActivity<ChannelInfoViewModel>(R.layout.activi
} }
private fun initRecyclerView() { private fun initRecyclerView() {
rlv_book.layoutManager = LinearLayoutManager(this) binding.rlvBook.layoutManager = LinearLayoutManager(this)
adapter = ChannelInfoAdapter() adapter = ChannelInfoAdapter()
rlv_book.adapter = adapter binding.rlvBook.adapter = adapter
} }
private fun upRecyclerData() { private fun upRecyclerData() {
val channelName = intent.getStringExtra(IntentAction.channelName) ?: "" val channelName = intent.getStringExtra(IntentAction.channelName) ?: ""
title_bar.title = channelName binding.titleBar.title = channelName
onRefresh() onRefresh()
viewModel.run { viewModel.run {
bookListResp.observe(this@ChannelInfoActivity) { bookListResp.observe(this@ChannelInfoActivity) {
@ -88,9 +94,10 @@ class ChannelInfoActivity : VMBaseActivity<ChannelInfoViewModel>(R.layout.activi
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_book, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvBook, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }
} }

@ -1,28 +1,41 @@
package com.novel.read.ui.channel package com.novel.read.ui.channel
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.BookListResp import com.novel.read.data.model.BookListResp
import com.novel.read.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class ChannelInfoAdapter : class ChannelInfoAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) { override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.run { holder.itemView.run {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_book_name.text = item.getBBookName()
tv_book_description.text = item.getBIntroduction()
tv_book_author.text = item.getBAuthorName()
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000)
tv_category.text = item.getBCategoryName()
onClick { onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
} }
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvBookName.text = item.getBBookName()
tvBookDescription.text = item.getBIntroduction()
tvBookAuthor.text = item.getBAuthorName()
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000)
tvCategory.text = item.getBCategoryName()
}
}
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookCommonBinding {
return ItemBookCommonBinding.inflate(inflater,parent,false)
} }
} }

@ -1,19 +1,26 @@
package com.novel.read.ui.chapter package com.novel.read.ui.chapter
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.LayoutInflater
import com.chad.library.adapter.base.viewholder.BaseViewHolder import android.view.ViewGroup
import com.novel.read.R import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.Bookmark import com.novel.read.data.db.entity.Bookmark
import kotlinx.android.synthetic.main.item_bookmark.view.* import com.novel.read.databinding.ItemBookmarkBinding
class BookMarkAdapter :BaseQuickAdapter<Bookmark,BaseViewHolder>(R.layout.item_bookmark) { class BookMarkAdapter :BaseBindingAdapter<Bookmark,ItemBookmarkBinding>() {
override fun convert(holder: BaseViewHolder, item: Bookmark) { override fun convert(holder: VBViewHolder<ItemBookmarkBinding>, item: Bookmark) {
holder.itemView.run { holder.vb.run {
tv_chapter_name.text = item.chapterName tvChapterName.text = item.chapterName
tv_content.text = item.content tvContent.text = item.content
}
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookmarkBinding {
return ItemBookmarkBinding.inflate(inflater, parent, false)
} }
} }

@ -12,6 +12,7 @@ import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseFragment import com.novel.read.base.VMBaseFragment
import com.novel.read.data.db.entity.Bookmark import com.novel.read.data.db.entity.Bookmark
import com.novel.read.databinding.FragmentBookmarkBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.lib.dialogs.alert import com.novel.read.lib.dialogs.alert
import com.novel.read.lib.dialogs.customView import com.novel.read.lib.dialogs.customView
@ -19,8 +20,7 @@ import com.novel.read.lib.dialogs.noButton
import com.novel.read.lib.dialogs.yesButton import com.novel.read.lib.dialogs.yesButton
import com.novel.read.ui.widget.VerticalDivider import com.novel.read.ui.widget.VerticalDivider
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.android.synthetic.main.fragment_bookmark.*
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark), class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark),
ChapterListViewModel.BookmarkCallBack { ChapterListViewModel.BookmarkCallBack {
@ -28,6 +28,8 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java) get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private val binding by viewBinding(FragmentBookmarkBinding::bind)
private lateinit var adapter: BookMarkAdapter private lateinit var adapter: BookMarkAdapter
private var bookmarkLiveData = MutableLiveData<List<Bookmark>>() private var bookmarkLiveData = MutableLiveData<List<Bookmark>>()
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
@ -37,11 +39,11 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
} }
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(binding.recyclerView)
adapter = BookMarkAdapter() adapter = BookMarkAdapter()
recycler_view.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
recycler_view.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
recycler_view.adapter = adapter binding.recyclerView.adapter = adapter
} }
private fun initData() { private fun initData() {
@ -68,9 +70,10 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
requireContext().alert(R.string.bookmark) { requireContext().alert(R.string.bookmark) {
var editText: EditText? = null var editText: EditText? = null
message = book.bookName + "" + bookmark.chapterName message = book.bookName + "" + bookmark.chapterName
customView { customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view.apply { editText = findViewById<EditText>(R.id.edit_view).apply {
setHint(R.string.note_content) setHint(R.string.note_content)
setText(bookmark.content) setText(bookmark.content)
} }

@ -7,27 +7,31 @@ import androidx.core.view.isGone
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import com.google.android.material.tabs.TabLayout
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.databinding.ActivityChapterListBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_chapter_list.*
import kotlinx.android.synthetic.main.view_tab_layout.*
class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding,ChapterListViewModel>() {
class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activity_chapter_list) {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModel(ChapterListViewModel::class.java) get() = getViewModel(ChapterListViewModel::class.java)
override fun getViewBinding(): ActivityChapterListBinding {
return ActivityChapterListBinding.inflate(layoutInflater)
}
private lateinit var tabLayout: TabLayout
private var searchView: SearchView? = null private var searchView: SearchView? = null
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
tab_layout.isTabIndicatorFullWidth = false tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
tab_layout.setSelectedTabIndicatorColor(accentColor) tabLayout.isTabIndicatorFullWidth = false
tabLayout.setSelectedTabIndicatorColor(accentColor)
intent.getStringExtra("bookId")?.let { intent.getStringExtra("bookId")?.let {
viewModel.initBook(it) { viewModel.initBook(it) {
view_pager.adapter = TabFragmentPageAdapter(supportFragmentManager) binding.viewPager.adapter = TabFragmentPageAdapter(supportFragmentManager)
tab_layout.setupWithViewPager(view_pager) tabLayout.setupWithViewPager(binding.viewPager)
} }
} }
} }
@ -40,17 +44,17 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activi
searchView?.maxWidth = resources.displayMetrics.widthPixels searchView?.maxWidth = resources.displayMetrics.widthPixels
searchView?.onActionViewCollapsed() searchView?.onActionViewCollapsed()
searchView?.setOnCloseListener { searchView?.setOnCloseListener {
tab_layout.visible() tabLayout.visible()
false false
} }
searchView?.setOnSearchClickListener { tab_layout.gone() } searchView?.setOnSearchClickListener { tabLayout.gone() }
searchView?.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
} }
override fun onQueryTextChange(newText: String): Boolean { override fun onQueryTextChange(newText: String): Boolean {
if (tab_layout.selectedTabPosition == 1) { if (tabLayout.selectedTabPosition == 1) {
viewModel.startBookmarkSearch(newText) viewModel.startBookmarkSearch(newText)
} else { } else {
viewModel.startChapterListSearch(newText) viewModel.startChapterListSearch(newText)
@ -84,9 +88,9 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(R.layout.activi
} }
override fun onBackPressed() { override fun onBackPressed() {
if (tab_layout.isGone) { if (tabLayout.isGone) {
searchView?.onActionViewCollapsed() searchView?.onActionViewCollapsed()
tab_layout.visible() tabLayout.visible()
} else { } else {
super.onBackPressed() super.onBackPressed()
} }

@ -1,57 +1,72 @@
package com.novel.read.ui.chapter package com.novel.read.ui.chapter
import android.view.View import android.view.LayoutInflater
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.ViewGroup
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.BookChapter import com.novel.read.data.db.entity.BookChapter
import com.novel.read.databinding.ItemChapterListBinding
import com.novel.read.help.BookHelp import com.novel.read.help.BookHelp
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.item_chapter_list.view.*
class ChapterListAdapter(val callback: Callback) : class ChapterListAdapter(val callback: Callback) :
BaseQuickAdapter<BookChapter, BaseViewHolder>(R.layout.item_chapter_list) { BaseBindingAdapter<BookChapter, ItemChapterListBinding>() {
val cacheFileNames = hashSetOf<String>() val cacheFileNames = hashSetOf<String>()
override fun convert(holder: BaseViewHolder, item: BookChapter) {
holder.itemView.run { override fun convert(holder: VBViewHolder<ItemChapterListBinding>, item: BookChapter) {
holder.vb.run {
val isDur = callback.durChapterIndex() == item.chapterIndex val isDur = callback.durChapterIndex() == item.chapterIndex
val cached = callback.isLocalBook val cached = callback.isLocalBook
|| cacheFileNames.contains(BookHelp.formatChapterName(item)) || cacheFileNames.contains(BookHelp.formatChapterName(item))
if (isDur) { if (isDur) {
tv_chapter_name.setTextColor(context.accentColor) tvChapterName.setTextColor(context.accentColor)
} else { } else {
tv_chapter_name.setTextColor(context.getCompatColor(R.color.primaryText)) tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText))
} }
tv_chapter_name.text = item.chapterName tvChapterName.text = item.chapterName
if (!item.updateDate.isNullOrEmpty()) { if (!item.updateDate.isNullOrEmpty()) {
tv_tag.text = item.updateDate tvTag.text = item.updateDate
tv_tag.visible() tvTag.visible()
} }
upHasCache(this, isDur, cached) upHasCache(this, isDur, cached)
}
holder.itemView.run {
setOnClickListener { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition).let {
callback.openChapter(it) callback.openChapter(it)
} }
} }
} }
} }
private fun upHasCache(itemView: View, isDur: Boolean, cached: Boolean) = itemView.apply { private fun upHasCache(itemView: ItemChapterListBinding, isDur: Boolean, cached: Boolean) = itemView.run {
tv_chapter_name.paint.isFakeBoldText = cached tvChapterName.paint.isFakeBoldText = cached
iv_checked.setImageResource(R.drawable.ic_outline_cloud_24) ivChecked.setImageResource(R.drawable.ic_outline_cloud_24)
iv_checked.visible(!cached) ivChecked.visible(!cached)
if (isDur) { if (isDur) {
iv_checked.setImageResource(R.drawable.ic_check) ivChecked.setImageResource(R.drawable.ic_check)
iv_checked.visible() ivChecked.visible()
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemChapterListBinding {
return ItemChapterListBinding.inflate(inflater,parent,false)
}
interface Callback { interface Callback {
val isLocalBook: Boolean val isLocalBook: Boolean
fun openChapter(bookChapter: BookChapter) fun openChapter(bookChapter: BookChapter)
fun durChapterIndex(): Int fun durChapterIndex(): Int
} }
} }

@ -13,12 +13,13 @@ import com.novel.read.base.VMBaseFragment
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.data.db.entity.BookChapter import com.novel.read.data.db.entity.BookChapter
import com.novel.read.databinding.FragmentChapterListBinding
import com.novel.read.help.BookHelp import com.novel.read.help.BookHelp
import com.novel.read.ui.widget.UpLinearLayoutManager import com.novel.read.ui.widget.UpLinearLayoutManager
import com.novel.read.ui.widget.VerticalDivider import com.novel.read.ui.widget.VerticalDivider
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.fragment_chapter_list.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -27,7 +28,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list), class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list),
ChapterListViewModel.ChapterListCallBack,ChapterListAdapter.Callback { ChapterListViewModel.ChapterListCallBack,ChapterListAdapter.Callback {
lateinit var adapter: ChapterListAdapter private lateinit var adapter: ChapterListAdapter
private var durChapterIndex = 0 private var durChapterIndex = 0
private lateinit var mLayoutManager: UpLinearLayoutManager private lateinit var mLayoutManager: UpLinearLayoutManager
private var tocLiveData: MutableLiveData<List<BookChapter>>? = MutableLiveData() private var tocLiveData: MutableLiveData<List<BookChapter>>? = MutableLiveData()
@ -36,14 +37,16 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java) get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private val binding by viewBinding(FragmentChapterListBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
viewModel.chapterCallBack = this viewModel.chapterCallBack = this
val bbg = bottomBackground val bbg = bottomBackground
val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg)) val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg))
ll_chapter_base_info.setBackgroundColor(bbg) binding.llChapterBaseInfo.setBackgroundColor(bbg)
tv_current_chapter_info.setTextColor(btc) binding.tvCurrentChapterInfo.setTextColor(btc)
iv_chapter_top.setColorFilter(btc) binding.ivChapterTop.setColorFilter(btc)
iv_chapter_bottom.setColorFilter(btc) binding.ivChapterBottom.setColorFilter(btc)
initRecyclerView() initRecyclerView()
initView() initView()
initBook() initBook()
@ -52,19 +55,19 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
private fun initRecyclerView() { private fun initRecyclerView() {
adapter = ChapterListAdapter(this) adapter = ChapterListAdapter(this)
mLayoutManager = UpLinearLayoutManager(requireContext()) mLayoutManager = UpLinearLayoutManager(requireContext())
recycler_view.layoutManager = mLayoutManager binding.recyclerView.layoutManager = mLayoutManager
recycler_view.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
recycler_view.adapter = adapter binding.recyclerView.adapter = adapter
} }
private fun initView() { private fun initView() {
iv_chapter_top.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } binding.ivChapterTop.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) }
iv_chapter_bottom.onClick { binding.ivChapterBottom.onClick {
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0)
} }
} }
tv_current_chapter_info.onClick { binding.tvCurrentChapterInfo.onClick {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
} }
@ -76,7 +79,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
initDoc() initDoc()
viewModel.book?.let { viewModel.book?.let {
durChapterIndex = it.durChapterIndex durChapterIndex = it.durChapterIndex
tv_current_chapter_info.text = binding.tvCurrentChapterInfo.text =
"${it.durChapterTitle}(${it.durChapterIndex + 1}/${tocLiveData?.value?.size})" "${it.durChapterTitle}(${it.durChapterIndex + 1}/${tocLiveData?.value?.size})"
initCacheFileNames(it) initCacheFileNames(it)
} }

@ -8,28 +8,32 @@ import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivityDailyBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_daily.*
class DailyActivity : VMBaseActivity<DailyViewModel>(R.layout.activity_daily) { class DailyActivity : VMBaseActivity<ActivityDailyBinding,DailyViewModel>() {
override val viewModel: DailyViewModel override val viewModel: DailyViewModel
get() = getViewModel(DailyViewModel::class.java) get() = getViewModel(DailyViewModel::class.java)
override fun getViewBinding(): ActivityDailyBinding {
return ActivityDailyBinding.inflate(layoutInflater)
}
private lateinit var adapter: DailyAdapter private lateinit var adapter: DailyAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_daily) ATH.applyEdgeEffectColor(binding.rlvDaily)
initRecyclerView() initRecyclerView()
upRecyclerData() upRecyclerData()
initLoadMore() initLoadMore()
} }
private fun initRecyclerView() { private fun initRecyclerView() {
rlv_daily.layoutManager = LinearLayoutManager(this) binding.rlvDaily.layoutManager = LinearLayoutManager(this)
adapter = DailyAdapter() adapter = DailyAdapter()
rlv_daily.adapter = adapter binding.rlvDaily.adapter = adapter
} }
private fun upRecyclerData() { private fun upRecyclerData() {
@ -87,7 +91,7 @@ class DailyActivity : VMBaseActivity<DailyViewModel>(R.layout.activity_daily) {
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_daily, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvDaily, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }

@ -1,28 +1,37 @@
package com.novel.read.ui.daily package com.novel.read.ui.daily
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.BookListResp import com.novel.read.data.model.BookListResp
import com.novel.read.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class DailyAdapter : class DailyAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) { override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.run { holder.itemView.onClick {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId)
tv_book_name.text = item.getBBookName()
tv_book_description.text = item.getBIntroduction()
tv_book_author.text = item.getBAuthorName()
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000)
tv_category.text = item.getBCategoryName()
onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvBookName.text = item.getBBookName()
tvBookDescription.text = item.getBIntroduction()
tvBookAuthor.text = item.getBAuthorName()
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000)
tvCategory.text = item.getBCategoryName()
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookCommonBinding {
return ItemBookCommonBinding.inflate(inflater, parent, false)
}
} }

@ -8,28 +8,32 @@ import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivityEndBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_end.*
class EndActivity : VMBaseActivity<EndViewModel>(R.layout.activity_end) { class EndActivity : VMBaseActivity<ActivityEndBinding,EndViewModel>() {
override val viewModel: EndViewModel override val viewModel: EndViewModel
get() = getViewModel(EndViewModel::class.java) get() = getViewModel(EndViewModel::class.java)
override fun getViewBinding(): ActivityEndBinding {
return ActivityEndBinding.inflate(layoutInflater)
}
private lateinit var adapter: EndAdapter private lateinit var adapter: EndAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_end) ATH.applyEdgeEffectColor(binding.rlvEnd)
initRecyclerView() initRecyclerView()
upRecyclerData() upRecyclerData()
initLoadMore() initLoadMore()
} }
private fun initRecyclerView() { private fun initRecyclerView() {
rlv_end.layoutManager = LinearLayoutManager(this) binding.rlvEnd.layoutManager = LinearLayoutManager(this)
adapter = EndAdapter() adapter = EndAdapter()
rlv_end.adapter = adapter binding.rlvEnd.adapter = adapter
} }
private fun upRecyclerData() { private fun upRecyclerData() {
@ -87,10 +91,11 @@ class EndActivity : VMBaseActivity<EndViewModel>(R.layout.activity_end) {
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_end, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvEnd, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }
} }

@ -1,28 +1,39 @@
package com.novel.read.ui.end package com.novel.read.ui.end
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.BookListResp import com.novel.read.data.model.BookListResp
import com.novel.read.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class EndAdapter : class EndAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) { override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.run { holder.itemView.onClick {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId)
tv_book_name.text = item.getBBookName()
tv_book_description.text = item.getBIntroduction()
tv_book_author.text = item.getBAuthorName()
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000)
tv_category.text = item.getBCategoryName()
onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvBookName.text = item.getBBookName()
tvBookDescription.text = item.getBIntroduction()
tvBookAuthor.text = item.getBAuthorName()
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000)
tvCategory.text = item.getBCategoryName()
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookCommonBinding {
return ItemBookCommonBinding.inflate(inflater, parent, false)
}
} }

@ -5,22 +5,25 @@ import android.text.TextUtils
import androidx.lifecycle.observe import androidx.lifecycle.observe
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.databinding.ActivityFeedBackBinding
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_feed_back.*
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class FeedBackActivity : VMBaseActivity<FeedBackViewModel>(R.layout.activity_feed_back) { class FeedBackActivity : VMBaseActivity<ActivityFeedBackBinding,FeedBackViewModel>() {
override val viewModel: FeedBackViewModel override val viewModel: FeedBackViewModel
get() = getViewModel(FeedBackViewModel::class.java) get() = getViewModel(FeedBackViewModel::class.java)
override fun getViewBinding(): ActivityFeedBackBinding {
return ActivityFeedBackBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
button_report.setOnClickListener { binding.buttonReport.setOnClickListener {
if (TextUtils.isEmpty(et_feed.text.toString().trim())){ if (TextUtils.isEmpty(binding.etFeed.text.toString().trim())){
toast(getString(R.string.feedback_not_empty)) toast(getString(R.string.feedback_not_empty))
return@setOnClickListener return@setOnClickListener
} }
viewModel.feedback(et_feed.text.toString().trim()) viewModel.feedback(binding.etFeed.text.toString().trim())
} }
viewModel.success.observe(this){ viewModel.success.observe(this){
@ -32,4 +35,5 @@ class FeedBackActivity : VMBaseActivity<FeedBackViewModel>(R.layout.activity_fee
} }
} }

@ -13,17 +13,17 @@ import com.novel.read.constant.AppConst
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ActivityBookInfoBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.help.IntentDataHelp import com.novel.read.help.IntentDataHelp
import com.novel.read.ui.read.ReadBookActivity import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_book_info.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) { class BookInfoActivity : VMBaseActivity<ActivityBookInfoBinding,BookInfoViewModel>() {
private lateinit var adapter: BookInfoAdapter private lateinit var adapter: BookInfoAdapter
private val requestCodeRead = 432 private val requestCodeRead = 432
@ -31,6 +31,10 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override val viewModel: BookInfoViewModel override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java) get() = getViewModel(BookInfoViewModel::class.java)
override fun getViewBinding(): ActivityBookInfoBinding {
return ActivityBookInfoBinding.inflate(layoutInflater)
}
companion object { companion object {
fun actionBookInfo(context: Context, bookId: Long, bookTypeId: Int?) { fun actionBookInfo(context: Context, bookId: Long, bookTypeId: Int?) {
context.startActivity<BookInfoActivity>( context.startActivity<BookInfoActivity>(
@ -43,16 +47,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.initData(intent) viewModel.initData(intent)
viewModel.getRecommend(intent) viewModel.getRecommend(intent)
tv_shelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground))) binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
initRecycleView() initRecycleView()
initData() initData()
initClick() initClick()
} }
private fun initRecycleView() { private fun initRecycleView() {
rlv_recommend.layoutManager = GridLayoutManager(this, 4) binding.rlvRecommend.layoutManager = GridLayoutManager(this, 4)
adapter = BookInfoAdapter() adapter = BookInfoAdapter()
rlv_recommend.adapter = adapter binding.rlvRecommend.adapter = adapter
} }
private fun initData() { private fun initData() {
@ -61,17 +65,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} else { } else {
ColorUtils.shiftColor(backgroundColor, 0.95f) ColorUtils.shiftColor(backgroundColor, 0.95f)
} }
preference_divider_above.setBackgroundColor(dividerColor)
viewModel.bookResp.observe(this) {
iv_book.load(it.coverImageUrl, it.bookName, it.authorName)
tv_book_name.text = it.bookName
tv_book_author.text = it.authorName
tv_key.text = it.lastUpdateChapterDate
tv_status.text = it.categoryName
tv_word.text = getString(R.string.book_word, it.wordCount / 10000)
tv_tro.text = it.introduction
binding.preferenceDividerAbove.setBackgroundColor(dividerColor)
viewModel.bookResp.observe(this) {
binding.ivBook.load(it.coverImageUrl, it.bookName, it.authorName)
binding.tvBookName.text = it.bookName
binding.tvBookAuthor.text = it.authorName
binding.tvKey.text = it.lastUpdateChapterDate
binding.tvStatus.text = it.categoryName
binding.tvWord.text = getString(R.string.book_word, it.wordCount / 10000)
binding.tvTro.text = it.introduction
upTvBookshelf() upTvBookshelf()
} }
viewModel.bookListResp.observe(this) { viewModel.bookListResp.observe(this) {
@ -80,20 +83,20 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.status.observe(this) { viewModel.status.observe(this) {
when (it) { when (it) {
AppConst.loading -> { AppConst.loading -> {
refresh.showLoading() binding.refresh.showLoading()
} }
AppConst.complete -> { AppConst.complete -> {
refresh.showFinish() binding.refresh.showFinish()
} }
else -> { else -> {
refresh.showError() binding.refresh.showError()
} }
} }
} }
} }
private fun initClick() { private fun initClick() {
tv_shelf.onClick { binding.tvShelf.onClick {
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
deleteBook() deleteBook()
} else { } else {
@ -104,14 +107,14 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
tv_read.onClick { binding.tvRead.onClick {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
readBook(it) readBook(it)
} }
} }
refresh.setOnReloadingListener { binding.refresh.setOnReloadingListener {
viewModel.initData(intent) viewModel.initData(intent)
viewModel.getRecommend(intent) viewModel.getRecommend(intent)
} }
@ -139,9 +142,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
private fun upTvBookshelf() { private fun upTvBookshelf() {
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
tv_shelf.text = getString(R.string.remove_from_bookshelf) binding.tvShelf.text = getString(R.string.remove_from_bookshelf)
} else { } else {
tv_shelf.text = getString(R.string.add_to_shelf) binding.tvShelf.text = getString(R.string.add_to_shelf)
} }
postEvent(EventBus.UP_BOOK, 0L) postEvent(EventBus.UP_BOOK, 0L)
} }
@ -164,4 +167,5 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
} }
} }
} }

@ -1,23 +1,36 @@
package com.novel.read.ui.info package com.novel.read.ui.info
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.BookListResp import com.novel.read.data.model.BookListResp
import com.novel.read.databinding.ItemHotItemBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import kotlinx.android.synthetic.main.item_hot_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class BookInfoAdapter :BaseQuickAdapter<BookListResp,BaseViewHolder>(R.layout.item_hot_item) { class BookInfoAdapter :BaseBindingAdapter<BookListResp,ItemHotItemBinding>() {
override fun convert(holder: BaseViewHolder, item: BookListResp) { override fun convert(holder: VBViewHolder<ItemHotItemBinding>, item: BookListResp) {
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvName.text = item.getBBookName()
}
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick { onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemHotItemBinding {
return ItemHotItemBinding.inflate(inflater,parent,false)
}
} }

@ -1,73 +1,84 @@
package com.novel.read.ui.main.bookshelf package com.novel.read.ui.main.bookshelf
import android.os.Bundle import android.os.Bundle
import android.view.ViewGroup
import com.chad.library.adapter.base.entity.SectionEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.getViewBinding
import com.novel.read.base.withBinding
import com.novel.read.constant.BookType import com.novel.read.constant.BookType
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ItemBookshelfListBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_bookshelf_list.view.bv_unread
import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover
import kotlinx.android.synthetic.main.item_bookshelf_list.view.rl_loading
import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name
class BookShelfAdapter(private val callBack: CallBack) : BaseBookAdapter(R.layout.item_bookshelf_list) { class BookShelfAdapter(private val callBack: CallBack) : BaseBookAdapter(R.layout.item_bookshelf_list) {
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewHolder = super.onCreateDefViewHolder(parent, viewType)
return viewHolder.withBinding(ItemBookshelfListBinding::bind)
}
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) {
super.convert(holder, item, payloads) super.convert(holder, item, payloads)
val bundle = payloads.getOrNull(0) as? Bundle val bundle = payloads.getOrNull(0) as? Bundle
holder.itemView.run {
ATH.applyBackgroundTint(this) holder.getViewBinding<ItemBookshelfListBinding>().apply {
if (bundle == null) { if (bundle == null) {
tv_name.text = item.bookName tvName.text = item.bookName
tv_author.text = item.authorPenname tvAuthor.text = item.authorPenname
tv_read.text = item.durChapterTitle tvRead.text = item.durChapterTitle
tv_last.text = item.keyWord tvLast.text = item.keyWord
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item) upRefresh(this, item)
} else { } else {
tv_read.text = item.durChapterTitle tvRead.text = item.durChapterTitle
tv_last.text = item.keyWord tvLast.text = item.keyWord
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tv_name.text = item.bookName "name" -> tvName.text = item.bookName
"author" -> tv_author.text = item.authorPenname "author" -> tvAuthor.text = item.authorPenname
"cover" -> iv_cover.load( "cover" -> ivCover.load(
item.coverImageUrl, item.coverImageUrl,
item.bookName, item.bookName,
item.authorPenname item.authorPenname
) )
"refresh" -> upRefresh(holder, item) "refresh" -> upRefresh(this, item)
}
} }
} }
} }
holder.itemView.run {
ATH.applyBackgroundTint(this)
} }
} }
override fun convert(holder: BaseViewHolder, item: Book) { override fun convert(holder: BaseViewHolder, item: Book) {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
tv_name.text = item.bookName }
tv_author.text = item.authorPenname holder.getViewBinding<ItemBookshelfListBinding>().apply {
tv_read.text = item.durChapterTitle tvName.text = item.bookName
tv_last.text = item.keyWord tvAuthor.text = item.authorPenname
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) tvRead.text = item.durChapterTitle
upRefresh(holder, item) tvLast.text = item.keyWord
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(this, item)
} }
} }
private fun upRefresh(holder: BaseViewHolder, item: Book) { private fun upRefresh(holder: ItemBookshelfListBinding, item: Book) {
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) {
holder.itemView.bv_unread.invisible() holder.bvUnread.invisible()
holder.itemView.rl_loading.show() holder.rlLoading.show()
} else { } else {
holder.itemView.rl_loading.hide() holder.rlLoading.hide()
holder.itemView.bv_unread.setBadgeCount(0) holder.bvUnread.setBadgeCount(0)
holder.itemView.bv_unread.setHighlight(true) holder.bvUnread.setHighlight(true)
} }
} }

@ -1,61 +1,71 @@
package com.novel.read.ui.main.bookshelf package com.novel.read.ui.main.bookshelf
import android.os.Bundle import android.os.Bundle
import android.view.ViewGroup
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.getViewBinding
import com.novel.read.base.withBinding
import com.novel.read.constant.BookType import com.novel.read.constant.BookType
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ItemBookshelfGridBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.invisible import com.novel.read.utils.ext.invisible
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.*
class BooksAdapterGrid(private val callBack: CallBack) : class BooksAdapterGrid(private val callBack: CallBack) :
BaseBookAdapter(R.layout.item_bookshelf_grid) { BaseBookAdapter(R.layout.item_bookshelf_grid) {
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewHolder = super.onCreateDefViewHolder(parent, viewType)
return viewHolder.withBinding(ItemBookshelfGridBinding::bind)
}
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) {
super.convert(holder, item, payloads) super.convert(holder, item, payloads)
val bundle = payloads.getOrNull(0) as? Bundle val bundle = payloads.getOrNull(0) as? Bundle
holder.getViewBinding<ItemBookshelfGridBinding>().apply{
holder.itemView.run {
ATH.applyBackgroundTint(this)
if (bundle == null) { if (bundle == null) {
tv_name.text = item.bookName tvName.text = item.bookName
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item) upRefresh(this, item)
} else { } else {
bundle.keySet().forEach { bundle.keySet().forEach {
when (it) { when (it) {
"name" -> tv_name.text = item.bookName "name" -> tvName.text = item.bookName
"cover" -> iv_cover.load( "cover" -> ivCover.load(
item.coverImageUrl, item.coverImageUrl,
item.bookName, item.bookName,
item.authorPenname item.authorPenname
) )
"refresh" -> upRefresh(holder, item) "refresh" -> upRefresh(this, item)
} }
} }
} }
}
holder.itemView.run {
ATH.applyBackgroundTint(this)
} }
} }
override fun convert(holder: BaseViewHolder, item: Book) { override fun convert(holder: BaseViewHolder, item: Book) {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
tv_name.text = item.bookName }
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) holder.getViewBinding<ItemBookshelfGridBinding>().apply{
upRefresh(holder, item) tvName.text = item.bookName
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(this, item)
} }
} }
private fun upRefresh(holder: BaseViewHolder, item: Book) { private fun upRefresh(holder: ItemBookshelfGridBinding, item: Book) {
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) {
holder.itemView.bv_unread.invisible() holder.bvUnread.invisible()
holder.itemView.rl_loading.show() holder.rlLoading.show()
} else { } else {
holder.itemView.rl_loading.hide() holder.rlLoading.hide()
holder.itemView.bv_unread.setBadgeCount(0) holder.bvUnread.setBadgeCount(0)
holder.itemView.bv_unread.setHighlight(true) holder.bvUnread.setHighlight(true)
} }
} }
} }

@ -19,6 +19,8 @@ import com.novel.read.constant.EventBus
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.DialogBookshelfConfigBinding
import com.novel.read.databinding.FragmentBookShelfBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.help.IntentDataHelp import com.novel.read.help.IntentDataHelp
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
@ -32,23 +34,21 @@ import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.ui.search.SearchActivity import com.novel.read.ui.search.SearchActivity
import com.novel.read.utils.BooksDiffCallBack import com.novel.read.utils.BooksDiffCallBack
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_bookshelf_config.view.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.android.synthetic.main.fragment_book_shelf.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_shelf), BaseBookAdapter.CallBack { class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_shelf), BaseBookAdapter.CallBack {
override val viewModel: BookViewModel by viewModels() override val viewModel: BookViewModel by viewModels()
private val activityViewModel: MainViewModel private val activityViewModel: MainViewModel
by activityViewModels() by activityViewModels()
private val binding by viewBinding(FragmentBookShelfBinding::bind)
private lateinit var booksAdapter: BaseBookAdapter private lateinit var booksAdapter: BaseBookAdapter
private var bookshelfLiveData = MutableLiveData<List<Book>>() private var bookshelfLiveData = MutableLiveData<List<Book>>()
private lateinit var selectBook: Book private lateinit var selectBook: Book
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportToolbar(binding.titleBar.toolbar)
initRecycleView() initRecycleView()
upRecyclerData() upRecyclerData()
} }
@ -75,23 +75,23 @@ class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_s
} }
private fun initRecycleView() { private fun initRecycleView() {
ATH.applyEdgeEffectColor(rlv_book_shelf) ATH.applyEdgeEffectColor(binding.rlvBookShelf)
refresh_layout.setColorSchemeColors(accentColor) binding.refreshLayout.setColorSchemeColors(accentColor)
refresh_layout.setOnRefreshListener { binding.refreshLayout.setOnRefreshListener {
refresh_layout.isRefreshing = false binding.refreshLayout.isRefreshing = false
activityViewModel.upToc(booksAdapter.data) activityViewModel.upToc(booksAdapter.data)
} }
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout) val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
if (bookshelfLayout == 0) { if (bookshelfLayout == 0) {
rlv_book_shelf.layoutManager = LinearLayoutManager(context) binding.rlvBookShelf.layoutManager = LinearLayoutManager(context)
booksAdapter = BookShelfAdapter(this) booksAdapter = BookShelfAdapter(this)
} else { } else {
rlv_book_shelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2) binding.rlvBookShelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
booksAdapter = BooksAdapterGrid(this) booksAdapter = BooksAdapterGrid(this)
} }
rlv_book_shelf.adapter = booksAdapter binding.rlvBookShelf.adapter = booksAdapter
booksAdapter.setEmptyView(R.layout.view_empty) booksAdapter.setEmptyView(R.layout.view_empty)
booksAdapter.setDiffCallback(BooksDiffCallBack()) booksAdapter.setDiffCallback(BooksDiffCallBack())
@ -132,9 +132,9 @@ class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_s
fun gotoTop() { fun gotoTop() {
if (AppConfig.isEInkMode) { if (AppConfig.isEInkMode) {
rlv_book_shelf.scrollToPosition(0) binding.rlvBookShelf.scrollToPosition(0)
} else { } else {
rlv_book_shelf.smoothScrollToPosition(0) binding.rlvBookShelf.smoothScrollToPosition(0)
} }
} }
@ -143,21 +143,23 @@ class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_s
requireContext().alert(titleResource = R.string.bookshelf_layout) { requireContext().alert(titleResource = R.string.bookshelf_layout) {
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout) val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
val bookshelfSort = getPrefInt(PreferKey.bookshelfSort) val bookshelfSort = getPrefInt(PreferKey.bookshelfSort)
val root = LayoutInflater.from(requireContext()) val alertBinding =
.inflate(R.layout.dialog_bookshelf_config, null).apply { DialogBookshelfConfigBinding.inflate(layoutInflater)
rg_layout.checkByIndex(bookshelfLayout) .apply {
rg_sort.checkByIndex(bookshelfSort) rgLayout.checkByIndex(bookshelfLayout)
rgSort.checkByIndex(bookshelfSort)
} }
customView = root
customView = alertBinding.root
okButton { okButton {
root.apply { alertBinding.apply {
var changed = false var changed = false
if (bookshelfLayout != rg_layout.getCheckedIndex()) { if (bookshelfLayout != rgLayout.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfLayout, rg_layout.getCheckedIndex()) putPrefInt(PreferKey.bookshelfLayout, rgLayout.getCheckedIndex())
changed = true changed = true
} }
if (bookshelfSort != rg_sort.getCheckedIndex()) { if (bookshelfSort != rgSort.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfSort, rg_sort.getCheckedIndex()) putPrefInt(PreferKey.bookshelfSort, rgSort.getCheckedIndex())
changed = true changed = true
} }
if (changed) { if (changed) {

@ -8,6 +8,7 @@ import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ActivityArrangeBookBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.lib.dialogs.alert import com.novel.read.lib.dialogs.alert
import com.novel.read.lib.dialogs.okButton import com.novel.read.lib.dialogs.okButton
@ -15,26 +16,29 @@ import com.novel.read.ui.widget.VerticalDivider
import com.novel.read.utils.ext.applyTint import com.novel.read.utils.ext.applyTint
import com.novel.read.utils.ext.getPrefInt import com.novel.read.utils.ext.getPrefInt
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_arrange_book.*
class ArrangeBookActivity : VMBaseActivity<ArrangeBookViewModel>(R.layout.activity_arrange_book),ArrangeBookAdapter.CallBack { class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding,ArrangeBookViewModel>(),ArrangeBookAdapter.CallBack {
private lateinit var adapter: ArrangeBookAdapter private lateinit var adapter: ArrangeBookAdapter
override val viewModel: ArrangeBookViewModel override val viewModel: ArrangeBookViewModel
get() = getViewModel(ArrangeBookViewModel::class.java) get() = getViewModel(ArrangeBookViewModel::class.java)
override fun getViewBinding(): ActivityArrangeBookBinding {
return ActivityArrangeBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
initBookData() initBookData()
} }
private fun initView() { private fun initView() {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(binding.recyclerView)
recycler_view.layoutManager = LinearLayoutManager(this) binding.recyclerView.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration(VerticalDivider(this)) binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = ArrangeBookAdapter(this) adapter = ArrangeBookAdapter(this)
recycler_view.adapter = adapter binding.recyclerView.adapter = adapter
} }
private fun initBookData() { private fun initBookData() {

@ -1,36 +1,46 @@
package com.novel.read.ui.main.bookshelf.arrange package com.novel.read.ui.main.bookshelf.arrange
import android.view.LayoutInflater
import android.view.View import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.ViewGroup
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.novel.read.base.BaseBindingAdapter
import com.novel.read.R import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ItemArrangeBookBinding
import com.novel.read.utils.ext.backgroundColor import com.novel.read.utils.ext.backgroundColor
import kotlinx.android.synthetic.main.item_arrange_book.view.*
import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class ArrangeBookAdapter(val callBack: CallBack) : BaseQuickAdapter<Book, BaseViewHolder>(R.layout.item_arrange_book) { class ArrangeBookAdapter(val callBack: CallBack) :
override fun convert(holder: BaseViewHolder, item: Book) { BaseBindingAdapter<Book, ItemArrangeBookBinding>() {
holder.itemView.run {
backgroundColor = context.backgroundColor override fun convert(holder: VBViewHolder<ItemArrangeBookBinding>, item: Book) {
tv_name.text = item.bookName holder.itemView.backgroundColor = context.backgroundColor
tv_author.text = item.authorPenname holder.vb.run {
tv_author.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE tvName.text = item.bookName
tvAuthor.text = item.authorPenname
tvAuthor.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE
// checkbox.isChecked = selectedBooks.contains(item) // checkbox.isChecked = selectedBooks.contains(item)
iv_book.load(item.coverImageUrl, item.bookName, item.authorPenname) ivBook.load(item.coverImageUrl, item.bookName, item.authorPenname)
tv_delete.onClick { tvDelete.onClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition).let {
callBack.deleteBook(it) callBack.deleteBook(it)
} }
} }
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemArrangeBookBinding {
return ItemArrangeBookBinding.inflate(inflater, parent, false)
}
interface CallBack { interface CallBack {
fun upSelectCount() fun upSelectCount()
fun updateBook(vararg book: Book) fun updateBook(vararg book: Book)
fun deleteBook(book: Book) fun deleteBook(book: Book)
} }
} }

@ -10,31 +10,32 @@ import com.novel.read.R
import com.novel.read.base.VMBaseFragment import com.novel.read.base.VMBaseFragment
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.data.model.* import com.novel.read.data.model.*
import com.novel.read.databinding.FragmentMailBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.ui.main.mail.pick.PickAdapter import com.novel.read.ui.main.mail.pick.PickAdapter
import com.novel.read.ui.search.SearchActivity import com.novel.read.ui.search.SearchActivity
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.fragment_mail.rlv_home import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.android.synthetic.main.view_title_bar.*
import java.util.ArrayList import java.util.ArrayList
class MailFragment : VMBaseFragment<MailViewModel>(R.layout.fragment_mail) { class MailFragment : VMBaseFragment<MailViewModel>(R.layout.fragment_mail) {
override val viewModel: MailViewModel override val viewModel: MailViewModel
get() = getViewModel(MailViewModel::class.java) get() = getViewModel(MailViewModel::class.java)
private val binding by viewBinding(FragmentMailBinding::bind)
private lateinit var adapter: PickAdapter<MultiItemEntity> private lateinit var adapter: PickAdapter<MultiItemEntity>
private val data: MutableList<MultiItemEntity> = ArrayList() private val data: MutableList<MultiItemEntity> = ArrayList()
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportToolbar(binding.titleBar.toolbar)
ATH.applyEdgeEffectColor(rlv_home) ATH.applyEdgeEffectColor(binding.rlvHome)
initRecycleView() initRecycleView()
upRecyclerData() upRecyclerData()
} }
private fun initRecycleView() { private fun initRecycleView() {
rlv_home.layoutManager = LinearLayoutManager(context) binding.rlvHome.layoutManager = LinearLayoutManager(context)
adapter = PickAdapter(data) adapter = PickAdapter(data)
rlv_home.adapter = adapter binding.rlvHome.adapter = adapter
} }
private fun upRecyclerData() { private fun upRecyclerData() {
@ -78,7 +79,7 @@ class MailFragment : VMBaseFragment<MailViewModel>(R.layout.fragment_mail) {
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_home, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvHome, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }

@ -1,24 +1,35 @@
package com.novel.read.ui.main.mail.pick package com.novel.read.ui.main.mail.pick
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.ClickRank import com.novel.read.data.model.ClickRank
import com.novel.read.databinding.ItemClickItemBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_click_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class ClickAdapter :BaseQuickAdapter<ClickRank,BaseViewHolder>(R.layout.item_click_item) { class ClickAdapter : BaseBindingAdapter<ClickRank, ItemClickItemBinding>() {
override fun convert(holder: BaseViewHolder, item: ClickRank) { override fun convert(holder: VBViewHolder<ItemClickItemBinding>, item: ClickRank) {
holder.itemView.run { holder.vb.run {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName() tvName.text = item.getBBookName()
tv_count.text = context.getString(R.string.book_word, item.wordCount / 10000) tvCount.text = context.getString(R.string.book_word, item.wordCount / 10000)
onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
holder.itemView.onClick {
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId)
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemClickItemBinding {
return ItemClickItemBinding.inflate(inflater, parent, false)
}
} }

@ -1,25 +1,38 @@
package com.novel.read.ui.main.mail.pick package com.novel.read.ui.main.mail.pick
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.EndRank import com.novel.read.data.model.EndRank
import com.novel.read.databinding.ItemEndItemBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_end_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class EndAdapter :BaseQuickAdapter<EndRank,BaseViewHolder>(R.layout.item_end_item) { class EndAdapter :BaseBindingAdapter<EndRank,ItemEndItemBinding>() {
override fun convert(holder: BaseViewHolder, item: EndRank) { override fun convert(holder: VBViewHolder<ItemEndItemBinding>, item: EndRank) {
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvName.text = item.getBBookName()
}
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick { onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemEndItemBinding {
return ItemEndItemBinding.inflate(inflater,parent,false)
}
} }

@ -1,24 +1,37 @@
package com.novel.read.ui.main.mail.pick package com.novel.read.ui.main.mail.pick
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.HotRank import com.novel.read.data.model.HotRank
import com.novel.read.databinding.ItemHotItemBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_hot_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class HotAdapter :BaseQuickAdapter<HotRank,BaseViewHolder>(R.layout.item_hot_item) { class HotAdapter :BaseBindingAdapter<HotRank,ItemHotItemBinding>() {
override fun convert(holder: BaseViewHolder, item: HotRank) { override fun convert(holder: VBViewHolder<ItemHotItemBinding>, item: HotRank) {
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBName(), item.getBAuthor())
tvName.text = item.getBName()
}
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBName(), item.getBAuthor())
tv_name.text = item.getBName()
onClick { onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemHotItemBinding {
return ItemHotItemBinding.inflate(inflater,parent,false)
}
} }

@ -1,21 +1,24 @@
package com.novel.read.ui.main.mail.pick package com.novel.read.ui.main.mail.pick
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.entity.MultiItemEntity import com.chad.library.adapter.base.entity.MultiItemEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.getViewBinding
import com.novel.read.base.withBinding
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.constant.LayoutType import com.novel.read.constant.LayoutType
import com.novel.read.data.model.* import com.novel.read.data.model.*
import com.novel.read.databinding.ItemHotBinding
import com.novel.read.databinding.ItemPickHeadBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.ui.channel.ChannelActivity import com.novel.read.ui.channel.ChannelActivity
import com.novel.read.ui.daily.DailyActivity import com.novel.read.ui.daily.DailyActivity
import com.novel.read.ui.end.EndActivity import com.novel.read.ui.end.EndActivity
import com.novel.read.ui.rank.RankActivity import com.novel.read.ui.rank.RankActivity
import kotlinx.android.synthetic.main.item_hot.view.*
import kotlinx.android.synthetic.main.item_pick_head.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -31,113 +34,133 @@ class PickAdapter<T : MultiItemEntity>(data: MutableList<T>?) :
addItemType(LayoutType.END, R.layout.item_hot) addItemType(LayoutType.END, R.layout.item_hot)
} }
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewHolder = super.onCreateDefViewHolder(parent, viewType)
return when (viewType) {
LayoutType.OTHER -> viewHolder.withBinding(ItemPickHeadBinding::bind)
LayoutType.HOT -> viewHolder.withBinding(ItemHotBinding::bind)
LayoutType.CLICK -> viewHolder.withBinding(ItemHotBinding::bind)
LayoutType.RECOMMEND -> viewHolder.withBinding(ItemHotBinding::bind)
LayoutType.END -> viewHolder.withBinding(ItemHotBinding::bind)
else -> throw IllegalStateException()
}
}
override fun convert(holder: BaseViewHolder, item: T) { override fun convert(holder: BaseViewHolder, item: T) {
when (item) { when (item) {
is TypeEntity -> { is TypeEntity -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
tv_daily.onClick { }
holder.getViewBinding<ItemPickHeadBinding>().apply {
tvDaily.onClick {
context.startActivity<DailyActivity>() context.startActivity<DailyActivity>()
} }
tv_rank.onClick { tvRank.onClick {
context.startActivity<RankActivity>( context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.HOT), Pair(IntentAction.rankType, LayoutType.HOT),
Pair(IntentAction.homeType, AppConst.home) Pair(IntentAction.homeType, AppConst.home)
) )
} }
tv_end.onClick { tvEnd.onClick {
context.startActivity<EndActivity>() context.startActivity<EndActivity>()
} }
tvType.onClick {
tv_type.onClick {
context.startActivity<ChannelActivity>() context.startActivity<ChannelActivity>()
} }
} }
} }
is HotEntity -> { is HotEntity -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
rlv_hot.setHasFixedSize(true) }
ll_title.onClick { holder.getViewBinding<ItemHotBinding>().apply{
rlvHot.setHasFixedSize(true)
llTitle.onClick {
context.startActivity<RankActivity>( context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.HOT), Pair(IntentAction.rankType, LayoutType.HOT),
Pair(IntentAction.homeType, AppConst.home) Pair(IntentAction.homeType, AppConst.home)
) )
} }
if (rlv_hot.layoutManager == null) { if (rlvHot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4) rlvHot.layoutManager = GridLayoutManager(context, 4)
} }
if (rlv_hot.adapter == null) { if (rlvHot.adapter == null) {
val hotAdapter = HotAdapter() val hotAdapter = HotAdapter()
hotAdapter.setList(item.hotRanks) hotAdapter.setList(item.hotRanks)
rlv_hot.adapter = hotAdapter rlvHot.adapter = hotAdapter
} }
} }
} }
is ClickEntity -> { is ClickEntity -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_click) }
tv_head.text=context.getString(R.string.click_title) holder.getViewBinding<ItemHotBinding>().apply{
ll_title.onClick { ivHead.setImageResource(R.drawable.ic_click)
tvHead.text=context.getString(R.string.click_title)
llTitle.onClick {
context.startActivity<RankActivity>( context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.CLICK), Pair(IntentAction.rankType, LayoutType.CLICK),
Pair(IntentAction.homeType, AppConst.home) Pair(IntentAction.homeType, AppConst.home)
) )
} }
rlv_hot.setHasFixedSize(true) rlvHot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) { if (rlvHot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 2) rlvHot.layoutManager = GridLayoutManager(context, 2)
} }
if (rlv_hot.adapter == null) { if (rlvHot.adapter == null) {
val clickAdapter = ClickAdapter() val clickAdapter = ClickAdapter()
clickAdapter.setList(item.clickRanks) clickAdapter.setList(item.clickRanks)
rlv_hot.adapter = clickAdapter rlvHot.adapter = clickAdapter
} }
} }
} }
is RecommendEntity -> { is RecommendEntity -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_recommend) }
tv_head.text=context.getString(R.string.recommend_title) holder.getViewBinding<ItemHotBinding>().apply{
ll_title.onClick { ivHead.setImageResource(R.drawable.ic_recommend)
tvHead.text=context.getString(R.string.recommend_title)
llTitle.onClick {
context.startActivity<RankActivity>( context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.RECOMMEND), Pair(IntentAction.rankType, LayoutType.RECOMMEND),
Pair(IntentAction.homeType, AppConst.home) Pair(IntentAction.homeType, AppConst.home)
) )
} }
rlv_hot.setHasFixedSize(true) rlvHot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) { if (rlvHot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4) rlvHot.layoutManager = GridLayoutManager(context, 4)
} }
if (rlv_hot.adapter == null) { if (rlvHot.adapter == null) {
val recommendAdapter = RecommendAdapter() val recommendAdapter = RecommendAdapter()
recommendAdapter.setList(item.recommendRanks) recommendAdapter.setList(item.recommendRanks)
rlv_hot.adapter = recommendAdapter rlvHot.adapter = recommendAdapter
} }
} }
} }
is EndEntity -> { is EndEntity -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_end) }
tv_head.text=context.getString(R.string.end_title) holder.getViewBinding<ItemHotBinding>().apply{
ll_title.onClick { ivHead.setImageResource(R.drawable.ic_end)
tvHead.text=context.getString(R.string.end_title)
llTitle.onClick {
context.startActivity<RankActivity>( context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.END), Pair(IntentAction.rankType, LayoutType.END),
Pair(IntentAction.homeType, AppConst.home) Pair(IntentAction.homeType, AppConst.home)
) )
} }
rlv_hot.setHasFixedSize(true) rlvHot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) { if (rlvHot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4) rlvHot.layoutManager = GridLayoutManager(context, 4)
} }
if (rlv_hot.adapter == null) { if (rlvHot.adapter == null) {
val endAdapter = EndAdapter() val endAdapter = EndAdapter()
endAdapter.setList(item.endRanks) endAdapter.setList(item.endRanks)
rlv_hot.adapter = endAdapter rlvHot.adapter = endAdapter
} }
} }
} }

@ -1,13 +1,17 @@
package com.novel.read.ui.main.mail.pick package com.novel.read.ui.main.mail.pick
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.getViewBinding
import com.novel.read.base.withBinding
import com.novel.read.constant.LayoutType import com.novel.read.constant.LayoutType
import com.novel.read.data.model.RecommendRank import com.novel.read.data.model.RecommendRank
import com.novel.read.databinding.ItemRecommentFirstItemBinding
import com.novel.read.databinding.ItemRecommentItemBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_end_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class RecommendAdapter : BaseMultiItemQuickAdapter<RecommendRank, BaseViewHolder>() { class RecommendAdapter : BaseMultiItemQuickAdapter<RecommendRank, BaseViewHolder>() {
@ -17,24 +21,38 @@ class RecommendAdapter : BaseMultiItemQuickAdapter<RecommendRank, BaseViewHolder
addItemType(LayoutType.HEAD, R.layout.item_recomment_first_item) addItemType(LayoutType.HEAD, R.layout.item_recomment_first_item)
} }
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val viewHolder = super.onCreateDefViewHolder(parent, viewType)
return when (viewType) {
LayoutType.RECOMMEND -> viewHolder.withBinding(ItemRecommentItemBinding::bind)
LayoutType.HEAD -> viewHolder.withBinding(ItemRecommentFirstItemBinding::bind)
else -> throw IllegalStateException()
}
}
override fun convert(holder: BaseViewHolder, item: RecommendRank) { override fun convert(holder: BaseViewHolder, item: RecommendRank) {
when (item.itemType) { when (item.itemType) {
LayoutType.HEAD -> { LayoutType.HEAD -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) }
tv_name.text = item.getBBookName() holder.getViewBinding<ItemRecommentFirstItemBinding>().apply{
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvName.text = item.getBBookName()
} }
} }
LayoutType.RECOMMEND -> { LayoutType.RECOMMEND -> {
holder.itemView.run { holder.itemView.run {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick { onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
} }
} }
holder.getViewBinding<ItemRecommentItemBinding>().apply{
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvName.text = item.getBBookName()
}
} }
} }
} }

@ -1,59 +1,31 @@
package com.novel.read.ui.main.my package com.novel.read.ui.main.my
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseFragment import com.novel.read.base.BaseFragment
import com.novel.read.databinding.FragmentMyBinding
import com.novel.read.ui.feedback.FeedBackActivity import com.novel.read.ui.feedback.FeedBackActivity
import com.novel.read.ui.setting.SettingActivity import com.novel.read.ui.setting.SettingActivity
import com.novel.read.ui.widget.dialog.AppraiseDialog import com.novel.read.ui.widget.dialog.AppraiseDialog
import com.novel.read.utils.ext.startActivity import com.novel.read.utils.ext.startActivity
import com.novel.read.utils.ext.toast import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.android.synthetic.main.fragment_my.*
import kotlinx.android.synthetic.main.view_title_bar.*
class MyFragment : BaseFragment(R.layout.fragment_my) { class MyFragment : BaseFragment(R.layout.fragment_my) {
private val binding by viewBinding(FragmentMyBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar) setSupportToolbar(binding.titleBar.toolbar)
tv_options.setOnClickListener { binding.tvOptions.setOnClickListener {
startActivity<FeedBackActivity>() startActivity<FeedBackActivity>()
} }
tv_setting.setOnClickListener { binding.tvSetting.setOnClickListener {
startActivity<SettingActivity>() startActivity<SettingActivity>()
} }
tv_appraise.setOnClickListener { binding.tvAppraise.setOnClickListener {
val dialog = AppraiseDialog(requireActivity()) AppraiseDialog().show(childFragmentManager,"AppDialog")
dialog.appraiseDialog {
goToMarket(App.INSTANCE, App.INSTANCE.packageName)
dialog.dismiss()
}
dialog.show()
}
}
@SuppressLint("QueryPermissionsNeeded")
fun goToMarket(context: Context, packageName: String) {
val uri = Uri.parse("market://details?id=$packageName")
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
val googlePlay = "com.android.vending" //这里对应的是谷歌商店,跳转别的商店改成对应的即可
goToMarket.setPackage(googlePlay) //这里对应的是谷歌商店,跳转别的商店改成对应的即可
try {
startActivity(goToMarket)
} catch (e: ActivityNotFoundException) {
if (goToMarket.resolveActivity(context.packageManager) != null) { //有浏览器
startActivity(goToMarket)
} else {
toast(R.string.no_google)
}
e.printStackTrace()
} }
} }

@ -1,19 +0,0 @@
package com.novel.read.ui.main.my
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R
import com.novel.read.data.model.Tools
import com.novel.read.lib.ATH
import kotlinx.android.synthetic.main.item_tools.view.*
class ToolsAdapter : BaseQuickAdapter<Tools, BaseViewHolder>(R.layout.item_tools) {
override fun convert(holder: BaseViewHolder, item: Tools) {
holder.itemView.run {
ATH.applyBackgroundTint(this)
tv_tools.text = item.title
iv_tools.setImageResource(item.img)
}
}
}

@ -11,33 +11,36 @@ import com.novel.read.constant.AppConst
import com.novel.read.constant.IntentAction import com.novel.read.constant.IntentAction
import com.novel.read.constant.LayoutType import com.novel.read.constant.LayoutType
import com.novel.read.data.model.* import com.novel.read.data.model.*
import com.novel.read.databinding.ActivityRankBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_rank.*
class RankActivity : VMBaseActivity<RankViewModel>(R.layout.activity_rank) { class RankActivity : VMBaseActivity<ActivityRankBinding,RankViewModel>() {
override val viewModel: RankViewModel override val viewModel: RankViewModel
get() = getViewModel(RankViewModel::class.java) get() = getViewModel(RankViewModel::class.java)
override fun getViewBinding(): ActivityRankBinding {
return ActivityRankBinding.inflate(layoutInflater)
}
private lateinit var adapter: RankAdapter private lateinit var adapter: RankAdapter
private lateinit var typeAdapter: TypeAdapter private lateinit var typeAdapter: TypeAdapter
private lateinit var mTypes: List<TypeName> private lateinit var mTypes: List<TypeName>
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) = with(binding){
ATH.applyEdgeEffectColor(rlv_rank) ATH.applyEdgeEffectColor(rlvRank)
ATH.applyEdgeEffectColor(lv_type) ATH.applyEdgeEffectColor(rlvType)
initRecyclerView() initRecyclerView()
upRecyclerData() upRecyclerData()
initLoadMore() initLoadMore()
} }
private fun initRecyclerView() { private fun initRecyclerView() {
rlv_rank.layoutManager = LinearLayoutManager(this) binding.rlvRank.layoutManager = LinearLayoutManager(this)
adapter = RankAdapter() adapter = RankAdapter()
rlv_rank.adapter = adapter binding.rlvRank.adapter = adapter
lv_type.layoutManager = LinearLayoutManager(this) binding.rlvType.layoutManager = LinearLayoutManager(this)
typeAdapter = TypeAdapter() typeAdapter = TypeAdapter()
lv_type.adapter = typeAdapter binding.rlvType.adapter = typeAdapter
} }
@ -124,10 +127,11 @@ class RankActivity : VMBaseActivity<RankViewModel>(R.layout.activity_rank) {
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_rank, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvRank, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }
} }

@ -1,28 +1,38 @@
package com.novel.read.ui.rank package com.novel.read.ui.rank
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.BookListResp import com.novel.read.data.model.BookListResp
import com.novel.read.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class RankAdapter : class RankAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) { override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.run {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) holder.vb.run {
tv_book_name.text = item.getBBookName() ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_book_description.text = item.getBIntroduction() tvBookName.text = item.getBBookName()
tv_book_author.text = item.getBAuthorName() tvBookDescription.text = item.getBIntroduction()
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) tvBookAuthor.text = item.getBAuthorName()
tv_category.text = item.getBCategoryName() tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000)
onClick { tvCategory.text = item.getBCategoryName()
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) }
holder.itemView.onClick {
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId)
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookCommonBinding {
return ItemBookCommonBinding.inflate(inflater, parent, false)
} }
} }

@ -1,26 +1,32 @@
package com.novel.read.ui.rank package com.novel.read.ui.rank
import android.view.LayoutInflater
import android.view.View import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.ViewGroup
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.TypeName import com.novel.read.data.model.TypeName
import kotlinx.android.synthetic.main.item_type.view.* import com.novel.read.databinding.ItemTypeBinding
class TypeAdapter : class TypeAdapter :
BaseQuickAdapter<TypeName, BaseViewHolder>(R.layout.item_type), LoadMoreModule { BaseBindingAdapter<TypeName, ItemTypeBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: TypeName) { override fun convert(holder: VBViewHolder<ItemTypeBinding>, item: TypeName) {
holder.itemView.run { holder.vb.run {
tv_type.text = item.name tvType.text = item.name
if (item.check) { if (item.check) {
iv_check.visibility = View.VISIBLE ivCheck.visibility = View.VISIBLE
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background)) llBg.setBackgroundColor(context.resources.getColor(R.color.background))
} else { } else {
iv_check.visibility = View.GONE ivCheck.visibility = View.GONE
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background_menu)) llBg.setBackgroundColor(context.resources.getColor(R.color.background_menu))
} }
} }
} }
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemTypeBinding {
return ItemTypeBinding.inflate(inflater, parent, false)
}
} }

@ -4,9 +4,6 @@ import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
@ -15,14 +12,11 @@ import androidx.core.view.isVisible
import androidx.lifecycle.observe import androidx.lifecycle.observe
import com.novel.read.BuildConfig import com.novel.read.BuildConfig
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.constant.Status import com.novel.read.constant.Status
import com.novel.read.data.db.entity.Book import com.novel.read.data.db.entity.Book
import com.novel.read.data.db.entity.BookChapter import com.novel.read.data.db.entity.BookChapter
import com.novel.read.help.ReadBookConfig
import com.novel.read.lib.ATH
import com.novel.read.lib.dialogs.alert import com.novel.read.lib.dialogs.alert
import com.novel.read.lib.dialogs.noButton import com.novel.read.lib.dialogs.noButton
import com.novel.read.lib.dialogs.okButton import com.novel.read.lib.dialogs.okButton
@ -41,58 +35,47 @@ import com.novel.read.ui.read.page.delegate.PageDelegate
import com.novel.read.ui.widget.dialog.AutoReadDialog import com.novel.read.ui.widget.dialog.AutoReadDialog
import com.novel.read.ui.widget.dialog.TextDialog import com.novel.read.ui.widget.dialog.TextDialog
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.view_read_menu.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import java.lang.Runnable import java.lang.Runnable
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book), class ReadBookActivity :ReadBookBaseActivity(),
View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, ContentTextView.CallBack, View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, ContentTextView.CallBack,
ReadBook.CallBack, ReadBook.CallBack,
ReadMenu.CallBack, ReadMenu.CallBack,
ReadAloudDialog.CallBack { ReadAloudDialog.CallBack {
override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java)
override val selectedText: String override val selectedText: String
get() = page_view.curPage.selectedText get() = binding.pageView.curPage.selectedText
private val requestCodeChapterList = 568 private val requestCodeChapterList = 568
private val requestCodeSearchResult = 123 private val requestCodeSearchResult = 123
private var menu: Menu? = null private var menu: Menu? = null
private var textActionMenu: TextActionMenu? = null private val textActionMenu: TextActionMenu by lazy {
TextActionMenu(this, this)
}
override val scope: CoroutineScope get() = this override val scope: CoroutineScope get() = this
override val isInitFinish: Boolean get() = viewModel.isInitFinish override val isInitFinish: Boolean get() = viewModel.isInitFinish
override val isScroll: Boolean get() = page_view.isScroll override val isScroll: Boolean get() = binding.pageView.isScroll
private val mHandler = Handler(Looper.getMainLooper()) private val mHandler = Handler(Looper.getMainLooper())
private val keepScreenRunnable: Runnable = private val keepScreenRunnable: Runnable =
Runnable { ReadBookActivityHelp.keepScreenOn(window, false) } Runnable { keepScreenOn(window, false) }
override var autoPageProgress = 0 override var autoPageProgress = 0
override var isAutoPage = false override var isAutoPage = false
private var screenTimeOut: Long = 0 private var screenTimeOut: Long = 0
private var loadStates: Boolean = false private var loadStates: Boolean = false
override val pageFactory: TextPageFactory get() = page_view.pageFactory override val pageFactory: TextPageFactory get() = binding.pageView.pageFactory
override val headerHeight: Int get() = page_view.curPage.headerHeight override val headerHeight: Int get() = binding.pageView.curPage.headerHeight
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
ReadBookActivityHelp.setOrientation(this)
super.onCreate(savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ReadBookActivityHelp.upLayoutInDisplayCutoutMode(window)
initView() initView()
upScreenTimeOut() upScreenTimeOut()
setScreenBrightness(getPrefInt("brightness", 100)) setScreenBrightness(getPrefInt("brightness", 100))
ReadBook.callBack = this ReadBook.callBack = this
ReadBook.titleDate.observe(this) { ReadBook.titleDate.observe(this) {
title_bar.title = it binding.readMenu.setTitle(it)
upMenu() upMenu()
upView() upView()
} }
@ -106,7 +89,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
page_view.upStatusBar() binding.pageView.upStatusBar()
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} }
@ -137,19 +120,19 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
R.id.menu_refresh -> { R.id.menu_refresh -> {
ReadBook.book?.let { ReadBook.book?.let {
ReadBook.curTextChapter = null ReadBook.curTextChapter = null
page_view.upContent() binding.pageView.upContent()
viewModel.refreshContent(it) viewModel.refreshContent(it)
} }
} }
R.id.menu_download -> ReadBookActivityHelp.showDownloadDialog(this) R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> ReadBookActivityHelp.showBookMark(this) R.id.menu_add_bookmark -> showBookMark(this)
R.id.menu_copy_text -> R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent()) TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let { R.id.menu_update_toc -> ReadBook.book?.let {
loadChapterList(it) loadChapterList(it)
} }
R.id.menu_page_anim -> ReadBookActivityHelp.showPageAnimConfig(this) { R.id.menu_page_anim -> showPageAnimConfig {
page_view.upPageAnim() binding.pageView.upPageAnim()
} }
R.id.menu_book_info -> ReadBook.book?.let { R.id.menu_book_info -> ReadBook.book?.let {
BookInfoActivity.actionBookInfo(this, it.bookId, it.bookTypeId) BookInfoActivity.actionBookInfo(this, it.bookId, it.bookTypeId)
@ -162,7 +145,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
super.onResume() super.onResume()
ReadBook.readStartTime = System.currentTimeMillis() ReadBook.readStartTime = System.currentTimeMillis()
upSystemUiVisibility() upSystemUiVisibility()
page_view.upTime() binding.pageView.upTime()
} }
override fun onPause() { override fun onPause() {
@ -171,41 +154,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
upSystemUiVisibility() upSystemUiVisibility()
} }
override fun upNavigationBarColor() {
when {
read_menu == null -> return
read_menu.isVisible -> {
ATH.setNavigationBarColorAuto(this)
}
ReadBookConfig.bg is ColorDrawable -> {
ATH.setNavigationBarColorAuto(this, ReadBookConfig.bgMeanColor)
}
else -> {
ATH.setNavigationBarColorAuto(this, Color.BLACK)
}
}
}
/** /**
* 初始化View * 初始化View
*/ */
@SuppressLint("ClickableViewAccessibility")
private fun initView() { private fun initView() {
cursor_left.setColorFilter(accentColor) binding.cursorLeft.setColorFilter(accentColor)
cursor_right.setColorFilter(accentColor) binding.cursorRight.setColorFilter(accentColor)
cursor_left.setOnTouchListener(this) binding.cursorLeft.setOnTouchListener(this)
cursor_right.setOnTouchListener(this) binding.cursorRight.setOnTouchListener(this)
tv_chapter_name.onClick {
}
tv_chapter_url.onClick {
runCatching {
val url = tv_chapter_url.text.toString()
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
startActivity(intent)
}
}
} }
override fun clickCenter() { override fun clickCenter() {
@ -217,29 +174,26 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
AutoReadDialog().show(supportFragmentManager, "autoRead") AutoReadDialog().show(supportFragmentManager, "autoRead")
} }
else -> { else -> {
read_menu.runMenuIn() binding.readMenu.runMenuIn()
} }
} }
} }
override fun showTextActionMenu() { override fun showTextActionMenu() = with(binding){
textActionMenu ?: let { textActionMenu.let { popup ->
textActionMenu = TextActionMenu(this, this)
}
textActionMenu?.let { popup ->
popup.contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) popup.contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val popupHeight = popup.contentView.measuredHeight val popupHeight = popup.contentView.measuredHeight
val x = text_menu_position.x.toInt() val x = textMenuPosition.x.toInt()
var y = text_menu_position.y.toInt() - popupHeight var y = textMenuPosition.y.toInt() - popupHeight
if (y < statusBarHeight) { if (y < statusBarHeight) {
y = (cursor_left.y + cursor_left.height).toInt() y = (cursorLeft.y + cursorLeft.height).toInt()
} }
if (cursor_right.y > y && cursor_right.y < y + popupHeight) { if (cursorRight.y > y && cursorRight.y < y + popupHeight) {
y = (cursor_right.y + cursor_right.height).toInt() y = (cursorRight.y + cursorRight.height).toInt()
} }
if (!popup.isShowing) { if (!popup.isShowing) {
popup.showAtLocation(text_menu_position, Gravity.TOP or Gravity.START, x, y) popup.showAtLocation(textMenuPosition, Gravity.TOP or Gravity.START, x, y)
} else { } else {
popup.update( popup.update(
x, y, x, y,
@ -258,38 +212,29 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun upContent(relativePosition: Int, resetPageOffset: Boolean) { override fun upContent(relativePosition: Int, resetPageOffset: Boolean) {
autoPageProgress = 0 autoPageProgress = 0
launch { launch {
page_view.upContent(relativePosition, resetPageOffset) binding.pageView.upContent(relativePosition, resetPageOffset)
seek_read_page.progress = ReadBook.durPageIndex binding.readMenu.setSeekPage(ReadBook.durPageIndex)
loadStates = false
} }
loadStates = false loadStates = false
} }
override fun upView() { override fun upView() {
launch { launch {
ReadBook.curTextChapter?.let { binding.readMenu.upBookView()
tv_chapter_name.text = it.title
// tv_chapter_name.visible()
if (!ReadBook.isLocalBook) {
tv_chapter_url.text = it.title
// tv_chapter_url.visible()
} else {
tv_chapter_url.gone()
} }
seek_read_page.max = it.pageSize.minus(1)
seek_read_page.progress = ReadBook.durPageIndex
tv_pre.isEnabled = ReadBook.durChapterIndex != 0
tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
} ?: let {
tv_chapter_name.gone()
tv_chapter_url.gone()
} }
override fun upPageAnim() {
launch {
binding.pageView.upPageAnim()
} }
} }
override fun pageChanged() { override fun pageChanged() {
autoPageProgress = 0 autoPageProgress = 0
launch { launch {
seek_read_page.progress = ReadBook.durPageIndex binding.readMenu.setSeekPage(ReadBook.durPageIndex)
} }
} }
@ -301,26 +246,28 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
loadStates = true loadStates = true
} }
override fun upSelectedStart(x: Float, y: Float, top: Float) { override fun upSelectedStart(x: Float, y: Float, top: Float) = with(binding){
cursor_left.x = x - cursor_left.width cursorLeft.x = x - cursorLeft.width
cursor_left.y = y cursorLeft.y = y
cursor_left.visible(true) cursorLeft.visible(true)
text_menu_position.x = x textMenuPosition.x = x
text_menu_position.y = top textMenuPosition.y = top
} }
override fun upSelectedEnd(x: Float, y: Float) { override fun upSelectedEnd(x: Float, y: Float) = with(binding){
cursor_right.x = x cursorRight.x = x
cursor_right.y = y cursorRight.y = y
cursor_right.visible(true) cursorRight.visible(true)
} }
override fun onCancelSelect() { /**
cursor_left.invisible() * 取消文字选择
cursor_right.invisible() */
textActionMenu?.dismiss() override fun onCancelSelect() = with(binding) {
cursorLeft.invisible()
cursorRight.invisible()
textActionMenu.dismiss()
} }
private fun upScreenTimeOut() { private fun upScreenTimeOut() {
getPrefString(PreferKey.keepLight)?.let { getPrefString(PreferKey.keepLight)?.let {
screenTimeOut = it.toLong() * 1000 screenTimeOut = it.toLong() * 1000
@ -330,32 +277,32 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun screenOffTimerStart() { override fun screenOffTimerStart() {
if (screenTimeOut < 0) { if (screenTimeOut < 0) {
ReadBookActivityHelp.keepScreenOn(window, true) keepScreenOn(window, true)
return return
} }
val t = screenTimeOut - sysScreenOffTime val t = screenTimeOut - sysScreenOffTime
if (t > 0) { if (t > 0) {
mHandler.removeCallbacks(keepScreenRunnable) mHandler.removeCallbacks(keepScreenRunnable)
ReadBookActivityHelp.keepScreenOn(window, true) keepScreenOn(window, true)
mHandler.postDelayed(keepScreenRunnable, screenTimeOut) mHandler.postDelayed(keepScreenRunnable, screenTimeOut)
} else { } else {
ReadBookActivityHelp.keepScreenOn(window, false) keepScreenOn(window, false)
} }
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean { override fun onTouch(v: View, event: MotionEvent): Boolean = with(binding){
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> textActionMenu?.dismiss() MotionEvent.ACTION_DOWN -> textActionMenu.dismiss()
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
when (v.id) { when (v.id) {
R.id.cursor_left -> page_view.curPage.selectStartMove( R.id.cursor_left -> binding.pageView.curPage.selectStartMove(
event.rawX + cursor_left.width, event.rawX + cursorLeft.width,
event.rawY - cursor_left.height event.rawY - cursorLeft.height
) )
R.id.cursor_right -> page_view.curPage.selectEndMove( R.id.cursor_right -> binding.pageView.curPage.selectEndMove(
event.rawX - cursor_right.width, event.rawX - cursorRight.width,
event.rawY - cursor_right.height event.rawY - cursorRight.height
) )
} }
} }
@ -366,15 +313,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when { when {
ReadBookActivityHelp.isPrevKey(this, keyCode) -> { isPrevKey(this, keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV) binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV)
return true return true
} }
} }
ReadBookActivityHelp.isNextKey(this, keyCode) -> { isNextKey(this, keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT) binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true return true
} }
} }
@ -389,7 +336,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
keyCode == KeyEvent.KEYCODE_SPACE -> { keyCode == KeyEvent.KEYCODE_SPACE -> {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT) binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true return true
} }
} }
@ -400,13 +347,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
* 音量键翻页 * 音量键翻页
*/ */
private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean { private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean {
if (!read_menu.isVisible) { if (!binding.readMenu.isVisible) {
if (getPrefBoolean("volumeKeyPage", true)) { if (getPrefBoolean("volumeKeyPage", true)) {
if (getPrefBoolean("volumeKeyPageOnPlay") if (getPrefBoolean("volumeKeyPageOnPlay")
|| BaseReadAloudService.pause || BaseReadAloudService.pause
) { ) {
page_view.pageDelegate?.isCancel = false binding.pageView.pageDelegate?.isCancel = false
page_view.pageDelegate?.keyTurnPage(direction) binding.pageView.pageDelegate?.keyTurnPage(direction)
return true return true
} }
} }
@ -416,11 +363,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun observeLiveBus() { override fun observeLiveBus() {
super.observeLiveBus() super.observeLiveBus()
observeEvent<String>(EventBus.TIME_CHANGED) { page_view.upTime() } observeEvent<String>(EventBus.TIME_CHANGED) { binding.pageView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent<Int>(EventBus.BATTERY_CHANGED) { binding.pageView.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) { observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.chapterIndex, ReadBook.durPageIndex) viewModel.openChapter(it.chapterIndex, ReadBook.durPageIndex)
page_view.upContent() binding.pageView.upContent()
} }
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) { observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) { if (it) {
@ -431,13 +378,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
observeEvent<Boolean>(EventBus.UP_CONFIG) { observeEvent<Boolean>(EventBus.UP_CONFIG) {
upSystemUiVisibility() upSystemUiVisibility()
page_view.upBg() binding.pageView.upBg()
page_view.upTipStyle() binding.pageView.upTipStyle()
page_view.upStyle() binding.pageView.upStyle()
if (it) { if (it) {
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} else { } else {
page_view.upContent(resetPageOffset = false) binding.pageView.upContent(resetPageOffset = false)
} }
} }
observeEvent<Int>(EventBus.ALOUD_STATE) { observeEvent<Int>(EventBus.ALOUD_STATE) {
@ -446,7 +393,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
val page = textChapter.page(ReadBook.durPageIndex) val page = textChapter.page(ReadBook.durPageIndex)
if (page != null) { if (page != null) {
page.removePageAloudSpan() page.removePageAloudSpan()
page_view.upContent(resetPageOffset = false) binding.pageView.upContent(resetPageOffset = false)
} }
} }
} }
@ -467,7 +414,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
upScreenTimeOut() upScreenTimeOut()
} }
observeEvent<Boolean>(PreferKey.textSelectAble) { observeEvent<Boolean>(PreferKey.textSelectAble) {
page_view.curPage.upSelectAble(it) binding.pageView.curPage.upSelectAble(it)
} }
observeEvent<String>(PreferKey.showBrightnessView) { observeEvent<String>(PreferKey.showBrightnessView) {
setScreenBrightness(getPrefInt("brightness", 100)) setScreenBrightness(getPrefInt("brightness", 100))
@ -501,7 +448,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
override fun showMenuBar() { override fun showMenuBar() {
read_menu.runMenuIn() binding.readMenu.runMenuIn()
} }
override fun openChapterList() { override fun openChapterList() {
@ -579,27 +526,27 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
ReadBook.skipToPage(positions[0]) ReadBook.skipToPage(positions[0])
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
page_view.curPage.selectStartMoveIndex( binding.pageView.curPage.selectStartMoveIndex(
0, 0,
positions[1], positions[1],
positions[2] positions[2]
) )
delay(20L) delay(20L)
when (positions[3]) { when (positions[3]) {
0 -> page_view.curPage.selectEndMoveIndex( 0 -> binding.pageView.curPage.selectEndMoveIndex(
0, 0,
positions[1], positions[1],
positions[2] + viewModel.searchContentQuery.length - 1 positions[2] + viewModel.searchContentQuery.length - 1
) )
1 -> page_view.curPage.selectEndMoveIndex( 1 -> binding.pageView.curPage.selectEndMoveIndex(
0, 0,
positions[1] + 1, positions[1] + 1,
positions[4] positions[4]
) )
//todo: consider change page, jump to scroll position //todo: consider change page, jump to scroll position
-1 -> page_view.curPage.selectEndMoveIndex(1, 0, positions[4]) -1 -> binding.pageView.curPage.selectEndMoveIndex(1, 0, positions[4])
} }
page_view.isTextSelected = true binding.pageView.isTextSelected = true
delay(100L) delay(100L)
} }
} }
@ -621,9 +568,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
override fun onMenuActionFinally() { override fun onMenuActionFinally() {
textActionMenu?.dismiss() textActionMenu.dismiss()
page_view.curPage.cancelSelect() binding.pageView.curPage.cancelSelect()
page_view.isTextSelected = false binding.pageView.isTextSelected = false
} }
override fun finish() { override fun finish() {
@ -649,7 +596,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
postEvent(EventBus.UP_BOOK, 0L) postEvent(EventBus.UP_BOOK, 0L)
mHandler.removeCallbacks(keepScreenRunnable) mHandler.removeCallbacks(keepScreenRunnable)
textActionMenu?.dismiss() textActionMenu?.dismiss()
page_view.onDestroy() binding.pageView.onDestroy()
ReadBook.msg = null ReadBook.msg = null
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
// SyncBookProgress.uploadBookProgress() // SyncBookProgress.uploadBookProgress()

@ -1,20 +1,24 @@
package com.novel.read.ui.read package com.novel.read.ui.read
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.view.LayoutInflater import android.os.Bundle
import android.view.View import android.view.*
import android.view.Window
import android.view.WindowManager
import android.widget.EditText import android.widget.EditText
import androidx.activity.viewModels
import androidx.core.view.isVisible
import com.novel.read.App import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.data.db.entity.Bookmark import com.novel.read.data.db.entity.Bookmark
import com.novel.read.databinding.ActivityReadBookBinding
import com.novel.read.databinding.DialogDownloadChoiceBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.help.ReadBookConfig import com.novel.read.help.ReadBookConfig
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
@ -26,54 +30,32 @@ import com.novel.read.utils.ext.applyTint
import com.novel.read.utils.ext.backgroundColor import com.novel.read.utils.ext.backgroundColor
import com.novel.read.utils.ext.getPrefString import com.novel.read.utils.ext.getPrefString
import com.novel.read.utils.ext.requestInputMethod import com.novel.read.utils.ext.requestInputMethod
import kotlinx.android.synthetic.main.dialog_download_choice.view.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import org.jetbrains.anko.layoutInflater
/**
* 阅读界面
*/
abstract class ReadBookBaseActivity :
VMBaseActivity<ActivityReadBookBinding, ReadBookViewModel>() {
object ReadBookActivityHelp { override val viewModel: ReadBookViewModel by viewModels()
var bottomDialog = 0
/** override fun getViewBinding(): ActivityReadBookBinding {
* 更新状态栏,导航栏 return ActivityReadBookBinding.inflate(layoutInflater)
*/
fun upSystemUiVisibility(
window: Window,
isInMultiWindow: Boolean,
toolBarHide: Boolean = true
) {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
if (!isInMultiWindow) {
flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
if (ReadBookConfig.hideNavigationBar) {
flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
if (toolBarHide) {
if (ReadBookConfig.hideStatusBar) {
flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN
}
if (ReadBookConfig.hideNavigationBar) {
flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
window.decorView.systemUiVisibility = flag
if (toolBarHide) {
ATH.setLightStatusBar(window, ReadBookConfig.durConfig.curStatusIconDark())
} else {
ATH.setLightStatusBarAuto(
window,
ThemeStore.statusBarColor(App.INSTANCE, AppConfig.isTransparentStatusBar)
)
} }
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
setOrientation()
upLayoutInDisplayCutoutMode()
super.onCreate(savedInstanceState)
} }
/** /**
* 屏幕方向 * 屏幕方向
*/ */
@SuppressLint("SourceLockedOrientationActivity") @SuppressLint("SourceLockedOrientationActivity")
fun setOrientation(activity: Activity) = activity.apply { fun setOrientation() {
when (AppConfig.requestedDirection) { when (AppConfig.requestedDirection) {
"0" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED "0" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
"1" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT "1" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
@ -82,6 +64,19 @@ object ReadBookActivityHelp {
} }
} }
override fun upNavigationBarColor() {
when {
binding.readMenu.isVisible -> super.upNavigationBarColor()
bottomDialog > 0 -> super.upNavigationBarColor()
ReadBookConfig.bg is ColorDrawable -> {
ATH.setNavigationBarColorAuto(this, ReadBookConfig.bgMeanColor)
}
else -> {
ATH.setNavigationBarColorAuto(this, Color.BLACK)
}
}
}
/** /**
* 保持亮屏 * 保持亮屏
@ -97,7 +92,7 @@ object ReadBookActivityHelp {
/** /**
* 适配刘海 * 适配刘海
*/ */
fun upLayoutInDisplayCutoutMode(window: Window) { private fun upLayoutInDisplayCutoutMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && AppConfig.readBodyToLh) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && AppConfig.readBodyToLh) {
window.attributes = window.attributes.apply { window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode = layoutInDisplayCutoutMode =
@ -107,34 +102,28 @@ object ReadBookActivityHelp {
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
fun showDownloadDialog(context: Context) { fun showDownloadDialog() {
ReadBook.book?.let { book -> ReadBook.book?.let { book ->
context.alert(titleResource = R.string.offline_cache) { alert(titleResource = R.string.offline_cache) {
var view: View? = null val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply {
customView { root.setBackgroundColor(root.context.backgroundColor)
LayoutInflater.from(context).inflate(R.layout.dialog_download_choice, null) editStart.setText((book.durChapterIndex + 1).toString())
.apply { editEnd.setText(book.totalChapterNum.toString())
view = this
setBackgroundColor(context.backgroundColor)
edit_start.setText((book.durChapterIndex + 1).toString())
edit_end.setText(
App.db.getChapterDao().getChapterCount(bookId = book.bookId).toString()
)
}
} }
customView { alertBinding.root }
yesButton { yesButton {
view?.apply { alertBinding.run {
val start = edit_start?.text?.toString()?.toInt() ?: 0 val start = editStart.text?.toString()?.toInt() ?: 0
val end = edit_end?.text?.toString()?.toInt() ?: App.db.getChapterDao() val end = editEnd.text?.toString()?.toInt() ?: book.totalChapterNum
.getChapterCount(bookId = book.bookId) CacheBook.start(this@ReadBookBaseActivity, book.bookId, start - 1, end - 1)
CacheBook.start(context, book.bookId, start - 1, end - 1)
} }
} }
noButton() noButton()
}.show().applyTint() }.show()
} }
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
fun showBookMark(context: Context) = with(context) { fun showBookMark(context: Context) = with(context) {
val book = ReadBook.book ?: return val book = ReadBook.book ?: return
@ -144,7 +133,7 @@ object ReadBookActivityHelp {
message = book.bookName + "" + textChapter.title message = book.bookName + "" + textChapter.title
customView { customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view.apply { editText = findViewById<EditText>(R.id.edit_view).apply {
setHint(R.string.note_content) setHint(R.string.note_content)
} }
} }
@ -168,30 +157,8 @@ object ReadBookActivityHelp {
}.show().applyTint().requestInputMethod() }.show().applyTint().requestInputMethod()
} }
@SuppressLint("InflateParams")
fun showCharsetConfig(context: Context) = with(context) { fun showPageAnimConfig(success: () -> Unit) {
// val charsets =
// arrayListOf("UTF-8", "GB2312", "GBK", "Unicode", "UTF-16", "UTF-16LE", "ASCII")
// alert(R.string.set_charset) {
// var editText: AutoCompleteTextView? = null
// customView {
// layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
// editText = edit_view
// edit_view.setFilterValues(charsets)
// edit_view.setText(ReadBook.book?.charset)
// }
// }
// okButton {
// val text = editText?.text?.toString()
// text?.let {
// ReadBook.setCharset(it)
// }
// }
// cancelButton()
// }.show().applyTint()
}
fun showPageAnimConfig(context: Context, success: () -> Unit) = with(context) {
val items = arrayListOf<String>() val items = arrayListOf<String>()
items.add(getString(R.string.btn_default_s)) items.add(getString(R.string.btn_default_s))
items.add(getString(R.string.page_anim_cover)) items.add(getString(R.string.page_anim_cover))

@ -1,9 +1,12 @@
package com.novel.read.ui.read package com.novel.read.ui.read
import android.content.Context import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.WindowManager import android.view.WindowManager
import android.view.animation.Animation import android.view.animation.Animation
import android.widget.FrameLayout import android.widget.FrameLayout
@ -12,6 +15,7 @@ import androidx.core.view.isVisible
import com.novel.read.App import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.databinding.ViewReadMenuBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.help.ReadBookConfig import com.novel.read.help.ReadBookConfig
import com.novel.read.lib.Selector import com.novel.read.lib.Selector
@ -20,7 +24,6 @@ import com.novel.read.utils.AnimationUtilsSupport
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.SystemUtils import com.novel.read.utils.SystemUtils
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.view_read_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
@ -32,7 +35,8 @@ class ReadMenu @JvmOverloads constructor(
attrs: AttributeSet? = null attrs: AttributeSet? = null
) : FrameLayout(context, attrs) { ) : FrameLayout(context, attrs) {
var cnaShowMenu: Boolean = false var cnaShowMenu: Boolean = false
private val callBack: CallBack? get() = activity as? CallBack private val callBack: CallBack get() = activity as CallBack
private val binding = ViewReadMenuBinding.inflate(LayoutInflater.from(context), this, true)
private lateinit var menuTopIn: Animation private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation private lateinit var menuTopOut: Animation
private lateinit var menuBottomIn: Animation private lateinit var menuBottomIn: Animation
@ -47,33 +51,32 @@ class ReadMenu @JvmOverloads constructor(
val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true) val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true)
init { init {
inflate(context, R.layout.view_read_menu, this)
if (AppConfig.isNightTheme) { if (AppConfig.isNightTheme) {
fabNightTheme.setImageResource(R.drawable.ic_daytime) binding.fabNightTheme.setImageResource(R.drawable.ic_daytime)
} else { } else {
fabNightTheme.setImageResource(R.drawable.ic_brightness) binding.fabNightTheme.setImageResource(R.drawable.ic_brightness)
} }
initAnimation() initAnimation()
val brightnessBackground = GradientDrawable() val brightnessBackground = GradientDrawable()
brightnessBackground.cornerRadius = 5F.dp brightnessBackground.cornerRadius = 5F.dp
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
ll_bottom_bg.setBackgroundColor(bgColor) binding.llBottomBg.setBackgroundColor(bgColor)
fabSearch.backgroundTintList = bottomBackgroundList binding.fabSearch.backgroundTintList = bottomBackgroundList
fabSearch.setColorFilter(textColor) binding.fabSearch.setColorFilter(textColor)
fabNightTheme.backgroundTintList = bottomBackgroundList binding.fabNightTheme.backgroundTintList = bottomBackgroundList
fabNightTheme.setColorFilter(textColor) binding.fabNightTheme.setColorFilter(textColor)
tv_pre.setTextColor(textColor) binding.tvPre.setTextColor(textColor)
tv_next.setTextColor(textColor) binding.tvNext.setTextColor(textColor)
iv_catalog.setColorFilter(textColor) binding.ivCatalog.setColorFilter(textColor)
tv_catalog.setTextColor(textColor) binding.tvCatalog.setTextColor(textColor)
iv_read_aloud.setColorFilter(textColor) binding.ivReadAloud.setColorFilter(textColor)
tv_read_aloud.setTextColor(textColor) binding.tvReadAloud.setTextColor(textColor)
iv_font.setColorFilter(textColor) binding.ivFont.setColorFilter(textColor)
tv_font.setTextColor(textColor) binding.tvFont.setTextColor(textColor)
iv_setting.setColorFilter(textColor) binding.ivSetting.setColorFilter(textColor)
tv_setting.setTextColor(textColor) binding.tvSetting.setTextColor(textColor)
vw_bg.onClick { } binding.vwBg.onClick { }
vwNavigationBar.onClick { } binding.vwNavigationBar.onClick { }
bindEvent() bindEvent()
} }
@ -94,17 +97,17 @@ class ReadMenu @JvmOverloads constructor(
fun runMenuIn() { fun runMenuIn() {
this.visible() this.visible()
title_bar.visible() binding.titleBar.visible()
bottom_menu.visible() binding.bottomMenu.visible()
title_bar.startAnimation(menuTopIn) binding.titleBar.startAnimation(menuTopIn)
bottom_menu.startAnimation(menuBottomIn) binding.bottomMenu.startAnimation(menuBottomIn)
} }
fun runMenuOut(onMenuOutEnd: (() -> Unit)? = null) { fun runMenuOut(onMenuOutEnd: (() -> Unit)? = null) {
this.onMenuOutEnd = onMenuOutEnd this.onMenuOutEnd = onMenuOutEnd
if (this.isVisible) { if (this.isVisible) {
title_bar.startAnimation(menuTopOut) binding.titleBar.startAnimation(menuTopOut)
bottom_menu.startAnimation(menuBottomOut) binding.bottomMenu.startAnimation(menuBottomOut)
} }
} }
@ -112,10 +115,20 @@ class ReadMenu @JvmOverloads constructor(
return context.getPrefBoolean("brightnessAuto", true) || !showBrightnessView return context.getPrefBoolean("brightnessAuto", true) || !showBrightnessView
} }
private fun bindEvent() { private fun bindEvent() = with(binding){
tvChapterName.onClick {
}
tvChapterUrl.onClick {
runCatching {
val url = tvChapterUrl.text.toString()
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
context.startActivity(intent)
}
}
//阅读进度 //阅读进度
seek_read_page.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seekReadPage.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) {
} }
@ -143,37 +156,37 @@ class ReadMenu @JvmOverloads constructor(
} }
//上一章 //上一章
tv_pre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
//下一章 //下一章
tv_next.onClick { ReadBook.moveToNextChapter(true) } tvNext.onClick { ReadBook.moveToNextChapter(true) }
//目录 //目录
ll_catalog.onClick { llCatalog.onClick {
runMenuOut { runMenuOut {
callBack?.openChapterList() callBack?.openChapterList()
} }
} }
//朗读 //朗读
ll_read_aloud.onClick { llReadAloud.onClick {
runMenuOut { runMenuOut {
callBack?.onClickReadAloud() callBack?.onClickReadAloud()
} }
} }
ll_read_aloud.onLongClick { llReadAloud.onLongClick {
runMenuOut { callBack?.showReadAloudDialog() } runMenuOut { callBack?.showReadAloudDialog() }
true true
} }
//界面 //界面
ll_font.onClick { llFont.onClick {
runMenuOut { runMenuOut {
callBack?.showAdjust() callBack?.showAdjust()
} }
} }
//设置 //设置
ll_setting.onClick { llSetting.onClick {
runMenuOut { runMenuOut {
callBack?.showReadStyle() callBack?.showReadStyle()
} }
@ -190,8 +203,8 @@ class ReadMenu @JvmOverloads constructor(
} }
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
vw_menu_bg.onClick { runMenuOut() } binding.vwMenuBg.onClick { runMenuOut() }
vwNavigationBar.layoutParams = vwNavigationBar.layoutParams.apply { binding.vwNavigationBar.layoutParams = binding.vwNavigationBar.layoutParams.apply {
height = height =
if (ReadBookConfig.hideNavigationBar if (ReadBookConfig.hideNavigationBar
&& SystemUtils.isNavigationBarExist(activity) && SystemUtils.isNavigationBarExist(activity)
@ -210,13 +223,13 @@ class ReadMenu @JvmOverloads constructor(
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out) AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
menuTopOut.setAnimationListener(object : Animation.AnimationListener { menuTopOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) { override fun onAnimationStart(animation: Animation) {
vw_menu_bg.setOnClickListener(null) binding.vwMenuBg.setOnClickListener(null)
} }
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
this@ReadMenu.invisible() this@ReadMenu.invisible()
title_bar.invisible() binding.titleBar.invisible()
bottom_menu.invisible() binding.bottomMenu.invisible()
cnaShowMenu = false cnaShowMenu = false
onMenuOutEnd?.invoke() onMenuOutEnd?.invoke()
callBack?.upSystemUiVisibility() callBack?.upSystemUiVisibility()
@ -227,6 +240,33 @@ class ReadMenu @JvmOverloads constructor(
} }
fun setTitle(title: String) {
binding.titleBar.title = title
}
fun upBookView() {
ReadBook.curTextChapter?.let {
binding.tvChapterName.text = it.title
binding.tvChapterName.visible()
if (!ReadBook.isLocalBook) {
binding.tvChapterUrl.text = it.title
binding.tvChapterUrl.visible()
} else {
binding.tvChapterUrl.gone()
}
binding.seekReadPage.max = it.pageSize.minus(1)
binding.seekReadPage.progress = ReadBook.durPageIndex
binding.tvPre.isEnabled = ReadBook.durChapterIndex != 0
binding.tvNext.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
} ?: let {
binding.tvChapterName.gone()
binding.tvChapterUrl.gone()
}
}
fun setSeekPage(seek: Int) {
binding.seekReadPage.progress = seek
}
interface CallBack { interface CallBack {
fun autoPage() fun autoPage()

@ -15,13 +15,13 @@ import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl import androidx.appcompat.view.menu.MenuItemImpl
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.databinding.ItemTextBinding
import com.novel.read.databinding.PopupActionMenuBinding
import com.novel.read.service.BaseReadAloudService import com.novel.read.service.BaseReadAloudService
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.item_text.view.*
import kotlinx.android.synthetic.main.popup_action_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.util.* import java.util.*
@ -30,7 +30,7 @@ import java.util.*
class TextActionMenu(private val context: Context, private val callBack: CallBack) : class TextActionMenu(private val context: Context, private val callBack: CallBack) :
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT), PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT),
TextToSpeech.OnInitListener { TextToSpeech.OnInitListener {
private val binding = PopupActionMenuBinding.inflate(LayoutInflater.from(context))
private val adapter = Adapter() private val adapter = Adapter()
private val menu = MenuBuilder(context) private val menu = MenuBuilder(context)
private val moreMenu = MenuBuilder(context) private val moreMenu = MenuBuilder(context)
@ -46,46 +46,46 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
initRecyclerView() initRecyclerView()
setOnDismissListener { setOnDismissListener {
contentView.apply { contentView.apply {
iv_menu_more.setImageResource(R.drawable.ic_more_vert) binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert)
recycler_view_more.gone() binding.recyclerViewMore.gone()
adapter.setList(menu.visibleItems) adapter.setList(menu.visibleItems)
recycler_view.visible() binding.recyclerView.visible()
} }
} }
} }
private fun initRecyclerView() = with(contentView) { private fun initRecyclerView() = with(binding) {
recycler_view.adapter = adapter recyclerView.adapter = adapter
recycler_view_more.adapter = adapter recyclerViewMore.adapter = adapter
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)
adapter.setList(menu.visibleItems) adapter.setList(menu.visibleItems)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
onInitializeMenu(moreMenu) onInitializeMenu(moreMenu)
} }
if (moreMenu.size() > 0) { if (moreMenu.size() > 0) {
iv_menu_more.visible() ivMenuMore.visible()
} }
iv_menu_more.onClick { ivMenuMore.onClick {
if (recycler_view.isVisible) { if (recyclerView.isVisible) {
iv_menu_more.setImageResource(R.drawable.ic_arrow_back) ivMenuMore.setImageResource(R.drawable.ic_arrow_back)
adapter.setList(menu.visibleItems) adapter.setList(menu.visibleItems)
recycler_view.gone() recyclerView.gone()
recycler_view_more.visible() recyclerViewMore.visible()
} else { } else {
iv_menu_more.setImageResource(R.drawable.ic_more_vert) ivMenuMore.setImageResource(R.drawable.ic_more_vert)
recycler_view_more.gone() recyclerViewMore.gone()
adapter.setList(menu.visibleItems) adapter.setList(menu.visibleItems)
recycler_view.visible() recyclerView.visible()
} }
} }
} }
inner class Adapter : inner class Adapter :
BaseQuickAdapter<MenuItemImpl, BaseViewHolder>(R.layout.item_text){ BaseBindingAdapter<MenuItemImpl, ItemTextBinding>(){
override fun convert(holder: BaseViewHolder, item: MenuItemImpl) { override fun convert(holder: VBViewHolder<ItemTextBinding>, item: MenuItemImpl) {
holder.itemView.run { holder.vb.run {
text_view.text = item.title textView.text = item.title
} }
holder.itemView.onClick { holder.itemView.onClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
@ -97,6 +97,13 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemTextBinding {
return ItemTextBinding.inflate(inflater,parent,false)
}
} }
private fun onMenuItemSelected(item: MenuItemImpl) { private fun onMenuItemSelected(item: MenuItemImpl) {

@ -7,14 +7,16 @@ import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.constant.PreferKey import com.novel.read.constant.PreferKey
import com.novel.read.databinding.DialogReadAdjustBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.ui.read.ReadBookActivity import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_read_adjust.* import com.novel.read.utils.viewbindingdelegate.viewBinding
class ReadAdjustDialog :BaseDialogFragment() { class ReadAdjustDialog :BaseDialogFragment() {
val callBack get() = activity as? ReadBookActivity val callBack get() = activity as? ReadBookActivity
private val binding by viewBinding(DialogReadAdjustBinding::bind)
val showBrightnessView get() = context?.getPrefBoolean(PreferKey.showBrightnessView, true) val showBrightnessView get() = context?.getPrefBoolean(PreferKey.showBrightnessView, true)
override fun onStart() { override fun onStart() {
@ -49,33 +51,33 @@ class ReadAdjustDialog :BaseDialogFragment() {
private fun initView() { private fun initView() {
} }
private fun initData() { private fun initData() = with(binding) {
scb_follow_sys.isChecked = brightnessAuto() binding.scbFollowSys.isChecked = brightnessAuto()
hpb_light.progress = requireContext().getPrefInt("brightness", 100) binding.hpbLight.progress = requireContext().getPrefInt("brightness", 100)
upBrightnessState() upBrightnessState()
swt_dark.isChecked=AppConfig.isNightTheme binding.swtDark.isChecked=AppConfig.isNightTheme
swt_dark.setOnCheckedChangeListener { compoundButton, b -> binding.swtDark.setOnCheckedChangeListener { compoundButton, b ->
AppConfig.isNightTheme = b AppConfig.isNightTheme = b
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
} }
} }
private fun initViewEvent() { private fun initViewEvent() = with(binding){
//亮度调节 //亮度调节
scb_follow_sys.setOnClickListener { scbFollowSys.setOnClickListener {
if (scb_follow_sys.isChecked) { if (scbFollowSys.isChecked) {
scb_follow_sys.setChecked(checked = false, animate = true) scbFollowSys.setChecked(checked = false, animate = true)
} else { } else {
scb_follow_sys.setChecked(checked = true, animate = true) scbFollowSys.setChecked(checked = true, animate = true)
} }
context?.putPrefBoolean("brightnessAuto", !brightnessAuto()) context?.putPrefBoolean("brightnessAuto", !brightnessAuto())
upBrightnessState() upBrightnessState()
} }
//亮度调节 //亮度调节
hpb_light.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { hpbLight.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
setScreenBrightness(progress) setScreenBrightness(progress)
} }
@ -85,14 +87,14 @@ class ReadAdjustDialog :BaseDialogFragment() {
} }
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
context?.putPrefInt("brightness", hpb_light.progress) context?.putPrefInt("brightness", hpbLight.progress)
} }
}) })
} }
private fun upBrightnessState() { private fun upBrightnessState() {
hpb_light.isEnabled = !brightnessAuto() binding.hpbLight.isEnabled = !brightnessAuto()
context?.getPrefInt("brightness", 100)?.let { setScreenBrightness(it) } context?.getPrefInt("brightness", 100)?.let { setScreenBrightness(it) }
} }

@ -6,6 +6,7 @@ import android.widget.SeekBar
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.databinding.DialogReadAloudBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.service.BaseReadAloudService import com.novel.read.service.BaseReadAloudService
import com.novel.read.service.help.ReadAloud import com.novel.read.service.help.ReadAloud
@ -13,12 +14,11 @@ import com.novel.read.service.help.ReadBook
import com.novel.read.ui.widget.dialog.ReadAloudConfigDialog import com.novel.read.ui.widget.dialog.ReadAloudConfigDialog
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_read_aloud.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick
class ReadAloudDialog : BaseDialogFragment() { class ReadAloudDialog : BaseDialogFragment() {
var callBack: CallBack? = null var callBack: CallBack? = null
private val binding by viewBinding(DialogReadAloudBinding::bind)
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
dialog?.window?.let { dialog?.window?.let {
@ -46,59 +46,61 @@ class ReadAloudDialog : BaseDialogFragment() {
val bg = requireContext().bottomBackground val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg) val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight) val textColor = requireContext().getPrimaryTextColor(isLight)
root_view.setBackgroundColor(bg) with(binding) {
tv_pre.setTextColor(textColor) rootView.setBackgroundColor(bg)
tv_next.setTextColor(textColor) tvPre.setTextColor(textColor)
iv_play_prev.setColorFilter(textColor) tvNext.setTextColor(textColor)
iv_play_pause.setColorFilter(textColor) ivPlayPrev.setColorFilter(textColor)
iv_play_next.setColorFilter(textColor) ivPlayPause.setColorFilter(textColor)
iv_stop.setColorFilter(textColor) ivPlayNext.setColorFilter(textColor)
iv_timer.setColorFilter(textColor) ivStop.setColorFilter(textColor)
tv_timer.setTextColor(textColor) ivTimer.setColorFilter(textColor)
tv_tts_speed.setTextColor(textColor) tvTimer.setTextColor(textColor)
iv_catalog.setColorFilter(textColor) tvTtsSpeed.setTextColor(textColor)
tv_catalog.setTextColor(textColor) ivCatalog.setColorFilter(textColor)
iv_main_menu.setColorFilter(textColor) tvCatalog.setTextColor(textColor)
tv_main_menu.setTextColor(textColor) ivMainMenu.setColorFilter(textColor)
iv_to_backstage.setColorFilter(textColor) tvMainMenu.setTextColor(textColor)
tv_to_backstage.setTextColor(textColor) ivToBackstage.setColorFilter(textColor)
iv_setting.setColorFilter(textColor) tvToBackstage.setTextColor(textColor)
tv_setting.setTextColor(textColor) ivSetting.setColorFilter(textColor)
cb_tts_follow_sys.setTextColor(textColor) tvSetting.setTextColor(textColor)
cbTtsFollowSys.setTextColor(textColor)
}
initOnChange() initOnChange()
initData() initData()
initEvent() initEvent()
} }
private fun initData() { private fun initData() = with(binding) {
upPlayState() upPlayState()
upTimerText(BaseReadAloudService.timeMinute) upTimerText(BaseReadAloudService.timeMinute)
seek_timer.progress = BaseReadAloudService.timeMinute seekTimer.progress = BaseReadAloudService.timeMinute
cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) cbTtsFollowSys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true)
seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked seekTtsSpeechRate.isEnabled = !cbTtsFollowSys.isChecked
seek_tts_SpeechRate.progress = AppConfig.ttsSpeechRate seekTtsSpeechRate.progress = AppConfig.ttsSpeechRate
} }
private fun initOnChange() { private fun initOnChange() = with(binding){
cb_tts_follow_sys.setOnCheckedChangeListener { buttonView, isChecked -> cbTtsFollowSys.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed) { if (buttonView.isPressed) {
requireContext().putPrefBoolean("ttsFollowSys", isChecked) requireContext().putPrefBoolean("ttsFollowSys", isChecked)
seek_tts_SpeechRate.isEnabled = !isChecked seekTtsSpeechRate.isEnabled = !isChecked
upTtsSpeechRate() upTtsSpeechRate()
} }
} }
seek_tts_SpeechRate.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seekTtsSpeechRate.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar) {
AppConfig.ttsSpeechRate = seek_tts_SpeechRate.progress AppConfig.ttsSpeechRate = seekBar.progress
upTtsSpeechRate() upTtsSpeechRate()
} }
}) })
seek_timer.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seekTimer.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
upTimerText(progress) upTimerText(progress)
} }
@ -106,40 +108,46 @@ class ReadAloudDialog : BaseDialogFragment() {
override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
ReadAloud.setTimer(requireContext(), seek_timer.progress) ReadAloud.setTimer(requireContext(), seekTimer.progress)
} }
}) })
} }
private fun initEvent() { private fun initEvent() = with(binding) {
ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() } llMainMenu.setOnClickListener {
ll_setting.onClick { callBack?.showMenuBar()
dismissAllowingStateLoss()
}
llSetting.setOnClickListener {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
tv_pre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tv_next.onClick { ReadBook.moveToNextChapter(true) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
iv_stop.onClick { ReadAloud.stop(requireContext()); dismiss() } ivStop.setOnClickListener {
iv_play_pause.onClick { callBack?.onClickReadAloud() } ReadAloud.stop(requireContext())
iv_play_prev.onClick { ReadAloud.prevParagraph(requireContext()) } dismissAllowingStateLoss()
iv_play_next.onClick { ReadAloud.nextParagraph(requireContext()) } }
ll_catalog.onClick { callBack?.openChapterList() } ivPlayPause.setOnClickListener { callBack?.onClickReadAloud() }
ll_to_backstage.onClick { callBack?.finish() } ivPlayPrev.setOnClickListener { ReadAloud.prevParagraph(requireContext()) }
ivPlayNext.setOnClickListener { ReadAloud.nextParagraph(requireContext()) }
llCatalog.setOnClickListener { callBack?.openChapterList() }
llToBackstage.setOnClickListener { callBack?.finish() }
} }
private fun upPlayState() { private fun upPlayState() {
if (!BaseReadAloudService.pause) { if (!BaseReadAloudService.pause) {
iv_play_pause.setImageResource(R.drawable.ic_pause_24dp) binding.ivPlayPause.setImageResource(R.drawable.ic_pause_24dp)
} else { } else {
iv_play_pause.setImageResource(R.drawable.ic_play_24dp) binding.ivPlayPause.setImageResource(R.drawable.ic_play_24dp)
} }
val bg = requireContext().bottomBackground val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg) val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight) val textColor = requireContext().getPrimaryTextColor(isLight)
iv_play_pause.setColorFilter(textColor) binding.ivPlayPause.setColorFilter(textColor)
} }
private fun upTimerText(timeMinute: Int) { private fun upTimerText(timeMinute: Int) {
tv_timer.text = requireContext().getString(R.string.timer_m, timeMinute) binding.tvTimer.text = requireContext().getString(R.string.timer_m, timeMinute)
} }
private fun upTtsSpeechRate() { private fun upTtsSpeechRate() {
@ -152,7 +160,7 @@ class ReadAloudDialog : BaseDialogFragment() {
override fun observeLiveBus() { override fun observeLiveBus() {
observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() } observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() }
observeEvent<Int>(EventBus.TTS_DS) { seek_timer.progress = it } observeEvent<Int>(EventBus.TTS_DS) { binding.seekTimer.progress = it }
} }
interface CallBack { interface CallBack {

@ -7,21 +7,23 @@ import androidx.core.view.get
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.base.VBViewHolder
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.databinding.DialogReadBookStyleBinding
import com.novel.read.databinding.ItemReadStyleBinding
import com.novel.read.help.ReadBookConfig import com.novel.read.help.ReadBookConfig
import com.novel.read.service.help.ReadBook import com.novel.read.service.help.ReadBook
import com.novel.read.ui.read.ReadBookActivity import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_read_book_style.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.item_read_style.view.*
import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onCheckedChange
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadStyleDialog : BaseDialogFragment() { class ReadStyleDialog : BaseDialogFragment() {
private val binding by viewBinding(DialogReadBookStyleBinding::bind)
val callBack get() = activity as? ReadBookActivity val callBack get() = activity as? ReadBookActivity
private lateinit var styleAdapter: StyleAdapter private lateinit var styleAdapter: StyleAdapter
@ -54,11 +56,11 @@ class ReadStyleDialog : BaseDialogFragment() {
initViewEvent() initViewEvent()
} }
private fun initView() { private fun initView()= with(binding) {
val bg = requireContext().bottomBackground val bg = requireContext().bottomBackground
root_view.setBackgroundColor(bg) rootView.setBackgroundColor(bg)
styleAdapter = StyleAdapter() styleAdapter = StyleAdapter()
rv_style.adapter = styleAdapter rvStyle.adapter = styleAdapter
} }
@ -67,23 +69,23 @@ class ReadStyleDialog : BaseDialogFragment() {
styleAdapter.setList(ReadBookConfig.configList) styleAdapter.setList(ReadBookConfig.configList)
} }
private fun initViewEvent() { private fun initViewEvent() = with(binding){
tv_font_type.onChanged { tvFontType.onChanged {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
fl_text_Bold.onChanged { flTextBold.onChanged {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
fl_text_font.onClick { flTextFont.onClick {
// FontSelectDialog().show(childFragmentManager, "fontSelectDialog") // FontSelectDialog().show(childFragmentManager, "fontSelectDialog")
} }
rg_page_anim.onCheckedChange { _, checkedId -> rgPageAnim.onCheckedChange { _, checkedId ->
ReadBookConfig.pageAnim = -1 ReadBookConfig.pageAnim = -1
ReadBookConfig.pageAnim = rg_page_anim.getIndexById(checkedId) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.page_view?.upPageAnim() callBack?.upPageAnim()
} }
nbTextSizeAdd.setOnClickListener { nbTextSizeAdd.setOnClickListener {
@ -100,27 +102,30 @@ class ReadStyleDialog : BaseDialogFragment() {
inner class StyleAdapter : inner class StyleAdapter :
BaseQuickAdapter<ReadBookConfig.Config, BaseViewHolder>(R.layout.item_read_style) { BaseBindingAdapter<ReadBookConfig.Config, ItemReadStyleBinding>() {
override fun convert(holder: BaseViewHolder, item: ReadBookConfig.Config) { override fun convert(
holder.itemView.run { holder: VBViewHolder<ItemReadStyleBinding>,
iv_style.setText(item.name.ifBlank { "文字" }) item: ReadBookConfig.Config
iv_style.setTextColor(item.curTextColor()) ) {
iv_style.setImageDrawable(item.curBgDrawable(100, 150)) holder.vb.run {
ivStyle.setText(item.name.ifBlank { "文字" })
ivStyle.setTextColor(item.curTextColor())
ivStyle.setImageDrawable(item.curBgDrawable(100, 150))
if (ReadBookConfig.styleSelect == holder.layoutPosition) { if (ReadBookConfig.styleSelect == holder.layoutPosition) {
iv_style.borderColor = accentColor ivStyle.borderColor = accentColor
iv_style.setTextBold(true) ivStyle.setTextBold(true)
} else { } else {
iv_style.borderColor = item.curTextColor() ivStyle.borderColor = item.curTextColor()
iv_style.setTextBold(false) ivStyle.setTextBold(false)
} }
iv_style.onClick { ivStyle.onClick {
if (iv_style.isInView) { if (ivStyle.isInView) {
changeBg(holder.layoutPosition) changeBg(holder.layoutPosition)
} }
} }
iv_style.onLongClick { ivStyle.onLongClick {
if (iv_style.isInView) { if (ivStyle.isInView) {
showBgTextConfig(holder.layoutPosition) showBgTextConfig(holder.layoutPosition)
} else { } else {
false false
@ -128,6 +133,13 @@ class ReadStyleDialog : BaseDialogFragment() {
} }
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemReadStyleBinding {
return ItemReadStyleBinding.inflate(inflater, parent, false)
}
} }
@ -150,11 +162,11 @@ class ReadStyleDialog : BaseDialogFragment() {
return true return true
} }
private fun upView() { private fun upView() = with(binding){
ReadBook.pageAnim().let { ReadBook.pageAnim().let {
if (it >= 0 && it < rg_page_anim.childCount) { if (it >= 0 && it < rgPageAnim.childCount) {
rg_page_anim.check(rg_page_anim[it].id) rgPageAnim.check(rgPageAnim[it].id)
} }
} }
ReadBookConfig.let { ReadBookConfig.let {

@ -3,6 +3,7 @@ package com.novel.read.ui.read.page
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
@ -10,19 +11,18 @@ import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.constant.AppConst.timeFormat import com.novel.read.constant.AppConst.timeFormat
import com.novel.read.data.read.TextPage import com.novel.read.data.read.TextPage
import com.novel.read.databinding.ViewBookPageBinding
import com.novel.read.help.ReadBookConfig import com.novel.read.help.ReadBookConfig
import com.novel.read.help.ReadTipConfig import com.novel.read.help.ReadTipConfig
import com.novel.read.service.help.ReadBook import com.novel.read.service.help.ReadBook
import com.novel.read.ui.widget.BatteryView import com.novel.read.ui.widget.BatteryView
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import kotlinx.android.synthetic.main.view_book_page.view.*
import org.jetbrains.anko.topPadding import org.jetbrains.anko.topPadding
import java.util.* import java.util.*
class ContentView(context: Context) : FrameLayout(context) { class ContentView(context: Context) : FrameLayout(context) {
private val binding = ViewBookPageBinding.inflate(LayoutInflater.from(context), this, true)
private var battery = 100 private var battery = 100
private var tvTitle: BatteryView? = null private var tvTitle: BatteryView? = null
private var tvTime: BatteryView? = null private var tvTime: BatteryView? = null
@ -35,55 +35,54 @@ class ContentView(context: Context) : FrameLayout(context) {
val headerHeight: Int val headerHeight: Int
get() { get() {
val h1 = if (ReadBookConfig.hideStatusBar) 0 else context.statusBarHeight val h1 = if (ReadBookConfig.hideStatusBar) 0 else context.statusBarHeight
val h2 = if (ll_header.isGone) 0 else ll_header.height val h2 = if (binding.llHeader.isGone) 0 else binding.llHeader.height
return h1 + h2 return h1 + h2
} }
init { init {
//设置背景防止切换背景时文字重叠 //设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background)) setBackgroundColor(context.getCompatColor(R.color.background))
inflate(context, R.layout.view_book_page, this)
upTipStyle() upTipStyle()
upStyle() upStyle()
content_text_view.upView = { binding.contentTextView.upView = {
setProgress(it) setProgress(it)
} }
} }
fun upStyle() { fun upStyle() = with(binding){
ReadBookConfig.apply { ReadBookConfig.apply {
bv_header_left.typeface = ChapterProvider.typeface bvHeaderLeft.typeface = ChapterProvider.typeface
tv_header_left.typeface = ChapterProvider.typeface tvHeaderLeft.typeface = ChapterProvider.typeface
tv_header_middle.typeface = ChapterProvider.typeface tvHeaderMiddle.typeface = ChapterProvider.typeface
tv_header_right.typeface = ChapterProvider.typeface tvHeaderRight.typeface = ChapterProvider.typeface
bv_footer_left.typeface = ChapterProvider.typeface bvFooterLeft.typeface = ChapterProvider.typeface
tv_footer_left.typeface = ChapterProvider.typeface tvFooterLeft.typeface = ChapterProvider.typeface
tv_footer_middle.typeface = ChapterProvider.typeface tvFooterMiddle.typeface = ChapterProvider.typeface
tv_footer_right.typeface = ChapterProvider.typeface tvFooterRight.typeface = ChapterProvider.typeface
bv_header_left.setColor(textColor) bvHeaderLeft.setColor(textColor)
tv_header_left.setColor(textColor) tvHeaderLeft.setColor(textColor)
tv_header_middle.setColor(textColor) tvHeaderMiddle.setColor(textColor)
tv_header_right.setColor(textColor) tvHeaderRight.setColor(textColor)
bv_footer_left.setColor(textColor) bvFooterLeft.setColor(textColor)
tv_footer_left.setColor(textColor) tvFooterLeft.setColor(textColor)
tv_footer_middle.setColor(textColor) tvFooterMiddle.setColor(textColor)
tv_footer_right.setColor(textColor) tvFooterRight.setColor(textColor)
upStatusBar() upStatusBar()
ll_header.setPadding( binding.llHeader.setPadding(
headerPaddingLeft.dp, headerPaddingLeft.dp,
headerPaddingTop.dp, headerPaddingTop.dp,
headerPaddingRight.dp, headerPaddingRight.dp,
headerPaddingBottom.dp headerPaddingBottom.dp
) )
ll_footer.setPadding( llFooter.setPadding(
footerPaddingLeft.dp, footerPaddingLeft.dp,
footerPaddingTop.dp, footerPaddingTop.dp,
footerPaddingRight.dp, footerPaddingRight.dp,
footerPaddingBottom.dp footerPaddingBottom.dp
) )
vw_top_divider.visible(showHeaderLine) vwTopDivider.visible(showHeaderLine)
vw_bottom_divider.visible(showFooterLine) vwBottomDivider.visible(showFooterLine)
content_text_view.upVisibleRect() binding.contentTextView.upVisibleRect()
} }
upTime() upTime()
upBattery(battery) upBattery(battery)
@ -92,32 +91,32 @@ class ContentView(context: Context) : FrameLayout(context) {
/** /**
* 显示状态栏时隐藏header * 显示状态栏时隐藏header
*/ */
fun upStatusBar() { fun upStatusBar() = with(binding.vwStatusBar){
vw_status_bar.topPadding = context.statusBarHeight setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom)
vw_status_bar.isGone = isGone =
ReadBookConfig.hideStatusBar || (activity as? BaseActivity)?.isInMultiWindow == true ReadBookConfig.hideStatusBar || (activity as? BaseActivity<*>)?.isInMultiWindow == true
} }
fun upTipStyle() { fun upTipStyle() = with(binding) {
ReadTipConfig.apply { ReadTipConfig.apply {
tv_header_left.isInvisible = tipHeaderLeft != chapterTitle tvHeaderLeft.isInvisible = tipHeaderLeft != chapterTitle
bv_header_left.isInvisible = tipHeaderLeft == none || !tv_header_left.isInvisible bvHeaderLeft.isInvisible = tipHeaderLeft == none || !tvHeaderLeft.isInvisible
tv_header_right.isGone = tipHeaderRight == none tvHeaderRight.isGone = tipHeaderRight == none
tv_header_middle.isGone = tipHeaderMiddle == none tvHeaderMiddle.isGone = tipHeaderMiddle == none
tv_footer_left.isInvisible = tipFooterLeft != chapterTitle tvFooterLeft.isInvisible = tipFooterLeft != chapterTitle
bv_footer_left.isInvisible = tipFooterLeft == none || !tv_footer_left.isInvisible bvFooterLeft.isInvisible = tipFooterLeft == none || !tvFooterLeft.isInvisible
tv_footer_right.isGone = tipFooterRight == none tvFooterRight.isGone = tipFooterRight == none
tv_footer_middle.isGone = tipFooterMiddle == none tvFooterMiddle.isGone = tipFooterMiddle == none
ll_header.isGone = hideHeader binding.llHeader.isGone = hideHeader
ll_footer.isGone = hideFooter llFooter.isGone = hideFooter
} }
tvTitle = when (ReadTipConfig.chapterTitle) { tvTitle = when (ReadTipConfig.chapterTitle) {
ReadTipConfig.tipHeaderLeft -> tv_header_left ReadTipConfig.tipHeaderLeft -> tvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> tv_footer_left ReadTipConfig.tipFooterLeft -> tvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvTitle?.apply { tvTitle?.apply {
@ -125,12 +124,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvTime = when (ReadTipConfig.time) { tvTime = when (ReadTipConfig.time) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvTime?.apply { tvTime?.apply {
@ -138,12 +137,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvBattery = when (ReadTipConfig.battery) { tvBattery = when (ReadTipConfig.battery) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvBattery?.apply { tvBattery?.apply {
@ -151,12 +150,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 10f textSize = 10f
} }
tvPage = when (ReadTipConfig.page) { tvPage = when (ReadTipConfig.page) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvPage?.apply { tvPage?.apply {
@ -164,12 +163,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvTotalProgress = when (ReadTipConfig.totalProgress) { tvTotalProgress = when (ReadTipConfig.totalProgress) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvTotalProgress?.apply { tvTotalProgress?.apply {
@ -177,12 +176,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvPageAndTotal = when (ReadTipConfig.pageAndTotal) { tvPageAndTotal = when (ReadTipConfig.pageAndTotal) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvPageAndTotal?.apply { tvPageAndTotal?.apply {
@ -190,12 +189,12 @@ class ContentView(context: Context) : FrameLayout(context) {
textSize = 12f textSize = 12f
} }
tvBookName = when (ReadTipConfig.bookName) { tvBookName = when (ReadTipConfig.bookName) {
ReadTipConfig.tipHeaderLeft -> bv_header_left ReadTipConfig.tipHeaderLeft -> bvHeaderLeft
ReadTipConfig.tipHeaderMiddle -> tv_header_middle ReadTipConfig.tipHeaderMiddle -> tvHeaderMiddle
ReadTipConfig.tipHeaderRight -> tv_header_right ReadTipConfig.tipHeaderRight -> tvHeaderRight
ReadTipConfig.tipFooterLeft -> bv_footer_left ReadTipConfig.tipFooterLeft -> bvFooterLeft
ReadTipConfig.tipFooterMiddle -> tv_footer_middle ReadTipConfig.tipFooterMiddle -> tvFooterMiddle
ReadTipConfig.tipFooterRight -> tv_footer_right ReadTipConfig.tipFooterRight -> tvFooterRight
else -> null else -> null
} }
tvBookName?.apply { tvBookName?.apply {
@ -205,7 +204,7 @@ class ContentView(context: Context) : FrameLayout(context) {
} }
fun setBg(bg: Drawable?) { fun setBg(bg: Drawable?) {
page_panel.background = bg binding.pagePanel.background = bg
} }
fun upTime() { fun upTime() {
@ -221,11 +220,11 @@ class ContentView(context: Context) : FrameLayout(context) {
setProgress(textPage) setProgress(textPage)
if (resetPageOffset) if (resetPageOffset)
resetPageOffset() resetPageOffset()
content_text_view.setContent(textPage) binding.contentTextView.setContent(textPage)
} }
fun resetPageOffset() { fun resetPageOffset() {
content_text_view.resetPageOffset() binding.contentTextView.resetPageOffset()
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@ -238,40 +237,40 @@ class ContentView(context: Context) : FrameLayout(context) {
} }
fun onScroll(offset: Float) { fun onScroll(offset: Float) {
content_text_view.onScroll(offset) binding.contentTextView.onScroll(offset)
} }
fun upSelectAble(selectAble: Boolean) { fun upSelectAble(selectAble: Boolean) {
content_text_view.selectAble = selectAble binding.contentTextView.selectAble = selectAble
} }
fun selectText( fun selectText(
x: Float, y: Float, x: Float, y: Float,
select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit
) { ) {
return content_text_view.selectText(x, y - headerHeight, select) return binding.contentTextView.selectText(x, y - headerHeight, select)
} }
fun selectStartMove(x: Float, y: Float) { fun selectStartMove(x: Float, y: Float) {
content_text_view.selectStartMove(x, y - headerHeight) binding.contentTextView.selectStartMove(x, y - headerHeight)
} }
fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) {
content_text_view.selectStartMoveIndex(relativePage, lineIndex, charIndex) binding.contentTextView.selectStartMoveIndex(relativePage, lineIndex, charIndex)
} }
fun selectEndMove(x: Float, y: Float) { fun selectEndMove(x: Float, y: Float) {
content_text_view.selectEndMove(x, y - headerHeight) binding.contentTextView.selectEndMove(x, y - headerHeight)
} }
fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) {
content_text_view.selectEndMoveIndex(relativePage, lineIndex, charIndex) binding.contentTextView.selectEndMoveIndex(relativePage, lineIndex, charIndex)
} }
fun cancelSelect() { fun cancelSelect() {
content_text_view.cancelSelect() binding.contentTextView.cancelSelect()
} }
val selectedText: String get() = content_text_view.selectedText val selectedText: String get() = binding.contentTextView.selectedText
} }

@ -19,7 +19,6 @@ import com.novel.read.utils.ext.activity
import com.novel.read.utils.ext.screenshot import com.novel.read.utils.ext.screenshot
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import kotlinx.android.synthetic.main.activity_read_book.view.*
import kotlin.math.abs import kotlin.math.abs
class PageView(context: Context, attrs: AttributeSet) : class PageView(context: Context, attrs: AttributeSet) :
@ -35,7 +34,7 @@ class PageView(context: Context, attrs: AttributeSet) :
field = value field = value
upContent() upContent()
} }
var isScroll = ReadBook.pageAnim() == 3 var isScroll = false
var prevPage: ContentView = ContentView(context) var prevPage: ContentView = ContentView(context)
var curPage: ContentView = ContentView(context) var curPage: ContentView = ContentView(context)
var nextPage: ContentView = ContentView(context) var nextPage: ContentView = ContentView(context)
@ -102,16 +101,15 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun dispatchDraw(canvas: Canvas) { override fun dispatchDraw(canvas: Canvas) {
super.dispatchDraw(canvas) super.dispatchDraw(canvas)
pageDelegate?.onDraw(canvas) pageDelegate?.onDraw(canvas)
if (callBack.isAutoPage) { if (!isInEditMode && callBack.isAutoPage && !isScroll) {
nextPage.screenshot()?.let { nextPage.screenshot()?.let {
val bottom = val bottom = callBack.autoPageProgress
page_view.height * callBack.autoPageProgress / (ReadBookConfig.autoReadSpeed * 10) autoPageRect.set(0, 0, width, bottom)
autoPageRect.set(0, 0, page_view.width, bottom)
canvas.drawBitmap(it, autoPageRect, autoPageRect, null) canvas.drawBitmap(it, autoPageRect, autoPageRect, null)
canvas.drawRect( canvas.drawRect(
0f, 0f,
bottom.toFloat() - 1, bottom.toFloat() - 1,
page_view.width.toFloat(), width.toFloat(),
bottom.toFloat(), bottom.toFloat(),
autoPagePint autoPagePint
) )

@ -1,19 +1,27 @@
package com.novel.read.ui.record package com.novel.read.ui.record
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.App import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.ReadRecord import com.novel.read.data.db.entity.ReadRecord
import kotlinx.android.synthetic.main.activity_read_record.* import com.novel.read.databinding.ActivityReadRecordBinding
import kotlinx.android.synthetic.main.item_book_common.view.tv_book_name import com.novel.read.databinding.ItemReadRecordBinding
import kotlinx.android.synthetic.main.item_read_record.view.*
class ReadRecordActivity : BaseActivity(R.layout.activity_read_record) { class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
lateinit var adapter: RecordAdapter lateinit var adapter: RecordAdapter
private var sortMode = 0 private var sortMode = 0
override fun getViewBinding(): ActivityReadRecordBinding {
return ActivityReadRecordBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
initData() initData()
@ -26,19 +34,27 @@ class ReadRecordActivity : BaseActivity(R.layout.activity_read_record) {
private fun initView() { private fun initView() {
adapter = RecordAdapter() adapter = RecordAdapter()
recycler_view.adapter = adapter binding.recyclerView.adapter = adapter
} }
inner class RecordAdapter : inner class RecordAdapter :
BaseQuickAdapter<ReadRecord, BaseViewHolder>(R.layout.item_read_record) { BaseBindingAdapter<ReadRecord, ItemReadRecordBinding>() {
override fun convert(holder: BaseViewHolder, item: ReadRecord) {
holder.itemView.run { override fun convert(holder: VBViewHolder<ItemReadRecordBinding>, item: ReadRecord) {
tv_book_name.text = item.bookName holder.vb.run {
tv_read_time.text = formatDuring(item.readTime) tvBookName.text = item.bookName
tvReadTime.text = formatDuring(item.readTime)
} }
} }
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemReadRecordBinding {
return ItemReadRecordBinding.inflate(inflater, parent, false)
}
// private fun sureDelAlert(item: ReadRecord) { // private fun sureDelAlert(item: ReadRecord) {
// alert(R.string.delete) { // alert(R.string.delete) {
// setMessage(getString(R.string.sure_del_any, item.bookName)) // setMessage(getString(R.string.sure_del_any, item.bookName))
@ -65,5 +81,8 @@ class ReadRecordActivity : BaseActivity(R.layout.activity_read_record) {
} }
return time return time
} }
} }
} }

@ -1,17 +1,22 @@
package com.novel.read.ui.search package com.novel.read.ui.search
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.LayoutInflater
import com.chad.library.adapter.base.viewholder.BaseViewHolder import android.view.ViewGroup
import com.novel.read.R import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.SearchHistory import com.novel.read.data.db.entity.SearchHistory
import kotlinx.android.synthetic.main.item_label.view.* import com.novel.read.databinding.ItemLabelBinding
class HistoryAdapter : BaseQuickAdapter<SearchHistory, BaseViewHolder>(R.layout.item_label) { class HistoryAdapter : BaseBindingAdapter<SearchHistory, ItemLabelBinding>() {
override fun convert(holder: BaseViewHolder, item: SearchHistory) { override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: SearchHistory) {
holder.itemView.run { holder.vb.run {
tv_label.text = item.getBKey() tvLabel.text = item.getBKey()
} }
} }
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemLabelBinding {
return ItemLabelBinding.inflate(inflater, parent, false)
}
} }

@ -1,19 +1,27 @@
package com.novel.read.ui.search package com.novel.read.ui.search
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.databinding.ItemLabelBinding
import com.novel.read.utils.StringUtils import com.novel.read.utils.StringUtils
import kotlinx.android.synthetic.main.item_label.view.*
class HotAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_label) { class HotAdapter : BaseBindingAdapter<String, ItemLabelBinding>() {
override fun convert(holder: BaseViewHolder, item: String) { override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: String) {
holder.itemView.run { holder.vb.run {
tv_label.text = StringUtils.convertCC(item) tvLabel.text = StringUtils.convertCC(item)
tv_label.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8]) tvLabel.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8])
} }
} }
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemLabelBinding {
return ItemLabelBinding.inflate(inflater, parent, false)
}
} }

@ -5,6 +5,7 @@ import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.listener.OnLoadMoreListener import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.google.android.flexbox.AlignItems import com.google.android.flexbox.AlignItems
@ -15,19 +16,15 @@ import com.novel.read.App
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.VMBaseActivity import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivitySearchBinding
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.lib.dialogs.alert import com.novel.read.lib.dialogs.alert
import com.novel.read.lib.dialogs.noButton import com.novel.read.lib.dialogs.noButton
import com.novel.read.lib.dialogs.yesButton import com.novel.read.lib.dialogs.yesButton
import com.novel.read.utils.ext.applyTint import com.novel.read.utils.ext.*
import com.novel.read.utils.ext.getViewModel
import com.novel.read.utils.ext.requestInputMethod
import kotlinx.android.synthetic.main.activity_daily.*
import kotlinx.android.synthetic.main.activity_search.*
import kotlinx.android.synthetic.main.view_search.*
//这个页面为了赶进度写的很蠢 //这个页面写的很蠢
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search) { class SearchActivity : VMBaseActivity<ActivitySearchBinding,SearchViewModel>() {
private lateinit var mHisAdapter: HistoryAdapter private lateinit var mHisAdapter: HistoryAdapter
private lateinit var mHotAdapter: HotAdapter private lateinit var mHotAdapter: HotAdapter
@ -36,10 +33,19 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
override val viewModel: SearchViewModel override val viewModel: SearchViewModel
get() = getViewModel(SearchViewModel::class.java) get() = getViewModel(SearchViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun getViewBinding(): ActivitySearchBinding {
ATH.applyEdgeEffectColor(rlv_history) return ActivitySearchBinding.inflate(layoutInflater)
ATH.applyEdgeEffectColor(rlv_hot) }
ATH.applyEdgeEffectColor(rlv_history)
private lateinit var tvSearch: TextView
private lateinit var tvCancel: TextView
override fun onActivityCreated(savedInstanceState: Bundle?)= with(binding) {
ATH.applyEdgeEffectColor(binding.rlvHistory)
ATH.applyEdgeEffectColor(binding.rlvHot)
ATH.applyEdgeEffectColor(binding.rlvSearch)
tvSearch=binding.titleBar.findViewById(R.id.tv_search)
tvCancel=binding.titleBar.findViewById(R.id.tv_cancel)
viewModel.initData() viewModel.initData()
initHotAdapter() initHotAdapter()
initHisAdapter() initHisAdapter()
@ -49,28 +55,28 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
initLoadMore() initLoadMore()
} }
private fun initClick() { private fun initClick() = with(binding){
tv_search.addTextChangedListener(object : TextWatcher { tvSearch.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
} }
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.toString().trim { it <= ' ' } == "") { if (s.toString().trim { it <= ' ' } == "") {
head_hot.visibility = View.VISIBLE headHot.visibility = View.VISIBLE
head_history.visibility = View.VISIBLE headHistory.visibility = View.VISIBLE
rlv_hot.visibility = View.VISIBLE rlvHot.visibility = View.VISIBLE
rlv_history.visibility = View.VISIBLE rlvHistory.visibility = View.VISIBLE
rlv_search.visibility=View.GONE rlvSearch.visibility=View.GONE
} else { } else {
head_hot.visibility = View.GONE headHot.visibility = View.GONE
head_history.visibility = View.GONE headHistory.visibility = View.GONE
rlv_hot.visibility = View.GONE rlvHot.visibility = View.GONE
rlv_history.visibility = View.GONE rlvHistory.visibility = View.GONE
viewModel.page = 1 viewModel.page = 1
viewModel.searchKey = s.toString().trim() viewModel.searchKey = s.toString().trim()
onRefresh() onRefresh()
rlv_search.visibility=View.VISIBLE rlvSearch.visibility=View.VISIBLE
} }
} }
@ -81,7 +87,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
}) })
//键盘的搜索 //键盘的搜索
tv_search.setOnKeyListener { v, keyCode, event -> tvSearch.setOnKeyListener { v, keyCode, event ->
//修改回车键功能 //修改回车键功能
if (keyCode == KeyEvent.KEYCODE_ENTER) { if (keyCode == KeyEvent.KEYCODE_ENTER) {
saveKey() saveKey()
@ -90,11 +96,11 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
false false
} }
tv_cancel.setOnClickListener { tvCancel.setOnClickListener {
onBackPressed() onBackPressed()
} }
head_history.setOnClickListener { binding.headHistory.setOnClickListener {
alert(title = "操作提示", message = "確認清空全部記錄?") { alert(title = "操作提示", message = "確認清空全部記錄?") {
yesButton { yesButton {
App.db.getSearchDao().deleteAll() App.db.getSearchDao().deleteAll()
@ -153,12 +159,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
} }
private fun initSearchAdapter() { private fun initSearchAdapter() {
rlv_search.layoutManager = LinearLayoutManager(this) binding.rlvSearch.layoutManager = LinearLayoutManager(this)
mSearchAdapter = SearchAdapter() mSearchAdapter = SearchAdapter()
rlv_search.adapter = mSearchAdapter binding.rlvSearch.adapter = mSearchAdapter
mSearchAdapter.setOnItemChildClickListener { adapter, view, position -> mSearchAdapter.setOnItemChildClickListener { adapter, view, position ->
tv_search.setText(viewModel.mList[position].getBBookName()) tvSearch.text = viewModel.mList[position].getBBookName()
saveKey() saveKey()
} }
} }
@ -171,12 +177,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
manager2.flexWrap = FlexWrap.WRAP manager2.flexWrap = FlexWrap.WRAP
manager2.alignItems = AlignItems.STRETCH manager2.alignItems = AlignItems.STRETCH
mHisAdapter = HistoryAdapter() mHisAdapter = HistoryAdapter()
rlv_history.layoutManager = manager2 binding.rlvHistory.layoutManager = manager2
rlv_history.adapter = mHisAdapter binding.rlvHistory.adapter = mHisAdapter
mHisAdapter.setOnItemClickListener { adapter, view, position -> mHisAdapter.setOnItemClickListener { adapter, view, position ->
rlv_search.visibility = View.VISIBLE binding.rlvSearch.visibility = View.VISIBLE
tv_search.setText(viewModel.hisKey.value?.get(position)?.getBKey()) tvSearch.setText(viewModel.hisKey.value?.get(position)?.getBKey())
saveKey() saveKey()
} }
} }
@ -188,12 +194,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
//设置是否换行 //设置是否换行
manager.flexWrap = FlexWrap.WRAP manager.flexWrap = FlexWrap.WRAP
manager.alignItems = AlignItems.STRETCH manager.alignItems = AlignItems.STRETCH
rlv_hot.layoutManager = manager binding.rlvHot.layoutManager = manager
mHotAdapter = HotAdapter() mHotAdapter = HotAdapter()
rlv_hot.adapter = mHotAdapter binding.rlvHot.adapter = mHotAdapter
mHotAdapter.setOnItemClickListener { adapter, view, position -> mHotAdapter.setOnItemClickListener { adapter, view, position ->
rlv_search.visibility = View.VISIBLE binding.rlvSearch.visibility = View.VISIBLE
tv_search.setText(mHotAdapter.data[position]) tvSearch.text = mHotAdapter.data[position]
saveKey() saveKey()
} }
} }
@ -212,18 +218,18 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
} }
private fun saveKey() { private fun saveKey() {
val key = tv_search.text.toString().trim { it <= ' ' } val key = tvSearch.text.toString().trim { it <= ' ' }
viewModel.saveKey(key) viewModel.saveKey(key)
} }
private fun onRefresh() { private fun onRefresh() {
mSearchAdapter.setEmptyView(R.layout.view_loading) mSearchAdapter.setEmptyView(R.layout.view_loading)
viewModel.searchKey = tv_search.text.toString().trim() viewModel.searchKey = tvSearch.text.toString().trim()
viewModel.searchBook() viewModel.searchBook()
} }
private fun getErrorView(): View { private fun getErrorView(): View {
val errorView: View = layoutInflater.inflate(R.layout.view_net_error, rlv_daily, false) val errorView: View = layoutInflater.inflate(R.layout.view_net_error, binding.rlvSearch, false)
errorView.setOnClickListener { onRefresh() } errorView.setOnClickListener { onRefresh() }
return errorView return errorView
} }
@ -232,4 +238,5 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
super.onBackPressed() super.onBackPressed()
overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out) overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out)
} }
} }

@ -1,31 +1,39 @@
package com.novel.read.ui.search package com.novel.read.ui.search
import com.chad.library.adapter.base.BaseQuickAdapter import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.module.LoadMoreModule import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.model.SearchResp import com.novel.read.data.model.SearchResp
import com.novel.read.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import kotlinx.android.synthetic.main.item_init_search.view.tv_book_name
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter : BaseQuickAdapter<SearchResp, BaseViewHolder>(R.layout.item_book_common), class SearchAdapter : BaseBindingAdapter<SearchResp, ItemBookCommonBinding>(),
LoadMoreModule { LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: SearchResp) { override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: SearchResp) {
holder.itemView.run { holder.vb.run {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_book_name.text = item.getBBookName() tvBookName.text = item.getBBookName()
tv_book_description.text = item.getBIntroduction() tvBookDescription.text = item.getBIntroduction()
tv_book_author.text = item.getBAuthorName() tvBookAuthor.text = item.getBAuthorName()
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000)
tv_category.text = item.getBCategoryName() tvCategory.text = item.getBCategoryName()
onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
} }
holder.itemView.onClick {
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId)
}
}
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemBookCommonBinding {
return ItemBookCommonBinding.inflate(inflater, parent, false)
} }

@ -4,9 +4,14 @@ import android.os.Bundle
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.constant.EventBus import com.novel.read.constant.EventBus
import com.novel.read.databinding.ActivitySettingActivityBinding
import com.novel.read.utils.ext.observeEvent import com.novel.read.utils.ext.observeEvent
class SettingActivity : BaseActivity(R.layout.activity_setting_activity) { class SettingActivity : BaseActivity<ActivitySettingActivityBinding>() {
override fun getViewBinding(): ActivitySettingActivityBinding {
return ActivitySettingActivityBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
val fTag = "otherConfigFragment" val fTag = "otherConfigFragment"
@ -23,4 +28,6 @@ class SettingActivity : BaseActivity(R.layout.activity_setting_activity) {
recreate() recreate()
} }
} }
} }

@ -3,9 +3,16 @@ package com.novel.read.ui.theme
import android.os.Bundle import android.os.Bundle
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.databinding.ActivityThemeBinding
class ThemeActivity : BaseActivity<ActivityThemeBinding>() {
override fun getViewBinding(): ActivityThemeBinding {
return ActivityThemeBinding.inflate(layoutInflater)
}
class ThemeActivity : BaseActivity(R.layout.activity_theme) {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
} }
} }

@ -7,17 +7,20 @@ import com.hankcs.hanlp.HanLP
import com.permissionx.guolindev.PermissionX import com.permissionx.guolindev.PermissionX
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseActivity import com.novel.read.base.BaseActivity
import com.novel.read.databinding.ActivityWelcomeBinding
import com.novel.read.help.AppConfig import com.novel.read.help.AppConfig
import com.novel.read.ui.MainActivity import com.novel.read.ui.MainActivity
import com.novel.read.ui.read.ReadBookActivity import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ext.getPrefBoolean import com.novel.read.utils.ext.getPrefBoolean
import com.novel.read.help.coroutine.Coroutine import com.novel.read.help.coroutine.Coroutine
import kotlinx.android.synthetic.main.activity_welcome.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
override fun getViewBinding(): ActivityWelcomeBinding {
return ActivityWelcomeBinding.inflate(layoutInflater)
}
private var flag = false private var flag = false
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -46,14 +49,14 @@ class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
) )
.request { allGranted, grantedList, deniedList -> .request { allGranted, grantedList, deniedList ->
if (allGranted) { if (allGranted) {
root_view.postDelayed({ startMainActivity() }, 2500) binding.rootView.postDelayed({ startMainActivity() }, 2500)
} else { } else {
toast("权限被拒绝,将导致部分功能异常,请到设置中开启相关权限") toast("权限被拒绝,将导致部分功能异常,请到设置中开启相关权限")
// finish() // finish()
} }
} }
tvSkip.setOnClickListener { startMainActivity() } binding.tvSkip.setOnClickListener { startMainActivity() }
} }
@Synchronized @Synchronized
@ -71,4 +74,5 @@ class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
flag = true flag = true
super.onDestroy() super.onDestroy()
} }
} }

@ -8,11 +8,12 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatAutoCompleteTextView import androidx.appcompat.widget.AppCompatAutoCompleteTextView
import com.novel.read.R import com.novel.read.R
import com.novel.read.lib.ATH import com.novel.read.lib.ATH
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.item_1line_text_and_del.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@Suppress("unused") @Suppress("unused")
@ -55,9 +56,11 @@ class AutoCompleteTextView @JvmOverloads constructor(
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = convertView ?: LayoutInflater.from(context) val view = convertView ?: LayoutInflater.from(context)
.inflate(R.layout.item_1line_text_and_del, parent, false) .inflate(R.layout.item_1line_text_and_del, parent, false)
view.text_view.text = getItem(position) val textView = view.findViewById<TextView>(R.id.text_view)
if (delCallBack != null) view.iv_delete.visible() else view.iv_delete.gone() textView.text = getItem(position)
view.iv_delete.onClick { val ivDelete = view.findViewById<ImageView>(R.id.iv_delete)
if (delCallBack != null) ivDelete.visible() else ivDelete.gone()
ivDelete.onClick {
getItem(position)?.let { getItem(position)?.let {
remove(it) remove(it)
delCallBack?.invoke(it) delCallBack?.invoke(it)

@ -1,37 +1,44 @@
package com.novel.read.ui.widget.dialog package com.novel.read.ui.widget.dialog
import android.app.Dialog
import android.content.Context import android.content.Context
import android.os.Bundle
import android.view.* import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import com.novel.read.R import com.novel.read.R
import kotlinx.android.synthetic.main.dialog_go_appraise.* import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogGoAppraiseBinding
class AppraiseDialog(context: Context) : Dialog(context, R.style.dialog) { import com.novel.read.utils.ext.goShop
private val view: View = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null) import com.novel.read.utils.viewbindingdelegate.viewBinding
init { class AppraiseDialog : BaseDialogFragment() {
view.setHasTransientState(true) private val binding by viewBinding(DialogGoAppraiseBinding::bind)
setContentView(
view, LinearLayout.LayoutParams( override fun onStart() {
LinearLayout.LayoutParams.MATCH_PARENT, super.onStart()
LinearLayout.LayoutParams.MATCH_PARENT dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
) )
)
setCancelable(false)
initView()
} }
private fun initView() { override fun onCreateView(
val mTvCancel = findViewById<TextView>(R.id.tv_cancel) inflater: LayoutInflater,
container: ViewGroup?,
mTvCancel.setOnClickListener { dismiss() } savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_go_appraise, container)
} }
fun appraiseDialog(receiveClickListener: View.OnClickListener) { override fun onCreate(savedInstanceState: Bundle?) {
tv_appraise.setOnClickListener(receiveClickListener) super.onCreate(savedInstanceState)
setStyle(STYLE_NO_TITLE, R.style.dialog_app)
} }
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?){
binding.tvAppraise.setOnClickListener{
context?.goShop()
dismiss()
}
binding.clBg.setBackgroundResource(R.color.transparent)
binding.tvCancel.setOnClickListener { dismiss() }
}
} }

@ -5,18 +5,21 @@ import android.view.*
import android.widget.SeekBar import android.widget.SeekBar
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogAutoReadBinding
import com.novel.read.help.ReadBookConfig import com.novel.read.help.ReadBookConfig
import com.novel.read.service.BaseReadAloudService import com.novel.read.service.BaseReadAloudService
import com.novel.read.service.help.ReadAloud import com.novel.read.service.help.ReadAloud
import com.novel.read.utils.ColorUtils import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.bottomBackground import com.novel.read.utils.ext.bottomBackground
import com.novel.read.utils.ext.getPrimaryTextColor import com.novel.read.utils.ext.getPrimaryTextColor
import kotlinx.android.synthetic.main.dialog_auto_read.* import com.novel.read.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class AutoReadDialog : BaseDialogFragment() { class AutoReadDialog : BaseDialogFragment() {
var callBack: CallBack? = null var callBack: CallBack? = null
private val binding by viewBinding(DialogAutoReadBinding::bind)
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
dialog?.window?.let { dialog?.window?.let {
@ -44,17 +47,17 @@ class AutoReadDialog : BaseDialogFragment() {
val bg = requireContext().bottomBackground val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg) val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight) val textColor = requireContext().getPrimaryTextColor(isLight)
root_view.setBackgroundColor(bg) binding.root.setBackgroundColor(bg)
tv_read_speed_title.setTextColor(textColor) binding.tvReadSpeedTitle.setTextColor(textColor)
tv_read_speed.setTextColor(textColor) binding.tvReadSpeed.setTextColor(textColor)
iv_catalog.setColorFilter(textColor) binding.ivCatalog.setColorFilter(textColor)
tv_catalog.setTextColor(textColor) binding.tvCatalog.setTextColor(textColor)
iv_main_menu.setColorFilter(textColor) binding.ivMainMenu.setColorFilter(textColor)
tv_main_menu.setTextColor(textColor) binding.tvMainMenu.setTextColor(textColor)
iv_auto_page_stop.setColorFilter(textColor) binding.ivAutoPageStop.setColorFilter(textColor)
tv_auto_page_stop.setTextColor(textColor) binding.tvAutoPageStop.setTextColor(textColor)
iv_setting.setColorFilter(textColor) binding.ivSetting.setColorFilter(textColor)
tv_setting.setTextColor(textColor) binding.tvSetting.setTextColor(textColor)
initOnChange() initOnChange()
initData() initData()
initEvent() initEvent()
@ -62,34 +65,34 @@ class AutoReadDialog : BaseDialogFragment() {
private fun initData() { private fun initData() {
val speed = if (ReadBookConfig.autoReadSpeed < 10) 10 else ReadBookConfig.autoReadSpeed val speed = if (ReadBookConfig.autoReadSpeed < 10) 10 else ReadBookConfig.autoReadSpeed
tv_read_speed.text = String.format("%ds", speed) binding.tvReadSpeed.text = String.format("%ds", speed)
seek_auto_read.progress = speed binding.seekAutoRead.progress = speed
} }
private fun initOnChange() { private fun initOnChange() {
seek_auto_read.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { binding.seekAutoRead.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
val speed = if (progress < 10) 10 else progress val speed = if (progress < 10) 10 else progress
tv_read_speed.text = String.format("%ds", speed) binding.tvReadSpeed.text = String.format("%ds", speed)
} }
override fun onStartTrackingTouch(seekBar: SeekBar) = Unit override fun onStartTrackingTouch(seekBar: SeekBar) = Unit
override fun onStopTrackingTouch(seekBar: SeekBar) { override fun onStopTrackingTouch(seekBar: SeekBar) {
ReadBookConfig.autoReadSpeed = ReadBookConfig.autoReadSpeed =
if (seek_auto_read.progress < 10) 10 else seek_auto_read.progress if (binding.seekAutoRead.progress < 10) 10 else binding.seekAutoRead.progress
upTtsSpeechRate() upTtsSpeechRate()
} }
}) })
} }
private fun initEvent() { private fun initEvent() {
ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() } binding.llMainMenu.onClick { callBack?.showMenuBar(); dismiss() }
ll_setting.onClick { binding.llSetting.onClick {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
ll_catalog.onClick { callBack?.openChapterList() } binding.llCatalog.onClick { callBack?.openChapterList() }
ll_auto_page_stop.onClick { binding.llAutoPageStop.onClick {
callBack?.autoPageStop() callBack?.autoPageStop()
dismiss() dismiss()
} }

@ -7,9 +7,10 @@ import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogPhotoViewBinding
import com.novel.read.service.help.ReadBook import com.novel.read.service.help.ReadBook
import com.novel.read.utils.viewbindingdelegate.viewBinding
import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.ImageProvider
import kotlinx.android.synthetic.main.dialog_photo_view.*
class PhotoDialog : BaseDialogFragment() { class PhotoDialog : BaseDialogFragment() {
@ -30,6 +31,8 @@ class PhotoDialog : BaseDialogFragment() {
} }
private val binding by viewBinding(DialogPhotoViewBinding::bind)
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
dialog?.window?.setLayout( dialog?.window?.setLayout(
@ -56,7 +59,7 @@ class PhotoDialog : BaseDialogFragment() {
ImageProvider.getImage(book, chapterIndex, src) ImageProvider.getImage(book, chapterIndex, src)
}.onSuccess { bitmap -> }.onSuccess { bitmap ->
if (bitmap != null) { if (bitmap != null) {
photo_view.setImageBitmap(bitmap) binding.photoView.setImageBitmap(bitmap)
} }
} }
} }

@ -7,10 +7,11 @@ import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import com.novel.read.R import com.novel.read.R
import com.novel.read.base.BaseDialogFragment import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogTextViewBinding
import com.novel.read.utils.ext.* import com.novel.read.utils.ext.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
import io.noties.markwon.Markwon import io.noties.markwon.Markwon
import io.noties.markwon.image.glide.GlideImagesPlugin import io.noties.markwon.image.glide.GlideImagesPlugin
import kotlinx.android.synthetic.main.dialog_text_view.*
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -38,9 +39,8 @@ class TextDialog : BaseDialogFragment() {
} }
} }
private val binding by viewBinding(DialogTextViewBinding::bind)
private var time = 0L private var time = 0L
private var autoClose: Boolean = false private var autoClose: Boolean = false
override fun onStart() { override fun onStart() {
@ -61,23 +61,23 @@ class TextDialog : BaseDialogFragment() {
arguments?.let { arguments?.let {
val content = it.getString("content") ?: "" val content = it.getString("content") ?: ""
when (it.getInt("mode")) { when (it.getInt("mode")) {
MD -> text_view.post { MD -> binding.textView.post {
Markwon.builder(requireContext()) Markwon.builder(requireContext())
.usePlugin(GlideImagesPlugin.create(requireContext())) .usePlugin(GlideImagesPlugin.create(requireContext()))
.build() .build()
.setMarkdown(text_view, content) .setMarkdown(binding.textView, content)
} }
else -> text_view.text = content else -> binding.textView.text = content
} }
time = it.getLong("time", 0L) time = it.getLong("time", 0L)
} }
if (time > 0) { if (time > 0) {
badge_view.setBadgeCount((time / 1000).toInt()) binding.badgeView.setBadgeCount((time / 1000).toInt())
launch { launch {
while (time > 0) { while (time > 0) {
delay(1000) delay(1000)
time -= 1000 time -= 1000
badge_view.setBadgeCount((time / 1000).toInt()) binding.badgeView.setBadgeCount((time / 1000).toInt())
if (time <= 0) { if (time <= 0) {
view.post { view.post {
dialog?.setCancelable(true) dialog?.setCancelable(true)

@ -0,0 +1,60 @@
@file:Suppress("RedundantVisibilityModifier", "unused")
package com.novel.read.utils.viewbindingdelegate
import android.view.View
import androidx.annotation.IdRes
import androidx.core.app.ComponentActivity
import androidx.viewbinding.ViewBinding
private class ActivityViewBindingProperty<A : ComponentActivity, T : ViewBinding>(
viewBinder: (A) -> T
) : ViewBindingProperty<A, T>(viewBinder) {
override fun getLifecycleOwner(thisRef: A) = thisRef
}
/**
* Create new [ViewBinding] associated with the [Activity][ComponentActivity] and allow customize how
* a [View] will be bounded to the view binding.
*/
@JvmName("viewBindingActivity")
public fun <A : ComponentActivity, T : ViewBinding> ComponentActivity.viewBinding(
viewBinder: (A) -> T
): ViewBindingProperty<A, T> {
return ActivityViewBindingProperty(viewBinder)
}
/**
* Create new [ViewBinding] associated with the [Activity][ComponentActivity] and allow customize how
* a [View] will be bounded to the view binding.
*/
@JvmName("viewBindingActivity")
public inline fun <A : ComponentActivity, T : ViewBinding> ComponentActivity.viewBinding(
crossinline vbFactory: (View) -> T,
crossinline viewProvider: (A) -> View
): ViewBindingProperty<A, T> {
return viewBinding { activity: A -> vbFactory(viewProvider(activity)) }
}
/**
* Create new [ViewBinding] associated with the [Activity][this] and allow customize how
* a [View] will be bounded to the view binding.
*
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used
* @param viewBindingRootId Root view's id that will be used as root for the view binding
*/
@Suppress("unused")
@JvmName("viewBindingActivity")
public inline fun <T : ViewBinding> ComponentActivity.viewBinding(
crossinline vbFactory: (View) -> T,
@IdRes viewBindingRootId: Int
): ViewBindingProperty<ComponentActivity, T> {
return viewBinding { activity: ComponentActivity ->
vbFactory(
activity.findViewById(
viewBindingRootId
)
)
}
}

@ -0,0 +1,54 @@
@file:Suppress("RedundantVisibilityModifier", "unused")
@file:JvmName("ReflectionFragmentViewBindings")
package com.novel.read.utils.viewbindingdelegate
import android.view.View
import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
private class FragmentViewBindingProperty<F : Fragment, T : ViewBinding>(
viewBinder: (F) -> T
) : ViewBindingProperty<F, T>(viewBinder) {
override fun getLifecycleOwner(thisRef: F) = thisRef.viewLifecycleOwner
}
/**
* Create new [ViewBinding] associated with the [Fragment]
*/
@JvmName("viewBindingFragment")
public fun <F : Fragment, T : ViewBinding> Fragment.viewBinding(viewBinder: (F) -> T): ViewBindingProperty<F, T> {
return FragmentViewBindingProperty(viewBinder)
}
/**
* Create new [ViewBinding] associated with the [Fragment]
*
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used
* @param viewProvider Provide a [View] from the Fragment. By default call [Fragment.requireView]
*/
@JvmName("viewBindingFragment")
public inline fun <F : Fragment, T : ViewBinding> Fragment.viewBinding(
crossinline vbFactory: (View) -> T,
crossinline viewProvider: (F) -> View = Fragment::requireView
): ViewBindingProperty<F, T> {
return viewBinding { fragment: F -> vbFactory(viewProvider(fragment)) }
}
/**
* Create new [ViewBinding] associated with the [Fragment]
*
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used
* @param viewBindingRootId Root view's id that will be used as root for the view binding
*/
@JvmName("viewBindingFragment")
public inline fun <T : ViewBinding> Fragment.viewBinding(
crossinline vbFactory: (View) -> T,
@IdRes viewBindingRootId: Int
): ViewBindingProperty<Fragment, T> {
return viewBinding(vbFactory) { fragment: Fragment ->
fragment.requireView().findViewById(viewBindingRootId)
}
}

@ -0,0 +1,57 @@
@file:Suppress("RedundantVisibilityModifier")
package com.novel.read.utils.viewbindingdelegate
import android.os.Handler
import android.os.Looper
import androidx.annotation.MainThread
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
public abstract class ViewBindingProperty<in R : Any, T : ViewBinding>(
private val viewBinder: (R) -> T
) : ReadOnlyProperty<R, T> {
private var viewBinding: T? = null
private val lifecycleObserver = ClearOnDestroyLifecycleObserver()
private var thisRef: R? = null
protected abstract fun getLifecycleOwner(thisRef: R): LifecycleOwner
@MainThread
public override fun getValue(thisRef: R, property: KProperty<*>): T {
viewBinding?.let { return it }
this.thisRef = thisRef
val lifecycle = getLifecycleOwner(thisRef).lifecycle
if (lifecycle.currentState == Lifecycle.State.DESTROYED) {
mainHandler.post { viewBinding = null }
} else {
lifecycle.addObserver(lifecycleObserver)
}
return viewBinder(thisRef).also { viewBinding = it }
}
@MainThread
public fun clear() {
val thisRef = thisRef ?: return
this.thisRef = null
getLifecycleOwner(thisRef).lifecycle.removeObserver(lifecycleObserver)
mainHandler.post { viewBinding = null }
}
private inner class ClearOnDestroyLifecycleObserver : DefaultLifecycleObserver {
@MainThread
override fun onDestroy(owner: LifecycleOwner): Unit = clear()
}
private companion object {
private val mainHandler = Handler(Looper.getMainLooper())
}
}

@ -19,7 +19,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_type" android:id="@+id/rlv_type"
android:layout_width="90dp" android:layout_width="90dp"
android:layout_height="0dp" android:layout_height="0dp"
android:scrollbars="none" android:scrollbars="none"
@ -34,7 +34,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/lv_type" app:layout_constraintLeft_toRightOf="@+id/rlv_type"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" /> app:layout_constraintTop_toBottomOf="@+id/title_bar" />

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout 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"
android:orientation="vertical" android:id="@+id/cl_bg"
android:layout_width="300dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/transparent"> android:background="@color/transparent">
@ -18,8 +17,7 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:background="@drawable/bg_corner_white" android:background="@drawable/bg_corner_white">
android:layout_alignParentTop="true">
<TextView <TextView

@ -1,55 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:id="@+id/cv_tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="@+id/iv_tools"
android:layout_width="22dp"
android:layout_height="22dp"
android:src="@drawable/ic_tools_history"
app:layout_constraintHorizontal_bias="0"
android:layout_marginHorizontal="15dp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_tools"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/tv_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="常用工具"
android:textSize="13sp"
android:textColor="@color/primaryText"
app:layout_constraintLeft_toRightOf="@+id/iv_tools"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="@drawable/ic_arrow_right"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="15dp"
app:layout_constraintBottom_toBottomOf="parent"/>
<View android:layout_width="0dp"
android:layout_height="0.5dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/bg_divider_line"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -88,4 +88,13 @@
<item name="android:backgroundDimAmount">0.6</item> <item name="android:backgroundDimAmount">0.6</item>
</style> </style>
<style name="dialog_app" parent="android:style/Theme.Dialog">
<item name="android:background">@color/transparent</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:windowEnterAnimation">@anim/message_fade_in</item>
<item name="android:windowExitAnimation">@anim/message_fade_out</item>
</style>
</resources> </resources>

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.10' ext.kotlin_version = "1.4.21"
repositories { repositories {
google() google()
jcenter() jcenter()

Loading…
Cancel
Save