Skip to content

Commit

Permalink
KeepUnreadボタンをLsPatch用に作成することにより、rootしている端末は、保存するように
Browse files Browse the repository at this point in the history
  • Loading branch information
areteruhiro committed Nov 3, 2024
1 parent 1304e28 commit 8e978ff
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public Option(String name, int id, boolean checked) {
public Option preventUnsendMessage = new Option("prevent_unsend_message", R.string.switch_prevent_unsend_message, false);
public Option sendMuteMessage = new Option("mute_message", R.string.switch_send_mute_message, false);
public Option removeKeepUnread = new Option("remove_keep_unread", R.string.switch_remove_keep_unread, false);
public Option KeepUnreadLSpatch = new Option("Keep_UnreadLSpatch", R.string.switch_KeepUnreadLSpatch, false);
public Option blockTracking = new Option("block_tracking", R.string.switch_block_tracking, false);
public Option stopVersionCheck = new Option("stop_version_check", R.string.switch_stop_version_check, false);
public Option outputCommunication = new Option("output_communication", R.string.switch_output_communication, false);
Expand All @@ -57,6 +58,7 @@ public Option(String name, int id, boolean checked) {
archived,
sendMuteMessage,
removeKeepUnread,
KeepUnreadLSpatch,
blockTracking,
stopVersionCheck,
outputCommunication,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.github.chipppppppppp.lime.hooks.EmbedOptions;
import io.github.chipppppppppp.lime.hooks.IHook;
import io.github.chipppppppppp.lime.hooks.KeepUnread;
import io.github.chipppppppppp.lime.hooks.KeepUnreadLSpatch;
import io.github.chipppppppppp.lime.hooks.ModifyRequest;
import io.github.chipppppppppp.lime.hooks.ModifyResponse;
import io.github.chipppppppppp.lime.hooks.OutputRequest;
Expand Down Expand Up @@ -67,7 +68,8 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
new OutputRequest(),
new Archived(),
new Ringtone(),
new UnsentCap()
new UnsentCap(),
new KeepUnreadLSpatch()
};

public void handleLoadPackage(@NonNull XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand Down
102 changes: 74 additions & 28 deletions app/src/main/java/io/github/chipppppppppp/lime/hooks/KeepUnread.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,98 @@
import io.github.chipppppppppp.lime.R;

public class KeepUnread implements IHook {
static boolean keepUnread = false;

@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (limeOptions.removeKeepUnread.checked) return;

Class<?> hookTarget;
hookTarget = loadPackageParam.classLoader.loadClass("jp.naver.line.android.common.view.listview.PopupListView");
XposedBridge.hookAllConstructors(hookTarget, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.hookAllConstructors(
loadPackageParam.classLoader.loadClass("jp.naver.line.android.common.view.listview.PopupListView"),
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
ViewGroup viewGroup = (ViewGroup) param.thisObject;
Context context = viewGroup.getContext();
context.getApplicationContext().createPackageContext(Constants.MODULE_NAME, Context.CONTEXT_IGNORE_SECURITY);

ViewGroup viewGroup = (ViewGroup) param.thisObject;
Context context = viewGroup.getContext();
Context moduleContext = context.getApplicationContext().createPackageContext(Constants.MODULE_NAME, Context.CONTEXT_IGNORE_SECURITY);
String textKeepUnread = moduleContext.getResources().getString(R.string.switch_keep_unread);
RelativeLayout layout = new RelativeLayout(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
Context moduleContext = context.getApplicationContext().createPackageContext(Constants.MODULE_NAME, Context.CONTEXT_IGNORE_SECURITY);
String textKeepUnread = moduleContext.getResources().getString(R.string.switch_keep_unread);

Switch switchView = new Switch(context);
switchView.setText(textKeepUnread);
RelativeLayout.LayoutParams switchParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
switchParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
keepUnread = readStateFromFile(context);

switchView.setChecked(false);
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
});
RelativeLayout container = new RelativeLayout(context);
RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
container.setLayoutParams(containerParams);

layout.addView(switchView, switchParams);
GradientDrawable background = new GradientDrawable();
background.setShape(GradientDrawable.RECTANGLE);
background.setColor(Color.parseColor("#06C755"));
background.setCornerRadii(new float[]{100, 100, 80, 30, 100, 100, 80, 30});
container.setBackground(background);

((ListView) viewGroup.getChildAt(0)).addFooterView(layout);
}
});

TextView label = new TextView(context);
label.setText(textKeepUnread);
label.setTextSize(18);
label.setTextColor(Color.WHITE);
label.setId(View.generateViewId());
RelativeLayout.LayoutParams labelParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
labelParams.setMargins(40, 0, 0, 0);
container.addView(label, labelParams);

Switch switchView = new Switch(context);
RelativeLayout.LayoutParams switchParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
switchParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
switchParams.setMargins(0, 0, 40, 0);
switchView.setChecked(keepUnread);
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
keepUnread = isChecked;
saveStateToFile(context, isChecked);
});

container.addView(switchView, switchParams);

((ListView) viewGroup.getChildAt(0)).addFooterView(container);
}
}
);
XposedHelpers.findAndHookMethod(
loadPackageParam.classLoader.loadClass(Constants.MARK_AS_READ_HOOK.className),
Constants.MARK_AS_READ_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (keepUnread) {
param.setResult(null);
}
}
}
);
}

}
private void saveStateToFile(Context context, boolean state) {
String filename = "keep_unread_state.txt";
try (FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE)) {
fos.write((state ? "1" : "0").getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
private boolean readStateFromFile(Context context) {
String filename = "keep_unread_state.txt";
try (FileInputStream fis = context.openFileInput(filename)) {
int c;
StringBuilder sb = new StringBuilder();
while ((c = fis.read()) != -1) {
sb.append((char) c);
}
return "1".equals(sb.toString());
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.github.chipppppppppp.lime.hooks;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;
import io.github.chipppppppppp.lime.R;

public class KeepUnreadLSpatch implements IHook {
static boolean keepUnread = false;

@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.KeepUnreadLSpatch.checked) return;

XposedBridge.hookAllConstructors(
loadPackageParam.classLoader.loadClass("jp.naver.line.android.common.view.listview.PopupListView"),
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
ViewGroup viewGroup = (ViewGroup) param.thisObject;
Context context = viewGroup.getContext();

Context moduleContext = context.getApplicationContext().createPackageContext(Constants.MODULE_NAME, Context.CONTEXT_IGNORE_SECURITY);
String textKeepUnread = moduleContext.getResources().getString(R.string.switch_keep_unread);

RelativeLayout container = new RelativeLayout(context);
RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
container.setLayoutParams(containerParams);

GradientDrawable background = new GradientDrawable();
background.setShape(GradientDrawable.RECTANGLE);
background.setColor(Color.parseColor("#06C755"));
background.setCornerRadii(new float[]{100, 100, 80, 30, 100, 100, 80, 30});

container.setBackground(background);

TextView label = new TextView(context);
label.setText(textKeepUnread);
label.setTextSize(18);
label.setTextColor(Color.WHITE);
label.setId(View.generateViewId());
RelativeLayout.LayoutParams labelParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
labelParams.setMargins(40, 0, 0, 0);
container.addView(label, labelParams);

Switch switchView = new Switch(context);
RelativeLayout.LayoutParams switchParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
switchParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
switchParams.setMargins(0, 0, 40, 0);
switchView.setChecked(false);
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
keepUnread = isChecked;
});

container.addView(switchView, switchParams);

((ListView) viewGroup.getChildAt(0)).addFooterView(container);
}
}
);

XposedHelpers.findAndHookMethod(
loadPackageParam.classLoader.loadClass(Constants.MARK_AS_READ_HOOK.className),
Constants.MARK_AS_READ_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (keepUnread) {
param.setResult(null);
}
}
}
);
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

<!-- Menu -->
<string name="switch_keep_unread">未読のまま閲覧</string>
<string name="switch_KeepUnreadLSpatch">LsPatch用「未読のまま閲覧」スイッチを表示</string>

<!-- UNSENT CAP -->
<string name="backup">バックアップ</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
<string name="confirm_delete">Really want to delete it?</string>
<string name="no_backup_found">Nothing backed up</string>
<string name="no_get_restart_app">Could not get properly.\nPlease restart the app</string>
<string name="switch_KeepUnreadLSpatch">Show \"Read as unread\" switch for LsPatch</string>

</resources>

0 comments on commit 8e978ff

Please sign in to comment.