Skip to content

Commit

Permalink
Stop syncronizing embedded options and unembedded options
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipppppppppp committed Feb 19, 2024
1 parent 86b8d98 commit db2e825
Showing 1 changed file with 97 additions and 101 deletions.
198 changes: 97 additions & 101 deletions app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit db2e825

Please sign in to comment.