diff --git a/FCL/src/main/java/com/tungsten/fcl/ui/PageManager.java b/FCL/src/main/java/com/tungsten/fcl/ui/PageManager.java index fa33943a..1f08c9d5 100644 --- a/FCL/src/main/java/com/tungsten/fcl/ui/PageManager.java +++ b/FCL/src/main/java/com/tungsten/fcl/ui/PageManager.java @@ -18,7 +18,7 @@ public abstract class PageManager { private final FCLUILayout parent; private final int defaultPageId; - private final ArrayList allPages; + public final ArrayList 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 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()) { diff --git a/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.java b/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.java deleted file mode 100644 index b7b009b8..00000000 --- a/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.java +++ /dev/null @@ -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 getAllPages() { - ArrayList 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); - } -} diff --git a/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.kt b/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.kt new file mode 100644 index 00000000..bfe6923a --- /dev/null +++ b/FCL/src/main/java/com/tungsten/fcl/ui/manage/ManagePageManager.kt @@ -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 { + return ArrayList().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) + } +} \ No newline at end of file