refactored dnr/dnt modules
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import com.vk.im.engine.commands.messages.SetUserActivityCmd;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import ru.vtosters.lite.dialogs.helpers.DoNotReadDBHelper;
|
||||
import ru.vtosters.lite.dialogs.helpers.DoNotTypeDBHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DNRModule {
|
||||
public static DoNotReadDBHelper mDoNotReadDBHelper = new DoNotReadDBHelper();
|
||||
public static DoNotTypeDBHelper mDoNotTypeDBHelper = new DoNotTypeDBHelper();
|
||||
|
||||
public static boolean isDnrEnabledFor(int id) {
|
||||
return mDoNotReadDBHelper.isEnabledForPeerId(id);
|
||||
}
|
||||
|
||||
public static List<Integer> getDnrEnabled() {
|
||||
return mDoNotReadDBHelper.get();
|
||||
}
|
||||
|
||||
public static List<Integer> getDntEnabled() {
|
||||
return mDoNotTypeDBHelper.get();
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(int id) {
|
||||
return mDoNotTypeDBHelper.isEnabledForPeerId(id);
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(SetUserActivityCmd cmd) {
|
||||
return isDntEnabledFor(cmd.b);
|
||||
}
|
||||
|
||||
public static boolean isDnrEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
return isDnrEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
return isDntEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public static void hookDNR(int peerId) {
|
||||
mDoNotReadDBHelper.setEnabledForPeerId(peerId, !mDoNotReadDBHelper.isEnabledForPeerId(peerId));
|
||||
}
|
||||
|
||||
public static void hookDNT(int peerId) {
|
||||
mDoNotTypeDBHelper.setEnabledForPeerId(peerId, !mDoNotTypeDBHelper.isEnabledForPeerId(peerId));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package ru.vtosters.lite.dnr;
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Environment;
|
||||
import com.vk.im.engine.ImEngine1;
|
||||
import com.vk.im.engine.events.OnDialogUpdateEvent;
|
||||
import com.vk.im.engine.models.EntityIntMap;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.ui.components.common.DialogAction;
|
||||
import com.vk.im.ui.views.dialog_actions.DialogActionsListView;
|
||||
import ru.vtosters.lite.downloaders.messages.HtmlDialogDownloaderFormatProvider;
|
||||
import ru.vtosters.lite.downloaders.messages.MessagesDownloader;
|
||||
import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.hooks.CryptImHook;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DialogHeaderInjector {
|
||||
public static boolean onClick(DialogAction action, Dialog dialog) { // header menu
|
||||
int peerId;
|
||||
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case MARK_AS_READ -> {
|
||||
Requests.hookRead(dialog);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
}
|
||||
case DNR_ON, DNR_OFF -> {
|
||||
DNRModule.hookDNR(peerId);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
}
|
||||
case DNT_ON, DNT_OFF -> {
|
||||
DNRModule.hookDNT(peerId);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
}
|
||||
case ENCRYPT_SETT -> {
|
||||
CryptImHook.hookPref(peerId);
|
||||
return true;
|
||||
}
|
||||
case ENCRYPT -> {
|
||||
CryptImHook.hook(peerId, dialog);
|
||||
return true;
|
||||
}
|
||||
case DOWNLOAD -> {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "dialog-" + peerId + ".html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
AndroidUtils.sendToast(AndroidUtils.getString(com.vtosters.lite.R.string.download_dl_error));
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case STAT -> {
|
||||
Requests.hookDialogInfo(dialog);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<DialogAction> injectToListAccess(List<DialogAction> actions, Dialog dialog) {
|
||||
int peerId;
|
||||
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
actions.add(DialogAction.STAT);
|
||||
|
||||
actions.add(DialogAction.DOWNLOAD);
|
||||
|
||||
if (DNRModule.isDnrEnabledFor(peerId)) {
|
||||
actions.add(DialogAction.DNR_OFF);
|
||||
} else {
|
||||
actions.add(DialogAction.DNR_ON);
|
||||
}
|
||||
|
||||
if (DNRModule.isDntEnabledFor(peerId)) {
|
||||
actions.add(DialogAction.DNT_OFF);
|
||||
} else {
|
||||
actions.add(DialogAction.DNT_ON);
|
||||
}
|
||||
|
||||
actions.add(DialogAction.ENCRYPT);
|
||||
|
||||
IMProcessor prov = EncryptProvider.getProcessorFor(peerId);
|
||||
if (prov != null && !prov.isPublic()) {
|
||||
actions.add(DialogAction.ENCRYPT_SETT);
|
||||
}
|
||||
|
||||
actions.add(DialogAction.MARK_AS_READ);
|
||||
return actions;
|
||||
}
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
public static List<Object> injectToList(List<Object> actions) {
|
||||
var list = new ArrayList<>(actions);
|
||||
|
||||
// list.add(new DialogActionsListView.b.a(DialogAction.STAT, 1, R.attr.im_ic_stats, R.string.dialogstats)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DOWNLOAD, 1, com.vtosters.lite.R.attr.im_ic_msgdl, com.vtosters.lite.R.string.download_dl)); // DialogAction, Int, Icon, String
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNR_ON, 2, com.vtosters.lite.R.attr.im_ic_pinned_msg_hide, com.vtosters.lite.R.string.DNR_ON)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNR_OFF, 2, com.vtosters.lite.R.attr.im_ic_pinned_msg_show, com.vtosters.lite.R.string.DNR_OFF)); // DialogAction, Int, Icon, String
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_ON, 2, com.vtosters.lite.R.attr.im_ic_edit_msg, com.vtosters.lite.R.string.DNT_ON)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_OFF, 2, com.vtosters.lite.R.attr.im_ic_edit_msg, com.vtosters.lite.R.string.DNT_OFF)); // DialogAction, Int, Icon, String
|
||||
|
||||
if (!AndroidUtils.isTablet()) {
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT, 3, com.vtosters.lite.R.attr.im_ic_keyboard, com.vtosters.lite.R.string.encryption)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT_SETT, 3, com.vtosters.lite.R.attr.im_ic_more_vertical, com.vtosters.lite.R.string.encryption_sett)); // DialogAction, Int, Icon, String
|
||||
}
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.MARK_AS_READ, 4, com.vtosters.lite.R.attr.im_ic_done, com.vtosters.lite.R.string.vkim_dialogs_list_option_mark_as_read)); // DialogAction, Int, Icon, String
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void forceInvalidateDialogActions(Dialog d) {
|
||||
EntityIntMap<Dialog> map = new EntityIntMap<>();
|
||||
map.a(d.getId(), d);
|
||||
ImEngine1.a().a(new OnDialogUpdateEvent(null, map));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import android.os.Environment;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.ui.components.common.DialogAction;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.downloaders.messages.HtmlDialogDownloaderFormatProvider;
|
||||
import ru.vtosters.lite.downloaders.messages.MessagesDownloader;
|
||||
import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.hooks.CryptImHook;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DialogMenuInjectors {
|
||||
public static void inject(Dialog dialog, List<DialogAction> list) {
|
||||
int peerId;
|
||||
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
|
||||
list.add(DialogAction.STAT);
|
||||
list.add(DialogAction.DOWNLOAD);
|
||||
|
||||
list.add(DialogAction.pinmsg);
|
||||
list.add(DialogAction.unpinmsg);
|
||||
|
||||
list.add(DNRModule.isDnrEnabledFor(peerId) ? DialogAction.DNR_OFF : DialogAction.DNR_ON);
|
||||
|
||||
list.add(DNRModule.isDntEnabledFor(peerId) ? DialogAction.DNT_OFF : DialogAction.DNT_ON);
|
||||
|
||||
list.add(DialogAction.ENCRYPT);
|
||||
|
||||
IMProcessor prov = EncryptProvider.getProcessorFor(peerId);
|
||||
if (prov != null && !prov.isPublic())
|
||||
list.add(DialogAction.ENCRYPT_SETT);
|
||||
}
|
||||
|
||||
public static LinkedHashMap<DialogAction, Integer> injectToHashMap(LinkedHashMap<DialogAction, Integer> hashMap) {
|
||||
// hashMap.put(DialogAction.STAT, AndroidUtils.getIdentifier("dialogstats", "string"));
|
||||
hashMap.put(DialogAction.DOWNLOAD, R.string.download_dl);
|
||||
|
||||
hashMap.put(DialogAction.DNR_ON, R.string.DNR_ON);
|
||||
hashMap.put(DialogAction.DNR_OFF, R.string.DNR_OFF);
|
||||
hashMap.put(DialogAction.DNT_ON, R.string.DNT_ON);
|
||||
hashMap.put(DialogAction.DNT_OFF, R.string.DNT_OFF);
|
||||
|
||||
hashMap.put(DialogAction.ENCRYPT, R.string.encryption);
|
||||
hashMap.put(DialogAction.ENCRYPT_SETT, R.string.encryption_sett);
|
||||
|
||||
// hashMap.put(DialogAction.pinmsg, getIdentifier("pinmsg", "string"));
|
||||
// hashMap.put(DialogAction.unpinmsg, getIdentifier("unpinmsg", "string"));
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
public static boolean onClick(Dialog dialog, DialogAction action) { // popup menu in dialogs
|
||||
int peerId;
|
||||
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case MARK_AS_READ -> Requests.hookRead(dialog);
|
||||
case STAT -> {
|
||||
Requests.hookDialogInfo(dialog);
|
||||
return true;
|
||||
}
|
||||
case DOWNLOAD -> {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), peerId + "-dialog.html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case DNR_ON, DNR_OFF -> {
|
||||
DNRModule.hookDNR(peerId);
|
||||
return true;
|
||||
}
|
||||
case DNT_ON, DNT_OFF -> {
|
||||
DNRModule.hookDNT(peerId);
|
||||
return true;
|
||||
}
|
||||
case pinmsg -> {
|
||||
Requests.pinnedMsg(peerId, true);
|
||||
return true;
|
||||
}
|
||||
case unpinmsg -> {
|
||||
Requests.pinnedMsg(peerId, false);
|
||||
return true;
|
||||
}
|
||||
case ENCRYPT_SETT -> {
|
||||
CryptImHook.hookPref(peerId);
|
||||
return true;
|
||||
}
|
||||
case ENCRYPT -> {
|
||||
CryptImHook.hook(peerId, dialog);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import com.vk.im.engine.models.messages.Msg;
|
||||
import com.vk.im.engine.models.messages.MsgFromUser;
|
||||
import com.vk.im.ui.components.common.MsgAction;
|
||||
import com.vk.im.ui.components.viewcontrollers.popup.DelegateMsg;
|
||||
import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.ui.dialogs.Translate;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class DialogMessageInjector {
|
||||
public static LinkedHashMap<MsgAction, DelegateMsg.a.a> injectToHashMap(LinkedHashMap<MsgAction, DelegateMsg.a.a> hashMap) {
|
||||
hashMap.put(MsgAction.KICK, new DelegateMsg.a.a(com.vtosters.lite.R.string.vkim_accessibility_kick_from_chat));
|
||||
hashMap.put(MsgAction.TRANSLATE, new DelegateMsg.a.a(com.vtosters.lite.R.string.translator));
|
||||
hashMap.put(MsgAction.READTO, new DelegateMsg.a.a(com.vtosters.lite.R.string.readto));
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
public static boolean onClick(Context context, MsgAction action, Msg msg) { // popup menu in chat
|
||||
var peerId = msg.v1();
|
||||
|
||||
switch (action) {
|
||||
case KICK -> {
|
||||
Requests.hookKick(msg);
|
||||
return true;
|
||||
}
|
||||
case READTO -> {
|
||||
Requests.hookReadStartMsgTo(msg);
|
||||
return true;
|
||||
}
|
||||
case TRANSLATE -> {
|
||||
if (msg instanceof MsgFromUser) {
|
||||
var text = ((MsgFromUser) msg).f();
|
||||
var isTextExist = !text.isEmpty() && !text.equals(" ");
|
||||
|
||||
if (isTextExist) {
|
||||
Translate.showTranslatedText(context, EncryptProvider.decryptMessage(text, peerId));
|
||||
} else {
|
||||
AndroidUtils.sendToast(context.getString(com.vtosters.lite.R.string.translator_no_text));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+21
-45
@@ -1,12 +1,12 @@
|
||||
package ru.vtosters.lite.dnr;
|
||||
package ru.vtosters.lite.dialogs;
|
||||
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.core.util.LangUtils;
|
||||
import com.vk.im.engine.commands.messages.SetUserActivityCmd;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.engine.models.messages.Msg;
|
||||
import com.vk.im.engine.utils.ImDialogsUtils;
|
||||
import ru.vtosters.lite.dnr.helpers.DoNotReadDBHelper;
|
||||
import ru.vtosters.lite.dnr.helpers.DoNotTypeDBHelper;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import ru.vtosters.lite.net.Request;
|
||||
import ru.vtosters.lite.proxy.ProxyUtils;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
@@ -14,42 +14,7 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DNRModule {
|
||||
public static DoNotReadDBHelper mDoNotReadDBHelper = new DoNotReadDBHelper();
|
||||
public static DoNotTypeDBHelper mDoNotTypeDBHelper = new DoNotTypeDBHelper();
|
||||
|
||||
public static boolean isDnrEnabledFor(int id) {
|
||||
return mDoNotReadDBHelper.isEnabledForPeerId(id);
|
||||
}
|
||||
|
||||
public static List<Integer> getDnrEnabled() {
|
||||
return mDoNotReadDBHelper.get();
|
||||
}
|
||||
|
||||
public static List<Integer> getDntEnabled() {
|
||||
return mDoNotTypeDBHelper.get();
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(int id) {
|
||||
return mDoNotTypeDBHelper.isEnabledForPeerId(id);
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(SetUserActivityCmd cmd) {
|
||||
return isDntEnabledFor(cmd.b);
|
||||
}
|
||||
|
||||
public static boolean isDnrEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
return isDnrEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public static boolean isDntEnabledFor(Dialog dialog) {
|
||||
if (dialog == null) return false;
|
||||
return isDntEnabledFor(dialog.getId());
|
||||
}
|
||||
|
||||
public class Requests {
|
||||
public static void hookRead(Dialog dialog) {
|
||||
Request.makeRequest("https://" + ProxyUtils.getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.119&access_token=" + AccountManagerUtils.getUserToken(), response -> {
|
||||
});
|
||||
@@ -76,11 +41,22 @@ public class DNRModule {
|
||||
ThemesUtils.hexx(ThemesUtils.getAccentColor()), LifecycleUtils.getCurrentActivity());
|
||||
}
|
||||
|
||||
public static void hookDNR(int peerId) {
|
||||
mDoNotReadDBHelper.setEnabledForPeerId(peerId, !mDoNotReadDBHelper.isEnabledForPeerId(peerId));
|
||||
}
|
||||
public static void pinnedMsg(int dialogid, boolean needToBePinned) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
var request = new okhttp3.Request.a()
|
||||
.b("https://" + ProxyUtils.getApi() + "/method/" + (needToBePinned ? "messages.pinConversation" : "messages.unpinConversation") + "?peer_id=" + dialogid + "&access_token=" + AccountManagerUtils.getUserToken() + "&v=5.119")
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
|
||||
.a();
|
||||
|
||||
public static void hookDNT(int peerId) {
|
||||
mDoNotTypeDBHelper.setEnabledForPeerId(peerId, !mDoNotTypeDBHelper.isEnabledForPeerId(peerId));
|
||||
new OkHttpClient().a(request).execute().a().g();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
|
||||
AndroidUtils.sendToast(AndroidUtils.getString(com.vtosters.lite.R.string.pin_dialog) + " " + AndroidUtils.getString(needToBePinned ? com.vtosters.lite.R.string.dialog_pinned : com.vtosters.lite.R.string.dialog_unpinned));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package ru.vtosters.lite.dnr.helpers;
|
||||
package ru.vtosters.lite.dialogs.helpers;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import ru.vtosters.lite.dnr.DNRPrefs;
|
||||
import ru.vtosters.lite.dialogs.DNRPrefs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package ru.vtosters.lite.dnr.helpers;
|
||||
package ru.vtosters.lite.dialogs.helpers;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import ru.vtosters.lite.dnr.DNRPrefs;
|
||||
import ru.vtosters.lite.dialogs.DNRPrefs;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -1,384 +0,0 @@
|
||||
package ru.vtosters.lite.dnr;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import com.vk.core.network.Network;
|
||||
import com.vk.im.engine.ImEngine1;
|
||||
import com.vk.im.engine.events.OnDialogUpdateEvent;
|
||||
import com.vk.im.engine.models.EntityIntMap;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.engine.models.messages.Msg;
|
||||
import com.vk.im.engine.models.messages.MsgFromUser;
|
||||
import com.vk.im.ui.components.common.DialogAction;
|
||||
import com.vk.im.ui.components.common.MsgAction;
|
||||
import com.vk.im.ui.components.viewcontrollers.popup.DelegateMsg;
|
||||
import com.vk.im.ui.views.dialog_actions.DialogActionsListView;
|
||||
import com.vtosters.lite.R;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import ru.vtosters.lite.downloaders.messages.HtmlDialogDownloaderFormatProvider;
|
||||
import ru.vtosters.lite.downloaders.messages.MessagesDownloader;
|
||||
import ru.vtosters.lite.encryption.EncryptProvider;
|
||||
import ru.vtosters.lite.encryption.base.IMProcessor;
|
||||
import ru.vtosters.lite.hooks.CryptImHook;
|
||||
import ru.vtosters.lite.proxy.ProxyUtils;
|
||||
import ru.vtosters.lite.ui.dialogs.Translate;
|
||||
import ru.vtosters.lite.utils.AccountManagerUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DNRInjector {
|
||||
public static void inject(Dialog dialog, List<DialogAction> list) {
|
||||
int peerId = 0;
|
||||
if (dialog != null) {
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
list.add(DialogAction.STAT);
|
||||
list.add(DialogAction.DOWNLOAD);
|
||||
|
||||
list.add(DialogAction.pinmsg);
|
||||
list.add(DialogAction.unpinmsg);
|
||||
|
||||
if (DNRModule.isDnrEnabledFor(peerId)) {
|
||||
list.add(DialogAction.DNR_OFF);
|
||||
} else {
|
||||
list.add(DialogAction.DNR_ON);
|
||||
}
|
||||
|
||||
if (DNRModule.isDntEnabledFor(peerId)) {
|
||||
list.add(DialogAction.DNT_OFF);
|
||||
} else {
|
||||
list.add(DialogAction.DNT_ON);
|
||||
}
|
||||
|
||||
list.add(DialogAction.ENCRYPT);
|
||||
IMProcessor prov = EncryptProvider.getProcessorFor(peerId);
|
||||
if (prov != null && !prov.isPublic()) {
|
||||
list.add(DialogAction.ENCRYPT_SETT);
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedHashMap<DialogAction, Integer> injectToHashMap(LinkedHashMap<DialogAction, Integer> hashMap) {
|
||||
// hashMap.put(DialogAction.STAT, AndroidUtils.getIdentifier("dialogstats", "string"));
|
||||
hashMap.put(DialogAction.DOWNLOAD, R.string.download_dl);
|
||||
|
||||
hashMap.put(DialogAction.DNR_ON, R.string.DNR_ON);
|
||||
hashMap.put(DialogAction.DNR_OFF, R.string.DNR_OFF);
|
||||
hashMap.put(DialogAction.DNT_ON, R.string.DNT_ON);
|
||||
hashMap.put(DialogAction.DNT_OFF, R.string.DNT_OFF);
|
||||
|
||||
hashMap.put(DialogAction.ENCRYPT, R.string.encryption);
|
||||
hashMap.put(DialogAction.ENCRYPT_SETT, R.string.encryption_sett);
|
||||
|
||||
// hashMap.put(DialogAction.pinmsg, getIdentifier("pinmsg", "string"));
|
||||
// hashMap.put(DialogAction.unpinmsg, getIdentifier("unpinmsg", "string"));
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
public static List<Object> injectToList(List<Object> actions) {
|
||||
var list = new ArrayList<>(actions);
|
||||
|
||||
// list.add(new DialogActionsListView.b.a(DialogAction.STAT, 1, R.attr.im_ic_stats, R.string.dialogstats)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DOWNLOAD, 1, R.attr.im_ic_msgdl, R.string.download_dl)); // DialogAction, Int, Icon, String
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNR_ON, 2, R.attr.im_ic_pinned_msg_hide, R.string.DNR_ON)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNR_OFF, 2, R.attr.im_ic_pinned_msg_show, R.string.DNR_OFF)); // DialogAction, Int, Icon, String
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_ON, 2, R.attr.im_ic_edit_msg, R.string.DNT_ON)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.DNT_OFF, 2, R.attr.im_ic_edit_msg, R.string.DNT_OFF)); // DialogAction, Int, Icon, String
|
||||
|
||||
if (!AndroidUtils.isTablet()) {
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT, 3, R.attr.im_ic_keyboard, R.string.encryption)); // DialogAction, Int, Icon, String
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.ENCRYPT_SETT, 3, R.attr.im_ic_more_vertical, R.string.encryption_sett)); // DialogAction, Int, Icon, String
|
||||
}
|
||||
|
||||
list.add(new DialogActionsListView.b.a(DialogAction.MARK_AS_READ, 4, R.attr.im_ic_done, R.string.vkim_dialogs_list_option_mark_as_read)); // DialogAction, Int, Icon, String
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void forceInvalidateDialogActions(Dialog d) {
|
||||
EntityIntMap<Dialog> map = new EntityIntMap<>();
|
||||
map.a(d.getId(), d);
|
||||
ImEngine1.a().a(new OnDialogUpdateEvent(null, map));
|
||||
}
|
||||
|
||||
public static List<DialogAction> injectToListAccess(List<DialogAction> actions, Dialog dialog) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
actions.add(DialogAction.STAT);
|
||||
|
||||
actions.add(DialogAction.DOWNLOAD);
|
||||
|
||||
if (DNRModule.isDnrEnabledFor(peerId)) {
|
||||
actions.add(DialogAction.DNR_OFF);
|
||||
} else {
|
||||
actions.add(DialogAction.DNR_ON);
|
||||
}
|
||||
|
||||
if (DNRModule.isDntEnabledFor(peerId)) {
|
||||
actions.add(DialogAction.DNT_OFF);
|
||||
} else {
|
||||
actions.add(DialogAction.DNT_ON);
|
||||
}
|
||||
|
||||
actions.add(DialogAction.ENCRYPT);
|
||||
IMProcessor prov = EncryptProvider.getProcessorFor(peerId);
|
||||
if (prov != null && !prov.isPublic()) {
|
||||
actions.add(DialogAction.ENCRYPT_SETT);
|
||||
}
|
||||
|
||||
actions.add(DialogAction.MARK_AS_READ);
|
||||
return actions;
|
||||
}
|
||||
|
||||
public static boolean onClickHeader(DialogAction action, Dialog dialog) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.MARK_AS_READ) {
|
||||
DNRModule.hookRead(dialog);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
}
|
||||
|
||||
if (action == DialogAction.STAT) {
|
||||
DNRModule.hookDialogInfo(dialog);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "dialog-" + peerId + ".html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
AndroidUtils.sendToast(AndroidUtils.getString(R.string.download_dl_error));
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.DNR_ON) {
|
||||
setDnr(dialog, true);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
} else if (action == DialogAction.DNR_OFF) {
|
||||
setDnr(dialog, false);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.DNT_ON) {
|
||||
setDnt(dialog, true);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
} else if (action == DialogAction.DNT_OFF) {
|
||||
setDnt(dialog, false);
|
||||
forceInvalidateDialogActions(dialog);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.ENCRYPT_SETT) {
|
||||
CryptImHook.hookPref(peerId);
|
||||
return true;
|
||||
} else if (action == DialogAction.ENCRYPT) {
|
||||
CryptImHook.hook(peerId, dialog);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean onClick(Dialog dialog, DialogAction action) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
try {
|
||||
peerId = dialog.getId();
|
||||
} catch (Exception e) {
|
||||
Log.d("DialoggetId", "null");
|
||||
}
|
||||
}
|
||||
|
||||
if (peerId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.MARK_AS_READ) {
|
||||
DNRModule.hookRead(dialog);
|
||||
}
|
||||
|
||||
if (action == DialogAction.STAT) {
|
||||
DNRModule.hookDialogInfo(dialog);
|
||||
return true;
|
||||
}
|
||||
if (action == DialogAction.DOWNLOAD) {
|
||||
File out = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), peerId + "-dialog.html");
|
||||
try {
|
||||
new MessagesDownloader().downloadDialog(peerId, new HtmlDialogDownloaderFormatProvider(), out);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.DNR_ON) {
|
||||
setDnr(dialog, true);
|
||||
return true;
|
||||
} else if (action == DialogAction.DNR_OFF) {
|
||||
setDnr(dialog, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.DNT_ON) {
|
||||
setDnt(dialog, true);
|
||||
return true;
|
||||
} else if (action == DialogAction.DNT_OFF) {
|
||||
setDnt(dialog, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.pinmsg) {
|
||||
pinnedMsg(peerId, true);
|
||||
return true;
|
||||
} else if (action == DialogAction.unpinmsg) {
|
||||
pinnedMsg(peerId, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == DialogAction.ENCRYPT_SETT) {
|
||||
CryptImHook.hookPref(peerId);
|
||||
return true;
|
||||
} else if (action == DialogAction.ENCRYPT) {
|
||||
CryptImHook.hook(peerId, dialog);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<MsgAction, DelegateMsg.a.a> injectToHashMapMsg(LinkedHashMap<MsgAction, DelegateMsg.a.a> hashMap) {
|
||||
hashMap.put(MsgAction.KICK, new DelegateMsg.a.a(R.string.vkim_accessibility_kick_from_chat));
|
||||
hashMap.put(MsgAction.TRANSLATE, new DelegateMsg.a.a(R.string.translator));
|
||||
hashMap.put(MsgAction.READTO, new DelegateMsg.a.a(R.string.readto));
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
public static boolean onClickMsg(Context context, MsgAction action, Msg msg) {
|
||||
var peerId = msg.v1();
|
||||
|
||||
if (action == MsgAction.READTO) {
|
||||
DNRModule.hookReadStartMsgTo(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (action == MsgAction.KICK) {
|
||||
DNRModule.hookKick(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg instanceof MsgFromUser) {
|
||||
var text = ((MsgFromUser) msg).f();
|
||||
var isTextExist = !text.isEmpty() && !text.equals(" ");
|
||||
|
||||
if (isTextExist) {
|
||||
text = EncryptProvider.decryptMessage(text, peerId);
|
||||
}
|
||||
|
||||
if (action == MsgAction.TRANSLATE) {
|
||||
if (isTextExist) {
|
||||
Translate.showTranslatedText(context, text);
|
||||
} else {
|
||||
AndroidUtils.sendToast(context.getString(R.string.translator_no_text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void pinnedMsg(int dialogid, boolean needToBePinned) {
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
var request = new Request.a()
|
||||
.b("https://" + ProxyUtils.getApi() + "/method/" + (needToBePinned ? "messages.pinConversation" : "messages.unpinConversation") + "?peer_id=" + dialogid + "&access_token=" + AccountManagerUtils.getUserToken() + "&v=5.119")
|
||||
.a(Headers.a("User-Agent", Network.l.c().a(), "Content-Type", "application/x-www-form-urlencoded; charset=utf-8"))
|
||||
.a();
|
||||
|
||||
try {
|
||||
var response = new OkHttpClient().a(request).execute().a().g();
|
||||
Log.d("Pins", response);
|
||||
} catch (IOException e) {
|
||||
Log.e("Pins", "Error while pinning message", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
|
||||
AndroidUtils.sendToast(AndroidUtils.getString(R.string.pin_dialog) + " " + AndroidUtils.getString(needToBePinned ? R.string.dialog_pinned : R.string.dialog_unpinned));
|
||||
}
|
||||
|
||||
public static void setDnr(Dialog dialog, boolean value) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
}
|
||||
|
||||
DNRModule.hookDNR(peerId);
|
||||
}
|
||||
|
||||
public static void setDnt(Dialog dialog, boolean value) {
|
||||
int peerId = 0;
|
||||
|
||||
if (dialog != null) {
|
||||
peerId = dialog.getId();
|
||||
}
|
||||
|
||||
DNRModule.hookDNT(peerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static ru.vtosters.lite.dnr.DNRInjector.forceInvalidateDialogActions;
|
||||
import static ru.vtosters.lite.dialogs.DialogHeaderInjector.forceInvalidateDialogActions;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
|
||||
import static ru.vtosters.lite.utils.LifecycleUtils.getCurrentActivity;
|
||||
|
||||
Reference in New Issue
Block a user