From 099c699702468ff07baf0dbd93789195766c38c7 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:37:07 +0300 Subject: [PATCH] added vkn online fix disabler --- .../vtosters/hooks/OnlineFormatterHook.java | 23 ++++++++++++------- .../ru/vtosters/hooks/VerificationsHook.java | 5 ++-- .../ru/vtosters/hooks/other/Preferences.java | 4 ++++ .../java/ru/vtosters/lite/ssfs/UsersList.java | 3 ++- .../lite/ui/fragments/ActivityFragment.java | 3 +++ .../lite/ui/fragments/OtherFragment.java | 6 ++--- .../ru/vtosters/lite/utils/OnlineBypass.java | 7 +++--- .../vtosters/lite/utils/VTVerifications.java | 3 ++- smali/res/xml/preferences_activity.xml | 2 +- 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java b/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java index 0fb389137..f519330b8 100644 --- a/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java +++ b/app/src/main/java/ru/vtosters/hooks/OnlineFormatterHook.java @@ -5,6 +5,7 @@ import com.vtosters.lite.R; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import ru.vtosters.hooks.other.Preferences; import ru.vtosters.lite.utils.AndroidUtils; import java.io.IOException; @@ -115,14 +116,20 @@ public class OnlineFormatterHook { return AndroidUtils.getString(R.string.custom_online) + " " + appname; } - public static JSONObject onlineHook(JSONObject json) throws ParseException, IOException, JSONException { - if (getBoolValue("onlinefix", false)) JsonInjectors.setOnlineInfo(json); + public static JSONObject onlineHook(JSONObject json) { + if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return json; + + try { + JsonInjectors.setOnlineInfo(json); + } catch (JSONException e) { + Log.e("onlineHook", e.getMessage()); + } return json; } - public static JSONArray onlineHookList(JSONArray jsonArr) throws ParseException, IOException, JSONException { - if (!getBoolValue("onlinefix", false)) return jsonArr; + public static JSONArray onlineHookList(JSONArray jsonArr) { + if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return jsonArr; try { JsonInjectors.setOnlineInfoUsers(jsonArr); @@ -134,7 +141,7 @@ public class OnlineFormatterHook { } public static JSONObject onlineHookProfiles(JSONObject json) { - if (!getBoolValue("onlinefix", false)) return json; + if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return json; try { JsonInjectors.setOnlineInfoUsers(json.optJSONArray("profiles")); @@ -146,7 +153,7 @@ public class OnlineFormatterHook { } public static JSONObject onlineHookItems(JSONObject json) { - if (!getBoolValue("onlinefix", false)) return json; + if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return json; try { JsonInjectors.setOnlineInfoUsers(json.optJSONArray("items")); @@ -157,8 +164,8 @@ public class OnlineFormatterHook { return json; } - public static JSONObject onlineHookRequestsAndRecommendations(JSONObject json) throws ParseException, IOException, JSONException { - if (!getBoolValue("onlinefix", false)) return json; + public static JSONObject onlineHookRequestsAndRecommendations(JSONObject json) { + if (!getBoolValue("onlinefix", false) || Preferences.serverFeaturesDisable()) return json; try { JsonInjectors.setOnlineInfoUsers(json.optJSONObject("read_requests").optJSONArray("items")); diff --git a/app/src/main/java/ru/vtosters/hooks/VerificationsHook.java b/app/src/main/java/ru/vtosters/hooks/VerificationsHook.java index e37209392..553b195d2 100644 --- a/app/src/main/java/ru/vtosters/hooks/VerificationsHook.java +++ b/app/src/main/java/ru/vtosters/hooks/VerificationsHook.java @@ -2,6 +2,7 @@ package ru.vtosters.hooks; import com.vk.dto.common.VerifyInfo; import org.json.JSONObject; +import ru.vtosters.hooks.other.Preferences; import ru.vtosters.lite.utils.VTVerifications; import static ru.vtosters.hooks.other.Preferences.getBoolValue; @@ -20,7 +21,7 @@ public class VerificationsHook { return true; } - if (!getBoolValue("VT_Verification", true) || getBoolValue("serverFeaturesDisable", false)) { + if (!getBoolValue("VT_Verification", true) || Preferences.serverFeaturesDisable()) { return false; } @@ -32,7 +33,7 @@ public class VerificationsHook { return true; } - if (!getBoolValue("VT_Fire", true) || getBoolValue("serverFeaturesDisable", false)) { + if (!getBoolValue("VT_Fire", true) || Preferences.serverFeaturesDisable()) { return false; } diff --git a/app/src/main/java/ru/vtosters/hooks/other/Preferences.java b/app/src/main/java/ru/vtosters/hooks/other/Preferences.java index 22b9cfcf7..716938e9a 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/Preferences.java +++ b/app/src/main/java/ru/vtosters/hooks/other/Preferences.java @@ -242,6 +242,10 @@ public class Preferences { return getBoolValue("autoalltranslate", false); } + public static boolean serverFeaturesDisable() { + return getBoolValue("serverFeaturesDisable", false); + } + public static boolean shortinfo() { return getBoolValue("shortinfo", true); } diff --git a/app/src/main/java/ru/vtosters/lite/ssfs/UsersList.java b/app/src/main/java/ru/vtosters/lite/ssfs/UsersList.java index 8f36a2bcd..e2ef0eb1a 100644 --- a/app/src/main/java/ru/vtosters/lite/ssfs/UsersList.java +++ b/app/src/main/java/ru/vtosters/lite/ssfs/UsersList.java @@ -8,6 +8,7 @@ import okhttp3.Response; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import ru.vtosters.hooks.other.Preferences; import ru.vtosters.lite.di.singleton.VtOkHttpClient; import ru.vtosters.lite.utils.AccountManagerUtils; import ru.vtosters.lite.utils.AndroidUtils; @@ -27,7 +28,7 @@ public class UsersList { public static void getUsersList() { var prefs = AndroidUtils.getGlobalContext().getSharedPreferences("vt_another_data", 0); - if ((!NetworkUtils.isNetworkConnected() || NetworkUtils.isInternetSlow()) && prefs.contains("ids") || getBoolValue("serverFeaturesDisable", false)) { + if ((!NetworkUtils.isNetworkConnected() || NetworkUtils.isInternetSlow()) && prefs.contains("ids") || Preferences.serverFeaturesDisable()) { return; } diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/ActivityFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/ActivityFragment.java index 905f5a425..cd54a0712 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/ActivityFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/ActivityFragment.java @@ -3,7 +3,9 @@ package ru.vtosters.lite.ui.fragments; import android.os.Bundle; import androidx.preference.Preference; import com.vtosters.lite.R; +import ru.vtosters.hooks.other.Preferences; +import static ru.vtosters.hooks.other.Preferences.getBoolValue; import static ru.vtosters.hooks.other.Preferences.offline; public class ActivityFragment extends TrackedMaterialPreferenceToolbarFragment { @@ -12,6 +14,7 @@ public class ActivityFragment extends TrackedMaterialPreferenceToolbarFragment { super.onCreate(bundle); addPreferencesFromResource(R.xml.preferences_activity); findPreference("setoffline").setEnabled(offline()); + findPreference("onlinefixcategory").setVisible(!Preferences.serverFeaturesDisable()); } @Override diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/OtherFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/OtherFragment.java index c1d02f9e1..7562fbc67 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/OtherFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/OtherFragment.java @@ -112,9 +112,9 @@ public class OtherFragment extends TrackedMaterialPreferenceToolbarFragment { return true; }); - findPreference("VT_Verification").setVisible(!getBoolValue("serverFeaturesDisable", false)); - findPreference("VT_Fire").setVisible(!getBoolValue("serverFeaturesDisable", false)); - findPreference("updateverifdata").setVisible(!getBoolValue("serverFeaturesDisable", false)); + findPreference("VT_Verification").setVisible(!Preferences.serverFeaturesDisable()); + findPreference("VT_Fire").setVisible(!Preferences.serverFeaturesDisable()); + findPreference("updateverifdata").setVisible(!Preferences.serverFeaturesDisable()); var vkAdminTokenPref = findPreference("vk_admin_token"); vkAdminTokenPref.setVisible(Preferences.getPreferences().getBoolean("new_music_downloading_way", false)); diff --git a/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java b/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java index 293dbed14..b07306477 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java +++ b/app/src/main/java/ru/vtosters/lite/utils/OnlineBypass.java @@ -3,6 +3,7 @@ package ru.vtosters.lite.utils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import ru.vtosters.hooks.other.Preferences; import static ru.vtosters.lite.foaf.FoafBase.getBypassedOnlineInfo; @@ -13,7 +14,7 @@ public class OnlineBypass { return json; } var onlineinfo = json.optJSONObject("online_info"); - if (onlineinfo != null && !onlineinfo.optBoolean("visible")) { + if (onlineinfo != null && !onlineinfo.optBoolean("visible") && !Preferences.serverFeaturesDisable()) { var bypassed = getBypassedOnlineInfo(id); if (bypassed.optInt("last_seen", 0) != 0) { json.remove("online_info"); @@ -37,7 +38,7 @@ public class OnlineBypass { } public static JSONArray setOnlineInfoUsers(JSONArray profiles) throws JSONException { - if (profiles == null || profiles.length() == 0) return profiles; + if (profiles == null || profiles.length() == 0 || Preferences.serverFeaturesDisable()) return profiles; StringBuilder sb = new StringBuilder(); var curVkId = AccountManagerUtils.getUserId(); for (int i = 0; i < profiles.length(); i++) { @@ -51,7 +52,7 @@ public class OnlineBypass { sb.append(","); } var ids = sb.toString(); - if (ids.length() > 0) { + if (!ids.isEmpty()) { ids = ids.substring(0, ids.length() - 1); } else { return profiles; diff --git a/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java b/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java index 55ac55509..d79bd1cca 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java +++ b/app/src/main/java/ru/vtosters/lite/utils/VTVerifications.java @@ -7,6 +7,7 @@ import okhttp3.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import ru.vtosters.hooks.other.Preferences; import ru.vtosters.lite.di.singleton.VtOkHttpClient; import java.io.IOException; @@ -31,7 +32,7 @@ public class VTVerifications { return; } - if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids") || getBoolValue("serverFeaturesDisable", false)) { + if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids") || Preferences.serverFeaturesDisable()) { parseJson(prefs.getString("ids", "[]")); Log.d("VTVerifications", "load from memory. Roaming or Network issues"); isLoaded = true; diff --git a/smali/res/xml/preferences_activity.xml b/smali/res/xml/preferences_activity.xml index 617cec80d..2684ac7f2 100644 --- a/smali/res/xml/preferences_activity.xml +++ b/smali/res/xml/preferences_activity.xml @@ -92,7 +92,7 @@ android:key="listen_v" android:title="@string/listen_v_title"/> - +