Refactoring of some code that suggested what to fix in the comments in our vk group

This commit is contained in:
gdlbo
2022-06-02 12:33:52 +03:00
parent f200c6e59a
commit d9e867cb6e
14 changed files with 108 additions and 112 deletions
@@ -1,7 +1,7 @@
package bruhcollective.itaysonlab.libvkx.client;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.content.Context;
import android.os.RemoteException;
@@ -36,7 +36,7 @@ public class LibVKXClient {
}
public static boolean isIntegrationEnabled() {
return BooleanFalse("libvkx_integration") && isVkxInstalled();
return getBoolValue("libvkx_integration", false) && isVkxInstalled();
}
public static boolean play(MusicTrack musicTrack, List<MusicTrack> list, PlayerRefer playerRefer) {
@@ -1,10 +1,10 @@
package ru.vtosters.lite.dnr;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
public class DNRPrefs {
public static boolean getStoriesRead() {
return BooleanFalse("read_s");
return getBoolValue("read_s", false);
}
public static boolean getMarkAsReadWithoutExceptions(int peerId) {
@@ -28,27 +28,27 @@ public class DNRPrefs {
}
public static boolean readPM(int peer) {
return (peer > 0 && peer < 2000000000) && BooleanFalse("read_pm");
return (peer > 0 && peer < 2000000000) && getBoolValue("read_pm", false);
}
public static boolean readConversations(int peer) {
return (peer > 2000000000) && BooleanFalse("read_conversations");
return (peer > 2000000000) && getBoolValue("read_conversations", false);
}
public static boolean readBots(int peer) {
return (peer < 0) && BooleanFalse("read_bot");
return (peer < 0) && getBoolValue("read_bot", false);
}
public static boolean writePM(int peer) {
return (peer > 0 && peer < 2000000000) && BooleanFalse("write_pm");
return (peer > 0 && peer < 2000000000) && getBoolValue("write_pm", false);
}
public static boolean writeConversations(int peer) {
return (peer > 2000000000) && BooleanFalse("write_conversations");
return (peer > 2000000000) && getBoolValue("write_conversations", false);
}
public static boolean writeBots(int peer) {
return (peer < 0) && BooleanFalse("write_bot");
return (peer < 0) && getBoolValue("write_bot", false);
}
public static boolean getActivityWithoutExceptions(int peerId) {
@@ -1,7 +1,6 @@
package ru.vtosters.lite.encryption.base;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -50,29 +49,29 @@ public abstract class IMProcessor {
public boolean isUsed() {
//Log.d("IMProcessor", "Checking if decoded with "+getUIName());
return BooleanTrue("VT_IMDecode_"+getPrefKey());
return getBoolValue("VT_IMDecode_"+getPrefKey(), true);
}
public boolean isUsedToEncrypt(int id) {
//Log.d("IMProcessor", "Checking if "+id+" is ready to be encrypted with "+getUIName());
return BooleanFalse("VT_IMEncode_"+getPrefKey()+"_"+id);
return getBoolValue("VT_IMEncode_"+getPrefKey()+"_"+id, false);
}
public void enableEncryptFor(int id) {
Globals.getPrefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, true).apply();
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, true).apply();
}
public void disableEncryptFor(int id) {
Globals.getPrefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, false).apply();
Globals.getDefprefs().edit().putBoolean("VT_IMEncode_"+getPrefKey()+"_"+id, false).apply();
}
public void setEncryptionKeyFor(int id, @Nullable String key) {
if (key == null || key.isEmpty()) key = "VTAesDefault";
Globals.getPrefs().edit().putString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, key).apply();
Globals.getDefprefs().edit().putString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, key).apply();
}
@Nullable
public String getEncryptionKeyFor(int id) {
return Globals.getPrefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, null);
return Globals.getDefprefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, null);
}
}
@@ -113,7 +113,7 @@ public class VTostersAESProcessor extends IMProcessor {
@Nullable
@Override
public String getEncryptionKeyFor(int id) {
return Globals.getPrefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, "VTAesDefault");
return Globals.getDefprefs().getString("VT_IMEncodeKey_"+getPrefKey()+"_"+id, "VTAesDefault");
}
public static class Triple<F, S, T> {
@@ -1,6 +1,6 @@
package ru.vtosters.lite.f0x1d;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.content.Context;
import android.content.SharedPreferences;
@@ -136,7 +136,7 @@ public class VTVerifications {
return true;
}
if (!BooleanTrue("VT_Verification")) {
if (!getBoolValue("VT_Verification", true)) {
return false;
}
@@ -148,7 +148,7 @@ public class VTVerifications {
return true;
}
if (!BooleanTrue("VT_Fire")) {
if (!getBoolValue("VT_Fire", true)) {
return false;
}
@@ -156,7 +156,7 @@ public class VTVerifications {
}
public static boolean hasDeveloper(JSONObject jSONObject) {
if (!BooleanTrue("VT_Dev")) {
if (!getBoolValue("VT_Dev", true)) {
return false;
}
@@ -2,7 +2,7 @@ package ru.vtosters.lite.ui.dialogs;
import static ru.vtosters.lite.utils.Globals.edit;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.app.Activity;
import android.app.AlertDialog;
@@ -17,7 +17,7 @@ import ru.vtosters.lite.utils.OEMDetector;
public class DisableBattery {
public static void alert(Activity activity) {
if (OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && BooleanTrue("showDoze")) {
if (OEMDetector.isOEM() && Build.VERSION.SDK_INT >= 23 && getBoolValue("showDoze", true)) {
final Context context = getContext();
if (!((PowerManager) context.getSystemService(Context.POWER_SERVICE)).isIgnoringBatteryOptimizations(context.getPackageName())) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
@@ -3,7 +3,7 @@ package ru.vtosters.lite.ui.dialogs;
import static ru.vtosters.lite.utils.Globals.edit;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.isGmsInstalled;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.app.Activity;
import android.app.AlertDialog;
@@ -39,7 +39,7 @@ public class InstallGMS {
context.startActivity(a2);
}
});
if (BooleanTrue("showAlertGms")) {
if (getBoolValue("showAlertGms", true)) {
builder.show();
}
}
@@ -1,7 +1,7 @@
package ru.vtosters.lite.ui.dialogs;
import static ru.vtosters.lite.utils.Globals.edit;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.app.Activity;
import android.app.AlertDialog;
@@ -36,7 +36,7 @@ public class Start {
activity.startActivity(new Intent("android.intent.action.VIEW").setData(Uri.parse("https://t.me/vtosters")));
}
});
if (BooleanTrue("showAlert")) {
if (getBoolValue("showAlert", true)) {
builder.show();
}
}
@@ -2,14 +2,13 @@ package ru.vtosters.lite.utils;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import com.vk.core.ui.themes.VKTheme;
import com.vk.im.engine.events.OnMsgUpdateEvent;
import com.vk.im.engine.internal.longpoll.a.MsgDeleteLpTask;
import com.vk.im.engine.internal.storage.CacheEnvironment;
@@ -44,7 +43,7 @@ public class DeletedMessagesHandler {
}
public static boolean hook() {
return BooleanFalse("undeletemsg");
return getBoolValue("undeletemsg", false);
}
public static void setBodyDBParser(Msg msg) {
@@ -1,5 +1,6 @@
package ru.vtosters.lite.utils;
import static ru.vtosters.lite.utils.Preferences.preferences;
import static ru.vtosters.lite.utils.Preferences.getLocale;
import android.app.Activity;
@@ -34,11 +35,10 @@ import java.util.Locale;
public class Globals {
private static final List<Activity> activities = new ArrayList<>();
static SharedPreferences prefs = getContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
public static SharedPreferences getPrefs() {
if (prefs == null) prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
return prefs;
public static SharedPreferences getDefprefs() {
if (preferences == null) preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
return preferences;
}
public static void componentSwitcher(String component, Boolean enabled) {
@@ -4,14 +4,13 @@ import static java.lang.Long.MAX_VALUE;
import static ru.vtosters.lite.ui.fragments.dockbar.DockBarManager.getInstance;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.BooleanTrue;
import static ru.vtosters.lite.utils.Preferences.CommentsSort;
import static ru.vtosters.lite.utils.Preferences.adsgroup;
import static ru.vtosters.lite.utils.Preferences.adsstories;
import static ru.vtosters.lite.utils.Preferences.authorsrecomm;
import static ru.vtosters.lite.utils.Preferences.copyright_post;
import static ru.vtosters.lite.utils.Preferences.friendsrecomm;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Preferences.newfeed;
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
@@ -76,7 +75,7 @@ public class Newsfeed {
}
public static void getFilter(String boolname, String filename) {
if (BooleanTrue(boolname)) {
if (getBoolValue(boolname, true)) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getContext().getAssets().open(filename)));
while (true) {
@@ -23,6 +23,8 @@ import com.vtosters.lite.data.Users;
import java.util.Locale;
public class Preferences {
public static SharedPreferences preferences = getContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
public static String VERSIONNAME = "Beta";
public static Integer VKBUILD = 12116; // 3439 orig
@@ -39,71 +41,67 @@ public class Preferences {
systemThemeChanger();
} // VK Init
public static boolean BooleanFalse(String key) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
return prefs.getBoolean(key, false);
} // Make bool false by default + get current value
public static boolean BooleanTrue(String key) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
return prefs.getBoolean(key, true);
} // Make bool true by default + get current value
public static boolean getBoolValue(String key, Boolean value) {
if (preferences == null) {
preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
}
return preferences.getBoolean(key, value);
} // Set bool by default and get value
public static boolean opusmodule() {
return BooleanTrue("opusmodule");
return getBoolValue("opusmodule", true);
}
public static boolean systemtheme() {
return BooleanTrue("systemtheme");
return getBoolValue("systemtheme", true);
}
public static boolean authorsrecomm() {
return BooleanTrue("authorsrecomm");
return getBoolValue("authorsrecomm", true);
}
public static boolean captions() {
return BooleanTrue("captions");
return getBoolValue("captions", true);
}
public static boolean copyright_post() {
return BooleanFalse("copyright_post");
return getBoolValue("copyright_post", false);
}
public static boolean default_ad_list() {
return BooleanFalse("default_ad_list");
return getBoolValue("default_ad_list", false);
}
public static boolean shitposting() {
return BooleanFalse("shitposting");
return getBoolValue("shitposting", false);
}
public static boolean friendsrecomm() {
return BooleanTrue("friendsrecomm");
return getBoolValue("friendsrecomm", true);
}
public static boolean isBGStickersEnabled() {
return BooleanTrue("isBGStickersEnabled");
return getBoolValue("isBGStickersEnabled", true);
}
public static boolean ads() {
return BooleanFalse("__dbg_no_ads");
return getBoolValue("__dbg_no_ads", false);
}
public static boolean adsgroup() {
return BooleanFalse("adsgroup");
return getBoolValue("adsgroup", false);
}
public static boolean olddock() {
return BooleanFalse("olddock");
return getBoolValue("olddock", false);
}
public static boolean adsslider() {
return BooleanFalse("__dbg_no_slider_ads");
return getBoolValue("__dbg_no_slider_ads", false);
}
public static boolean adsstories() {
return BooleanFalse("adsstories");
return getBoolValue("adsstories", false);
}
public static boolean alteremoji(Context context) {
@@ -111,67 +109,67 @@ public class Preferences {
}
public static boolean alteremojipref() {
return BooleanFalse("alteremoji");
return getBoolValue("alteremoji", false);
}
public static boolean awayphp() {
return BooleanTrue("awayphp");
return getBoolValue("awayphp", true);
}
public static boolean VKUI_INJ() {
return BooleanTrue("VKUI_INJ");
return getBoolValue("VKUI_INJ", true);
}
public static boolean benchmark() {
return BooleanFalse("benchmark");
return getBoolValue("benchmark", false);
}
public static boolean calls() {
return BooleanTrue("calls");
return getBoolValue("calls", true);
}
public static boolean convUsersOnline() {
return BooleanFalse("convUsersOnline");
return getBoolValue("convUsersOnline", false);
}
public static boolean darkmode() {
return BooleanTrue("darkmode");
return getBoolValue("darkmode", true);
}
public static boolean dev() {
return BooleanFalse("dev");
return getBoolValue("dev", false);
}
public static boolean devmenu() {
return BooleanFalse("devmenu");
return getBoolValue("devmenu", false);
}
public static boolean dnr() {
return BooleanTrue("dnr");
return getBoolValue("dnr", true);
}
public static boolean dns() {
return BooleanTrue("dns");
return getBoolValue("dns", true);
}
public static boolean libverify() {
return BooleanFalse("libverify");
return getBoolValue("libverify", false);
}
public static boolean dnt() {
return BooleanTrue("dnt");
return getBoolValue("dnt", true);
}
public static boolean dockcounter() {
return BooleanTrue("dockcounter");
return getBoolValue("dockcounter", true);
}
public static boolean feedcache() {
return BooleanTrue("feedcache");
return getBoolValue("feedcache", true);
}
public static boolean CommentsSort() {
return BooleanFalse("commentssorting");
return getBoolValue("commentssorting", false);
}
public static void forceOffline() {
@@ -182,59 +180,59 @@ public class Preferences {
}
public static boolean fulltime() {
return BooleanTrue("fulltime");
return getBoolValue("fulltime", true);
}
public static boolean gcmfix() {
return BooleanTrue("gcmfix");
return getBoolValue("gcmfix", true);
}
public static boolean hasMusicSubscription() {
return BooleanTrue("hasMusicSubscription");
return getBoolValue("hasMusicSubscription", true);
}
public static boolean isEnableExternalOpening() {
return BooleanFalse("isEnableExternalOpening");
return getBoolValue("isEnableExternalOpening", false);
}
public static boolean iconvk() {
return BooleanFalse("iconvk");
return getBoolValue("iconvk", false);
}
public static boolean iconvkru() {
return BooleanFalse("iconvkru");
return getBoolValue("iconvkru", false);
}
public static boolean isMusicRestricted() {
return BooleanTrue("isMusicRestricted");
return getBoolValue("isMusicRestricted", true);
}
public static boolean msgflat() {
return BooleanFalse("msgflat");
return getBoolValue("msgflat", false);
}
public static boolean msgtails() {
return BooleanTrue("msgtails");
return getBoolValue("msgtails", true);
}
public static boolean navbar() {
return BooleanTrue("navbar");
return getBoolValue("navbar", true);
}
public static boolean newfeed() {
return BooleanTrue("newfeed");
return getBoolValue("newfeed", true);
}
public static boolean offline() {
return BooleanTrue("offline");
return getBoolValue("offline", true);
}
public static boolean oldabout() {
return BooleanFalse("oldabout");
return getBoolValue("oldabout", false);
}
public static boolean postsrecomm() {
return BooleanTrue("postsrecomm");
return getBoolValue("postsrecomm", true);
}
public static String readstatus() {
@@ -246,59 +244,59 @@ public class Preferences {
}
public static boolean refsfilter() {
return BooleanFalse("refsfilter");
return getBoolValue("refsfilter", false);
}
public static boolean setoffline() {
return BooleanFalse("setoffline");
return getBoolValue("setoffline", false);
}
public static boolean shortinfo() {
return BooleanTrue("shortinfo");
return getBoolValue("shortinfo", true);
}
public static boolean shortlinkfilter() {
return BooleanFalse("shortlinkfilter");
return getBoolValue("shortlinkfilter", false);
}
public static boolean shortpost() {
return BooleanTrue("shortpost");
return getBoolValue("shortpost", true);
}
public static boolean showmenu() {
return BooleanFalse("showmenu");
return getBoolValue("showmenu", false);
}
public static boolean ssl() {
return BooleanTrue("ssl");
return getBoolValue("ssl", true);
}
public static boolean stories() {
return BooleanTrue("stories");
return getBoolValue("stories", true);
}
public static boolean swipe() {
return BooleanTrue("swipe");
return getBoolValue("swipe", true);
}
public static boolean systememoji() {
return BooleanFalse("systememoji");
return getBoolValue("systememoji", false);
}
public static boolean unlockstats() {
return BooleanFalse("unlockstats");
return getBoolValue("unlockstats", false);
}
public static boolean usevkui() {
return BooleanTrue("usevkui");
return getBoolValue("usevkui", true);
}
public static boolean vksans() {
return BooleanFalse("vksans");
return getBoolValue("vksans", false);
}
public static boolean voice() {
return BooleanTrue("voice");
return getBoolValue("voice", true);
}
public static boolean newvideo() {
@@ -323,11 +321,11 @@ public class Preferences {
} // Fix photo picker for sdk 29+
public static boolean color_grishka() {
return BooleanTrue("color_grishka");
return getBoolValue("color_grishka", true);
}
public static boolean vkme_msg() {
return BooleanFalse("vkme_msg");
return getBoolValue("vkme_msg", false);
}
public static String VKVersion() {
@@ -3,7 +3,7 @@ package ru.vtosters.lite.utils;
import static java.lang.System.clearProperty;
import static java.lang.System.getProperties;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Preferences.BooleanFalse;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import java.util.Properties;
@@ -209,6 +209,6 @@ public class Proxy {
public static boolean proxyvk() {
return BooleanFalse("proxyvk");
return getBoolValue("proxyvk", false);
} // Official vk proxy enforcer
}
@@ -2,6 +2,7 @@ package ru.vtosters.lite.utils;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Themes.getColorFromAttr;
import static ru.vtosters.lite.utils.Themes.hex;
@@ -67,7 +68,7 @@ public class VKUIInjector {
public static void inject(WebView webView) {
String string = getPrefsValue("darktheme");
if (Preferences.BooleanTrue("VKUI_INJ")) {
if (getBoolValue("VKUI_INJ", true)) {
if (!isLoaded) {
load();
}