From db2e825277d66296b6d6108f8dde7b6a11a7a2b7 Mon Sep 17 00:00:00 2001 From: Chippppp <78024852+Chipppppppppp@users.noreply.github.com> Date: Tue, 20 Feb 2024 03:07:53 +0900 Subject: [PATCH] Stop syncronizing embedded options and unembedded options --- .../io/github/chipppppppppp/lime/Main.java | 198 +++++++++--------- 1 file changed, 97 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/io/github/chipppppppppp/lime/Main.java b/app/src/main/java/io/github/chipppppppppp/lime/Main.java index 4b34d70a..5a067e97 100644 --- a/app/src/main/java/io/github/chipppppppppp/lime/Main.java +++ b/app/src/main/java/io/github/chipppppppppp/lime/Main.java @@ -82,118 +82,114 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lparam) throws Thr Class hookTarget; - hookTarget = lparam.classLoader.loadClass("com.linecorp.line.settings.main.LineUserMainSettingsFragment"); - XposedBridge.hookAllMethods(hookTarget, "onViewCreated", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - ViewGroup viewGroup = ((ViewGroup) param.args[0]); - Context context = viewGroup.getContext(); - - Method mAddAddAssertPath = AssetManager.class.getDeclaredMethod("addAssetPath", String.class); - mAddAddAssertPath.setAccessible(true); - mAddAddAssertPath.invoke(context.getResources().getAssets(), MODULE_PATH); - - SharedPreferences prefs = AndroidAppHelper.currentApplication().getSharedPreferences(MODULE + "-options", Context.MODE_PRIVATE); + if (!xModulePrefs.getBoolean("unembed_options", false)) { + hookTarget = lparam.classLoader.loadClass("com.linecorp.line.settings.main.LineUserMainSettingsFragment"); + XposedBridge.hookAllMethods(hookTarget, "onViewCreated", new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) throws Throwable { + ViewGroup viewGroup = ((ViewGroup) param.args[0]); + Context context = viewGroup.getContext(); - if (xModulePrefs.getBoolean("unembed_options", false)) { + Method mAddAddAssertPath = AssetManager.class.getDeclaredMethod("addAssetPath", String.class); + mAddAddAssertPath.setAccessible(true); + mAddAddAssertPath.invoke(context.getResources().getAssets(), MODULE_PATH); + + SharedPreferences prefs = AndroidAppHelper.currentApplication().getSharedPreferences(MODULE + "-options", Context.MODE_PRIVATE); + + FrameLayout frameLayout = new FrameLayout(context); + frameLayout.setLayoutParams(new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT)); + + Button button = new Button(context); + button.setText("LIME"); + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + layoutParams.gravity = Gravity.TOP | Gravity.END; + layoutParams.rightMargin = Utils.dpToPx(10, context); + layoutParams.topMargin = Utils.dpToPx(5, context); + button.setLayoutParams(layoutParams); + + AlertDialog.Builder builder = new AlertDialog.Builder(context) + .setTitle(context.getString(R.string.options_title)) + .setCancelable(false); + + LinearLayout layout = new LinearLayout(context); + layout.setLayoutParams(new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT)); + layout.setOrientation(LinearLayout.VERTICAL); + layout.setPadding(Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context)); + + Switch switchRedirectWebView = null; for (LimeOptions.Option option : limeOptions.options) { - prefs.edit().putBoolean(option.name, xModulePrefs.getBoolean(option.name, option.checked)); - } - return; - } - - FrameLayout frameLayout = new FrameLayout(context); - frameLayout.setLayoutParams(new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT)); - - Button button = new Button(context); - button.setText("LIME"); - FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.WRAP_CONTENT, - FrameLayout.LayoutParams.WRAP_CONTENT); - layoutParams.gravity = Gravity.TOP | Gravity.END; - layoutParams.rightMargin = Utils.dpToPx(10, context); - layoutParams.topMargin = Utils.dpToPx(5, context); - button.setLayoutParams(layoutParams); - - AlertDialog.Builder builder = new AlertDialog.Builder(context) - .setTitle(context.getString(R.string.options_title)) - .setCancelable(false); - - LinearLayout layout = new LinearLayout(context); - layout.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.MATCH_PARENT)); - layout.setOrientation(LinearLayout.VERTICAL); - layout.setPadding(Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context)); - - Switch switchRedirectWebView = null; - for (LimeOptions.Option option : limeOptions.options) { - final String name = option.name; - - Switch switchView = new Switch(context); - switchView.setText(context.getString(option.id)); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - params.topMargin = Utils.dpToPx(20, context); - switchView.setLayoutParams(params); - - switchView.setChecked(option.checked); - switchView.setOnCheckedChangeListener((buttonView, isChecked) -> { - prefs.edit().putBoolean(name, isChecked).apply(); - }); - - if (name == "redirect_webview") switchRedirectWebView = switchView; - else if (name == "open_in_browser") { - switchRedirectWebView.setOnCheckedChangeListener((buttonView, isChecked) -> { - prefs.edit().putBoolean("redirect_webview", isChecked).apply(); - if (isChecked) switchView.setEnabled(true); - else { - switchView.setChecked(false); - switchView.setEnabled(false); - } + final String name = option.name; + + Switch switchView = new Switch(context); + switchView.setText(context.getString(option.id)); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + params.topMargin = Utils.dpToPx(20, context); + switchView.setLayoutParams(params); + + switchView.setChecked(option.checked); + switchView.setOnCheckedChangeListener((buttonView, isChecked) -> { + prefs.edit().putBoolean(name, isChecked).apply(); }); - switchView.setEnabled(limeOptions.redirectWebView.checked); - } - layout.addView(switchView); - } + if (name == "redirect_webview") switchRedirectWebView = switchView; + else if (name == "open_in_browser") { + switchRedirectWebView.setOnCheckedChangeListener((buttonView, isChecked) -> { + prefs.edit().putBoolean("redirect_webview", isChecked).apply(); + if (isChecked) switchView.setEnabled(true); + else { + switchView.setChecked(false); + switchView.setEnabled(false); + } + }); + switchView.setEnabled(limeOptions.redirectWebView.checked); + } - ScrollView scrollView = new ScrollView(context); - scrollView.addView(layout); - builder.setView(scrollView); + layout.addView(switchView); + } - builder.setPositiveButton(context.getString(R.string.positive), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - boolean optionChanged = false; - for (LimeOptions.Option option : limeOptions.options) { - if (option.checked != prefs.getBoolean(option.name, option.checked)) optionChanged = true; - } + ScrollView scrollView = new ScrollView(context); + scrollView.addView(layout); + builder.setView(scrollView); + + builder.setPositiveButton(context.getString(R.string.positive), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + boolean optionChanged = false; + for (LimeOptions.Option option : limeOptions.options) { + if (option.checked != prefs.getBoolean(option.name, option.checked)) + optionChanged = true; + } - if (optionChanged) { - Toast.makeText(context.getApplicationContext(), context.getString(R.string.restarting), Toast.LENGTH_SHORT).show(); - Process.killProcess(Process.myPid()); - context.startActivity(new Intent().setClassName(PACKAGE, "jp.naver.line.android.activity.SplashActivity")); + if (optionChanged) { + Toast.makeText(context.getApplicationContext(), context.getString(R.string.restarting), Toast.LENGTH_SHORT).show(); + Process.killProcess(Process.myPid()); + context.startActivity(new Intent().setClassName(PACKAGE, "jp.naver.line.android.activity.SplashActivity")); + } } - } - }); + }); - AlertDialog dialog = builder.create(); + AlertDialog dialog = builder.create(); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dialog.show(); - } - }); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dialog.show(); + } + }); - frameLayout.addView(button); - viewGroup.addView(frameLayout); - } - }); + frameLayout.addView(button); + viewGroup.addView(frameLayout); + } + }); + } hookTarget = lparam.classLoader.loadClass("jp.naver.line.android.activity.main.MainActivity"); XposedHelpers.findAndHookMethod(hookTarget, "onResume", new XC_MethodHook() {