Optimize ManagePageManager

This commit is contained in:
ShirosakiMio 2024-09-09 16:31:49 +08:00
parent d0797720eb
commit b464282f4a
3 changed files with 121 additions and 82 deletions

View File

@ -18,7 +18,7 @@ public abstract class PageManager {
private final FCLUILayout parent;
private final int defaultPageId;
private final ArrayList<FCLCommonPage> allPages;
public final ArrayList<FCLCommonPage> allPages;
private FCLCommonPage currentPage;
public PageManager (Context context, FCLUILayout parent, int defaultPageId, UIListener listener) {
@ -53,6 +53,10 @@ public abstract class PageManager {
public abstract ArrayList<FCLCommonPage> getAllPages();
public FCLCommonPage createPageById(int id){
return null;
}
public FCLCommonPage getPageById(int id) {
for (FCLCommonPage page : allPages) {
if (page.getId() == id) {
@ -66,7 +70,10 @@ public abstract class PageManager {
if (allPages.size() > 0) {
FCLCommonPage targetPage = getPageById(id);
if (targetPage == null) {
throw new IllegalStateException("Wrong page id, this should not happen!");
targetPage = createPageById(id);
if (targetPage == null){
throw new IllegalStateException("Wrong page id, this should not happen!");
}
}
if (currentPage != null && currentPage != targetPage) {
if (currentPage.isShowing()) {

View File

@ -1,80 +0,0 @@
package com.tungsten.fcl.ui.manage;
import android.content.Context;
import com.tungsten.fcl.R;
import com.tungsten.fcl.setting.Profile;
import com.tungsten.fcl.ui.PageManager;
import com.tungsten.fcl.ui.UIListener;
import com.tungsten.fcl.ui.download.DownloadPage;
import com.tungsten.fcl.ui.download.InstallVersionPage;
import com.tungsten.fcllibrary.component.ui.FCLCommonPage;
import com.tungsten.fcllibrary.component.view.FCLUILayout;
import java.util.ArrayList;
public class ManagePageManager extends PageManager {
public static final int PAGE_ID_MANAGE_MANAGE = 15000;
public static final int PAGE_ID_MANAGE_SETTING = 15001;
public static final int PAGE_ID_MANAGE_INSTALL = 15002;
public static final int PAGE_ID_MANAGE_MOD = 15003;
public static final int PAGE_ID_MANAGE_WORLD = 15004;
private static ManagePageManager instance;
private ManagePage managePage;
private VersionSettingPage versionSettingPage;
private InstallerListPage installerListPage;
private ModListPage modListPage;
private WorldListPage worldListPage;
public static ManagePageManager getInstance() {
if (instance == null) {
throw new IllegalStateException("ManagePageManager not initialized!");
}
return instance;
}
public ManagePageManager(Context context, FCLUILayout parent, int defaultPageId, UIListener listener) {
super(context, parent, defaultPageId, listener);
instance = this;
}
@Override
public void init(UIListener listener) {
managePage = new ManagePage(getContext(), PAGE_ID_MANAGE_MANAGE, getParent(), R.layout.page_manage);
versionSettingPage = new VersionSettingPage(getContext(), PAGE_ID_MANAGE_SETTING, getParent(), R.layout.page_version_setting, false);
installerListPage = new InstallerListPage(getContext(), PAGE_ID_MANAGE_INSTALL, getParent(), R.layout.page_installer_list);
modListPage = new ModListPage(getContext(), PAGE_ID_MANAGE_MOD, getParent(), R.layout.page_mod_list);
worldListPage = new WorldListPage(getContext(), PAGE_ID_MANAGE_WORLD, getParent(), R.layout.page_world_list);
if (listener != null) {
listener.onLoad();
}
}
@Override
public ArrayList<FCLCommonPage> getAllPages() {
ArrayList<FCLCommonPage> pages = new ArrayList<>();
pages.add(managePage);
pages.add(versionSettingPage);
pages.add(installerListPage);
pages.add(modListPage);
pages.add(worldListPage);
return pages;
}
public void loadVersion(Profile profile, String version) {
managePage.loadVersion(profile, version);
versionSettingPage.loadVersion(profile, version);
installerListPage.loadVersion(profile, version);
modListPage.loadVersion(profile, version);
worldListPage.loadVersion(profile, version);
}
public void onRunDirectoryChange(Profile profile, String version) {
modListPage.loadVersion(profile, version);
worldListPage.loadVersion(profile, version);
}
}

View File

@ -0,0 +1,112 @@
package com.tungsten.fcl.ui.manage
import android.content.Context
import com.tungsten.fcl.R
import com.tungsten.fcl.setting.Profile
import com.tungsten.fcl.ui.PageManager
import com.tungsten.fcl.ui.UIListener
import com.tungsten.fcl.ui.manage.ManageUI.VersionLoadable
import com.tungsten.fcllibrary.component.ui.FCLCommonPage
import com.tungsten.fcllibrary.component.view.FCLUILayout
class ManagePageManager(
context: Context,
parent: FCLUILayout,
defaultPageId: Int,
val listener: UIListener?
) : PageManager(context, parent, defaultPageId, listener) {
companion object {
@JvmStatic
var instance: ManagePageManager? = null
const val PAGE_ID_MANAGE_MANAGE: Int = 15000
const val PAGE_ID_MANAGE_SETTING: Int = 15001
const val PAGE_ID_MANAGE_INSTALL: Int = 15002
const val PAGE_ID_MANAGE_MOD: Int = 15003
const val PAGE_ID_MANAGE_WORLD: Int = 15004
}
var profile: Profile? = null
var version: String? = null
lateinit var managePage: ManagePage
lateinit var versionSettingPage: VersionSettingPage
lateinit var installerListPage: InstallerListPage
lateinit var modListPage: ModListPage
lateinit var worldListPage: WorldListPage
init {
instance = this
}
override fun init(listener: UIListener?) {
managePage =
ManagePage(context, PAGE_ID_MANAGE_MANAGE, parent, R.layout.page_manage)
listener?.onLoad()
}
override fun getAllPages(): ArrayList<FCLCommonPage> {
return ArrayList<FCLCommonPage>().apply {
add(managePage)
}
}
override fun createPageById(id: Int): FCLCommonPage? {
val page: FCLCommonPage? = when (id) {
PAGE_ID_MANAGE_SETTING -> {
versionSettingPage = VersionSettingPage(
context,
PAGE_ID_MANAGE_SETTING,
parent,
R.layout.page_version_setting,
false
)
versionSettingPage
}
PAGE_ID_MANAGE_INSTALL -> {
installerListPage = InstallerListPage(
context,
PAGE_ID_MANAGE_INSTALL,
parent,
R.layout.page_installer_list
)
installerListPage
}
PAGE_ID_MANAGE_MOD -> {
modListPage = ModListPage(
context,
PAGE_ID_MANAGE_MOD,
parent,
R.layout.page_mod_list
)
modListPage
}
PAGE_ID_MANAGE_WORLD -> {
worldListPage = WorldListPage(
context,
PAGE_ID_MANAGE_WORLD,
parent,
R.layout.page_world_list
)
worldListPage
}
else -> null
}
if (page != null) {
allPages.add(page)
(page as VersionLoadable).loadVersion(profile, version)
}
return page
}
fun loadVersion(profile: Profile?, version: String?) {
this.profile = profile
this.version = version
allPages.forEach {
(it as VersionLoadable).loadVersion(profile, version)
}
}
fun onRunDirectoryChange(profile: Profile?, version: String?) {
modListPage.loadVersion(profile, version)
worldListPage.loadVersion(profile, version)
}
}