edit viewModel

pull/840/head
gedoor 4 years ago
parent 4c0bc940fe
commit 440edccdc4
  1. 6
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  2. 5
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  3. 9
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  4. 5
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  5. 5
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  6. 8
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  7. 3
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  8. 5
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  9. 3
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  10. 6
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  11. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  12. 5
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt
  13. 9
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  14. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  15. 3
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  16. 3
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  17. 3
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  18. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  19. 4
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  20. 4
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  21. 3
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  22. 5
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  23. 5
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  24. 3
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  25. 3
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  26. 9
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  27. 6
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  28. 5
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt
  29. 6
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  30. 5
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  31. 6
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  32. 10
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  33. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  34. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  35. 5
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  36. 4
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  37. 4
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  38. 5
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  39. 10
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  40. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  41. 3
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  42. 5
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt
  43. 3
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  44. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  45. 3
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  46. 18
      app/src/main/java/io/legado/app/utils/ViewModelKt.kt

@ -2,11 +2,12 @@ package io.legado.app.ui.association
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.ui.main.MainActivity import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -20,8 +21,7 @@ class FileAssociationActivity :
return ActivityTranslucenceBinding.inflate(layoutInflater) return ActivityTranslucenceBinding.inflate(layoutInflater)
} }
override val viewModel: FileAssociationViewModel override val viewModel: FileAssociationViewModel by viewModels()
get() = getViewModel(FileAssociationViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()

@ -1,13 +1,14 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@ -21,7 +22,7 @@ class ImportBookSourceActivity :
} }
override val viewModel: ImportBookSourceViewModel override val viewModel: ImportBookSourceViewModel
get() = getViewModel(ImportBookSourceViewModel::class.java) by viewModels()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()

@ -9,6 +9,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -23,8 +24,11 @@ import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.* import io.legado.app.utils.dp
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/** /**
@ -34,8 +38,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
val viewModel: ImportBookSourceViewModel val viewModel: ImportBookSourceViewModel by viewModels()
get() = getViewModelOfActivity(ImportBookSourceViewModel::class.java)
lateinit var adapter: SourcesAdapter lateinit var adapter: SourcesAdapter
override fun onStart() { override fun onStart() {

@ -1,6 +1,7 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
@ -8,7 +9,7 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
class ImportReplaceRuleActivity : class ImportReplaceRuleActivity :
@ -21,7 +22,7 @@ class ImportReplaceRuleActivity :
} }
override val viewModel: ImportReplaceRuleViewModel override val viewModel: ImportReplaceRuleViewModel
get() = getViewModel(ImportReplaceRuleViewModel::class.java) by viewModels()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()

@ -1,13 +1,14 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
class ImportRssSourceActivity : class ImportRssSourceActivity :
@ -20,7 +21,7 @@ class ImportRssSourceActivity :
} }
override val viewModel: ImportRssSourceViewModel override val viewModel: ImportRssSourceViewModel
get() = getViewModel(ImportRssSourceViewModel::class.java) by viewModels()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.show()

@ -9,6 +9,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -23,8 +24,11 @@ import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemSourceImportBinding import io.legado.app.databinding.ItemSourceImportBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.* import io.legado.app.utils.dp
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/** /**
* 导入rss源弹出窗口 * 导入rss源弹出窗口
@ -34,7 +38,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
val viewModel: ImportRssSourceViewModel val viewModel: ImportRssSourceViewModel
get() = getViewModelOfActivity(ImportRssSourceViewModel::class.java) by activityViewModels()
lateinit var adapter: SourcesAdapter lateinit var adapter: SourcesAdapter
override fun onStart() { override fun onStart() {

@ -9,6 +9,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.SeekBar import android.widget.SeekBar
import androidx.activity.viewModels
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions.bitmapTransform import com.bumptech.glide.request.RequestOptions.bitmapTransform
@ -39,7 +40,7 @@ class AudioPlayActivity :
ChangeSourceDialog.CallBack { ChangeSourceDialog.CallBack {
override val viewModel: AudioPlayViewModel override val viewModel: AudioPlayViewModel
get() = getViewModel(AudioPlayViewModel::class.java) by viewModels()
private var requestCodeChapter = 8461 private var requestCodeChapter = 8461
private var adjustProgress = false private var adjustProgress = false

@ -3,6 +3,7 @@ package io.legado.app.ui.book.arrange
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
@ -25,7 +26,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModel
class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBookViewModel>(), class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBookViewModel>(),
@ -34,7 +35,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
ArrangeBookAdapter.CallBack, ArrangeBookAdapter.CallBack,
GroupSelectDialog.CallBack { GroupSelectDialog.CallBack {
override val viewModel: ArrangeBookViewModel override val viewModel: ArrangeBookViewModel
get() = getViewModel(ArrangeBookViewModel::class.java) by viewModels()
override val groupList: ArrayList<BookGroup> = arrayListOf() override val groupList: ArrayList<BookGroup> = arrayListOf()
private val groupRequestCode = 22 private val groupRequestCode = 22
private val addToGroupRequestCode = 34 private val addToGroupRequestCode = 34

@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
@ -46,7 +47,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private var groupId: Long = -1 private var groupId: Long = -1
override val viewModel: CacheViewModel override val viewModel: CacheViewModel
get() = getViewModel(CacheViewModel::class.java) by viewModels()
override fun getViewBinding(): ActivityCacheBookBinding { override fun getViewBinding(): ActivityCacheBookBinding {
return ActivityCacheBookBinding.inflate(layoutInflater) return ActivityCacheBookBinding.inflate(layoutInflater)

@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
@ -14,7 +15,7 @@ import io.legado.app.databinding.DialogChangeCoverBinding
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize import io.legado.app.utils.getSize
import io.legado.app.utils.getViewModel
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -39,7 +40,7 @@ class ChangeCoverDialog : BaseDialogFragment(),
private val binding by viewBinding(DialogChangeCoverBinding::bind) private val binding by viewBinding(DialogChangeCoverBinding::bind)
private var callBack: CallBack? = null private var callBack: CallBack? = null
private lateinit var viewModel: ChangeCoverViewModel private val viewModel: ChangeCoverViewModel by viewModels()
lateinit var adapter: CoverAdapter lateinit var adapter: CoverAdapter
override fun onStart() { override fun onStart() {
@ -54,7 +55,6 @@ class ChangeCoverDialog : BaseDialogFragment(),
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
callBack = activity as? CallBack callBack = activity as? CallBack
viewModel = getViewModel(ChangeCoverViewModel::class.java)
return inflater.inflate(R.layout.dialog_change_cover, container) return inflater.inflate(R.layout.dialog_change_cover, container)
} }

@ -5,6 +5,7 @@ import android.view.*
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App import io.legado.app.App
@ -45,7 +46,7 @@ class ChangeSourceDialog : BaseDialogFragment(),
private val binding by viewBinding(DialogChangeSourceBinding::bind) private val binding by viewBinding(DialogChangeSourceBinding::bind)
private val groups = linkedSetOf<String>() private val groups = linkedSetOf<String>()
private var callBack: CallBack? = null private var callBack: CallBack? = null
private lateinit var viewModel: ChangeSourceViewModel private val viewModel: ChangeSourceViewModel by viewModels()
lateinit var adapter: ChangeSourceAdapter lateinit var adapter: ChangeSourceAdapter
override fun onStart() { override fun onStart() {
@ -60,7 +61,6 @@ class ChangeSourceDialog : BaseDialogFragment(),
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
callBack = activity as? CallBack callBack = activity as? CallBack
viewModel = getViewModel(ChangeSourceViewModel::class.java)
return inflater.inflate(R.layout.dialog_change_source, container) return inflater.inflate(R.layout.dialog_change_source, container)
} }

@ -1,6 +1,7 @@
package io.legado.app.ui.book.explore package io.legado.app.ui.book.explore
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -11,13 +12,13 @@ import io.legado.app.databinding.ViewLoadMoreBinding
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.getViewModel
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreShowViewModel>(), class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreShowViewModel>(),
ExploreShowAdapter.CallBack { ExploreShowAdapter.CallBack {
override val viewModel: ExploreShowViewModel override val viewModel: ExploreShowViewModel
get() = getViewModel(ExploreShowViewModel::class.java) by viewModels()
private lateinit var adapter: ExploreShowAdapter private lateinit var adapter: ExploreShowAdapter
private lateinit var loadMoreView: LoadMoreView private lateinit var loadMoreView: LoadMoreView

@ -8,6 +8,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -26,12 +27,15 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: GroupViewModel private val viewModel: GroupViewModel by viewModels()
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -46,7 +50,6 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModel(GroupViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container) return inflater.inflate(R.layout.dialog_recycler_view, container)
} }

@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -29,7 +30,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize import io.legado.app.utils.getSize
import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -52,7 +53,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private val binding by viewBinding(DialogBookGroupPickerBinding::bind) private val binding by viewBinding(DialogBookGroupPickerBinding::bind)
private var requestCode: Int = -1 private var requestCode: Int = -1
private lateinit var viewModel: GroupViewModel private val viewModel: GroupViewModel by viewModels()
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private var callBack: CallBack? = null private var callBack: CallBack? = null
private var groupId: Long = 0 private var groupId: Long = 0
@ -68,7 +69,6 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModel(GroupViewModel::class.java)
return inflater.inflate(R.layout.dialog_book_group_picker, container) return inflater.inflate(R.layout.dialog_book_group_picker, container)
} }

@ -9,6 +9,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.CheckBox import android.widget.CheckBox
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.activity.viewModels
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions.bitmapTransform import com.bumptech.glide.request.RequestOptions.bitmapTransform
@ -53,7 +54,7 @@ class BookInfoActivity :
private val requestCodeRead = 432 private val requestCodeRead = 432
override val viewModel: BookInfoViewModel override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java) by viewModels()
override fun getViewBinding(): ActivityBookInfoBinding { override fun getViewBinding(): ActivityBookInfoBinding {
return ActivityBookInfoBinding.inflate(layoutInflater) return ActivityBookInfoBinding.inflate(layoutInflater)

@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -24,7 +25,7 @@ class BookInfoEditActivity :
private val resultSelectCover = 132 private val resultSelectCover = 132
override val viewModel: BookInfoEditViewModel override val viewModel: BookInfoEditViewModel
get() = getViewModel(BookInfoEditViewModel::class.java) by viewModels()
override fun getViewBinding(): ActivityBookInfoEditBinding { override fun getViewBinding(): ActivityBookInfoEditBinding {
return ActivityBookInfoEditBinding.inflate(layoutInflater) return ActivityBookInfoEditBinding.inflate(layoutInflater)

@ -8,6 +8,7 @@ import android.os.Bundle
import android.provider.DocumentsContract import android.provider.DocumentsContract
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@ -48,7 +49,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private var path = sdPath private var path = sdPath
override val viewModel: ImportBookViewModel override val viewModel: ImportBookViewModel
get() = getViewModel(ImportBookViewModel::class.java) by viewModels()
override fun getViewBinding(): ActivityImportBookBinding { override fun getViewBinding(): ActivityImportBookBinding {
return ActivityImportBookBinding.inflate(layoutInflater) return ActivityImportBookBinding.inflate(layoutInflater)

@ -6,6 +6,7 @@ import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import androidx.activity.viewModels
import androidx.core.view.isVisible import androidx.core.view.isVisible
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -31,7 +32,7 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog
import io.legado.app.ui.book.read.config.ClickActionConfigDialog import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
/** /**
@ -41,7 +42,7 @@ abstract class ReadBookBaseActivity :
VMBaseActivity<ActivityBookReadBinding, ReadBookViewModel>() { VMBaseActivity<ActivityBookReadBinding, ReadBookViewModel>() {
override val viewModel: ReadBookViewModel override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java) by viewModels()
var bottomDialog = 0 var bottomDialog = 0
override fun getViewBinding(): ActivityBookReadBinding { override fun getViewBinding(): ActivityBookReadBinding {

@ -8,6 +8,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
@ -32,7 +33,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
lateinit var adapter: Adapter lateinit var adapter: Adapter
lateinit var viewModel: SpeakEngineViewModel private val viewModel: SpeakEngineViewModel by viewModels()
private var httpTTSData: LiveData<List<HttpTTS>>? = null private var httpTTSData: LiveData<List<HttpTTS>>? = null
var engineId = App.INSTANCE.getPrefLong(PreferKey.speakEngine) var engineId = App.INSTANCE.getPrefLong(PreferKey.speakEngine)
@ -47,7 +48,6 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModel(SpeakEngineViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container) return inflater.inflate(R.layout.dialog_recycler_view, container)
} }

@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -42,7 +43,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private var tocRegexLiveData: LiveData<List<TxtTocRule>>? = null private var tocRegexLiveData: LiveData<List<TxtTocRule>>? = null
var selectedName: String? = null var selectedName: String? = null
private var durRegex: String? = null private var durRegex: String? = null
lateinit var viewModel: TocRegexViewModel private val viewModel: TocRegexViewModel by viewModels()
private val binding by viewBinding(DialogTocRegexBinding::bind) private val binding by viewBinding(DialogTocRegexBinding::bind)
override fun onStart() { override fun onStart() {
@ -56,7 +57,6 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModel(TocRegexViewModel::class.java)
return inflater.inflate(R.layout.dialog_toc_regex, container) return inflater.inflate(R.layout.dialog_toc_regex, container)
} }

@ -6,6 +6,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -37,7 +38,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
SearchAdapter.CallBack { SearchAdapter.CallBack {
override val viewModel: SearchViewModel override val viewModel: SearchViewModel
get() = getViewModel(SearchViewModel::class.java) by viewModels()
lateinit var adapter: SearchAdapter lateinit var adapter: SearchAdapter
private lateinit var bookAdapter: BookAdapter private lateinit var bookAdapter: BookAdapter

@ -3,6 +3,7 @@ package io.legado.app.ui.book.searchContent
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
@ -21,7 +22,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -33,7 +34,7 @@ class SearchContentActivity :
SearchContentAdapter.Callback { SearchContentAdapter.Callback {
override val viewModel: SearchContentViewModel override val viewModel: SearchContentViewModel
get() = getViewModel(SearchContentViewModel::class.java) by viewModels()
lateinit var adapter: SearchContentAdapter lateinit var adapter: SearchContentAdapter
private lateinit var mLayoutManager: UpLinearLayoutManager private lateinit var mLayoutManager: UpLinearLayoutManager
private lateinit var searchView: SearchView private lateinit var searchView: SearchView

@ -4,6 +4,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -13,7 +14,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
@ -21,7 +22,7 @@ import org.jetbrains.anko.startActivityForResult
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() { class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {
override val viewModel: BookSourceDebugModel override val viewModel: BookSourceDebugModel
get() = getViewModel(BookSourceDebugModel::class.java) by viewModels()
private lateinit var adapter: BookSourceDebugAdapter private lateinit var adapter: BookSourceDebugAdapter
private lateinit var searchView: SearchView private lateinit var searchView: SearchView

@ -10,6 +10,7 @@ import android.view.MenuItem
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.EditText import android.widget.EditText
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import io.legado.app.R import io.legado.app.R
@ -38,7 +39,7 @@ class BookSourceEditActivity :
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
KeyboardToolPop.CallBack { KeyboardToolPop.CallBack {
override val viewModel: BookSourceEditViewModel override val viewModel: BookSourceEditViewModel
get() = getViewModel(BookSourceEditViewModel::class.java) by viewModels()
private val qrRequestCode = 101 private val qrRequestCode = 101
private val selectPathRequestCode = 102 private val selectPathRequestCode = 102

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
@ -49,7 +50,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
SelectActionBar.CallBack, SelectActionBar.CallBack,
SearchView.OnQueryTextListener { SearchView.OnQueryTextListener {
override val viewModel: BookSourceViewModel override val viewModel: BookSourceViewModel
get() = getViewModel(BookSourceViewModel::class.java) by viewModels()
private val importRecordKey = "bookSourceRecordKey" private val importRecordKey = "bookSourceRecordKey"
private val qrRequestCode = 101 private val qrRequestCode = 101
private val importRequestCode = 132 private val importRequestCode = 132

@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -22,12 +23,15 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: BookSourceViewModel private val viewModel: BookSourceViewModel by activityViewModels()
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -42,7 +46,6 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModelOfActivity(BookSourceViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container) return inflater.inflate(R.layout.dialog_recycler_view, container)
} }

@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.paging.LivePagedListBuilder import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList import androidx.paging.PagedList
@ -19,7 +20,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -27,8 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark), class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark),
BookmarkAdapter.Callback, BookmarkAdapter.Callback,
ChapterListViewModel.BookmarkCallBack { ChapterListViewModel.BookmarkCallBack {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel by activityViewModels()
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private val binding by viewBinding(FragmentBookmarkBinding::bind) private val binding by viewBinding(FragmentBookmarkBinding::bind)
private lateinit var adapter: BookmarkAdapter private lateinit var adapter: BookmarkAdapter
private var bookmarkLiveData: LiveData<PagedList<Bookmark>>? = null private var bookmarkLiveData: LiveData<PagedList<Bookmark>>? = null

@ -2,6 +2,7 @@ package io.legado.app.ui.book.toc
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -14,14 +15,14 @@ import io.legado.app.databinding.ActivityChapterListBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterListViewModel>() { class ChapterListActivity : VMBaseActivity<ActivityChapterListBinding, ChapterListViewModel>() {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel
get() = getViewModel(ChapterListViewModel::class.java) by viewModels()
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
private var searchView: SearchView? = null private var searchView: SearchView? = null

@ -5,6 +5,7 @@ import android.app.Activity.RESULT_OK
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -19,7 +20,7 @@ import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -32,8 +33,7 @@ import kotlin.math.min
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list), class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list),
ChapterListAdapter.Callback, ChapterListAdapter.Callback,
ChapterListViewModel.ChapterListCallBack { ChapterListViewModel.ChapterListCallBack {
override val viewModel: ChapterListViewModel override val viewModel: ChapterListViewModel by activityViewModels()
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private val binding by viewBinding(FragmentChapterListBinding::bind) private val binding by viewBinding(FragmentChapterListBinding::bind)
lateinit var adapter: ChapterListAdapter lateinit var adapter: ChapterListAdapter
private var durChapterIndex = 0 private var durChapterIndex = 0

@ -1,16 +1,17 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.databinding.ActivityConfigBinding import io.legado.app.databinding.ActivityConfigBinding
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>() { class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>() {
override val viewModel: ConfigViewModel override val viewModel: ConfigViewModel
get() = getViewModel(ConfigViewModel::class.java) by viewModels()
override fun getViewBinding(): ActivityConfigBinding { override fun getViewBinding(): ActivityConfigBinding {
return ActivityConfigBinding.inflate(layoutInflater) return ActivityConfigBinding.inflate(layoutInflater)

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.KeyEvent import android.view.KeyEvent
import android.view.MenuItem import android.view.MenuItem
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
@ -29,7 +30,7 @@ import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getViewModel
import io.legado.app.utils.hideSoftInput import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@ -39,8 +40,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
BottomNavigationView.OnNavigationItemSelectedListener, BottomNavigationView.OnNavigationItemSelectedListener,
BottomNavigationView.OnNavigationItemReselectedListener, BottomNavigationView.OnNavigationItemReselectedListener,
ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() {
override val viewModel: MainViewModel override val viewModel: MainViewModel by viewModels()
get() = getViewModel(MainViewModel::class.java)
private var exitTime: Long = 0 private var exitTime: Long = 0
private var bookshelfReselected: Long = 0 private var bookshelfReselected: Long = 0
private var exploreReselected: Long = 0 private var exploreReselected: Long = 0

@ -9,9 +9,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment import androidx.fragment.app.*
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import io.legado.app.App import io.legado.app.App
@ -49,10 +47,8 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private val requestCodeImportBookshelf = 312 private val requestCodeImportBookshelf = 312
private val binding by viewBinding(FragmentBookshelfBinding::bind) private val binding by viewBinding(FragmentBookshelfBinding::bind)
override val viewModel: BookshelfViewModel override val viewModel: BookshelfViewModel by viewModels()
get() = getViewModel(BookshelfViewModel::class.java) private val activityViewModel: MainViewModel by activityViewModels()
private val activityViewModel: MainViewModel
get() = getViewModelOfActivity(MainViewModel::class.java)
private lateinit var adapter: FragmentStatePagerAdapter private lateinit var adapter: FragmentStatePagerAdapter
private lateinit var tabLayout: TabLayout private lateinit var tabLayout: TabLayout
private var bookGroupLiveData: LiveData<List<BookGroup>>? = null private var bookGroupLiveData: LiveData<List<BookGroup>>? = null

@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf.books
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -24,7 +25,10 @@ import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.* import io.legado.app.utils.cnCompare
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.observeEvent
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlin.math.max import kotlin.math.max
@ -47,7 +51,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private val binding by viewBinding(FragmentBooksBinding::bind) private val binding by viewBinding(FragmentBooksBinding::bind)
private val activityViewModel: MainViewModel private val activityViewModel: MainViewModel
get() = getViewModelOfActivity(MainViewModel::class.java) by activityViewModels()
private lateinit var booksAdapter: BaseBooksAdapter<*> private lateinit var booksAdapter: BaseBooksAdapter<*>
private var bookshelfLiveData: LiveData<List<Book>>? = null private var bookshelfLiveData: LiveData<List<Book>>? = null
private var position = 0 private var position = 0

@ -7,6 +7,7 @@ import android.view.SubMenu
import android.view.View import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -23,7 +24,7 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.explore.ExploreShowActivity import io.legado.app.ui.book.explore.ExploreShowActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -33,8 +34,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
*/ */
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore), class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
ExploreAdapter.CallBack { ExploreAdapter.CallBack {
override val viewModel: ExploreViewModel override val viewModel: ExploreViewModel by viewModels()
get() = getViewModel(ExploreViewModel::class.java)
private val binding by viewBinding(FragmentExploreBinding::bind) private val binding by viewBinding(FragmentExploreBinding::bind)
private lateinit var adapter: ExploreAdapter private lateinit var adapter: ExploreAdapter
private lateinit var linearLayoutManager: LinearLayoutManager private lateinit var linearLayoutManager: LinearLayoutManager

@ -6,6 +6,7 @@ import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import android.view.View import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -24,7 +25,7 @@ import io.legado.app.ui.rss.source.manage.RssSourceActivity
import io.legado.app.ui.rss.source.manage.RssSourceViewModel import io.legado.app.ui.rss.source.manage.RssSourceViewModel
import io.legado.app.ui.rss.subscription.RuleSubActivity import io.legado.app.ui.rss.subscription.RuleSubActivity
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -39,7 +40,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private lateinit var adapter: RssAdapter private lateinit var adapter: RssAdapter
private lateinit var searchView: SearchView private lateinit var searchView: SearchView
override val viewModel: RssSourceViewModel override val viewModel: RssSourceViewModel
get() = getViewModel(RssSourceViewModel::class.java) by viewModels()
private var liveRssData: LiveData<List<RssSource>>? = null private var liveRssData: LiveData<List<RssSource>>? = null
private val groups = linkedSetOf<String>() private val groups = linkedSetOf<String>()
private var liveGroup: LiveData<List<String>>? = null private var liveGroup: LiveData<List<String>>? = null

@ -9,6 +9,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -27,7 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: ReplaceRuleViewModel private val viewModel: ReplaceRuleViewModel by activityViewModels()
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -42,7 +43,6 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModelOfActivity(ReplaceRuleViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container) return inflater.inflate(R.layout.dialog_recycler_view, container)
} }

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
@ -50,8 +51,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
SelectActionBar.CallBack, SelectActionBar.CallBack,
ReplaceRuleAdapter.CallBack { ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel override val viewModel: ReplaceRuleViewModel by viewModels()
get() = getViewModel(ReplaceRuleViewModel::class.java)
private val importRecordKey = "replaceRuleRecordKey" private val importRecordKey = "replaceRuleRecordKey"
private val importRequestCode = 132 private val importRequestCode = 132
private val importRequestCodeQr = 133 private val importRequestCodeQr = 133

@ -10,6 +10,7 @@ import android.view.MenuItem
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.EditText import android.widget.EditText
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
@ -18,7 +19,7 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceEditBinding import io.legado.app.databinding.ActivityReplaceEditBinding
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getViewModel
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.displayMetrics
@ -56,7 +57,7 @@ class ReplaceEditActivity :
} }
override val viewModel: ReplaceEditViewModel override val viewModel: ReplaceEditViewModel
get() = getViewModel(ReplaceEditViewModel::class.java) by viewModels()
private var mSoftKeyboardTool: PopupWindow? = null private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false private var mIsSoftKeyBoardShowing = false

@ -2,6 +2,8 @@ package io.legado.app.ui.rss.article
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -16,8 +18,8 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.getViewModel
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -37,9 +39,9 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
private val binding by viewBinding(FragmentRssArticlesBinding::bind) private val binding by viewBinding(FragmentRssArticlesBinding::bind)
private val activityViewModel: RssSortViewModel private val activityViewModel: RssSortViewModel
get() = getViewModelOfActivity(RssSortViewModel::class.java) by activityViewModels()
override val viewModel: RssArticlesViewModel override val viewModel: RssArticlesViewModel
get() = getViewModel(RssArticlesViewModel::class.java) by viewModels()
lateinit var adapter: BaseRssArticlesAdapter<*> lateinit var adapter: BaseRssArticlesAdapter<*>
private lateinit var loadMoreView: LoadMoreView private lateinit var loadMoreView: LoadMoreView
private var rssArticlesData: LiveData<List<RssArticle>>? = null private var rssArticlesData: LiveData<List<RssArticle>>? = null

@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.viewModels
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
@ -12,7 +13,7 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRssArtivlesBinding import io.legado.app.databinding.ActivityRssArtivlesBinding
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
@ -20,7 +21,7 @@ import org.jetbrains.anko.startActivityForResult
class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() { class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() {
override val viewModel: RssSortViewModel override val viewModel: RssSortViewModel
get() = getViewModel(RssSortViewModel::class.java) by viewModels()
private val editSource = 12319 private val editSource = 12319
private val fragments = linkedMapOf<String, RssArticlesFragment>() private val fragments = linkedMapOf<String, RssArticlesFragment>()
private lateinit var adapter: TabFragmentPageAdapter private lateinit var adapter: TabFragmentPageAdapter

@ -10,6 +10,7 @@ import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.view.* import android.view.*
import android.webkit.* import android.webkit.*
import androidx.activity.viewModels
import androidx.core.view.size import androidx.core.view.size
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -34,7 +35,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
ReadRssViewModel.CallBack { ReadRssViewModel.CallBack {
override val viewModel: ReadRssViewModel override val viewModel: ReadRssViewModel
get() = getViewModel(ReadRssViewModel::class.java) by viewModels()
private val savePathRequestCode = 132 private val savePathRequestCode = 132
private val imagePathKey = "" private val imagePathKey = ""
private var starMenuItem: MenuItem? = null private var starMenuItem: MenuItem? = null

@ -2,12 +2,13 @@ package io.legado.app.ui.rss.source.debug
import android.os.Bundle import android.os.Bundle
import android.widget.SearchView import android.widget.SearchView
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivitySourceDebugBinding import io.legado.app.databinding.ActivitySourceDebugBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -16,7 +17,7 @@ import kotlinx.coroutines.launch
class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSourceDebugModel>() { class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSourceDebugModel>() {
override val viewModel: RssSourceDebugModel override val viewModel: RssSourceDebugModel
get() = getViewModel(RssSourceDebugModel::class.java) by viewModels()
private lateinit var adapter: RssSourceDebugAdapter private lateinit var adapter: RssSourceDebugAdapter

@ -10,6 +10,7 @@ import android.view.MenuItem
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.EditText import android.widget.EditText
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.activity.viewModels
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
@ -42,7 +43,7 @@ class RssSourceEditActivity :
} }
override val viewModel: RssSourceEditViewModel override val viewModel: RssSourceEditViewModel
get() = getViewModel(RssSourceEditViewModel::class.java) by viewModels()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()

@ -8,6 +8,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -27,7 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: RssSourceViewModel private val viewModel: RssSourceViewModel by activityViewModels()
private lateinit var adapter: GroupAdapter private lateinit var adapter: GroupAdapter
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -42,7 +43,6 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
viewModel = getViewModelOfActivity(RssSourceViewModel::class.java)
return inflater.inflate(R.layout.dialog_recycler_view, container) return inflater.inflate(R.layout.dialog_recycler_view, container)
} }

@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import androidx.activity.viewModels
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
@ -46,7 +47,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
RssSourceAdapter.CallBack { RssSourceAdapter.CallBack {
override val viewModel: RssSourceViewModel override val viewModel: RssSourceViewModel
get() = getViewModel(RssSourceViewModel::class.java) by viewModels()
private val importRecordKey = "rssSourceRecordKey" private val importRecordKey = "rssSourceRecordKey"
private val qrRequestCode = 101 private val qrRequestCode = 101
private val importRequestCode = 124 private val importRequestCode = 124

@ -1,18 +0,0 @@
package io.legado.app.utils
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
fun <T : ViewModel> AppCompatActivity.getViewModel(clazz: Class<T>) =
ViewModelProvider(this).get(clazz)
fun <T : ViewModel> Fragment.getViewModel(clazz: Class<T>) =
ViewModelProvider(this).get(clazz)
/**
* 与activity数据同步
*/
fun <T : ViewModel> Fragment.getViewModelOfActivity(clazz: Class<T>) =
ViewModelProvider(requireActivity()).get(clazz)
Loading…
Cancel
Save