1
0
mirror of https://github.com/areteruhiro/LIME-beta-hiro.git synced 2025-02-11 07:51:37 +09:00

バージョン14.17.0に対応、既読つけるボタンの配置場所の変更

LsPatch
This commit is contained in:
areteruhiro 2024-10-29 02:00:21 +09:00
parent 9b06a7d606
commit e3066fc1ac
2 changed files with 11 additions and 48 deletions

View File

@ -10,7 +10,7 @@ android {
minSdk 28
targetSdk 34
versionCode 15
versionName "1.11.2Root"
versionName "1.11.2LsPatch"
multiDexEnabled false
proguardFiles += 'proguard-rules.pro'
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"141700420"'

View File

@ -1,10 +1,7 @@
package io.github.hiro.lime.hooks;
import android.app.AndroidAppHelper;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -23,10 +20,12 @@ import io.github.hiro.lime.LimeOptions;
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;
XposedHelpers.findAndHookMethod(
"com.linecorp.line.chatlist.view.fragment.ChatListFragment",
loadPackageParam.classLoader,
@ -37,34 +36,24 @@ public class KeepUnread implements IHook {
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
View rootView = (View) param.getResult();
Context context = rootView.getContext();
keepUnread = readStateFromFile(context);
// レイアウトを作成
RelativeLayout layout = new RelativeLayout(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(layoutParams);
// スイッチの状態をファイルから読み取る
boolean isChecked = readStateFromFile(context); // ファイルから状態を読み込む
// スイッチを作成
Switch switchView = new Switch(context);
switchView.setText(""); // テキストが必要ない場合は空に
switchView.setTextColor(Color.WHITE); // テキストの色を白に設定
switchView.setText("");
// スイッチのレイアウトパラメータを設定
RelativeLayout.LayoutParams switchParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
switchParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); // 中央に配置
// スイッチの状態を設定
switchView.setChecked(isChecked);
// スイッチのリスナーを設定
switchView.setOnCheckedChangeListener((buttonView, isChecked1) -> {
saveStateToFile(context, isChecked1); // ファイルに状態を保存
switchView.setChecked(false);
switchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
keepUnread = isChecked;
});
// レイアウトにスイッチを追加
layout.addView(switchView, switchParams);
@ -80,49 +69,23 @@ public class KeepUnread implements IHook {
}
}
// スイッチの状態をファイルに保存するメソッド
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; // 例外が発生した場合はデフォルト値を返す
}
}
}
);
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 {
protected void beforeHookedMethod(MethodHookParam param) {
if (keepUnread) {
param.setResult(null);
}
}
}
);
}
}