mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
91bc160859
commit
ca94be0521
@ -320,7 +320,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
observeEvent<Boolean>(EventBus.NOTIFY_MAIN) {
|
||||
binding.apply {
|
||||
upBottomMenu()
|
||||
viewPagerMain.adapter?.notifyDataSetChanged()
|
||||
if (it) {
|
||||
viewPagerMain.setCurrentItem(bottomMenuCount - 1, false)
|
||||
}
|
||||
@ -350,6 +349,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
index++
|
||||
realPositions[index] = idMy
|
||||
bottomMenuCount = index + 1
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun getFragmentId(position: Int): Int {
|
||||
@ -383,17 +383,27 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
return getFragmentId(position)
|
||||
}
|
||||
|
||||
override fun getItemPosition(`object`: Any): Int {
|
||||
override fun getItemPosition(any: Any): Int {
|
||||
val position = (any as MainFragmentInterface).position
|
||||
val fragmentId = getId(position)
|
||||
if ((fragmentId == idBookshelf1 && any is BookshelfFragment1)
|
||||
|| (fragmentId == idBookshelf2 && any is BookshelfFragment2)
|
||||
|| (fragmentId == idExplore && any is ExploreFragment)
|
||||
|| (fragmentId == idRss && any is RssFragment)
|
||||
|| (fragmentId == idMy && any is MyFragment)
|
||||
) {
|
||||
return POSITION_UNCHANGED
|
||||
}
|
||||
return POSITION_NONE
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (getId(position)) {
|
||||
idBookshelf1 -> BookshelfFragment1()
|
||||
idBookshelf2 -> BookshelfFragment2()
|
||||
idExplore -> ExploreFragment()
|
||||
idRss -> RssFragment()
|
||||
else -> MyFragment()
|
||||
idBookshelf1 -> BookshelfFragment1(position)
|
||||
idBookshelf2 -> BookshelfFragment2(position)
|
||||
idExplore -> ExploreFragment(position)
|
||||
idRss -> RssFragment(position)
|
||||
else -> MyFragment(position)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package io.legado.app.ui.main
|
||||
|
||||
interface MainFragmentInterface {
|
||||
|
||||
val position: Int
|
||||
|
||||
}
|
@ -26,10 +26,12 @@ import io.legado.app.ui.book.import.remote.RemoteBookActivity
|
||||
import io.legado.app.ui.book.manage.BookshelfManageActivity
|
||||
import io.legado.app.ui.book.search.SearchActivity
|
||||
import io.legado.app.ui.file.HandleFileContract
|
||||
import io.legado.app.ui.main.MainFragmentInterface
|
||||
import io.legado.app.ui.main.MainViewModel
|
||||
import io.legado.app.utils.*
|
||||
|
||||
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId) {
|
||||
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId),
|
||||
MainFragmentInterface {
|
||||
|
||||
val activityViewModel by activityViewModels<MainViewModel>()
|
||||
override val viewModel by viewModels<BookshelfViewModel>()
|
||||
@ -83,15 +85,19 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
R.id.menu_bookshelf_manage -> startActivity<BookshelfManageActivity> {
|
||||
putExtra("groupId", groupId)
|
||||
}
|
||||
|
||||
R.id.menu_download -> startActivity<CacheActivity> {
|
||||
putExtra("groupId", groupId)
|
||||
}
|
||||
|
||||
R.id.menu_export_bookshelf -> viewModel.exportBookshelf(books) { file ->
|
||||
exportResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = HandleFileContract.FileData("bookshelf.json", file, "application/json")
|
||||
fileData =
|
||||
HandleFileContract.FileData("bookshelf.json", file, "application/json")
|
||||
}
|
||||
}
|
||||
|
||||
R.id.menu_import_bookshelf -> importBookshelfAlert(groupId)
|
||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||
}
|
||||
|
@ -30,10 +30,18 @@ import kotlin.collections.set
|
||||
/**
|
||||
* 书架界面
|
||||
*/
|
||||
class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
TabLayout.OnTabSelectedListener,
|
||||
SearchView.OnQueryTextListener {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
||||
private val tabLayout: TabLayout by lazy {
|
||||
@ -134,8 +142,8 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
||||
* 确定视图位置是否更改时调用
|
||||
* @return POSITION_NONE 已更改,刷新视图. POSITION_UNCHANGED 未更改,不刷新视图
|
||||
*/
|
||||
override fun getItemPosition(`object`: Any): Int {
|
||||
val fragment = `object` as BooksFragment
|
||||
override fun getItemPosition(any: Any): Int {
|
||||
val fragment = any as BooksFragment
|
||||
val position = fragment.position
|
||||
val group = bookGroups.getOrNull(position)
|
||||
if (fragment.groupId != group?.groupId) {
|
||||
|
@ -42,10 +42,18 @@ import kotlin.math.max
|
||||
/**
|
||||
* 书架界面
|
||||
*/
|
||||
class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf2),
|
||||
class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2),
|
||||
SearchView.OnQueryTextListener,
|
||||
BaseBooksAdapter.CallBack {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf2Binding::bind)
|
||||
private val bookshelfLayout by lazy {
|
||||
getPrefInt(PreferKey.bookshelfLayout)
|
||||
|
@ -24,6 +24,7 @@ import io.legado.app.lib.theme.primaryTextColor
|
||||
import io.legado.app.ui.book.explore.ExploreShowActivity
|
||||
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
|
||||
import io.legado.app.ui.main.MainActivity
|
||||
import io.legado.app.ui.main.MainFragmentInterface
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.cnCompare
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
@ -42,8 +43,18 @@ import kotlinx.coroutines.launch
|
||||
/**
|
||||
* 发现界面
|
||||
*/
|
||||
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
|
||||
ExploreAdapter.CallBack, MainActivity.Callback {
|
||||
class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
|
||||
MainFragmentInterface,
|
||||
ExploreAdapter.CallBack,
|
||||
MainActivity.Callback {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
||||
|
||||
override val viewModel by viewModels<ExploreViewModel>()
|
||||
private val binding by viewBinding(FragmentExploreBinding::bind)
|
||||
|
@ -30,12 +30,29 @@ import io.legado.app.ui.config.ConfigActivity
|
||||
import io.legado.app.ui.config.ConfigTag
|
||||
import io.legado.app.ui.dict.rule.DictRuleActivity
|
||||
import io.legado.app.ui.file.FileManageActivity
|
||||
import io.legado.app.ui.main.MainFragmentInterface
|
||||
import io.legado.app.ui.replace.ReplaceRuleActivity
|
||||
import io.legado.app.ui.widget.dialog.TextDialog
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.LogUtils
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
import io.legado.app.utils.observeEventSticky
|
||||
import io.legado.app.utils.openUrl
|
||||
import io.legado.app.utils.putPrefBoolean
|
||||
import io.legado.app.utils.sendToClip
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
||||
class MyFragment() : BaseFragment(R.layout.fragment_my_config), MainFragmentInterface {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
||||
|
||||
private val binding by viewBinding(FragmentMyConfigBinding::bind)
|
||||
|
||||
@ -131,6 +148,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
||||
WebService.stop(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
"recordLog" -> LogUtils.upLevel()
|
||||
}
|
||||
}
|
||||
@ -145,12 +163,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
||||
"setting" -> startActivity<ConfigActivity> {
|
||||
putExtra("configTag", ConfigTag.OTHER_CONFIG)
|
||||
}
|
||||
|
||||
"web_dav_setting" -> startActivity<ConfigActivity> {
|
||||
putExtra("configTag", ConfigTag.BACKUP_CONFIG)
|
||||
}
|
||||
|
||||
"theme_setting" -> startActivity<ConfigActivity> {
|
||||
putExtra("configTag", ConfigTag.THEME_CONFIG)
|
||||
}
|
||||
|
||||
"fileManage" -> startActivity<FileManageActivity>()
|
||||
"readRecord" -> startActivity<ReadRecordActivity>()
|
||||
"donate" -> startActivity<DonateActivity>()
|
||||
|
@ -18,6 +18,7 @@ import io.legado.app.databinding.ItemRssBinding
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.lib.theme.primaryTextColor
|
||||
import io.legado.app.ui.main.MainFragmentInterface
|
||||
import io.legado.app.ui.rss.article.RssSortActivity
|
||||
import io.legado.app.ui.rss.favorites.RssFavoritesActivity
|
||||
import io.legado.app.ui.rss.read.ReadRssActivity
|
||||
@ -25,7 +26,12 @@ import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
|
||||
import io.legado.app.ui.rss.source.manage.RssSourceActivity
|
||||
import io.legado.app.ui.rss.source.manage.RssSourceViewModel
|
||||
import io.legado.app.ui.rss.subscription.RuleSubActivity
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.cnCompare
|
||||
import io.legado.app.utils.openUrl
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.catch
|
||||
@ -36,9 +42,18 @@ import kotlinx.coroutines.launch
|
||||
/**
|
||||
* 订阅界面
|
||||
*/
|
||||
class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
||||
class RssFragment() : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
||||
MainFragmentInterface,
|
||||
RssAdapter.CallBack {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
||||
|
||||
private val binding by viewBinding(FragmentRssBinding::bind)
|
||||
override val viewModel by viewModels<RssSourceViewModel>()
|
||||
private val adapter by lazy { RssAdapter(requireContext(), this) }
|
||||
|
Loading…
Reference in New Issue
Block a user