From 4dee7cacbf3c19691fcadec4a6f15b112a1d0276 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <1964762970@qq.com> Date: Tue, 29 Oct 2024 12:41:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D[=E6=B8=B2=E6=9F=93=E5=99=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9]:=20=E4=BF=AE=E5=A4=8D=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E5=99=A8=E5=AE=9E=E9=AA=8C=E6=80=A7=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=B6ListPre=E6=9C=AA=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LauncherPreferenceVideoFragment.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java index 73abc463..5f65c835 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java @@ -80,19 +80,10 @@ public void onCreatePreferences(Bundle b, String str) { SwitchPreference.class); sustainedPerfSwitch.setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N); - final ListPreference rendererListPreference = requirePreference("renderer", ListPreference.class); - setListPreference(rendererListPreference, "renderer"); - - rendererListPreference.setOnPreferenceChangeListener((pre, obj) -> { - Tools.LOCAL_RENDERER = (String) obj; - return true; - }); - - Preference driverPreference = requirePreference("zinkPreferSystemDriver"); - if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) { - driverPreference.setVisible(false); - } SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class); + if (!Tools.checkVulkanSupport(useSystemVulkan.getContext().getPackageManager())) { + useSystemVulkan.setVisible(false); + } useSystemVulkan.setOnPreferenceChangeListener((p, v) -> { boolean set = (boolean) v; boolean isAdreno = PGWTools.isAdrenoGPU(); @@ -110,14 +101,21 @@ public void onCreatePreferences(Bundle b, String str) { return true; }); + final ListPreference rendererListPref = requirePreference("renderer", ListPreference.class); final ChooseMesaListPref CMesaLibP = requirePreference("CMesaLibrary", ChooseMesaListPref.class); final ListPreference CDriverModelP = requirePreference("CDriverModels", ListPreference.class); final ListPreference CMesaLDOP = requirePreference("ChooseMldo", ListPreference.class); + setListPreference(rendererListPref, "renderer"); setListPreference(CMesaLibP, "CMesaLibrary"); setListPreference(CDriverModelP, "CDriverModels"); setListPreference(CMesaLDOP, "ChooseMldo"); + rendererListPref.setOnPreferenceChangeListener((pre, obj) -> { + Tools.LOCAL_RENDERER = (String) obj; + return true; + }); + CMesaLibP.setOnPreferenceChangeListener((pre, obj) -> { Tools.MESA_LIBS = (String) obj; setListPreference(CDriverModelP, "CDriverModels"); @@ -137,12 +135,15 @@ public void onCreatePreferences(Bundle b, String str) { SwitchPreference expRendererPref = requirePreference("ExperimentalSetup", SwitchPreference.class); expRendererPref.setOnPreferenceChangeListener((p, v) -> { - onChangeRenderer(); boolean isExpRenderer = (boolean) v; if (isExpRenderer) { onExpRendererDialog(p); + } else { + setListPreference(rendererListPref, "renderer"); + onChangeRenderer(rendererListPref); + return true; } - return true; + return false; }); // Custom GL/GLSL @@ -294,16 +295,17 @@ private void onCheckGPUDialog(Preference pre) { .show(); } - private void onExpRendererDialog(Preference pre) { + private void onExpRendererDialog(Preference pre, ListPreference rendererListPref) { new CustomDialog.Builder(getContext()) .setTitle(getString(R.string.preference_rendererexp_alertdialog_warning)) .setMessage(getString(R.string.preference_rendererexp_alertdialog_message)) - .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> true) - .setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> { - onChangeRenderer(); - ((SwitchPreference) pre).setChecked(false); + .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> { + setListPreference(rendererListPref, "renderer"); + onChangeRenderer(rendererListPref); + ((SwitchPreference) pre).setChecked(true); return true; }) + .setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> true) .setCancelable(false) .setDraggable(true) .build() @@ -372,16 +374,20 @@ private boolean isValidVersion(String version, String minVersion, String maxVers } } - private void onChangeRenderer() { + private void onChangeRenderer(ListPreference rendererListPref) { String rendererValue = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); if ("mesa_3d".equals(rendererValue)) { LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", expRenderer).apply(); + if (expRenderer != null) { + rendererListPref.setValue(expRenderer); + } else rendererListPref.setValueIndex(0); } else if ("vulkan_zink".equals(rendererValue) || "virglrenderer".equals(rendererValue) || "freedreno".equals(rendererValue) || "panfrost".equals(rendererValue)) { - expRenderer = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); + expRenderer = rendererValue; LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", "mesa_3d").apply(); + rendererListPref.setValue("mesa_3d"); } }