优化
This commit is contained in:
@@ -320,7 +320,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
|||||||
observeEvent<Boolean>(EventBus.NOTIFY_MAIN) {
|
observeEvent<Boolean>(EventBus.NOTIFY_MAIN) {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
upBottomMenu()
|
upBottomMenu()
|
||||||
viewPagerMain.adapter?.notifyDataSetChanged()
|
|
||||||
if (it) {
|
if (it) {
|
||||||
viewPagerMain.setCurrentItem(bottomMenuCount - 1, false)
|
viewPagerMain.setCurrentItem(bottomMenuCount - 1, false)
|
||||||
}
|
}
|
||||||
@@ -350,6 +349,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
|||||||
index++
|
index++
|
||||||
realPositions[index] = idMy
|
realPositions[index] = idMy
|
||||||
bottomMenuCount = index + 1
|
bottomMenuCount = index + 1
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFragmentId(position: Int): Int {
|
private fun getFragmentId(position: Int): Int {
|
||||||
@@ -383,17 +383,27 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
|||||||
return getFragmentId(position)
|
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
|
return POSITION_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItem(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
return when (getId(position)) {
|
return when (getId(position)) {
|
||||||
idBookshelf1 -> BookshelfFragment1()
|
idBookshelf1 -> BookshelfFragment1(position)
|
||||||
idBookshelf2 -> BookshelfFragment2()
|
idBookshelf2 -> BookshelfFragment2(position)
|
||||||
idExplore -> ExploreFragment()
|
idExplore -> ExploreFragment(position)
|
||||||
idRss -> RssFragment()
|
idRss -> RssFragment(position)
|
||||||
else -> MyFragment()
|
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.manage.BookshelfManageActivity
|
||||||
import io.legado.app.ui.book.search.SearchActivity
|
import io.legado.app.ui.book.search.SearchActivity
|
||||||
import io.legado.app.ui.file.HandleFileContract
|
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.ui.main.MainViewModel
|
||||||
import io.legado.app.utils.*
|
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>()
|
val activityViewModel by activityViewModels<MainViewModel>()
|
||||||
override val viewModel by viewModels<BookshelfViewModel>()
|
override val viewModel by viewModels<BookshelfViewModel>()
|
||||||
@@ -83,15 +85,19 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
|||||||
R.id.menu_bookshelf_manage -> startActivity<BookshelfManageActivity> {
|
R.id.menu_bookshelf_manage -> startActivity<BookshelfManageActivity> {
|
||||||
putExtra("groupId", groupId)
|
putExtra("groupId", groupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.menu_download -> startActivity<CacheActivity> {
|
R.id.menu_download -> startActivity<CacheActivity> {
|
||||||
putExtra("groupId", groupId)
|
putExtra("groupId", groupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.menu_export_bookshelf -> viewModel.exportBookshelf(books) { file ->
|
R.id.menu_export_bookshelf -> viewModel.exportBookshelf(books) { file ->
|
||||||
exportResult.launch {
|
exportResult.launch {
|
||||||
mode = HandleFileContract.EXPORT
|
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_import_bookshelf -> importBookshelfAlert(groupId)
|
||||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
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,
|
TabLayout.OnTabSelectedListener,
|
||||||
SearchView.OnQueryTextListener {
|
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 binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||||
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
||||||
private val tabLayout: TabLayout by lazy {
|
private val tabLayout: TabLayout by lazy {
|
||||||
@@ -134,8 +142,8 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf1),
|
|||||||
* 确定视图位置是否更改时调用
|
* 确定视图位置是否更改时调用
|
||||||
* @return POSITION_NONE 已更改,刷新视图. POSITION_UNCHANGED 未更改,不刷新视图
|
* @return POSITION_NONE 已更改,刷新视图. POSITION_UNCHANGED 未更改,不刷新视图
|
||||||
*/
|
*/
|
||||||
override fun getItemPosition(`object`: Any): Int {
|
override fun getItemPosition(any: Any): Int {
|
||||||
val fragment = `object` as BooksFragment
|
val fragment = any as BooksFragment
|
||||||
val position = fragment.position
|
val position = fragment.position
|
||||||
val group = bookGroups.getOrNull(position)
|
val group = bookGroups.getOrNull(position)
|
||||||
if (fragment.groupId != group?.groupId) {
|
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,
|
SearchView.OnQueryTextListener,
|
||||||
BaseBooksAdapter.CallBack {
|
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 binding by viewBinding(FragmentBookshelf2Binding::bind)
|
||||||
private val bookshelfLayout by lazy {
|
private val bookshelfLayout by lazy {
|
||||||
getPrefInt(PreferKey.bookshelfLayout)
|
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.explore.ExploreShowActivity
|
||||||
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
|
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
|
||||||
import io.legado.app.ui.main.MainActivity
|
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.applyTint
|
||||||
import io.legado.app.utils.cnCompare
|
import io.legado.app.utils.cnCompare
|
||||||
import io.legado.app.utils.setEdgeEffectColor
|
import io.legado.app.utils.setEdgeEffectColor
|
||||||
@@ -42,8 +43,18 @@ import kotlinx.coroutines.launch
|
|||||||
/**
|
/**
|
||||||
* 发现界面
|
* 发现界面
|
||||||
*/
|
*/
|
||||||
class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
|
class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explore),
|
||||||
ExploreAdapter.CallBack, MainActivity.Callback {
|
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>()
|
override val viewModel by viewModels<ExploreViewModel>()
|
||||||
private val binding by viewBinding(FragmentExploreBinding::bind)
|
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.config.ConfigTag
|
||||||
import io.legado.app.ui.dict.rule.DictRuleActivity
|
import io.legado.app.ui.dict.rule.DictRuleActivity
|
||||||
import io.legado.app.ui.file.FileManageActivity
|
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.replace.ReplaceRuleActivity
|
||||||
import io.legado.app.ui.widget.dialog.TextDialog
|
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
|
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)
|
private val binding by viewBinding(FragmentMyConfigBinding::bind)
|
||||||
|
|
||||||
@@ -131,6 +148,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
|||||||
WebService.stop(requireContext())
|
WebService.stop(requireContext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"recordLog" -> LogUtils.upLevel()
|
"recordLog" -> LogUtils.upLevel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,12 +163,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
|
|||||||
"setting" -> startActivity<ConfigActivity> {
|
"setting" -> startActivity<ConfigActivity> {
|
||||||
putExtra("configTag", ConfigTag.OTHER_CONFIG)
|
putExtra("configTag", ConfigTag.OTHER_CONFIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
"web_dav_setting" -> startActivity<ConfigActivity> {
|
"web_dav_setting" -> startActivity<ConfigActivity> {
|
||||||
putExtra("configTag", ConfigTag.BACKUP_CONFIG)
|
putExtra("configTag", ConfigTag.BACKUP_CONFIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
"theme_setting" -> startActivity<ConfigActivity> {
|
"theme_setting" -> startActivity<ConfigActivity> {
|
||||||
putExtra("configTag", ConfigTag.THEME_CONFIG)
|
putExtra("configTag", ConfigTag.THEME_CONFIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
"fileManage" -> startActivity<FileManageActivity>()
|
"fileManage" -> startActivity<FileManageActivity>()
|
||||||
"readRecord" -> startActivity<ReadRecordActivity>()
|
"readRecord" -> startActivity<ReadRecordActivity>()
|
||||||
"donate" -> startActivity<DonateActivity>()
|
"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.dialogs.alert
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
import io.legado.app.lib.theme.primaryTextColor
|
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.article.RssSortActivity
|
||||||
import io.legado.app.ui.rss.favorites.RssFavoritesActivity
|
import io.legado.app.ui.rss.favorites.RssFavoritesActivity
|
||||||
import io.legado.app.ui.rss.read.ReadRssActivity
|
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.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.*
|
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 io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.catch
|
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 {
|
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)
|
private val binding by viewBinding(FragmentRssBinding::bind)
|
||||||
override val viewModel by viewModels<RssSourceViewModel>()
|
override val viewModel by viewModels<RssSourceViewModel>()
|
||||||
private val adapter by lazy { RssAdapter(requireContext(), this) }
|
private val adapter by lazy { RssAdapter(requireContext(), this) }
|
||||||
|
|||||||
Reference in New Issue
Block a user