Skip to content

Commit

Permalink
Notif_invalid 機能の追加
Browse files Browse the repository at this point in the history
  • Loading branch information
areteruhiro committed Nov 20, 2024
1 parent b7844f4 commit d70fdcb
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public Option(String name, int id, boolean checked) {
public Option callTone = new Option("call_tone", R.string.call_tone, false);
public Option NaviColor = new Option("NaviColor", R.string.NaviColor, false);
public Option ReadChecker = new Option("ReadChecker", R.string.ReadChecker, false);
public Option Notif_invalid = new Option("Notif_invalid", R.string.Notif_invalid, false);


public Option[] options = {
removeVoom,
Expand Down Expand Up @@ -66,6 +68,8 @@ public Option(String name, int id, boolean checked) {
stopVersionCheck,
outputCommunication,
callTone,
NaviColor
NaviColor,
Notif_invalid

};
}
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 @@ -23,6 +23,7 @@
import io.github.chipppppppppp.lime.hooks.ModifyRequest;
import io.github.chipppppppppp.lime.hooks.ModifyResponse;
import io.github.chipppppppppp.lime.hooks.NaviColor;
import io.github.chipppppppppp.lime.hooks.Notif_invalid;
import io.github.chipppppppppp.lime.hooks.OutputRequest;
import io.github.chipppppppppp.lime.hooks.OutputResponse;
import io.github.chipppppppppp.lime.hooks.PreventMarkAsRead;
Expand Down Expand Up @@ -73,7 +74,8 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
new UnsentCap(),
new KeepUnreadLSpatch(),
new NaviColor(),
new AutomaticBackup()
new AutomaticBackup(),
new Notif_invalid()
};

public void handleLoadPackage(@NonNull XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
import android.widget.Switch;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
Expand Down Expand Up @@ -249,6 +256,19 @@ public void onClick(View v) {
}
});


Button MuteGroups_Button = new Button(context);
MuteGroups_Button.setLayoutParams(buttonParams);
MuteGroups_Button.setText("通知を無効にしているグループ");
MuteGroups_Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MuteGroups_Button(context);
}
});
layout.addView(MuteGroups_Button);


buttonLayout.addView(copyButton);

Button pasteButton = new Button(context);
Expand Down Expand Up @@ -302,6 +322,10 @@ public void onDismiss(DialogInterface dialog) {
}
});





AlertDialog dialog = builder.create();

Button button = new Button(context);
Expand Down Expand Up @@ -394,4 +418,67 @@ public void onClick(View view) {
}
);
}


private void MuteGroups_Button(Context context) {
// ファイルパスを指定
File dir = context.getFilesDir(); // 例えば内部ストレージのファイルディレクトリ
File file = new File(dir, "Notification.txt");

// ファイルが存在する場合、内容を読み込む
StringBuilder fileContent = new StringBuilder();
if (file.exists()) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
fileContent.append(line).append("\n");
}
} catch (IOException e) {
XposedBridge.log("Error reading the file: " + e.getMessage());
}
}

// 新しい内容を編集できるようにEditTextを表示する
final EditText editText = new EditText(context);
editText.setText(fileContent.toString());
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setMinLines(10); // 適切な行数を設定
editText.setGravity(Gravity.TOP); // 上から入力されるように設定

// ボタン用のレイアウトパラメータを設定
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
buttonParams.setMargins(16, 16, 16, 16); // 任意のマージン設定

// 保存ボタンを作成
Button saveButton = new Button(context);
saveButton.setText("Save");
saveButton.setLayoutParams(buttonParams); // レイアウトパラメータを設定
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 編集した内容をファイルに保存
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(editText.getText().toString());
XposedBridge.log("File saved successfully.");
} catch (IOException e) {
XposedBridge.log("Error saving the file: " + e.getMessage());
}
}
});

// 編集画面を表示するためのLayoutに追加
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(editText);
layout.addView(saveButton);

// ダイアログを表示して編集画面を表示する
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("通知を無効にしているグループ");
builder.setView(layout);
builder.setNegativeButton("キャンセル", null);
builder.show();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package io.github.chipppppppppp.lime.hooks;

import android.app.AndroidAppHelper;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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;

public class Notif_invalid implements IHook {
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.Notif_invalid.checked) return;
XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.RESPONSE_HOOK.className),
Constants.RESPONSE_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String paramValue = param.args[1].toString();
if (paramValue.contains("chatName:") && paramValue.contains("getChats_result")) {
String chatName = extractChatName(paramValue);
if (chatName != null) {
// XposedBridge.log("Extracted chatName: " + chatName);
Context moduleContext = AndroidAppHelper.currentApplication();
File dir = moduleContext.getFilesDir();
saveChatNameToFile(chatName, dir);
}
}
}

private String extractChatName(String paramValue) {
String marker = "chatName:";
int startIndex = paramValue.indexOf(marker);
if (startIndex != -1) {
startIndex += marker.length();
int endIndex = paramValue.indexOf(',', startIndex);
if (endIndex != -1) {
return paramValue.substring(startIndex, endIndex).trim();
}
}
return null;
}

private void saveChatNameToFile(String chatName, File dir) {
if (!dir.exists() && !dir.mkdirs()) {
XposedBridge.log("Failed to create directory: " + dir.getPath());
return;
}

File file = new File(dir, "Notification.txt");

try {
if (!file.exists() && !file.createNewFile()) {
XposedBridge.log("Failed to create file: " + file.getPath());
return;
}

List<String> existingChatNames = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
existingChatNames.add(line.trim());
}
} catch (IOException e) {
XposedBridge.log("Error reading file: " + e.getMessage());
}

if (!existingChatNames.contains(chatName.trim())) {
try (FileWriter writer = new FileWriter(file, true)) {
writer.write(chatName + "\n");
XposedBridge.log("Saved chatName: " + chatName);
} catch (IOException e) {
XposedBridge.log("Error writing to file: " + e.getMessage());
}
} else {
XposedBridge.log("Chat name already exists: " + chatName);
}
} catch (IOException e) {
XposedBridge.log("Error accessing file: " + e.getMessage());
}
}
});

XposedHelpers.findAndHookMethod(NotificationManager.class, "notify",
String.class, int.class, Notification.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

int id = (int) param.args[1];
Notification notification = (Notification) param.args[2];

logNotificationDetails("NotificationManager.notify (with tag)", id, notification);
String subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT);
List<String> chatNamesFromFile = loadNamesFromFile();
for (String chatName : chatNamesFromFile) {
if (subText != null && subText.contains(chatName)) {
param.setResult(null);
return;
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = notification.getChannelId();
NotificationManager manager = (NotificationManager) AndroidAppHelper.currentApplication().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = manager.getNotificationChannel(channelId);

if (channel != null) {
String channelName = channel.getName().toString();
// XposedBridge.log("Notification Channel Name: " + channelName);
}
}
}
});

XposedHelpers.findAndHookMethod(Notification.Builder.class, "setContentTitle",
CharSequence.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
CharSequence title = (CharSequence) param.args[0];

List<String> chatNamesFromFile = loadNamesFromFile();

for (String chatName : chatNamesFromFile) {
if (title != null && title.toString().contains(chatName)) {
//XposedBridge.log("Notification title contains chatName from file. Title: " + title);
param.setResult(null); // nullを返して通知を表示しない
return;
}
}
//XposedBridge.log("Notification title does not contain any chatName from file. Title: " + title);
}
});
}

// 通知の詳細をログに記録するヘルパーメソッド
private void logNotificationDetails(String method, int id, Notification notification) {
XposedBridge.log(method + " called. ID: " + id);

if (notification.extras != null) {

String title = notification.extras.getString(Notification.EXTRA_TITLE); // タイトル
String text = notification.extras.getString(Notification.EXTRA_TEXT); // メインのテキスト
String subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT); // サブテキスト

/*
XposedBridge.log("Notification Title: " + (title != null ? title : "No Title"));
XposedBridge.log("Notification Text: " + (text != null ? text : "No Text"));
XposedBridge.log("Notification SubText: " + (subText != null ? subText : "No SubText"));
*/
} else {
// XposedBridge.log("Notification extras is null.");
}
//XposedBridge.log("Notification Icon: " + notification.icon);
}

private List<String> loadNamesFromFile() {
List<String> names = new ArrayList<>();
Context moduleContext = AndroidAppHelper.currentApplication();
File dir = moduleContext.getFilesDir();
File file = new File(dir, "Notification.txt");
if (!file.exists()) {
return names;
}

try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
names.add(line.trim());
}
} catch (IOException e) {
// XposedBridge.log("Error reading names from file: " + e.getMessage());
}

return names;
}
}
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 @@ -78,4 +78,5 @@
<string name="no_backup_found">何もバックアップされていません</string>
<string name="no_get_restart_app">正しく取得できませんでした。\nアプリを再起動してください</string>
<string name="ReadChecker">送信したメッセージの既読者の確認</string>
<string name="Notif_invalid">登録しているグループの通知をオフに</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
<string name="button_paste">貼上</string>
<!-- Menu -->
<string name="switch_keep_unread">保持未讀</string>
<string name="Notif_invalid">登録しているグループの通知をオフに</string>
</resources>
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 @@ -78,4 +78,5 @@
<string name="switch_KeepUnreadLSpatch">Show \"Read as unread\" switch for LSPatch</string>
<string name="NaviColor">Set nav color to Black</string>
<string name="ReadChecker">Check read friends</string>
<string name="Notif_invalid">登録しているグループの通知をオフに</string>
</resources>

0 comments on commit d70fdcb

Please sign in to comment.