viewBinding

pull/517/head
gedoor 4 years ago
parent 5801607f4c
commit 95bf1d8330
  1. 14
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/about/AboutActivity.kt
  3. 4
      app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
  4. 4
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  6. 4
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  7. 4
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  8. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  9. 4
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  10. 4
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  12. 4
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt
  13. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  14. 4
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  15. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  16. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  17. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  18. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  19. 4
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  20. 4
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  21. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  22. 4
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt
  23. 4
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  24. 4
      app/src/main/java/io/legado/app/ui/login/SourceLogin.kt
  25. 4
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  26. 4
      app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt
  27. 4
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  28. 4
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  29. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  30. 4
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt
  31. 4
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  32. 4
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt
  33. 4
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  34. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  35. 4
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  36. 60
      app/src/main/java/io/legado/app/utils/viewbindingdelegate/ActivityViewBindings.kt

@ -5,7 +5,6 @@ import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -24,7 +23,6 @@ import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import java.lang.reflect.ParameterizedType
abstract class BaseActivity<VB : ViewBinding>( abstract class BaseActivity<VB : ViewBinding>(
@ -35,15 +33,7 @@ abstract class BaseActivity<VB : ViewBinding>(
) : AppCompatActivity(), ) : AppCompatActivity(),
CoroutineScope by MainScope() { CoroutineScope by MainScope() {
protected val binding: VB by lazy { protected val binding: VB by lazy { getViewBinding() }
//使用反射得到viewBinding的class
val type = javaClass.genericSuperclass as ParameterizedType
val aClass = type.actualTypeArguments[0] as Class<*>
val method = aClass.getDeclaredMethod("inflate", LayoutInflater::class.java)
@Suppress("UNCHECKED_CAST")
method.invoke(null, layoutInflater) as VB
}
val isInMultiWindow: Boolean val isInMultiWindow: Boolean
get() { get() {
@ -58,6 +48,8 @@ abstract class BaseActivity<VB : ViewBinding>(
super.attachBaseContext(LanguageUtils.setConfiguration(newBase)) super.attachBaseContext(LanguageUtils.setConfiguration(newBase))
} }
protected abstract fun getViewBinding(): VB
override fun onCreateView( override fun onCreateView(
parent: View?, parent: View?,
name: String, name: String,

@ -17,6 +17,10 @@ import org.jetbrains.anko.share
class AboutActivity : BaseActivity<ActivityAboutBinding>() { class AboutActivity : BaseActivity<ActivityAboutBinding>() {
override fun getViewBinding(): ActivityAboutBinding {
return ActivityAboutBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.llAbout.background = ATH.getDialogBackground() binding.llAbout.background = ATH.getDialogBackground()
val fTag = "aboutFragment" val fTag = "aboutFragment"

@ -13,6 +13,10 @@ import io.legado.app.databinding.ActivityDonateBinding
class DonateActivity : BaseActivity<ActivityDonateBinding>() { class DonateActivity : BaseActivity<ActivityDonateBinding>() {
override fun getViewBinding(): ActivityDonateBinding {
return ActivityDonateBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
val fTag = "donateFragment" val fTag = "donateFragment"
var donateFragment = supportFragmentManager.findFragmentByTag(fTag) var donateFragment = supportFragmentManager.findFragmentByTag(fTag)

@ -22,6 +22,10 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
lateinit var adapter: RecordAdapter lateinit var adapter: RecordAdapter
override fun getViewBinding(): ActivityReadRecordBinding {
return ActivityReadRecordBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
initData() initData()

@ -16,6 +16,10 @@ class FileAssociationActivity :
theme = Theme.Transparent theme = Theme.Transparent
) { ) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val viewModel: FileAssociationViewModel override val viewModel: FileAssociationViewModel
get() = getViewModel(FileAssociationViewModel::class.java) get() = getViewModel(FileAssociationViewModel::class.java)

@ -16,6 +16,10 @@ class ImportBookSourceActivity :
theme = Theme.Transparent theme = Theme.Transparent
) { ) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val viewModel: ImportBookSourceViewModel override val viewModel: ImportBookSourceViewModel
get() = getViewModel(ImportBookSourceViewModel::class.java) get() = getViewModel(ImportBookSourceViewModel::class.java)

@ -16,6 +16,10 @@ class ImportReplaceRuleActivity :
theme = Theme.Transparent theme = Theme.Transparent
) { ) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val viewModel: ImportReplaceRuleViewModel override val viewModel: ImportReplaceRuleViewModel
get() = getViewModel(ImportReplaceRuleViewModel::class.java) get() = getViewModel(ImportReplaceRuleViewModel::class.java)

@ -15,6 +15,10 @@ class ImportRssSourceActivity :
theme = Theme.Transparent theme = Theme.Transparent
) { ) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val viewModel: ImportRssSourceViewModel override val viewModel: ImportRssSourceViewModel
get() = getViewModel(ImportRssSourceViewModel::class.java) get() = getViewModel(ImportRssSourceViewModel::class.java)

@ -42,6 +42,10 @@ class AudioPlayActivity :
private var requestCodeChapter = 8461 private var requestCodeChapter = 8461
private var adjustProgress = false private var adjustProgress = false
override fun getViewBinding(): ActivityAudioPlayBinding {
return ActivityAudioPlayBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent() binding.titleBar.transparent()
AudioPlay.titleData.observe(this, { binding.titleBar.title = it }) AudioPlay.titleData.observe(this, { binding.titleBar.title = it })

@ -43,6 +43,10 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
private var menu: Menu? = null private var menu: Menu? = null
private var groupId: Long = -1 private var groupId: Long = -1
override fun getViewBinding(): ActivityArrangeBookBinding {
return ActivityArrangeBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
groupId = intent.getLongExtra("groupId", -1) groupId = intent.getLongExtra("groupId", -1)
binding.titleBar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all) binding.titleBar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all)

@ -48,6 +48,10 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
override val viewModel: CacheViewModel override val viewModel: CacheViewModel
get() = getViewModel(CacheViewModel::class.java) get() = getViewModel(CacheViewModel::class.java)
override fun getViewBinding(): ActivityCacheBookBinding {
return ActivityCacheBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
groupId = intent.getLongExtra("groupId", -1) groupId = intent.getLongExtra("groupId", -1)
binding.titleBar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all) binding.titleBar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all)

@ -24,6 +24,10 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
private lateinit var loadMoreView: LoadMoreView private lateinit var loadMoreView: LoadMoreView
private var isLoading = true private var isLoading = true
override fun getViewBinding(): ActivityExploreShowBinding {
return ActivityExploreShowBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.title = intent.getStringExtra("exploreName") binding.titleBar.title = intent.getStringExtra("exploreName")
initRecyclerView() initRecyclerView()

@ -57,6 +57,10 @@ class BookInfoActivity :
override val viewModel: BookInfoViewModel override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java) get() = getViewModel(BookInfoViewModel::class.java)
override fun getViewBinding(): ActivityBookInfoBinding {
return ActivityBookInfoBinding.inflate(layoutInflater)
}
@SuppressLint("PrivateResource") @SuppressLint("PrivateResource")
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent() binding.titleBar.transparent()

@ -28,6 +28,10 @@ class BookInfoEditActivity :
override val viewModel: BookInfoEditViewModel override val viewModel: BookInfoEditViewModel
get() = getViewModel(BookInfoEditViewModel::class.java) get() = getViewModel(BookInfoEditViewModel::class.java)
override fun getViewBinding(): ActivityBookInfoEditBinding {
return ActivityBookInfoEditBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.bookData.observe(this, { upView(it) }) viewModel.bookData.observe(this, { upView(it) })
if (viewModel.bookData.value == null) { if (viewModel.bookData.value == null) {

@ -52,6 +52,10 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
override val viewModel: ImportBookViewModel override val viewModel: ImportBookViewModel
get() = getViewModel(ImportBookViewModel::class.java) get() = getViewModel(ImportBookViewModel::class.java)
override fun getViewBinding(): ActivityImportBookBinding {
return ActivityImportBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
initEvent() initEvent()

@ -45,6 +45,10 @@ abstract class ReadBookBaseActivity :
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
var bottomDialog = 0 var bottomDialog = 0
override fun getViewBinding(): ActivityBookReadBinding {
return ActivityBookReadBinding.inflate(layoutInflater)
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null ReadBook.msg = null
setOrientation() setOrientation()

@ -52,6 +52,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private var precisionSearchMenuItem: MenuItem? = null private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>() private var groups = linkedSetOf<String>()
override fun getViewBinding(): ActivityBookSearchBinding {
return ActivityBookSearchBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.llHistory.setBackgroundColor(backgroundColor) binding.llHistory.setBackgroundColor(backgroundColor)
serchView = binding.titleBar.findViewById(R.id.search_view) serchView = binding.titleBar.findViewById(R.id.search_view)

@ -42,6 +42,10 @@ class SearchContentActivity :
private var durChapterIndex = 0 private var durChapterIndex = 0
private var searchResultList: MutableList<SearchResult> = mutableListOf() private var searchResultList: MutableList<SearchResult> = mutableListOf()
override fun getViewBinding(): ActivitySearchContentBinding {
return ActivitySearchContentBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view) searchView = binding.titleBar.findViewById(R.id.search_view)
val bbg = bottomBackground val bbg = bottomBackground

@ -25,6 +25,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
private lateinit var searchView: SearchView private lateinit var searchView: SearchView
private val qrRequestCode = 101 private val qrRequestCode = 101
override fun getViewBinding(): ActivitySourceDebugBinding {
return ActivitySourceDebugBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view) searchView = binding.titleBar.findViewById(R.id.search_view)
viewModel.init(intent.getStringExtra("key")) viewModel.init(intent.getStringExtra("key"))

@ -53,6 +53,10 @@ class BookSourceEditActivity :
private var mSoftKeyboardTool: PopupWindow? = null private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false private var mIsSoftKeyBoardShowing = false
override fun getViewBinding(): ActivityBookSourceEditBinding {
return ActivityBookSourceEditBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
viewModel.initData(intent) { viewModel.initData(intent) {

@ -67,6 +67,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var sortAscending = 0 private var sortAscending = 0
private var snackBar: Snackbar? = null private var snackBar: Snackbar? = null
override fun getViewBinding(): ActivityBookSourceBinding {
return ActivityBookSourceBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view) searchView = binding.titleBar.findViewById(R.id.search_view)
initRecyclerView() initRecyclerView()

@ -26,6 +26,10 @@ class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterLi
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
private var searchView: SearchView? = null private var searchView: SearchView? = null
override fun getViewBinding(): ActivityChapterListBinding {
return ActivityChapterListBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
tabLayout = binding.titleBar.findViewById(R.id.tab_layout) tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
tabLayout.isTabIndicatorFullWidth = false tabLayout.isTabIndicatorFullWidth = false

@ -12,6 +12,10 @@ class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>()
override val viewModel: ConfigViewModel override val viewModel: ConfigViewModel
get() = getViewModel(ConfigViewModel::class.java) get() = getViewModel(ConfigViewModel::class.java)
override fun getViewBinding(): ActivityConfigBinding {
return ActivityConfigBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
intent.getIntExtra("configType", -1).let { intent.getIntExtra("configType", -1).let {
if (it != -1) viewModel.configType = it if (it != -1) viewModel.configType = it

@ -21,6 +21,10 @@ class SourceLogin : BaseActivity<ActivitySourceLoginBinding>() {
var loginUrl: String? = null var loginUrl: String? = null
var checking = false var checking = false
override fun getViewBinding(): ActivitySourceLoginBinding {
return ActivitySourceLoginBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
sourceUrl = intent.getStringExtra("sourceUrl") sourceUrl = intent.getStringExtra("sourceUrl")
loginUrl = intent.getStringExtra("loginUrl") loginUrl = intent.getStringExtra("loginUrl")

@ -47,6 +47,10 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
private var pagePosition = 0 private var pagePosition = 0
private val fragmentMap = hashMapOf<Int, Fragment>() private val fragmentMap = hashMapOf<Int, Fragment>()
override fun getViewBinding(): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(binding.viewPagerMain) ATH.applyEdgeEffectColor(binding.viewPagerMain)
ATH.applyBottomNavigationColor(binding.bottomNavigationView) ATH.applyBottomNavigationColor(binding.bottomNavigationView)

@ -21,6 +21,10 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), QRCodeView.
private val requestQrImage = 202 private val requestQrImage = 202
private var flashlightIsOpen: Boolean = false private var flashlightIsOpen: Boolean = false
override fun getViewBinding(): ActivityQrcodeCaptureBinding {
return ActivityQrcodeCaptureBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.zXingView.setDelegate(this) binding.zXingView.setDelegate(this)
binding.fabFlashlight.setOnClickListener { binding.fabFlashlight.setOnClickListener {

@ -60,6 +60,10 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null private var replaceRuleLiveData: LiveData<List<ReplaceRule>>? = null
private var dataInit = false private var dataInit = false
override fun getViewBinding(): ActivityReplaceRuleBinding {
return ActivityReplaceRuleBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()

@ -52,6 +52,10 @@ class ReplaceEditActivity :
} }
} }
override fun getViewBinding(): ActivityReplaceEditBinding {
return ActivityReplaceEditBinding.inflate(layoutInflater)
}
override val viewModel: ReplaceEditViewModel override val viewModel: ReplaceEditViewModel
get() = getViewModel(ReplaceEditViewModel::class.java) get() = getViewModel(ReplaceEditViewModel::class.java)

@ -25,6 +25,10 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
private val fragments = linkedMapOf<String, RssArticlesFragment>() private val fragments = linkedMapOf<String, RssArticlesFragment>()
private lateinit var adapter: TabFragmentPageAdapter private lateinit var adapter: TabFragmentPageAdapter
override fun getViewBinding(): ActivityRssArtivlesBinding {
return ActivityRssArtivlesBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
adapter = TabFragmentPageAdapter(supportFragmentManager) adapter = TabFragmentPageAdapter(supportFragmentManager)
binding.tabLayout.setupWithViewPager(binding.viewPager) binding.tabLayout.setupWithViewPager(binding.viewPager)

@ -18,6 +18,10 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
private var liveData: LiveData<List<RssStar>>? = null private var liveData: LiveData<List<RssStar>>? = null
private lateinit var adapter: RssFavoritesAdapter private lateinit var adapter: RssFavoritesAdapter
override fun getViewBinding(): ActivityRssFavoritesBinding {
return ActivityRssFavoritesBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
initData() initData()

@ -43,6 +43,10 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null
private var webPic: String? = null private var webPic: String? = null
override fun getViewBinding(): ActivityRssReadBinding {
return ActivityRssReadBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.callBack = this viewModel.callBack = this
binding.titleBar.title = intent.getStringExtra("title") binding.titleBar.title = intent.getStringExtra("title")

@ -18,6 +18,10 @@ class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSou
private lateinit var adapter: RssSourceDebugAdapter private lateinit var adapter: RssSourceDebugAdapter
override fun getViewBinding(): ActivitySourceDebugBinding {
return ActivitySourceDebugBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()

@ -40,6 +40,10 @@ class RssSourceEditActivity :
private val adapter = RssSourceEditAdapter() private val adapter = RssSourceEditAdapter()
private val sourceEntities: ArrayList<EditEntity> = ArrayList() private val sourceEntities: ArrayList<EditEntity> = ArrayList()
override fun getViewBinding(): ActivityRssSourceEditBinding {
return ActivityRssSourceEditBinding.inflate(layoutInflater)
}
override val viewModel: RssSourceEditViewModel override val viewModel: RssSourceEditViewModel
get() = getViewModel(RssSourceEditViewModel::class.java) get() = getViewModel(RssSourceEditViewModel::class.java)

@ -60,6 +60,10 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private var groups = hashSetOf<String>() private var groups = hashSetOf<String>()
private var groupMenu: SubMenu? = null private var groupMenu: SubMenu? = null
override fun getViewBinding(): ActivityRssSourceBinding {
return ActivityRssSourceBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()

@ -20,6 +20,10 @@ import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() { open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
override fun getViewBinding(): ActivityWelcomeBinding {
return ActivityWelcomeBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.ivBook.setColorFilter(accentColor) binding.ivBook.setColorFilter(accentColor)
binding.vwTitleLine.setBackgroundColor(accentColor) binding.vwTitleLine.setBackgroundColor(accentColor)

@ -0,0 +1,60 @@
@file:Suppress("RedundantVisibilityModifier", "unused")
package io.legado.app.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
)
)
}
}
Loading…
Cancel
Save