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

@ -38,7 +38,7 @@ abstract class BaseActivity<VB : ViewBinding>(
) : AppCompatActivity(),
CoroutineScope by MainScope() {
protected val binding: VB by lazy { getViewBinding() }
protected abstract val binding: VB
val isInMultiWindow: Boolean
get() {
@ -53,8 +53,6 @@ abstract class BaseActivity<VB : ViewBinding>(
super.attachBaseContext(LanguageUtils.setConfiguration(newBase))
}
protected abstract fun getViewBinding(): VB
override fun onCreateView(
parent: View?,
name: String,

@ -13,13 +13,12 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.openUrl
import io.legado.app.utils.share
import io.legado.app.utils.viewbindingdelegate.viewBinding
class AboutActivity : BaseActivity<ActivityAboutBinding>() {
override fun getViewBinding(): ActivityAboutBinding {
return ActivityAboutBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityAboutBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.llAbout.background = ATH.getDialogBackground()

@ -5,6 +5,7 @@ import android.os.Bundle
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.databinding.ActivityDonateBinding
import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
* Created by GKF on 2018/1/13.
@ -13,9 +14,7 @@ import io.legado.app.databinding.ActivityDonateBinding
class DonateActivity : BaseActivity<ActivityDonateBinding>() {
override fun getViewBinding(): ActivityDonateBinding {
return ActivityDonateBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityDonateBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
val fTag = "donateFragment"

@ -18,6 +18,7 @@ import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.utils.cnCompare
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
@ -29,9 +30,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
lateinit var adapter: RecordAdapter
private var sortMode = 0
override fun getViewBinding(): ActivityReadRecordBinding {
return ActivityReadRecordBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityReadRecordBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()

@ -6,15 +6,14 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
class FileAssociationActivity :
VMBaseActivity<ActivityTranslucenceBinding, FileAssociationViewModel>(
theme = Theme.Transparent
) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel: FileAssociationViewModel by viewModels()

@ -10,6 +10,7 @@ import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ImportBookSourceActivity :
@ -17,9 +18,7 @@ class ImportBookSourceActivity :
theme = Theme.Transparent
) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel: ImportBookSourceViewModel
by viewModels()

@ -10,15 +10,14 @@ import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ImportReplaceRuleActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportReplaceRuleViewModel>(
theme = Theme.Transparent
) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel: ImportReplaceRuleViewModel
by viewModels()

@ -10,15 +10,14 @@ import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ImportRssSourceActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportRssSourceViewModel>(
theme = Theme.Transparent
) {
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
override val viewModel: ImportRssSourceViewModel
by viewModels()

@ -26,6 +26,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.cnCompare
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -36,6 +37,8 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
SelectActionBar.CallBack,
ArrangeBookAdapter.CallBack,
GroupSelectDialog.CallBack {
override val binding by viewBinding(ActivityArrangeBookBinding::inflate)
override val viewModel: ArrangeBookViewModel
by viewModels()
override val groupList: ArrayList<BookGroup> = arrayListOf()
@ -47,10 +50,6 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
private var menu: Menu? = null
private var groupId: Long = -1
override fun getViewBinding(): ActivityArrangeBookBinding {
return ActivityArrangeBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
groupId = intent.getLongExtra("groupId", -1)
launch {

@ -28,6 +28,7 @@ import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import splitties.views.onLongClick
import java.util.*
@ -38,6 +39,7 @@ class AudioPlayActivity :
VMBaseActivity<ActivityAudioPlayBinding, AudioPlayViewModel>(toolBarTheme = Theme.Dark),
ChangeSourceDialog.CallBack {
override val binding by viewBinding(ActivityAudioPlayBinding::inflate)
override val viewModel: AudioPlayViewModel
by viewModels()
@ -57,10 +59,6 @@ class AudioPlayActivity :
}
}
override fun getViewBinding(): ActivityAudioPlayBinding {
return ActivityAudioPlayBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent()
AudioPlay.titleData.observe(this, { binding.titleBar.title = it })

@ -28,6 +28,7 @@ import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.widget.dialog.TextListDialog
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
@ -58,13 +59,9 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private var exportPosition = -1
private val groupList: ArrayList<BookGroup> = arrayListOf()
private var groupId: Long = -1
override val binding by viewBinding(ActivityCacheBookBinding::inflate)
override val viewModel: CacheViewModel by viewModels()
override fun getViewBinding(): ActivityCacheBookBinding {
return ActivityCacheBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
groupId = intent.getLongExtra("groupId", -1)
launch {

@ -13,20 +13,17 @@ import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreShowViewModel>(),
ExploreShowAdapter.CallBack {
override val viewModel: ExploreShowViewModel
by viewModels()
override val binding by viewBinding(ActivityExploreShowBinding::inflate)
override val viewModel: ExploreShowViewModel by viewModels()
private lateinit var adapter: ExploreShowAdapter
private lateinit var loadMoreView: LoadMoreView
private var isLoading = true
override fun getViewBinding(): ActivityExploreShowBinding {
return ActivityExploreShowBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.title = intent.getStringExtra("exploreName")
initRecyclerView()

@ -38,6 +38,7 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -89,13 +90,9 @@ class BookInfoActivity :
}
}
override val binding by viewBinding(ActivityBookInfoBinding::inflate)
override val viewModel: BookInfoViewModel by viewModels()
override fun getViewBinding(): ActivityBookInfoBinding {
return ActivityBookInfoBinding.inflate(layoutInflater)
}
@SuppressLint("PrivateResource")
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent()

@ -16,6 +16,7 @@ import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
class BookInfoEditActivity :
@ -29,13 +30,10 @@ class BookInfoEditActivity :
}
}
override val binding by viewBinding(ActivityBookInfoEditBinding::inflate)
override val viewModel: BookInfoEditViewModel
by viewModels()
override fun getViewBinding(): ActivityBookInfoEditBinding {
return ActivityBookInfoEditBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.bookData.observe(this, { upView(it) })
if (viewModel.bookData.value == null) {

@ -17,13 +17,14 @@ import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.widget.SelectActionBar
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
@ -57,13 +58,10 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
}
}
override val binding by viewBinding(ActivityImportBookBinding::inflate)
override val viewModel: ImportBookViewModel
by viewModels()
override fun getViewBinding(): ActivityImportBookBinding {
return ActivityImportBookBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initEvent()

@ -34,6 +34,7 @@ import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.utils.getPrefString
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
* 阅读界面
@ -41,14 +42,11 @@ import io.legado.app.utils.requestInputMethod
abstract class ReadBookBaseActivity :
VMBaseActivity<ActivityBookReadBinding, ReadBookViewModel>(imageBg = false) {
override val binding by viewBinding(ActivityBookReadBinding::inflate)
override val viewModel: ReadBookViewModel
by viewModels()
var bottomDialog = 0
override fun getViewBinding(): ActivityBookReadBinding {
return ActivityBookReadBinding.inflate(layoutInflater)
}
override fun onCreate(savedInstanceState: Bundle?) {
ReadBook.msg = null
setOrientation()

@ -27,6 +27,7 @@ import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -36,6 +37,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
HistoryKeyAdapter.CallBack,
SearchAdapter.CallBack {
override val binding by viewBinding(ActivityBookSearchBinding::inflate)
override val viewModel: SearchViewModel
by viewModels()
@ -50,10 +52,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private var precisionSearchMenuItem: MenuItem? = null
private var groups = linkedSetOf<String>()
override fun getViewBinding(): ActivityBookSearchBinding {
return ActivityBookSearchBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.llHistory.setBackgroundColor(backgroundColor)
searchView = binding.titleBar.findViewById(R.id.search_view)

@ -23,6 +23,7 @@ import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -32,6 +33,7 @@ class SearchContentActivity :
VMBaseActivity<ActivitySearchContentBinding, SearchContentViewModel>(),
SearchContentAdapter.Callback {
override val binding by viewBinding(ActivitySearchContentBinding::inflate)
override val viewModel: SearchContentViewModel
by viewModels()
lateinit var adapter: SearchContentAdapter
@ -41,10 +43,6 @@ class SearchContentActivity :
private var durChapterIndex = 0
private var searchResultList: MutableList<SearchResult> = mutableListOf()
override fun getViewBinding(): ActivitySearchContentBinding {
return ActivitySearchContentBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view)
val bbg = bottomBackground

@ -14,10 +14,12 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {
override val binding by viewBinding(ActivitySourceDebugBinding::inflate)
override val viewModel: BookSourceDebugModel
by viewModels()
@ -29,10 +31,6 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
}
}
override fun getViewBinding(): ActivitySourceDebugBinding {
return ActivitySourceDebugBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view)
viewModel.init(intent.getStringExtra("key"))

@ -32,13 +32,15 @@ import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlin.math.abs
class BookSourceEditActivity :
VMBaseActivity<ActivityBookSourceEditBinding, BookSourceEditViewModel>(false),
KeyboardToolPop.CallBack {
override val viewModel: BookSourceEditViewModel
by viewModels()
override val binding by viewBinding(ActivityBookSourceEditBinding::inflate)
override val viewModel: BookSourceEditViewModel by viewModels()
private val adapter = BookSourceEditAdapter()
private val sourceEntities: ArrayList<EditEntity> = ArrayList()
@ -65,10 +67,6 @@ class BookSourceEditActivity :
private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false
override fun getViewBinding(): ActivityBookSourceEditBinding {
return ActivityBookSourceEditBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
viewModel.initData(intent) {

@ -39,6 +39,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
@ -46,8 +47,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
BookSourceAdapter.CallBack,
SelectActionBar.CallBack,
SearchView.OnQueryTextListener {
override val viewModel: BookSourceViewModel
by viewModels()
override val binding by viewBinding(ActivityBookSourceBinding::inflate)
override val viewModel: BookSourceViewModel by viewModels()
private val importRecordKey = "bookSourceRecordKey"
private lateinit var adapter: BookSourceAdapter
private lateinit var searchView: SearchView
@ -89,10 +90,6 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
override fun getViewBinding(): ActivityBookSourceBinding {
return ActivityBookSourceBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view)
initRecyclerView()

@ -19,20 +19,18 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.gone
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>() {
override val viewModel: TocViewModel
by viewModels()
override val binding by viewBinding(ActivityChapterListBinding::inflate)
override val viewModel: TocViewModel by viewModels()
private lateinit var tabLayout: TabLayout
private var searchView: SearchView? = null
override fun getViewBinding(): ActivityChapterListBinding {
return ActivityChapterListBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
tabLayout = binding.titleBar.findViewById(R.id.tab_layout)
tabLayout.isTabIndicatorFullWidth = false

@ -8,14 +8,12 @@ import io.legado.app.constant.EventBus
import io.legado.app.databinding.ActivityConfigBinding
import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>() {
override val viewModel: ConfigViewModel
by viewModels()
override fun getViewBinding(): ActivityConfigBinding {
return ActivityConfigBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityConfigBinding::inflate)
override val viewModel: ConfigViewModel by viewModels()
override fun onActivityCreated(savedInstanceState: Bundle?) {
intent.getIntExtra("configType", -1).let {

@ -14,6 +14,7 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
class FilePickerActivity :
@ -21,6 +22,8 @@ class FilePickerActivity :
theme = Theme.Transparent
), FilePickerDialog.CallBack {
override val binding by viewBinding(ActivityTranslucenceBinding::inflate)
private val selectDocTree =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) {
it ?: let {
@ -41,10 +44,6 @@ class FilePickerActivity :
onResult(Intent().setData(it))
}
override fun getViewBinding(): ActivityTranslucenceBinding {
return ActivityTranslucenceBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
val mode = intent.getIntExtra("mode", 0)
val allowExtensions = intent.getStringArrayExtra("allowExtensions")

@ -13,19 +13,17 @@ import io.legado.app.base.BaseActivity
import io.legado.app.databinding.ActivitySourceLoginBinding
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.snackbar
import io.legado.app.utils.viewbindingdelegate.viewBinding
class SourceLoginActivity : BaseActivity<ActivitySourceLoginBinding>() {
override val binding by viewBinding(ActivitySourceLoginBinding::inflate)
var sourceUrl: String? = null
var loginUrl: String? = null
var userAgent: String? = null
var checking = false
override fun getViewBinding(): ActivitySourceLoginBinding {
return ActivitySourceLoginBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
sourceUrl = intent.getStringExtra("sourceUrl")
loginUrl = intent.getStringExtra("loginUrl")

@ -36,11 +36,14 @@ import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.observeEvent
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
BottomNavigationView.OnNavigationItemSelectedListener,
BottomNavigationView.OnNavigationItemReselectedListener {
override val binding by viewBinding(ActivityMainBinding::inflate)
override val viewModel: MainViewModel by viewModels()
private var exitTime: Long = 0
private var bookshelfReselected: Long = 0
@ -50,10 +53,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
private var bottomMenuCount = 2
private val realPositions = arrayOf(0, 1, 2, 3)
override fun getViewBinding(): ActivityMainBinding {
return ActivityMainBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu()
binding.apply {

@ -13,9 +13,12 @@ import io.legado.app.base.BaseActivity
import io.legado.app.databinding.ActivityQrcodeCaptureBinding
import io.legado.app.utils.QRCodeUtils
import io.legado.app.utils.readBytes
import io.legado.app.utils.viewbindingdelegate.viewBinding
class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResultCallback {
override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate)
private val selectQrImage = registerForActivityResult(ActivityResultContracts.GetContent()) {
it.readBytes(this)?.let { bytes ->
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
@ -23,10 +26,6 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResul
}
}
override fun getViewBinding(): ActivityQrcodeCaptureBinding {
return ActivityQrcodeCaptureBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
val fTag = "qrCodeFragment"
val qrCodeFragment = QrCodeFragment()

@ -38,6 +38,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
/**
@ -48,6 +49,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
PopupMenu.OnMenuItemClickListener,
SelectActionBar.CallBack,
ReplaceRuleAdapter.CallBack {
override val binding by viewBinding(ActivityReplaceRuleBinding::inflate)
override val viewModel: ReplaceRuleViewModel by viewModels()
private val importRecordKey = "replaceRuleRecordKey"
private lateinit var adapter: ReplaceRuleAdapter
@ -93,10 +95,6 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
}
}
override fun getViewBinding(): ActivityReplaceRuleBinding {
return ActivityReplaceRuleBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
searchView = binding.titleBar.findViewById(R.id.search_view)
initRecyclerView()

@ -21,6 +21,7 @@ import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getSize
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlin.math.abs
/**
@ -50,10 +51,7 @@ class ReplaceEditActivity :
}
override fun getViewBinding(): ActivityReplaceEditBinding {
return ActivityReplaceEditBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityReplaceEditBinding::inflate)
override val viewModel: ReplaceEditViewModel
by viewModels()

@ -15,10 +15,12 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRssArtivlesBinding
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.gone
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() {
override val binding by viewBinding(ActivityRssArtivlesBinding::inflate)
override val viewModel: RssSortViewModel
by viewModels()
private lateinit var adapter: TabFragmentPageAdapter
@ -33,10 +35,6 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
}
}
override fun getViewBinding(): ActivityRssArtivlesBinding {
return ActivityRssArtivlesBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
adapter = TabFragmentPageAdapter()
binding.viewPager.adapter = adapter

@ -10,18 +10,16 @@ import io.legado.app.databinding.ActivityRssFavoritesBinding
import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
RssFavoritesAdapter.CallBack {
override val binding by viewBinding(ActivityRssFavoritesBinding::inflate)
private var liveData: LiveData<List<RssStar>>? = null
private lateinit var adapter: RssFavoritesAdapter
override fun getViewBinding(): ActivityRssFavoritesBinding {
return ActivityRssFavoritesBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initData()

@ -26,6 +26,7 @@ import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.document.FilePicker
import io.legado.app.ui.document.FilePickerParam
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch
import org.apache.commons.text.StringEscapeUtils
import org.jsoup.Jsoup
@ -35,8 +36,8 @@ import splitties.systemservices.downloadManager
class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>(false),
ReadRssViewModel.CallBack {
override val viewModel: ReadRssViewModel
by viewModels()
override val binding by viewBinding(ActivityRssReadBinding::inflate)
override val viewModel: ReadRssViewModel by viewModels()
private val imagePathKey = ""
private var starMenuItem: MenuItem? = null
private var ttsMenuItem: MenuItem? = null
@ -47,10 +48,6 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
viewModel.saveImage(webPic, it.toString())
}
override fun getViewBinding(): ActivityRssReadBinding {
return ActivityRssReadBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.callBack = this
binding.titleBar.title = intent.getStringExtra("title")

@ -14,20 +14,17 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.gone
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.launch
class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSourceDebugModel>() {
override val viewModel: RssSourceDebugModel
by viewModels()
override val binding by viewBinding(ActivitySourceDebugBinding::inflate)
override val viewModel: RssSourceDebugModel by viewModels()
private lateinit var adapter: RssSourceDebugAdapter
override fun getViewBinding(): ActivitySourceDebugBinding {
return ActivitySourceDebugBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
initSearchView()

@ -25,6 +25,7 @@ import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlin.math.abs
class RssSourceEditActivity :
@ -32,6 +33,7 @@ class RssSourceEditActivity :
ViewTreeObserver.OnGlobalLayoutListener,
KeyboardToolPop.CallBack {
override val binding by viewBinding(ActivityRssSourceEditBinding::inflate)
private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false
private val adapter = RssSourceEditAdapter()
@ -44,10 +46,6 @@ class RssSourceEditActivity :
}
}
override fun getViewBinding(): ActivityRssSourceEditBinding {
return ActivityRssSourceEditBinding.inflate(layoutInflater)
}
override val viewModel: RssSourceEditViewModel
by viewModels()

@ -34,6 +34,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
/**
@ -44,6 +45,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
SelectActionBar.CallBack,
RssSourceAdapter.CallBack {
override val binding by viewBinding(ActivityRssSourceBinding::inflate)
override val viewModel: RssSourceViewModel
by viewModels()
private val importRecordKey = "rssSourceRecordKey"
@ -82,10 +84,6 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}
}
override fun getViewBinding(): ActivityRssSourceBinding {
return ActivityRssSourceBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
initSearchView()

@ -19,6 +19,7 @@ import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -29,13 +30,10 @@ import kotlinx.coroutines.withContext
class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
RuleSubAdapter.Callback {
override val binding by viewBinding(ActivityRuleSubBinding::inflate)
private lateinit var adapter: RuleSubAdapter
private var liveData: LiveData<List<RuleSub>>? = null
override fun getViewBinding(): ActivityRuleSubBinding {
return ActivityRuleSubBinding.inflate(layoutInflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initData()

@ -15,13 +15,12 @@ import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
override fun getViewBinding(): ActivityWelcomeBinding {
return ActivityWelcomeBinding.inflate(layoutInflater)
}
override val binding by viewBinding(ActivityWelcomeBinding::inflate)
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.ivBook.setColorFilter(accentColor)

@ -2,59 +2,12 @@
package io.legado.app.utils.viewbindingdelegate
import android.view.View
import androidx.annotation.IdRes
import android.view.LayoutInflater
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
)
)
inline fun <T : ViewBinding> ComponentActivity.viewBinding(crossinline bindingInflater: (LayoutInflater) -> T) =
lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
val invoke = bindingInflater.invoke(layoutInflater)
invoke
}
}
Loading…
Cancel
Save