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

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

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

@ -10,6 +10,7 @@ import android.os.Build
import android.view.View
import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
import android.view.Window
import android.view.WindowInsetsController
import android.widget.EdgeEffect
import android.widget.ScrollView
import androidx.annotation.ColorInt
@ -23,7 +24,6 @@ import com.novel.read.help.AppConfig
import com.novel.read.help.TintHelper
import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.activity_main.view.*
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) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val decorView = activity.window.decorView
@ -207,7 +246,7 @@ object ATH {
val textColor = context.getSecondaryTextColor(textIsDark)
val colorStateList = Selector.colorBuild()
.setDefaultColor(textColor)
.setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create()
.setSelectedColor(ThemeStore.accentColor(context)).create()
itemIconTintList = colorStateList
itemTextColor = colorStateList
}

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

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

@ -26,7 +26,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
private val homeRepository by lazy { HomeRepository() }
private val bookRepository by lazy { BookRepository() }
var appResp = MutableLiveData<AppUpdateResp>()
val showEvaluate = MutableLiveData<Boolean>()
fun appUpdate() {
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 com.novel.read.R
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 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.constant.AppConst
import com.novel.read.data.model.ChannelSection
import com.novel.read.databinding.ActivityChannelBinding
import com.novel.read.lib.ATH
import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_channel.*
import java.util.ArrayList
class ChannelActivity : VMBaseActivity<ChannelViewModel>(R.layout.activity_channel) {
class ChannelActivity : VMBaseActivity<ActivityChannelBinding, ChannelViewModel>() {
override val viewModel: ChannelViewModel
get() = getViewModel(ChannelViewModel::class.java)
override fun getViewBinding(): ActivityChannelBinding {
return ActivityChannelBinding.inflate(layoutInflater)
}
private lateinit var adapter: ChannelAdapter
private val data: MutableList<ChannelSection> = ArrayList()
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_channel)
ATH.applyEdgeEffectColor(binding.rlvChannel)
initRecyclerView()
upRecyclerData()
}
private fun initRecyclerView() {
rlv_channel.layoutManager = GridLayoutManager(this, 2)
private fun initRecyclerView() = with(binding) {
rlvChannel.layoutManager = GridLayoutManager(this@ChannelActivity, 2)
adapter = ChannelAdapter()
rlv_channel.adapter = adapter
rlvChannel.adapter = adapter
}
private fun upRecyclerData() {
@ -69,9 +73,11 @@ class ChannelActivity : VMBaseActivity<ChannelViewModel>(R.layout.activity_chann
}
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() }
return errorView
}
}

@ -1,14 +1,18 @@
package com.novel.read.ui.channel
import android.annotation.SuppressLint
import android.view.ViewGroup
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.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.data.model.AllType
import com.novel.read.data.model.ChannelSection
import kotlinx.android.synthetic.main.item_channel.view.*
import kotlinx.android.synthetic.main.item_channel_head.view.*
import com.novel.read.databinding.ItemChannelBinding
import com.novel.read.databinding.ItemChannelHeadBinding
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity
@ -17,26 +21,35 @@ class ChannelAdapter : BaseSectionQuickAdapter<ChannelSection, BaseViewHolder>(
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) {
val value = item.obj as String
helper.itemView.run {
tv_sex.text = value
helper.getViewBinding<ItemChannelHeadBinding>().apply {
tvSex.text = value
}
}
@SuppressLint("SetTextI18n")
override fun convert(holder: BaseViewHolder, item: ChannelSection) {
val value = item.obj as AllType
holder.itemView.run {
tv_name.text = value.getBChannel()
iv_cover.load(value.typeImageUrl, "", "")
tv_count.text= "${value.bookCount}"
onClick {
context.startActivity<ChannelInfoActivity>(
Pair(IntentAction.bookTypeId, value.bookTypeId),
Pair(IntentAction.channelName, value.getBChannel()),
)
}
holder.itemView.onClick {
context.startActivity<ChannelInfoActivity>(
Pair(IntentAction.bookTypeId, value.bookTypeId),
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.constant.AppConst
import com.novel.read.constant.IntentAction
import com.novel.read.databinding.ActivityChannelInfoBinding
import com.novel.read.lib.ATH
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
get() = getViewModel(ChannelInfoViewModel::class.java)
override fun getViewBinding(): ActivityChannelInfoBinding {
return ActivityChannelInfoBinding.inflate(layoutInflater)
}
private lateinit var adapter: ChannelInfoAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_book)
ATH.applyEdgeEffectColor(binding.rlvBook)
initRecyclerView()
viewModel.initData(intent)
upRecyclerData()
@ -27,14 +33,14 @@ class ChannelInfoActivity : VMBaseActivity<ChannelInfoViewModel>(R.layout.activi
}
private fun initRecyclerView() {
rlv_book.layoutManager = LinearLayoutManager(this)
binding.rlvBook.layoutManager = LinearLayoutManager(this)
adapter = ChannelInfoAdapter()
rlv_book.adapter = adapter
binding.rlvBook.adapter = adapter
}
private fun upRecyclerData() {
val channelName = intent.getStringExtra(IntentAction.channelName) ?: ""
title_bar.title = channelName
binding.titleBar.title = channelName
onRefresh()
viewModel.run {
bookListResp.observe(this@ChannelInfoActivity) {
@ -88,9 +94,10 @@ class ChannelInfoActivity : VMBaseActivity<ChannelInfoViewModel>(R.layout.activi
}
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() }
return errorView
}
}

@ -1,28 +1,41 @@
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.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
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 {
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 {
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
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R
import android.view.LayoutInflater
import android.view.ViewGroup
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
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) {
holder.itemView.run {
tv_chapter_name.text = item.chapterName
tv_content.text = item.content
override fun convert(holder: VBViewHolder<ItemBookmarkBinding>, item: Bookmark) {
holder.vb.run {
tvChapterName.text = item.chapterName
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.base.VMBaseFragment
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.dialogs.alert
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.ui.widget.VerticalDivider
import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.fragment_bookmark.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark),
ChapterListViewModel.BookmarkCallBack {
@ -28,6 +28,8 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private val binding by viewBinding(FragmentBookmarkBinding::bind)
private lateinit var adapter: BookMarkAdapter
private var bookmarkLiveData = MutableLiveData<List<Bookmark>>()
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
@ -37,11 +39,11 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
}
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view)
ATH.applyEdgeEffectColor(binding.recyclerView)
adapter = BookMarkAdapter()
recycler_view.layoutManager = LinearLayoutManager(requireContext())
recycler_view.addItemDecoration(VerticalDivider(requireContext()))
recycler_view.adapter = adapter
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
binding.recyclerView.adapter = adapter
}
private fun initData() {
@ -68,9 +70,10 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
requireContext().alert(R.string.bookmark) {
var editText: EditText? = null
message = book.bookName + "" + bookmark.chapterName
customView {
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)
setText(bookmark.content)
}

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

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

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

@ -8,28 +8,32 @@ import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivityDailyBinding
import com.novel.read.lib.ATH
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
get() = getViewModel(DailyViewModel::class.java)
override fun getViewBinding(): ActivityDailyBinding {
return ActivityDailyBinding.inflate(layoutInflater)
}
private lateinit var adapter: DailyAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_daily)
ATH.applyEdgeEffectColor(binding.rlvDaily)
initRecyclerView()
upRecyclerData()
initLoadMore()
}
private fun initRecyclerView() {
rlv_daily.layoutManager = LinearLayoutManager(this)
binding.rlvDaily.layoutManager = LinearLayoutManager(this)
adapter = DailyAdapter()
rlv_daily.adapter = adapter
binding.rlvDaily.adapter = adapter
}
private fun upRecyclerData() {
@ -87,7 +91,7 @@ class DailyActivity : VMBaseActivity<DailyViewModel>(R.layout.activity_daily) {
}
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() }
return errorView
}

@ -1,28 +1,37 @@
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.viewholder.BaseViewHolder
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.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class DailyAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule {
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) {
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 {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.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.base.VMBaseActivity
import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivityEndBinding
import com.novel.read.lib.ATH
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
get() = getViewModel(EndViewModel::class.java)
override fun getViewBinding(): ActivityEndBinding {
return ActivityEndBinding.inflate(layoutInflater)
}
private lateinit var adapter: EndAdapter
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_end)
ATH.applyEdgeEffectColor(binding.rlvEnd)
initRecyclerView()
upRecyclerData()
initLoadMore()
}
private fun initRecyclerView() {
rlv_end.layoutManager = LinearLayoutManager(this)
binding.rlvEnd.layoutManager = LinearLayoutManager(this)
adapter = EndAdapter()
rlv_end.adapter = adapter
binding.rlvEnd.adapter = adapter
}
private fun upRecyclerData() {
@ -87,10 +91,11 @@ class EndActivity : VMBaseActivity<EndViewModel>(R.layout.activity_end) {
}
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() }
return errorView
}
}

@ -1,28 +1,39 @@
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.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class EndAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule {
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) {
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 {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
holder.itemView.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 com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.databinding.ActivityFeedBackBinding
import com.novel.read.utils.ext.getViewModel
import kotlinx.android.synthetic.main.activity_feed_back.*
import org.jetbrains.anko.toast
class FeedBackActivity : VMBaseActivity<FeedBackViewModel>(R.layout.activity_feed_back) {
class FeedBackActivity : VMBaseActivity<ActivityFeedBackBinding,FeedBackViewModel>() {
override val viewModel: FeedBackViewModel
get() = getViewModel(FeedBackViewModel::class.java)
override fun getViewBinding(): ActivityFeedBackBinding {
return ActivityFeedBackBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
button_report.setOnClickListener {
if (TextUtils.isEmpty(et_feed.text.toString().trim())){
binding.buttonReport.setOnClickListener {
if (TextUtils.isEmpty(binding.etFeed.text.toString().trim())){
toast(getString(R.string.feedback_not_empty))
return@setOnClickListener
}
viewModel.feedback(et_feed.text.toString().trim())
viewModel.feedback(binding.etFeed.text.toString().trim())
}
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.IntentAction
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.IntentDataHelp
import com.novel.read.ui.read.ReadBookActivity
import com.novel.read.utils.ColorUtils
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.startActivity
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 val requestCodeRead = 432
@ -31,6 +31,10 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java)
override fun getViewBinding(): ActivityBookInfoBinding {
return ActivityBookInfoBinding.inflate(layoutInflater)
}
companion object {
fun actionBookInfo(context: Context, bookId: Long, bookTypeId: Int?) {
context.startActivity<BookInfoActivity>(
@ -43,16 +47,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.initData(intent)
viewModel.getRecommend(intent)
tv_shelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
initRecycleView()
initData()
initClick()
}
private fun initRecycleView() {
rlv_recommend.layoutManager = GridLayoutManager(this, 4)
binding.rlvRecommend.layoutManager = GridLayoutManager(this, 4)
adapter = BookInfoAdapter()
rlv_recommend.adapter = adapter
binding.rlvRecommend.adapter = adapter
}
private fun initData() {
@ -61,17 +65,16 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} else {
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()
}
viewModel.bookListResp.observe(this) {
@ -80,20 +83,20 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.status.observe(this) {
when (it) {
AppConst.loading -> {
refresh.showLoading()
binding.refresh.showLoading()
}
AppConst.complete -> {
refresh.showFinish()
binding.refresh.showFinish()
}
else -> {
refresh.showError()
binding.refresh.showError()
}
}
}
}
private fun initClick() {
tv_shelf.onClick {
binding.tvShelf.onClick {
if (viewModel.inBookshelf) {
deleteBook()
} else {
@ -104,14 +107,14 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
}
tv_read.onClick {
binding.tvRead.onClick {
viewModel.bookData.value?.let {
readBook(it)
}
}
refresh.setOnReloadingListener {
binding.refresh.setOnReloadingListener {
viewModel.initData(intent)
viewModel.getRecommend(intent)
}
@ -139,9 +142,9 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
private fun upTvBookshelf() {
if (viewModel.inBookshelf) {
tv_shelf.text = getString(R.string.remove_from_bookshelf)
binding.tvShelf.text = getString(R.string.remove_from_bookshelf)
} else {
tv_shelf.text = getString(R.string.add_to_shelf)
binding.tvShelf.text = getString(R.string.add_to_shelf)
}
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
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemHotItemBinding
import com.novel.read.lib.ATH
import kotlinx.android.synthetic.main.item_hot_item.view.*
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 {
ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick {
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
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.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.data.db.entity.Book
import com.novel.read.databinding.ItemBookshelfListBinding
import com.novel.read.lib.ATH
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) {
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>) {
super.convert(holder, item, payloads)
val bundle = payloads.getOrNull(0) as? Bundle
holder.itemView.run {
ATH.applyBackgroundTint(this)
holder.getViewBinding<ItemBookshelfListBinding>().apply {
if (bundle == null) {
tv_name.text = item.bookName
tv_author.text = item.authorPenname
tv_read.text = item.durChapterTitle
tv_last.text = item.keyWord
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item)
tvName.text = item.bookName
tvAuthor.text = item.authorPenname
tvRead.text = item.durChapterTitle
tvLast.text = item.keyWord
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(this, item)
} else {
tv_read.text = item.durChapterTitle
tv_last.text = item.keyWord
tvRead.text = item.durChapterTitle
tvLast.text = item.keyWord
bundle.keySet().forEach {
when (it) {
"name" -> tv_name.text = item.bookName
"author" -> tv_author.text = item.authorPenname
"cover" -> iv_cover.load(
"name" -> tvName.text = item.bookName
"author" -> tvAuthor.text = item.authorPenname
"cover" -> ivCover.load(
item.coverImageUrl,
item.bookName,
item.authorPenname
)
"refresh" -> upRefresh(holder, item)
"refresh" -> upRefresh(this, item)
}
}
}
}
holder.itemView.run {
ATH.applyBackgroundTint(this)
}
}
override fun convert(holder: BaseViewHolder, item: Book) {
holder.itemView.run {
ATH.applyBackgroundTint(this)
tv_name.text = item.bookName
tv_author.text = item.authorPenname
tv_read.text = item.durChapterTitle
tv_last.text = item.keyWord
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item)
}
holder.getViewBinding<ItemBookshelfListBinding>().apply {
tvName.text = item.bookName
tvAuthor.text = item.authorPenname
tvRead.text = item.durChapterTitle
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)) {
holder.itemView.bv_unread.invisible()
holder.itemView.rl_loading.show()
holder.bvUnread.invisible()
holder.rlLoading.show()
} else {
holder.itemView.rl_loading.hide()
holder.itemView.bv_unread.setBadgeCount(0)
holder.itemView.bv_unread.setHighlight(true)
holder.rlLoading.hide()
holder.bvUnread.setBadgeCount(0)
holder.bvUnread.setHighlight(true)
}
}

@ -1,61 +1,71 @@
package com.novel.read.ui.main.bookshelf
import android.os.Bundle
import android.view.ViewGroup
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.data.db.entity.Book
import com.novel.read.databinding.ItemBookshelfGridBinding
import com.novel.read.lib.ATH
import com.novel.read.utils.ext.invisible
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.*
class BooksAdapterGrid(private val callBack: CallBack) :
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>) {
super.convert(holder, item, payloads)
val bundle = payloads.getOrNull(0) as? Bundle
holder.itemView.run {
ATH.applyBackgroundTint(this)
holder.getViewBinding<ItemBookshelfGridBinding>().apply{
if (bundle == null) {
tv_name.text = item.bookName
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item)
tvName.text = item.bookName
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(this, item)
} else {
bundle.keySet().forEach {
when (it) {
"name" -> tv_name.text = item.bookName
"cover" -> iv_cover.load(
"name" -> tvName.text = item.bookName
"cover" -> ivCover.load(
item.coverImageUrl,
item.bookName,
item.authorPenname
)
"refresh" -> upRefresh(holder, item)
"refresh" -> upRefresh(this, item)
}
}
}
}
holder.itemView.run {
ATH.applyBackgroundTint(this)
}
}
override fun convert(holder: BaseViewHolder, item: Book) {
holder.itemView.run {
ATH.applyBackgroundTint(this)
tv_name.text = item.bookName
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname)
upRefresh(holder, item)
}
holder.getViewBinding<ItemBookshelfGridBinding>().apply{
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)) {
holder.itemView.bv_unread.invisible()
holder.itemView.rl_loading.show()
holder.bvUnread.invisible()
holder.rlLoading.show()
} else {
holder.itemView.rl_loading.hide()
holder.itemView.bv_unread.setBadgeCount(0)
holder.itemView.bv_unread.setHighlight(true)
holder.rlLoading.hide()
holder.bvUnread.setBadgeCount(0)
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.PreferKey
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.IntentDataHelp
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.utils.BooksDiffCallBack
import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.dialog_bookshelf_config.view.*
import kotlinx.android.synthetic.main.fragment_book_shelf.*
import kotlinx.android.synthetic.main.view_title_bar.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.startActivity
class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_shelf), BaseBookAdapter.CallBack {
override val viewModel: BookViewModel by viewModels()
private val activityViewModel: MainViewModel
by activityViewModels()
private val binding by viewBinding(FragmentBookShelfBinding::bind)
private lateinit var booksAdapter: BaseBookAdapter
private var bookshelfLiveData = MutableLiveData<List<Book>>()
private lateinit var selectBook: Book
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
setSupportToolbar(binding.titleBar.toolbar)
initRecycleView()
upRecyclerData()
}
@ -75,23 +75,23 @@ class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_s
}
private fun initRecycleView() {
ATH.applyEdgeEffectColor(rlv_book_shelf)
ATH.applyEdgeEffectColor(binding.rlvBookShelf)
refresh_layout.setColorSchemeColors(accentColor)
refresh_layout.setOnRefreshListener {
refresh_layout.isRefreshing = false
binding.refreshLayout.setColorSchemeColors(accentColor)
binding.refreshLayout.setOnRefreshListener {
binding.refreshLayout.isRefreshing = false
activityViewModel.upToc(booksAdapter.data)
}
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
if (bookshelfLayout == 0) {
rlv_book_shelf.layoutManager = LinearLayoutManager(context)
binding.rlvBookShelf.layoutManager = LinearLayoutManager(context)
booksAdapter = BookShelfAdapter(this)
} else {
rlv_book_shelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
binding.rlvBookShelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2)
booksAdapter = BooksAdapterGrid(this)
}
rlv_book_shelf.adapter = booksAdapter
binding.rlvBookShelf.adapter = booksAdapter
booksAdapter.setEmptyView(R.layout.view_empty)
booksAdapter.setDiffCallback(BooksDiffCallBack())
@ -132,9 +132,9 @@ class BookshelfFragment : VMBaseFragment<BookViewModel>(R.layout.fragment_book_s
fun gotoTop() {
if (AppConfig.isEInkMode) {
rlv_book_shelf.scrollToPosition(0)
binding.rlvBookShelf.scrollToPosition(0)
} 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) {
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
val bookshelfSort = getPrefInt(PreferKey.bookshelfSort)
val root = LayoutInflater.from(requireContext())
.inflate(R.layout.dialog_bookshelf_config, null).apply {
rg_layout.checkByIndex(bookshelfLayout)
rg_sort.checkByIndex(bookshelfSort)
}
customView = root
val alertBinding =
DialogBookshelfConfigBinding.inflate(layoutInflater)
.apply {
rgLayout.checkByIndex(bookshelfLayout)
rgSort.checkByIndex(bookshelfSort)
}
customView = alertBinding.root
okButton {
root.apply {
alertBinding.apply {
var changed = false
if (bookshelfLayout != rg_layout.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfLayout, rg_layout.getCheckedIndex())
if (bookshelfLayout != rgLayout.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfLayout, rgLayout.getCheckedIndex())
changed = true
}
if (bookshelfSort != rg_sort.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfSort, rg_sort.getCheckedIndex())
if (bookshelfSort != rgSort.getCheckedIndex()) {
putPrefInt(PreferKey.bookshelfSort, rgSort.getCheckedIndex())
changed = true
}
if (changed) {

@ -8,6 +8,7 @@ import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.PreferKey
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.dialogs.alert
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.getPrefInt
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
override val viewModel: ArrangeBookViewModel
get() = getViewModel(ArrangeBookViewModel::class.java)
override fun getViewBinding(): ActivityArrangeBookBinding {
return ActivityArrangeBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initBookData()
}
private fun initView() {
ATH.applyEdgeEffectColor(recycler_view)
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration(VerticalDivider(this))
ATH.applyEdgeEffectColor(binding.recyclerView)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(VerticalDivider(this))
adapter = ArrangeBookAdapter(this)
recycler_view.adapter = adapter
binding.recyclerView.adapter = adapter
}
private fun initBookData() {

@ -1,36 +1,46 @@
package com.novel.read.ui.main.bookshelf.arrange
import android.view.LayoutInflater
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R
import android.view.ViewGroup
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
import com.novel.read.data.db.entity.Book
import com.novel.read.databinding.ItemArrangeBookBinding
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.sdk27.listeners.onClick
class ArrangeBookAdapter(val callBack: CallBack) : BaseQuickAdapter<Book, BaseViewHolder>(R.layout.item_arrange_book) {
override fun convert(holder: BaseViewHolder, item: Book) {
holder.itemView.run {
backgroundColor = context.backgroundColor
tv_name.text = item.bookName
tv_author.text = item.authorPenname
tv_author.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE
class ArrangeBookAdapter(val callBack: CallBack) :
BaseBindingAdapter<Book, ItemArrangeBookBinding>() {
override fun convert(holder: VBViewHolder<ItemArrangeBookBinding>, item: Book) {
holder.itemView.backgroundColor = context.backgroundColor
holder.vb.run {
tvName.text = item.bookName
tvAuthor.text = item.authorPenname
tvAuthor.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE
// checkbox.isChecked = selectedBooks.contains(item)
iv_book.load(item.coverImageUrl, item.bookName, item.authorPenname)
tv_delete.onClick {
getItem(holder.layoutPosition)?.let {
ivBook.load(item.coverImageUrl, item.bookName, item.authorPenname)
tvDelete.onClick {
getItem(holder.layoutPosition).let {
callBack.deleteBook(it)
}
}
}
}
override fun createViewBinding(
inflater: LayoutInflater,
parent: ViewGroup
): ItemArrangeBookBinding {
return ItemArrangeBookBinding.inflate(inflater, parent, false)
}
interface CallBack {
fun upSelectCount()
fun updateBook(vararg 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.constant.AppConst
import com.novel.read.data.model.*
import com.novel.read.databinding.FragmentMailBinding
import com.novel.read.lib.ATH
import com.novel.read.ui.main.mail.pick.PickAdapter
import com.novel.read.ui.search.SearchActivity
import com.novel.read.utils.ext.*
import kotlinx.android.synthetic.main.fragment_mail.rlv_home
import kotlinx.android.synthetic.main.view_title_bar.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
import java.util.ArrayList
class MailFragment : VMBaseFragment<MailViewModel>(R.layout.fragment_mail) {
override val viewModel: MailViewModel
get() = getViewModel(MailViewModel::class.java)
private val binding by viewBinding(FragmentMailBinding::bind)
private lateinit var adapter: PickAdapter<MultiItemEntity>
private val data: MutableList<MultiItemEntity> = ArrayList()
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
ATH.applyEdgeEffectColor(rlv_home)
setSupportToolbar(binding.titleBar.toolbar)
ATH.applyEdgeEffectColor(binding.rlvHome)
initRecycleView()
upRecyclerData()
}
private fun initRecycleView() {
rlv_home.layoutManager = LinearLayoutManager(context)
binding.rlvHome.layoutManager = LinearLayoutManager(context)
adapter = PickAdapter(data)
rlv_home.adapter = adapter
binding.rlvHome.adapter = adapter
}
private fun upRecyclerData() {
@ -78,7 +79,7 @@ class MailFragment : VMBaseFragment<MailViewModel>(R.layout.fragment_mail) {
}
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() }
return errorView
}

@ -1,24 +1,35 @@
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.viewholder.BaseViewHolder
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.databinding.ItemClickItemBinding
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_click_item.view.*
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) {
holder.itemView.run {
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
tv_count.text = context.getString(R.string.book_word, item.wordCount / 10000)
onClick {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
override fun convert(holder: VBViewHolder<ItemClickItemBinding>, item: ClickRank) {
holder.vb.run {
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tvName.text = item.getBBookName()
tvCount.text = context.getString(R.string.book_word, item.wordCount / 10000)
}
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
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemEndItemBinding
import com.novel.read.lib.ATH
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_end_item.view.*
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 {
ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick {
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
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemHotItemBinding
import com.novel.read.lib.ATH
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_hot_item.view.*
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 {
ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBName(), item.getBAuthor())
tv_name.text = item.getBName()
onClick {
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
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.IntentAction
import com.novel.read.constant.LayoutType
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.ui.channel.ChannelActivity
import com.novel.read.ui.daily.DailyActivity
import com.novel.read.ui.end.EndActivity
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.startActivity
@ -31,113 +34,133 @@ class PickAdapter<T : MultiItemEntity>(data: MutableList<T>?) :
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) {
when (item) {
is TypeEntity -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
tv_daily.onClick {
}
holder.getViewBinding<ItemPickHeadBinding>().apply {
tvDaily.onClick {
context.startActivity<DailyActivity>()
}
tv_rank.onClick {
tvRank.onClick {
context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.HOT),
Pair(IntentAction.homeType, AppConst.home)
)
}
tv_end.onClick {
tvEnd.onClick {
context.startActivity<EndActivity>()
}
tv_type.onClick {
tvType.onClick {
context.startActivity<ChannelActivity>()
}
}
}
is HotEntity -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
rlv_hot.setHasFixedSize(true)
ll_title.onClick {
}
holder.getViewBinding<ItemHotBinding>().apply{
rlvHot.setHasFixedSize(true)
llTitle.onClick {
context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.HOT),
Pair(IntentAction.homeType, AppConst.home)
)
}
if (rlv_hot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4)
if (rlvHot.layoutManager == null) {
rlvHot.layoutManager = GridLayoutManager(context, 4)
}
if (rlv_hot.adapter == null) {
if (rlvHot.adapter == null) {
val hotAdapter = HotAdapter()
hotAdapter.setList(item.hotRanks)
rlv_hot.adapter = hotAdapter
rlvHot.adapter = hotAdapter
}
}
}
is ClickEntity -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_click)
tv_head.text=context.getString(R.string.click_title)
ll_title.onClick {
}
holder.getViewBinding<ItemHotBinding>().apply{
ivHead.setImageResource(R.drawable.ic_click)
tvHead.text=context.getString(R.string.click_title)
llTitle.onClick {
context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.CLICK),
Pair(IntentAction.homeType, AppConst.home)
)
}
rlv_hot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 2)
rlvHot.setHasFixedSize(true)
if (rlvHot.layoutManager == null) {
rlvHot.layoutManager = GridLayoutManager(context, 2)
}
if (rlv_hot.adapter == null) {
if (rlvHot.adapter == null) {
val clickAdapter = ClickAdapter()
clickAdapter.setList(item.clickRanks)
rlv_hot.adapter = clickAdapter
rlvHot.adapter = clickAdapter
}
}
}
is RecommendEntity -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_recommend)
tv_head.text=context.getString(R.string.recommend_title)
ll_title.onClick {
}
holder.getViewBinding<ItemHotBinding>().apply{
ivHead.setImageResource(R.drawable.ic_recommend)
tvHead.text=context.getString(R.string.recommend_title)
llTitle.onClick {
context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.RECOMMEND),
Pair(IntentAction.homeType, AppConst.home)
)
}
rlv_hot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4)
rlvHot.setHasFixedSize(true)
if (rlvHot.layoutManager == null) {
rlvHot.layoutManager = GridLayoutManager(context, 4)
}
if (rlv_hot.adapter == null) {
if (rlvHot.adapter == null) {
val recommendAdapter = RecommendAdapter()
recommendAdapter.setList(item.recommendRanks)
rlv_hot.adapter = recommendAdapter
rlvHot.adapter = recommendAdapter
}
}
}
is EndEntity -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
iv_head.setImageResource(R.drawable.ic_end)
tv_head.text=context.getString(R.string.end_title)
ll_title.onClick {
}
holder.getViewBinding<ItemHotBinding>().apply{
ivHead.setImageResource(R.drawable.ic_end)
tvHead.text=context.getString(R.string.end_title)
llTitle.onClick {
context.startActivity<RankActivity>(
Pair(IntentAction.rankType, LayoutType.END),
Pair(IntentAction.homeType, AppConst.home)
)
}
rlv_hot.setHasFixedSize(true)
if (rlv_hot.layoutManager == null) {
rlv_hot.layoutManager = GridLayoutManager(context, 4)
rlvHot.setHasFixedSize(true)
if (rlvHot.layoutManager == null) {
rlvHot.layoutManager = GridLayoutManager(context, 4)
}
if (rlv_hot.adapter == null) {
if (rlvHot.adapter == null) {
val endAdapter = EndAdapter()
endAdapter.setList(item.endRanks)
rlv_hot.adapter = endAdapter
rlvHot.adapter = endAdapter
}
}
}

@ -1,13 +1,17 @@
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.viewholder.BaseViewHolder
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.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.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_end_item.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class RecommendAdapter : BaseMultiItemQuickAdapter<RecommendRank, BaseViewHolder>() {
@ -17,24 +21,38 @@ class RecommendAdapter : BaseMultiItemQuickAdapter<RecommendRank, BaseViewHolder
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) {
when (item.itemType) {
LayoutType.HEAD -> {
holder.itemView.run {
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 -> {
holder.itemView.run {
ATH.applyBackgroundTint(this)
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName())
tv_name.text = item.getBBookName()
onClick {
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
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.view.View
import com.novel.read.App
import com.novel.read.R
import com.novel.read.base.BaseFragment
import com.novel.read.databinding.FragmentMyBinding
import com.novel.read.ui.feedback.FeedBackActivity
import com.novel.read.ui.setting.SettingActivity
import com.novel.read.ui.widget.dialog.AppraiseDialog
import com.novel.read.utils.ext.startActivity
import com.novel.read.utils.ext.toast
import kotlinx.android.synthetic.main.fragment_my.*
import kotlinx.android.synthetic.main.view_title_bar.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
class MyFragment : BaseFragment(R.layout.fragment_my) {
private val binding by viewBinding(FragmentMyBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
tv_options.setOnClickListener {
setSupportToolbar(binding.titleBar.toolbar)
binding.tvOptions.setOnClickListener {
startActivity<FeedBackActivity>()
}
tv_setting.setOnClickListener {
binding.tvSetting.setOnClickListener {
startActivity<SettingActivity>()
}
tv_appraise.setOnClickListener {
val dialog = AppraiseDialog(requireActivity())
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()
binding.tvAppraise.setOnClickListener {
AppraiseDialog().show(childFragmentManager,"AppDialog")
}
}

@ -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.LayoutType
import com.novel.read.data.model.*
import com.novel.read.databinding.ActivityRankBinding
import com.novel.read.lib.ATH
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
get() = getViewModel(RankViewModel::class.java)
override fun getViewBinding(): ActivityRankBinding {
return ActivityRankBinding.inflate(layoutInflater)
}
private lateinit var adapter: RankAdapter
private lateinit var typeAdapter: TypeAdapter
private lateinit var mTypes: List<TypeName>
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_rank)
ATH.applyEdgeEffectColor(lv_type)
override fun onActivityCreated(savedInstanceState: Bundle?) = with(binding){
ATH.applyEdgeEffectColor(rlvRank)
ATH.applyEdgeEffectColor(rlvType)
initRecyclerView()
upRecyclerData()
initLoadMore()
}
private fun initRecyclerView() {
rlv_rank.layoutManager = LinearLayoutManager(this)
binding.rlvRank.layoutManager = LinearLayoutManager(this)
adapter = RankAdapter()
rlv_rank.adapter = adapter
lv_type.layoutManager = LinearLayoutManager(this)
binding.rlvRank.adapter = adapter
binding.rlvType.layoutManager = LinearLayoutManager(this)
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 {
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() }
return errorView
}
}

@ -1,28 +1,38 @@
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.viewholder.BaseViewHolder
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.databinding.ItemBookCommonBinding
import com.novel.read.ui.info.BookInfoActivity
import kotlinx.android.synthetic.main.item_book_common.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class RankAdapter :
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule {
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: BookListResp) {
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 {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) {
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()
}
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
import android.view.LayoutInflater
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.viewholder.BaseViewHolder
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 kotlinx.android.synthetic.main.item_type.view.*
import com.novel.read.databinding.ItemTypeBinding
class TypeAdapter :
BaseQuickAdapter<TypeName, BaseViewHolder>(R.layout.item_type), LoadMoreModule {
BaseBindingAdapter<TypeName, ItemTypeBinding>(), LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: TypeName) {
holder.itemView.run {
tv_type.text = item.name
override fun convert(holder: VBViewHolder<ItemTypeBinding>, item: TypeName) {
holder.vb.run {
tvType.text = item.name
if (item.check) {
iv_check.visibility = View.VISIBLE
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background))
ivCheck.visibility = View.VISIBLE
llBg.setBackgroundColor(context.resources.getColor(R.color.background))
} else {
iv_check.visibility = View.GONE
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background_menu))
ivCheck.visibility = View.GONE
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.content.Intent
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.Handler
import android.os.Looper
@ -15,14 +12,11 @@ import androidx.core.view.isVisible
import androidx.lifecycle.observe
import com.novel.read.BuildConfig
import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.EventBus
import com.novel.read.constant.PreferKey
import com.novel.read.constant.Status
import com.novel.read.data.db.entity.Book
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.noButton
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.TextDialog
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 org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivityForResult
import java.lang.Runnable
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book),
class ReadBookActivity :ReadBookBaseActivity(),
View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, ContentTextView.CallBack,
ReadBook.CallBack,
ReadMenu.CallBack,
ReadAloudDialog.CallBack {
override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java)
override val selectedText: String
get() = page_view.curPage.selectedText
get() = binding.pageView.curPage.selectedText
private val requestCodeChapterList = 568
private val requestCodeSearchResult = 123
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 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 keepScreenRunnable: Runnable =
Runnable { ReadBookActivityHelp.keepScreenOn(window, false) }
Runnable { keepScreenOn(window, false) }
override var autoPageProgress = 0
override var isAutoPage = false
private var screenTimeOut: Long = 0
private var loadStates: Boolean = false
override val pageFactory: TextPageFactory get() = page_view.pageFactory
override val headerHeight: Int get() = page_view.curPage.headerHeight
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
ReadBookActivityHelp.setOrientation(this)
super.onCreate(savedInstanceState)
}
override val pageFactory: TextPageFactory get() = binding.pageView.pageFactory
override val headerHeight: Int get() = binding.pageView.curPage.headerHeight
override fun onActivityCreated(savedInstanceState: Bundle?) {
ReadBookActivityHelp.upLayoutInDisplayCutoutMode(window)
initView()
upScreenTimeOut()
setScreenBrightness(getPrefInt("brightness", 100))
ReadBook.callBack = this
ReadBook.titleDate.observe(this) {
title_bar.title = it
binding.readMenu.setTitle(it)
upMenu()
upView()
}
@ -106,7 +89,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
page_view.upStatusBar()
binding.pageView.upStatusBar()
ReadBook.loadContent(resetPageOffset = false)
}
@ -137,19 +120,19 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
R.id.menu_refresh -> {
ReadBook.book?.let {
ReadBook.curTextChapter = null
page_view.upContent()
binding.pageView.upContent()
viewModel.refreshContent(it)
}
}
R.id.menu_download -> ReadBookActivityHelp.showDownloadDialog(this)
R.id.menu_add_bookmark -> ReadBookActivityHelp.showBookMark(this)
R.id.menu_download -> showDownloadDialog()
R.id.menu_add_bookmark -> showBookMark(this)
R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let {
loadChapterList(it)
}
R.id.menu_page_anim -> ReadBookActivityHelp.showPageAnimConfig(this) {
page_view.upPageAnim()
R.id.menu_page_anim -> showPageAnimConfig {
binding.pageView.upPageAnim()
}
R.id.menu_book_info -> ReadBook.book?.let {
BookInfoActivity.actionBookInfo(this, it.bookId, it.bookTypeId)
@ -162,7 +145,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
super.onResume()
ReadBook.readStartTime = System.currentTimeMillis()
upSystemUiVisibility()
page_view.upTime()
binding.pageView.upTime()
}
override fun onPause() {
@ -171,41 +154,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
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
*/
@SuppressLint("ClickableViewAccessibility")
private fun initView() {
cursor_left.setColorFilter(accentColor)
cursor_right.setColorFilter(accentColor)
cursor_left.setOnTouchListener(this)
cursor_right.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)
}
}
binding.cursorLeft.setColorFilter(accentColor)
binding.cursorRight.setColorFilter(accentColor)
binding.cursorLeft.setOnTouchListener(this)
binding.cursorRight.setOnTouchListener(this)
}
override fun clickCenter() {
@ -217,29 +174,26 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
AutoReadDialog().show(supportFragmentManager, "autoRead")
}
else -> {
read_menu.runMenuIn()
binding.readMenu.runMenuIn()
}
}
}
override fun showTextActionMenu() {
textActionMenu ?: let {
textActionMenu = TextActionMenu(this, this)
}
textActionMenu?.let { popup ->
override fun showTextActionMenu() = with(binding){
textActionMenu.let { popup ->
popup.contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val popupHeight = popup.contentView.measuredHeight
val x = text_menu_position.x.toInt()
var y = text_menu_position.y.toInt() - popupHeight
val x = textMenuPosition.x.toInt()
var y = textMenuPosition.y.toInt() - popupHeight
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) {
y = (cursor_right.y + cursor_right.height).toInt()
if (cursorRight.y > y && cursorRight.y < y + popupHeight) {
y = (cursorRight.y + cursorRight.height).toInt()
}
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 {
popup.update(
x, y,
@ -258,38 +212,29 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun upContent(relativePosition: Int, resetPageOffset: Boolean) {
autoPageProgress = 0
launch {
page_view.upContent(relativePosition, resetPageOffset)
seek_read_page.progress = ReadBook.durPageIndex
binding.pageView.upContent(relativePosition, resetPageOffset)
binding.readMenu.setSeekPage(ReadBook.durPageIndex)
loadStates = false
}
loadStates = false
}
override fun upView() {
launch {
ReadBook.curTextChapter?.let {
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()
}
binding.readMenu.upBookView()
}
}
override fun upPageAnim() {
launch {
binding.pageView.upPageAnim()
}
}
override fun pageChanged() {
autoPageProgress = 0
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
}
override fun upSelectedStart(x: Float, y: Float, top: Float) {
cursor_left.x = x - cursor_left.width
cursor_left.y = y
cursor_left.visible(true)
text_menu_position.x = x
text_menu_position.y = top
override fun upSelectedStart(x: Float, y: Float, top: Float) = with(binding){
cursorLeft.x = x - cursorLeft.width
cursorLeft.y = y
cursorLeft.visible(true)
textMenuPosition.x = x
textMenuPosition.y = top
}
override fun upSelectedEnd(x: Float, y: Float) {
cursor_right.x = x
cursor_right.y = y
cursor_right.visible(true)
override fun upSelectedEnd(x: Float, y: Float) = with(binding){
cursorRight.x = x
cursorRight.y = y
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() {
getPrefString(PreferKey.keepLight)?.let {
screenTimeOut = it.toLong() * 1000
@ -330,32 +277,32 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun screenOffTimerStart() {
if (screenTimeOut < 0) {
ReadBookActivityHelp.keepScreenOn(window, true)
keepScreenOn(window, true)
return
}
val t = screenTimeOut - sysScreenOffTime
if (t > 0) {
mHandler.removeCallbacks(keepScreenRunnable)
ReadBookActivityHelp.keepScreenOn(window, true)
keepScreenOn(window, true)
mHandler.postDelayed(keepScreenRunnable, screenTimeOut)
} else {
ReadBookActivityHelp.keepScreenOn(window, false)
keepScreenOn(window, false)
}
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {
override fun onTouch(v: View, event: MotionEvent): Boolean = with(binding){
when (event.action) {
MotionEvent.ACTION_DOWN -> textActionMenu?.dismiss()
MotionEvent.ACTION_DOWN -> textActionMenu.dismiss()
MotionEvent.ACTION_MOVE -> {
when (v.id) {
R.id.cursor_left -> page_view.curPage.selectStartMove(
event.rawX + cursor_left.width,
event.rawY - cursor_left.height
R.id.cursor_left -> binding.pageView.curPage.selectStartMove(
event.rawX + cursorLeft.width,
event.rawY - cursorLeft.height
)
R.id.cursor_right -> page_view.curPage.selectEndMove(
event.rawX - cursor_right.width,
event.rawY - cursor_right.height
R.id.cursor_right -> binding.pageView.curPage.selectEndMove(
event.rawX - cursorRight.width,
event.rawY - cursorRight.height
)
}
}
@ -366,15 +313,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when {
ReadBookActivityHelp.isPrevKey(this, keyCode) -> {
isPrevKey(this, keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV)
binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV)
return true
}
}
ReadBookActivityHelp.isNextKey(this, keyCode) -> {
isNextKey(this, keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true
}
}
@ -389,7 +336,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
keyCode == KeyEvent.KEYCODE_SPACE -> {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
binding.pageView.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true
}
}
@ -400,13 +347,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
* 音量键翻页
*/
private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean {
if (!read_menu.isVisible) {
if (!binding.readMenu.isVisible) {
if (getPrefBoolean("volumeKeyPage", true)) {
if (getPrefBoolean("volumeKeyPageOnPlay")
|| BaseReadAloudService.pause
) {
page_view.pageDelegate?.isCancel = false
page_view.pageDelegate?.keyTurnPage(direction)
binding.pageView.pageDelegate?.isCancel = false
binding.pageView.pageDelegate?.keyTurnPage(direction)
return true
}
}
@ -416,11 +363,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun observeLiveBus() {
super.observeLiveBus()
observeEvent<String>(EventBus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEvent<String>(EventBus.TIME_CHANGED) { binding.pageView.upTime() }
observeEvent<Int>(EventBus.BATTERY_CHANGED) { binding.pageView.upBattery(it) }
observeEvent<BookChapter>(EventBus.OPEN_CHAPTER) {
viewModel.openChapter(it.chapterIndex, ReadBook.durPageIndex)
page_view.upContent()
binding.pageView.upContent()
}
observeEvent<Boolean>(EventBus.MEDIA_BUTTON) {
if (it) {
@ -431,13 +378,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
observeEvent<Boolean>(EventBus.UP_CONFIG) {
upSystemUiVisibility()
page_view.upBg()
page_view.upTipStyle()
page_view.upStyle()
binding.pageView.upBg()
binding.pageView.upTipStyle()
binding.pageView.upStyle()
if (it) {
ReadBook.loadContent(resetPageOffset = false)
} else {
page_view.upContent(resetPageOffset = false)
binding.pageView.upContent(resetPageOffset = false)
}
}
observeEvent<Int>(EventBus.ALOUD_STATE) {
@ -446,7 +393,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
val page = textChapter.page(ReadBook.durPageIndex)
if (page != null) {
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()
}
observeEvent<Boolean>(PreferKey.textSelectAble) {
page_view.curPage.upSelectAble(it)
binding.pageView.curPage.upSelectAble(it)
}
observeEvent<String>(PreferKey.showBrightnessView) {
setScreenBrightness(getPrefInt("brightness", 100))
@ -501,7 +448,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun showMenuBar() {
read_menu.runMenuIn()
binding.readMenu.runMenuIn()
}
override fun openChapterList() {
@ -579,27 +526,27 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
ReadBook.skipToPage(positions[0])
}
withContext(Dispatchers.Main) {
page_view.curPage.selectStartMoveIndex(
binding.pageView.curPage.selectStartMoveIndex(
0,
positions[1],
positions[2]
)
delay(20L)
when (positions[3]) {
0 -> page_view.curPage.selectEndMoveIndex(
0 -> binding.pageView.curPage.selectEndMoveIndex(
0,
positions[1],
positions[2] + viewModel.searchContentQuery.length - 1
)
1 -> page_view.curPage.selectEndMoveIndex(
1 -> binding.pageView.curPage.selectEndMoveIndex(
0,
positions[1] + 1,
positions[4]
)
//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)
}
}
@ -621,9 +568,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
override fun onMenuActionFinally() {
textActionMenu?.dismiss()
page_view.curPage.cancelSelect()
page_view.isTextSelected = false
textActionMenu.dismiss()
binding.pageView.curPage.cancelSelect()
binding.pageView.isTextSelected = false
}
override fun finish() {
@ -649,7 +596,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
postEvent(EventBus.UP_BOOK, 0L)
mHandler.removeCallbacks(keepScreenRunnable)
textActionMenu?.dismiss()
page_view.onDestroy()
binding.pageView.onDestroy()
ReadBook.msg = null
if (!BuildConfig.DEBUG) {
// SyncBookProgress.uploadBookProgress()

@ -1,20 +1,24 @@
package com.novel.read.ui.read
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.AsyncTask
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.os.Bundle
import android.view.*
import android.widget.EditText
import androidx.activity.viewModels
import androidx.core.view.isVisible
import com.novel.read.App
import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.PreferKey
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.ReadBookConfig
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.getPrefString
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
/**
* 更新状态栏,导航栏
*/
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 getViewBinding(): ActivityReadBookBinding {
return ActivityReadBookBinding.inflate(layoutInflater)
}
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
setOrientation()
upLayoutInDisplayCutoutMode()
super.onCreate(savedInstanceState)
}
/**
* 屏幕方向
*/
@SuppressLint("SourceLockedOrientationActivity")
fun setOrientation(activity: Activity) = activity.apply {
fun setOrientation() {
when (AppConfig.requestedDirection) {
"0" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
"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) {
window.attributes = window.attributes.apply {
layoutInDisplayCutoutMode =
@ -107,34 +102,28 @@ object ReadBookActivityHelp {
}
@SuppressLint("InflateParams")
fun showDownloadDialog(context: Context) {
fun showDownloadDialog() {
ReadBook.book?.let { book ->
context.alert(titleResource = R.string.offline_cache) {
var view: View? = null
customView {
LayoutInflater.from(context).inflate(R.layout.dialog_download_choice, null)
.apply {
view = this
setBackgroundColor(context.backgroundColor)
edit_start.setText((book.durChapterIndex + 1).toString())
edit_end.setText(
App.db.getChapterDao().getChapterCount(bookId = book.bookId).toString()
)
}
alert(titleResource = R.string.offline_cache) {
val alertBinding = DialogDownloadChoiceBinding.inflate(layoutInflater).apply {
root.setBackgroundColor(root.context.backgroundColor)
editStart.setText((book.durChapterIndex + 1).toString())
editEnd.setText(book.totalChapterNum.toString())
}
customView { alertBinding.root }
yesButton {
view?.apply {
val start = edit_start?.text?.toString()?.toInt() ?: 0
val end = edit_end?.text?.toString()?.toInt() ?: App.db.getChapterDao()
.getChapterCount(bookId = book.bookId)
CacheBook.start(context, book.bookId, start - 1, end - 1)
alertBinding.run {
val start = editStart.text?.toString()?.toInt() ?: 0
val end = editEnd.text?.toString()?.toInt() ?: book.totalChapterNum
CacheBook.start(this@ReadBookBaseActivity, book.bookId, start - 1, end - 1)
}
}
noButton()
}.show().applyTint()
}.show()
}
}
@SuppressLint("InflateParams")
fun showBookMark(context: Context) = with(context) {
val book = ReadBook.book ?: return
@ -144,7 +133,7 @@ object ReadBookActivityHelp {
message = book.bookName + "" + textChapter.title
customView {
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)
}
}
@ -168,30 +157,8 @@ object ReadBookActivityHelp {
}.show().applyTint().requestInputMethod()
}
@SuppressLint("InflateParams")
fun showCharsetConfig(context: Context) = with(context) {
// 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) {
fun showPageAnimConfig(success: () -> Unit) {
val items = arrayListOf<String>()
items.add(getString(R.string.btn_default_s))
items.add(getString(R.string.page_anim_cover))

@ -1,9 +1,12 @@
package com.novel.read.ui.read
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.WindowManager
import android.view.animation.Animation
import android.widget.FrameLayout
@ -12,6 +15,7 @@ import androidx.core.view.isVisible
import com.novel.read.App
import com.novel.read.R
import com.novel.read.constant.PreferKey
import com.novel.read.databinding.ViewReadMenuBinding
import com.novel.read.help.AppConfig
import com.novel.read.help.ReadBookConfig
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.SystemUtils
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.onLongClick
@ -32,7 +35,8 @@ class ReadMenu @JvmOverloads constructor(
attrs: AttributeSet? = null
) : FrameLayout(context, attrs) {
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 menuTopOut: Animation
private lateinit var menuBottomIn: Animation
@ -47,33 +51,32 @@ class ReadMenu @JvmOverloads constructor(
val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true)
init {
inflate(context, R.layout.view_read_menu, this)
if (AppConfig.isNightTheme) {
fabNightTheme.setImageResource(R.drawable.ic_daytime)
binding.fabNightTheme.setImageResource(R.drawable.ic_daytime)
} else {
fabNightTheme.setImageResource(R.drawable.ic_brightness)
binding.fabNightTheme.setImageResource(R.drawable.ic_brightness)
}
initAnimation()
val brightnessBackground = GradientDrawable()
brightnessBackground.cornerRadius = 5F.dp
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
ll_bottom_bg.setBackgroundColor(bgColor)
fabSearch.backgroundTintList = bottomBackgroundList
fabSearch.setColorFilter(textColor)
fabNightTheme.backgroundTintList = bottomBackgroundList
fabNightTheme.setColorFilter(textColor)
tv_pre.setTextColor(textColor)
tv_next.setTextColor(textColor)
iv_catalog.setColorFilter(textColor)
tv_catalog.setTextColor(textColor)
iv_read_aloud.setColorFilter(textColor)
tv_read_aloud.setTextColor(textColor)
iv_font.setColorFilter(textColor)
tv_font.setTextColor(textColor)
iv_setting.setColorFilter(textColor)
tv_setting.setTextColor(textColor)
vw_bg.onClick { }
vwNavigationBar.onClick { }
binding.llBottomBg.setBackgroundColor(bgColor)
binding.fabSearch.backgroundTintList = bottomBackgroundList
binding.fabSearch.setColorFilter(textColor)
binding.fabNightTheme.backgroundTintList = bottomBackgroundList
binding.fabNightTheme.setColorFilter(textColor)
binding.tvPre.setTextColor(textColor)
binding.tvNext.setTextColor(textColor)
binding.ivCatalog.setColorFilter(textColor)
binding.tvCatalog.setTextColor(textColor)
binding.ivReadAloud.setColorFilter(textColor)
binding.tvReadAloud.setTextColor(textColor)
binding.ivFont.setColorFilter(textColor)
binding.tvFont.setTextColor(textColor)
binding.ivSetting.setColorFilter(textColor)
binding.tvSetting.setTextColor(textColor)
binding.vwBg.onClick { }
binding.vwNavigationBar.onClick { }
bindEvent()
}
@ -94,17 +97,17 @@ class ReadMenu @JvmOverloads constructor(
fun runMenuIn() {
this.visible()
title_bar.visible()
bottom_menu.visible()
title_bar.startAnimation(menuTopIn)
bottom_menu.startAnimation(menuBottomIn)
binding.titleBar.visible()
binding.bottomMenu.visible()
binding.titleBar.startAnimation(menuTopIn)
binding.bottomMenu.startAnimation(menuBottomIn)
}
fun runMenuOut(onMenuOutEnd: (() -> Unit)? = null) {
this.onMenuOutEnd = onMenuOutEnd
if (this.isVisible) {
title_bar.startAnimation(menuTopOut)
bottom_menu.startAnimation(menuBottomOut)
binding.titleBar.startAnimation(menuTopOut)
binding.bottomMenu.startAnimation(menuBottomOut)
}
}
@ -112,10 +115,20 @@ class ReadMenu @JvmOverloads constructor(
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) {
}
@ -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 {
callBack?.openChapterList()
}
}
//朗读
ll_read_aloud.onClick {
llReadAloud.onClick {
runMenuOut {
callBack?.onClickReadAloud()
}
}
ll_read_aloud.onLongClick {
llReadAloud.onLongClick {
runMenuOut { callBack?.showReadAloudDialog() }
true
}
//界面
ll_font.onClick {
llFont.onClick {
runMenuOut {
callBack?.showAdjust()
}
}
//设置
ll_setting.onClick {
llSetting.onClick {
runMenuOut {
callBack?.showReadStyle()
}
@ -190,8 +203,8 @@ class ReadMenu @JvmOverloads constructor(
}
override fun onAnimationEnd(animation: Animation) {
vw_menu_bg.onClick { runMenuOut() }
vwNavigationBar.layoutParams = vwNavigationBar.layoutParams.apply {
binding.vwMenuBg.onClick { runMenuOut() }
binding.vwNavigationBar.layoutParams = binding.vwNavigationBar.layoutParams.apply {
height =
if (ReadBookConfig.hideNavigationBar
&& SystemUtils.isNavigationBarExist(activity)
@ -210,13 +223,13 @@ class ReadMenu @JvmOverloads constructor(
AnimationUtilsSupport.loadAnimation(context, R.anim.anim_readbook_bottom_out)
menuTopOut.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
vw_menu_bg.setOnClickListener(null)
binding.vwMenuBg.setOnClickListener(null)
}
override fun onAnimationEnd(animation: Animation) {
this@ReadMenu.invisible()
title_bar.invisible()
bottom_menu.invisible()
binding.titleBar.invisible()
binding.bottomMenu.invisible()
cnaShowMenu = false
onMenuOutEnd?.invoke()
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 {
fun autoPage()

@ -15,13 +15,13 @@ import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
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.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.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.toast
import java.util.*
@ -30,7 +30,7 @@ import java.util.*
class TextActionMenu(private val context: Context, private val callBack: CallBack) :
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT),
TextToSpeech.OnInitListener {
private val binding = PopupActionMenuBinding.inflate(LayoutInflater.from(context))
private val adapter = Adapter()
private val menu = MenuBuilder(context)
private val moreMenu = MenuBuilder(context)
@ -46,46 +46,46 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
initRecyclerView()
setOnDismissListener {
contentView.apply {
iv_menu_more.setImageResource(R.drawable.ic_more_vert)
recycler_view_more.gone()
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert)
binding.recyclerViewMore.gone()
adapter.setList(menu.visibleItems)
recycler_view.visible()
binding.recyclerView.visible()
}
}
}
private fun initRecyclerView() = with(contentView) {
recycler_view.adapter = adapter
recycler_view_more.adapter = adapter
private fun initRecyclerView() = with(binding) {
recyclerView.adapter = adapter
recyclerViewMore.adapter = adapter
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)
adapter.setList(menu.visibleItems)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
onInitializeMenu(moreMenu)
}
if (moreMenu.size() > 0) {
iv_menu_more.visible()
ivMenuMore.visible()
}
iv_menu_more.onClick {
if (recycler_view.isVisible) {
iv_menu_more.setImageResource(R.drawable.ic_arrow_back)
ivMenuMore.onClick {
if (recyclerView.isVisible) {
ivMenuMore.setImageResource(R.drawable.ic_arrow_back)
adapter.setList(menu.visibleItems)
recycler_view.gone()
recycler_view_more.visible()
recyclerView.gone()
recyclerViewMore.visible()
} else {
iv_menu_more.setImageResource(R.drawable.ic_more_vert)
recycler_view_more.gone()
ivMenuMore.setImageResource(R.drawable.ic_more_vert)
recyclerViewMore.gone()
adapter.setList(menu.visibleItems)
recycler_view.visible()
recyclerView.visible()
}
}
}
inner class Adapter :
BaseQuickAdapter<MenuItemImpl, BaseViewHolder>(R.layout.item_text){
BaseBindingAdapter<MenuItemImpl, ItemTextBinding>(){
override fun convert(holder: BaseViewHolder, item: MenuItemImpl) {
holder.itemView.run {
text_view.text = item.title
override fun convert(holder: VBViewHolder<ItemTextBinding>, item: MenuItemImpl) {
holder.vb.run {
textView.text = item.title
}
holder.itemView.onClick {
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) {

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

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

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

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

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

@ -1,17 +1,22 @@
package com.novel.read.ui.search
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.novel.read.R
import android.view.LayoutInflater
import android.view.ViewGroup
import com.novel.read.base.BaseBindingAdapter
import com.novel.read.base.VBViewHolder
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) {
holder.itemView.run {
tv_label.text = item.getBKey()
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: SearchHistory) {
holder.vb.run {
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
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
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.databinding.ItemLabelBinding
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) {
holder.itemView.run {
tv_label.text = StringUtils.convertCC(item)
tv_label.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8])
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: String) {
holder.vb.run {
tvLabel.text = StringUtils.convertCC(item)
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.view.KeyEvent
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.listener.OnLoadMoreListener
import com.google.android.flexbox.AlignItems
@ -15,19 +16,15 @@ import com.novel.read.App
import com.novel.read.R
import com.novel.read.base.VMBaseActivity
import com.novel.read.constant.AppConst
import com.novel.read.databinding.ActivitySearchBinding
import com.novel.read.lib.ATH
import com.novel.read.lib.dialogs.alert
import com.novel.read.lib.dialogs.noButton
import com.novel.read.lib.dialogs.yesButton
import com.novel.read.utils.ext.applyTint
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.*
import com.novel.read.utils.ext.*
//这个页面为了赶进度写的很蠢
class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search) {
//这个页面写的很蠢
class SearchActivity : VMBaseActivity<ActivitySearchBinding,SearchViewModel>() {
private lateinit var mHisAdapter: HistoryAdapter
private lateinit var mHotAdapter: HotAdapter
@ -36,10 +33,19 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
override val viewModel: SearchViewModel
get() = getViewModel(SearchViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(rlv_history)
ATH.applyEdgeEffectColor(rlv_hot)
ATH.applyEdgeEffectColor(rlv_history)
override fun getViewBinding(): ActivitySearchBinding {
return ActivitySearchBinding.inflate(layoutInflater)
}
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()
initHotAdapter()
initHisAdapter()
@ -49,28 +55,28 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
initLoadMore()
}
private fun initClick() {
tv_search.addTextChangedListener(object : TextWatcher {
private fun initClick() = with(binding){
tvSearch.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.toString().trim { it <= ' ' } == "") {
head_hot.visibility = View.VISIBLE
head_history.visibility = View.VISIBLE
rlv_hot.visibility = View.VISIBLE
rlv_history.visibility = View.VISIBLE
rlv_search.visibility=View.GONE
headHot.visibility = View.VISIBLE
headHistory.visibility = View.VISIBLE
rlvHot.visibility = View.VISIBLE
rlvHistory.visibility = View.VISIBLE
rlvSearch.visibility=View.GONE
} else {
head_hot.visibility = View.GONE
head_history.visibility = View.GONE
rlv_hot.visibility = View.GONE
rlv_history.visibility = View.GONE
headHot.visibility = View.GONE
headHistory.visibility = View.GONE
rlvHot.visibility = View.GONE
rlvHistory.visibility = View.GONE
viewModel.page = 1
viewModel.searchKey = s.toString().trim()
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) {
saveKey()
@ -90,11 +96,11 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
false
}
tv_cancel.setOnClickListener {
tvCancel.setOnClickListener {
onBackPressed()
}
head_history.setOnClickListener {
binding.headHistory.setOnClickListener {
alert(title = "操作提示", message = "確認清空全部記錄?") {
yesButton {
App.db.getSearchDao().deleteAll()
@ -153,12 +159,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
}
private fun initSearchAdapter() {
rlv_search.layoutManager = LinearLayoutManager(this)
binding.rlvSearch.layoutManager = LinearLayoutManager(this)
mSearchAdapter = SearchAdapter()
rlv_search.adapter = mSearchAdapter
binding.rlvSearch.adapter = mSearchAdapter
mSearchAdapter.setOnItemChildClickListener { adapter, view, position ->
tv_search.setText(viewModel.mList[position].getBBookName())
tvSearch.text = viewModel.mList[position].getBBookName()
saveKey()
}
}
@ -171,12 +177,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
manager2.flexWrap = FlexWrap.WRAP
manager2.alignItems = AlignItems.STRETCH
mHisAdapter = HistoryAdapter()
rlv_history.layoutManager = manager2
rlv_history.adapter = mHisAdapter
binding.rlvHistory.layoutManager = manager2
binding.rlvHistory.adapter = mHisAdapter
mHisAdapter.setOnItemClickListener { adapter, view, position ->
rlv_search.visibility = View.VISIBLE
tv_search.setText(viewModel.hisKey.value?.get(position)?.getBKey())
binding.rlvSearch.visibility = View.VISIBLE
tvSearch.setText(viewModel.hisKey.value?.get(position)?.getBKey())
saveKey()
}
}
@ -188,12 +194,12 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
//设置是否换行
manager.flexWrap = FlexWrap.WRAP
manager.alignItems = AlignItems.STRETCH
rlv_hot.layoutManager = manager
binding.rlvHot.layoutManager = manager
mHotAdapter = HotAdapter()
rlv_hot.adapter = mHotAdapter
binding.rlvHot.adapter = mHotAdapter
mHotAdapter.setOnItemClickListener { adapter, view, position ->
rlv_search.visibility = View.VISIBLE
tv_search.setText(mHotAdapter.data[position])
binding.rlvSearch.visibility = View.VISIBLE
tvSearch.text = mHotAdapter.data[position]
saveKey()
}
}
@ -212,18 +218,18 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
}
private fun saveKey() {
val key = tv_search.text.toString().trim { it <= ' ' }
val key = tvSearch.text.toString().trim { it <= ' ' }
viewModel.saveKey(key)
}
private fun onRefresh() {
mSearchAdapter.setEmptyView(R.layout.view_loading)
viewModel.searchKey = tv_search.text.toString().trim()
viewModel.searchKey = tvSearch.text.toString().trim()
viewModel.searchBook()
}
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() }
return errorView
}
@ -232,4 +238,5 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_search)
super.onBackPressed()
overridePendingTransition(R.anim.message_fade_in, R.anim.message_fade_out)
}
}

@ -1,31 +1,39 @@
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.viewholder.BaseViewHolder
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.databinding.ItemBookCommonBinding
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
class SearchAdapter : BaseQuickAdapter<SearchResp, BaseViewHolder>(R.layout.item_book_common),
class SearchAdapter : BaseBindingAdapter<SearchResp, ItemBookCommonBinding>(),
LoadMoreModule {
override fun convert(holder: BaseViewHolder, item: SearchResp) {
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 {
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId)
}
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: SearchResp) {
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()
}
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.base.BaseActivity
import com.novel.read.constant.EventBus
import com.novel.read.databinding.ActivitySettingActivityBinding
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?) {
val fTag = "otherConfigFragment"
@ -23,4 +28,6 @@ class SettingActivity : BaseActivity(R.layout.activity_setting_activity) {
recreate()
}
}
}

@ -3,9 +3,16 @@ package com.novel.read.ui.theme
import android.os.Bundle
import com.novel.read.R
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?) {
}
}

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

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

@ -1,37 +1,44 @@
package com.novel.read.ui.widget.dialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import com.novel.read.R
import kotlinx.android.synthetic.main.dialog_go_appraise.*
class AppraiseDialog(context: Context) : Dialog(context, R.style.dialog) {
private val view: View = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null)
init {
view.setHasTransientState(true)
setContentView(
view, LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogGoAppraiseBinding
import com.novel.read.utils.ext.goShop
import com.novel.read.utils.viewbindingdelegate.viewBinding
class AppraiseDialog : BaseDialogFragment() {
private val binding by viewBinding(DialogGoAppraiseBinding::bind)
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
setCancelable(false)
initView()
}
private fun initView() {
val mTvCancel = findViewById<TextView>(R.id.tv_cancel)
mTvCancel.setOnClickListener { dismiss() }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_go_appraise, container)
}
fun appraiseDialog(receiveClickListener: View.OnClickListener) {
tv_appraise.setOnClickListener(receiveClickListener)
override fun onCreate(savedInstanceState: Bundle?) {
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 com.novel.read.R
import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogAutoReadBinding
import com.novel.read.help.ReadBookConfig
import com.novel.read.service.BaseReadAloudService
import com.novel.read.service.help.ReadAloud
import com.novel.read.utils.ColorUtils
import com.novel.read.utils.ext.bottomBackground
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
class AutoReadDialog : BaseDialogFragment() {
var callBack: CallBack? = null
private val binding by viewBinding(DialogAutoReadBinding::bind)
override fun onStart() {
super.onStart()
dialog?.window?.let {
@ -44,17 +47,17 @@ class AutoReadDialog : BaseDialogFragment() {
val bg = requireContext().bottomBackground
val isLight = ColorUtils.isColorLight(bg)
val textColor = requireContext().getPrimaryTextColor(isLight)
root_view.setBackgroundColor(bg)
tv_read_speed_title.setTextColor(textColor)
tv_read_speed.setTextColor(textColor)
iv_catalog.setColorFilter(textColor)
tv_catalog.setTextColor(textColor)
iv_main_menu.setColorFilter(textColor)
tv_main_menu.setTextColor(textColor)
iv_auto_page_stop.setColorFilter(textColor)
tv_auto_page_stop.setTextColor(textColor)
iv_setting.setColorFilter(textColor)
tv_setting.setTextColor(textColor)
binding.root.setBackgroundColor(bg)
binding.tvReadSpeedTitle.setTextColor(textColor)
binding.tvReadSpeed.setTextColor(textColor)
binding.ivCatalog.setColorFilter(textColor)
binding.tvCatalog.setTextColor(textColor)
binding.ivMainMenu.setColorFilter(textColor)
binding.tvMainMenu.setTextColor(textColor)
binding.ivAutoPageStop.setColorFilter(textColor)
binding.tvAutoPageStop.setTextColor(textColor)
binding.ivSetting.setColorFilter(textColor)
binding.tvSetting.setTextColor(textColor)
initOnChange()
initData()
initEvent()
@ -62,34 +65,34 @@ class AutoReadDialog : BaseDialogFragment() {
private fun initData() {
val speed = if (ReadBookConfig.autoReadSpeed < 10) 10 else ReadBookConfig.autoReadSpeed
tv_read_speed.text = String.format("%ds", speed)
seek_auto_read.progress = speed
binding.tvReadSpeed.text = String.format("%ds", speed)
binding.seekAutoRead.progress = speed
}
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) {
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 onStopTrackingTouch(seekBar: SeekBar) {
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()
}
})
}
private fun initEvent() {
ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() }
ll_setting.onClick {
binding.llMainMenu.onClick { callBack?.showMenuBar(); dismiss() }
binding.llSetting.onClick {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
}
ll_catalog.onClick { callBack?.openChapterList() }
ll_auto_page_stop.onClick {
binding.llCatalog.onClick { callBack?.openChapterList() }
binding.llAutoPageStop.onClick {
callBack?.autoPageStop()
dismiss()
}

@ -7,9 +7,10 @@ import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.novel.read.R
import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogPhotoViewBinding
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 kotlinx.android.synthetic.main.dialog_photo_view.*
class PhotoDialog : BaseDialogFragment() {
@ -30,6 +31,8 @@ class PhotoDialog : BaseDialogFragment() {
}
private val binding by viewBinding(DialogPhotoViewBinding::bind)
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
@ -56,7 +59,7 @@ class PhotoDialog : BaseDialogFragment() {
ImageProvider.getImage(book, chapterIndex, src)
}.onSuccess { bitmap ->
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 com.novel.read.R
import com.novel.read.base.BaseDialogFragment
import com.novel.read.databinding.DialogTextViewBinding
import com.novel.read.utils.ext.*
import com.novel.read.utils.viewbindingdelegate.viewBinding
import io.noties.markwon.Markwon
import io.noties.markwon.image.glide.GlideImagesPlugin
import kotlinx.android.synthetic.main.dialog_text_view.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -38,9 +39,8 @@ class TextDialog : BaseDialogFragment() {
}
}
private val binding by viewBinding(DialogTextViewBinding::bind)
private var time = 0L
private var autoClose: Boolean = false
override fun onStart() {
@ -61,23 +61,23 @@ class TextDialog : BaseDialogFragment() {
arguments?.let {
val content = it.getString("content") ?: ""
when (it.getInt("mode")) {
MD -> text_view.post {
MD -> binding.textView.post {
Markwon.builder(requireContext())
.usePlugin(GlideImagesPlugin.create(requireContext()))
.build()
.setMarkdown(text_view, content)
.setMarkdown(binding.textView, content)
}
else -> text_view.text = content
else -> binding.textView.text = content
}
time = it.getLong("time", 0L)
}
if (time > 0) {
badge_view.setBadgeCount((time / 1000).toInt())
binding.badgeView.setBadgeCount((time / 1000).toInt())
launch {
while (time > 0) {
delay(1000)
time -= 1000
badge_view.setBadgeCount((time / 1000).toInt())
binding.badgeView.setBadgeCount((time / 1000).toInt())
if (time <= 0) {
view.post {
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
android:id="@+id/lv_type"
android:id="@+id/rlv_type"
android:layout_width="90dp"
android:layout_height="0dp"
android:scrollbars="none"
@ -34,7 +34,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
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_constraintTop_toBottomOf="@+id/title_bar" />

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

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

Loading…
Cancel
Save