From 697189a2b919005149a5629830c3caabafc875ea Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Thu, 30 Jun 2022 17:40:20 +0300 Subject: [PATCH] superapp editor test --- .../lite/encryption/EncryptProvider.java | 2 +- .../processors/VTostersAESProcessor.java | 3 +- .../vtosters/lite/f0x1d/VTVerifications.java | 51 +++++++++-------- .../java/ru/vtosters/lite/net/Request.java | 4 +- .../vtosters/lite/ui/dialogs/OTADialog.java | 4 +- .../lite/ui/fragments/VTSettings.java | 47 +++++++++++++++- .../lite/ui/vkui/ModalBottomSheetWrapper.java | 6 +- .../vtosters/lite/ui/vkui/VBListBuilder.java | 56 +++++++++++++++++++ .../lite/ui/vkui/VBottomSheetBuilder.java | 47 ++++++++++++++++ .../java/ru/vtosters/lite/utils/Globals.java | 4 +- .../ru/vtosters/lite/utils/JsonInjectors.java | 36 ++---------- .../java/ru/vtosters/lite/utils/Newsfeed.java | 4 +- .../ru/vtosters/lite/utils/OTAHelper.java | 2 +- .../java/ru/vtosters/lite/utils/Toggles.java | 5 +- 14 files changed, 197 insertions(+), 74 deletions(-) create mode 100644 app/src/main/java/ru/vtosters/lite/ui/vkui/VBListBuilder.java create mode 100644 app/src/main/java/ru/vtosters/lite/ui/vkui/VBottomSheetBuilder.java diff --git a/app/src/main/java/ru/vtosters/lite/encryption/EncryptProvider.java b/app/src/main/java/ru/vtosters/lite/encryption/EncryptProvider.java index 58f1e2b2c..ae6aa1d7f 100644 --- a/app/src/main/java/ru/vtosters/lite/encryption/EncryptProvider.java +++ b/app/src/main/java/ru/vtosters/lite/encryption/EncryptProvider.java @@ -89,7 +89,7 @@ public class EncryptProvider{ String msgBody = getBody(msg); - Log.d("EncryptProvider", "encryptMessage: msg = " + msg.toString()); + Log.d("EncryptProvider", "encryptMessage: msg = " + msg); Log.d("EncryptProvider", "encryptMessage: body = " + msgBody); Log.d("EncryptProvider", "encryptMessage: peerId = " + getPeerId(msg)); diff --git a/app/src/main/java/ru/vtosters/lite/encryption/processors/VTostersAESProcessor.java b/app/src/main/java/ru/vtosters/lite/encryption/processors/VTostersAESProcessor.java index 41b555e13..c8c97d209 100644 --- a/app/src/main/java/ru/vtosters/lite/encryption/processors/VTostersAESProcessor.java +++ b/app/src/main/java/ru/vtosters/lite/encryption/processors/VTostersAESProcessor.java @@ -23,7 +23,8 @@ public class VTostersAESProcessor extends IMProcessor{ private final static String CIPHER_INSTANCE = "AES/CBC/PKCS7Padding"; private final static String KEY_METHOD = "AES"; - private HashMap decodeMap = new HashMap<>(), encodeMap = new HashMap<>(); + private final HashMap decodeMap = new HashMap<>(); + private final HashMap encodeMap = new HashMap<>(); public void free(byte[] key){ decodeMap.remove(key); diff --git a/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java b/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java index 8e10bcf79..4e2b4dd1c 100644 --- a/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java +++ b/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java @@ -26,20 +26,18 @@ import okhttp3.RequestBody; import okhttp3.Response; import ru.vtosters.lite.utils.Globals; -public class VTVerifications { - private static List sVerifications = new ArrayList<>(); - private static List sPrometheuses = new ArrayList<>(); - private static List sDevelopers = new ArrayList<>(); - private static List sServiceAccounts = new ArrayList<>(); - +public class VTVerifications{ private static final OkHttpClient sClient = new OkHttpClient(); - + private static final List sVerifications = new ArrayList<>(); + private static final List sPrometheuses = new ArrayList<>(); + private static final List sDevelopers = new ArrayList<>(); + private static final List sServiceAccounts = new ArrayList<>(); private static SharedPreferences sVerificationsPrefs; public static void load(Context context){ sVerificationsPrefs = context.getSharedPreferences("vt_another_data", 0); - if (!Globals.isNetworkConnected() && sVerificationsPrefs.contains("ids")) { + if(!Globals.isNetworkConnected() && sVerificationsPrefs.contains("ids")){ parseJson(sVerificationsPrefs.getString("ids", "[]")); return; } @@ -63,7 +61,7 @@ public class VTVerifications { } @Override - public void a(Call call, IOException e) { + public void a(Call call, IOException e){ Log.d("VTVerifications", "" + e); } @@ -74,8 +72,9 @@ public class VTVerifications { * 0 - Verifications * 228 - Prometheus * 404 - Developer - * 1337 - Service account*/ - private static void parseJson(String payload) { + * 1337 - Service account + */ + private static void parseJson(String payload){ try { var json = new JSONObject(payload); @@ -88,11 +87,11 @@ public class VTVerifications { } } - private static void processIds(JSONArray jsonIds, List member) { - if (jsonIds == null || jsonIds.length() == 0) + private static void processIds(JSONArray jsonIds, List member){ + if(jsonIds == null || jsonIds.length() == 0) return; - for (int i = 0; i < jsonIds.length(); i++) + for(int i = 0; i < jsonIds.length(); i++) member.add(jsonIds.optInt(i)); } @@ -112,52 +111,52 @@ public class VTVerifications { return sServiceAccounts.contains(i); } - public static boolean vtverif() { + public static boolean vtverif(){ return getBoolValue("VT_Verification", true); } - private static int getId(JSONObject json) { + private static int getId(JSONObject json){ var id = json.optInt("id", 0); - if (!json.optString(NavigatorKeys.e).equals("group") && !json.optString(NavigatorKeys.e).equals("page") + if(!json.optString(NavigatorKeys.e).equals("group") && !json.optString(NavigatorKeys.e).equals("page") || json.optString(NavigatorKeys.e) == null) return id; else return -id; } - public static boolean isVerified(JSONObject jSONObject) { - if (jSONObject.optInt("verified", 0) == 1) { + public static boolean isVerified(JSONObject jSONObject){ + if(jSONObject.optInt("verified", 0) == 1){ return true; } - if (!getBoolValue("VT_Verification", true)) { + if(!getBoolValue("VT_Verification", true)){ return false; } return isVerified(getId(jSONObject)); } - public static boolean hasPrometheus(JSONObject jSONObject) { - if (jSONObject.optInt("trending", 0) == 1) { + public static boolean hasPrometheus(JSONObject jSONObject){ + if(jSONObject.optInt("trending", 0) == 1){ return true; } - if (!getBoolValue("VT_Fire", true)) { + if(!getBoolValue("VT_Fire", true)){ return false; } return isPrometheus(getId(jSONObject)); } - public static boolean hasDeveloper(JSONObject jSONObject) { - if (!getBoolValue("VT_Dev", true)) { + public static boolean hasDeveloper(JSONObject jSONObject){ + if(!getBoolValue("VT_Dev", true)){ return false; } return isDeveloper(getId(jSONObject)); } - public static VerifyInfo VerifyInfo(JSONObject jSONObject) { + public static VerifyInfo VerifyInfo(JSONObject jSONObject){ return new VerifyInfo(isVerified(jSONObject), hasPrometheus(jSONObject)); } } diff --git a/app/src/main/java/ru/vtosters/lite/net/Request.java b/app/src/main/java/ru/vtosters/lite/net/Request.java index 48eb5a6d8..6b6718c0d 100644 --- a/app/src/main/java/ru/vtosters/lite/net/Request.java +++ b/app/src/main/java/ru/vtosters/lite/net/Request.java @@ -27,8 +27,8 @@ public class Request{ private static class MakeRequestTask extends AsyncTask{ private final RequestCallback callback; private final byte[] url; - private boolean mIsPut; - private boolean mIsVTostersRequest; + private final boolean mIsPut; + private final boolean mIsVTostersRequest; public MakeRequestTask(byte[] bArr, RequestCallback RequestCallback){ mIsVTostersRequest = false; diff --git a/app/src/main/java/ru/vtosters/lite/ui/dialogs/OTADialog.java b/app/src/main/java/ru/vtosters/lite/ui/dialogs/OTADialog.java index 5c2fb69ec..f84305798 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/dialogs/OTADialog.java +++ b/app/src/main/java/ru/vtosters/lite/ui/dialogs/OTADialog.java @@ -10,9 +10,9 @@ import ru.vtosters.lite.utils.OTAHelper; public class OTADialog implements OTAHelper.OTAListener{ - private Activity mActivity; + private final Activity mActivity; - private OTAHelper mHelper; + private final OTAHelper mHelper; public OTADialog(Activity activity){ mActivity = activity; diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java index e6b9310ee..aa5d3e123 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java @@ -2,11 +2,14 @@ package ru.vtosters.lite.ui.fragments; import static bruhcollective.itaysonlab.libvkx.client.LibVKXClient.isIntegrationEnabled; import static ru.vtosters.lite.f0x1d.VTVerifications.vtverif; +import static ru.vtosters.lite.ui.vkui.VBListBuilder.VBListItem; +import static ru.vtosters.lite.ui.vkui.VBListBuilder.buildListOf; +import static ru.vtosters.lite.ui.vkui.VBottomSheetBuilder.VBSContent; import static ru.vtosters.lite.utils.About.getBuildNumber; import static ru.vtosters.lite.utils.About.getCommitLink; import static ru.vtosters.lite.utils.CacheUtils.humanReadableByteCountBin; -import static ru.vtosters.lite.utils.Globals.getAvatarDrawable; import static ru.vtosters.lite.utils.Globals.edit; +import static ru.vtosters.lite.utils.Globals.getAvatarDrawable; import static ru.vtosters.lite.utils.Globals.getIdentifier; import static ru.vtosters.lite.utils.Globals.getPrefsValue; import static ru.vtosters.lite.utils.Globals.getUserPhoto; @@ -50,11 +53,15 @@ import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment; import com.vtosters.lite.general.fragments.SettingsAccountFragment; import com.vtosters.lite.general.fragments.SettingsGeneralFragment; +import java.util.Arrays; +import java.util.List; + import ru.vtosters.lite.ui.PreferencesUtil; import ru.vtosters.lite.ui.dialogs.OTADialog; import ru.vtosters.lite.ui.fragments.dockbar.DockBarFragment; import ru.vtosters.lite.ui.fragments.dockbar.DockBarManager; import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment; +import ru.vtosters.lite.ui.vkui.VBottomSheetBuilder; import ru.vtosters.lite.utils.CacheUtils; import ru.vtosters.lite.utils.Globals; import ru.vtosters.lite.utils.SSFS; @@ -374,6 +381,44 @@ public class VTSettings extends MaterialPreferenceToolbarFragment{ return true; }); } + + PreferencesUtil.addPreference(this, "p1", "Настроить скрытие пунктов меню", null, null, (preference) -> { + callEditorPopup(); + return true; + }); + } + + private void callEditorPopup(){ + List list = Arrays.asList( + new VBListItem("promo", "Mini Apps: промо"), + new VBListItem("miniapps", "Mini Apps: виджет"), + new VBListItem("vkpay_slim", "VK Pay"), + new VBListItem("greeting", "Приветствие"), + new VBListItem("holiday", "Дни рождения у друзей"), + new VBListItem("weather", "Погода"), + new VBListItem("sport", "Спортивные события"), + new VBListItem("games", "Игры"), + new VBListItem("informer", "Информер"), + new VBListItem("food", "Еда"), + new VBListItem("event", "Мероприятия"), + new VBListItem("music", "Музыка"), + new VBListItem("vk_run", "VK Run") + ); + + VBottomSheetBuilder.show(getActivity(), new VBSContent( + null, + null, + buildListOf(getActivity(), list), + + new VBSContent.VBSButton( + "Сохранить", + () -> { + for(VBListItem item : list) { + edit().putBoolean("superapp_" + item.id, item.checked).commit(); + } + } + ) + )); } @Override diff --git a/app/src/main/java/ru/vtosters/lite/ui/vkui/ModalBottomSheetWrapper.java b/app/src/main/java/ru/vtosters/lite/ui/vkui/ModalBottomSheetWrapper.java index 31f0290a7..9a2418829 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/vkui/ModalBottomSheetWrapper.java +++ b/app/src/main/java/ru/vtosters/lite/ui/vkui/ModalBottomSheetWrapper.java @@ -1,6 +1,7 @@ package ru.vtosters.lite.ui.vkui; import static ru.vtosters.lite.utils.Globals.getString; +import static ru.vtosters.lite.utils.Themes.getTextAttr; import android.app.Activity; import android.graphics.Typeface; @@ -11,7 +12,6 @@ import android.widget.TextView; import com.vk.core.dialogs.bottomsheet.ModalBottomSheet; import ru.vtosters.lite.utils.Globals; -import ru.vtosters.lite.utils.Themes; public class ModalBottomSheetWrapper{ public final ModalBottomSheet.a builder; @@ -37,13 +37,13 @@ public class ModalBottomSheetWrapper{ title.setTypeface(title.getTypeface(), Typeface.BOLD); title.setSingleLine(true); title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - title.setTextColor(Themes.getTextAttr()); + title.setTextColor(getTextAttr()); title.setTextSize(24.0f); container.addView(title, new LinearLayout.LayoutParams(-1, -2)); changelogView.setPadding(0, Globals.convertDpToPixel(8), 0, 0); changelogView.setText(getString("changelog") + ": \n" + changelog); - changelogView.setTextColor(Themes.getTextAttr()); + changelogView.setTextColor(getTextAttr()); container.addView(changelogView, new LinearLayout.LayoutParams(-1, -2)); builder.a(container); diff --git a/app/src/main/java/ru/vtosters/lite/ui/vkui/VBListBuilder.java b/app/src/main/java/ru/vtosters/lite/ui/vkui/VBListBuilder.java new file mode 100644 index 000000000..ab1a79c3f --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/ui/vkui/VBListBuilder.java @@ -0,0 +1,56 @@ +package ru.vtosters.lite.ui.vkui; +import static ru.vtosters.lite.utils.Globals.convertDpToPixel; +import static ru.vtosters.lite.utils.Preferences.getBoolValue; +import static ru.vtosters.lite.utils.Themes.getTextAttr; + +import android.content.Context; +import android.util.TypedValue; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.appcompat.widget.AppCompatCheckBox; + +import java.util.List; + +public class VBListBuilder{ + public static ViewGroup buildListOf(Context ctx, List items){ + LinearLayout mainView = new LinearLayout(ctx); + mainView.setOrientation(LinearLayout.VERTICAL); + mainView.setPadding(convertDpToPixel(8f), 0, convertDpToPixel(8f), 0); + + for(VBListItem item : items) { + AppCompatCheckBox mcb = new AppCompatCheckBox(ctx, null); + mcb.setPadding(0, convertDpToPixel(8f), 0, convertDpToPixel(8f)); + + mcb.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f); + mcb.setTextColor(getTextAttr()); + + mcb.setChecked(item.checked); + mcb.setText(item.title); + + mcb.setOnCheckedChangeListener((buttonView, isChecked) -> { + item.checked = isChecked; + }); + + mainView.addView(mcb); + } + + return mainView; + } + + public static class VBListItem{ + public String id; + public String title; + public boolean checked; + + public VBListItem(String id, String title){ + this(id, title, getBoolValue("superapp_" + id, false)); + } + + public VBListItem(String id, String title, boolean checked){ + this.id = id; + this.title = title; + this.checked = checked; + } + } +} diff --git a/app/src/main/java/ru/vtosters/lite/ui/vkui/VBottomSheetBuilder.java b/app/src/main/java/ru/vtosters/lite/ui/vkui/VBottomSheetBuilder.java new file mode 100644 index 000000000..f10c6c6ce --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/ui/vkui/VBottomSheetBuilder.java @@ -0,0 +1,47 @@ +package ru.vtosters.lite.ui.vkui; +import android.app.Activity; +import android.os.Handler; +import android.os.Looper; +import android.view.View; + +import androidx.annotation.Nullable; + +public class VBottomSheetBuilder{ + public static void show(Activity activity, VBSContent content){ + ModalBottomSheetWrapper builder = new ModalBottomSheetWrapper(activity); + + builder.setView(content.view); + + builder.setPositiveButton(content.button.title, () -> { + // Button OnClick + new Handler(Looper.getMainLooper()).post(content.button.action); + }); // Positive + + builder.show(); // Build+Show + } + + public static class VBSContent{ + public String title; + @Nullable + public String subtitle; + public View view; + public VBSButton button; + + public VBSContent(String title, @Nullable String subtitle, View view, VBSButton button){ + this.title = title; + this.subtitle = subtitle; + this.view = view; + this.button = button; + } + + public static class VBSButton{ + public String title; + public Runnable action; + + public VBSButton(String title, Runnable action){ + this.title = title; + this.action = action; + } + } + } +} diff --git a/app/src/main/java/ru/vtosters/lite/utils/Globals.java b/app/src/main/java/ru/vtosters/lite/utils/Globals.java index 09fe7d17f..d216bfa83 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Globals.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Globals.java @@ -87,11 +87,11 @@ public class Globals{ // VKIDProtection.alert(activity); } - public static byte[] readFileFully(File file) throws IOException { + public static byte[] readFileFully(File file) throws IOException{ return readFully(new FileInputStream(file)); } - public static byte[] readFully(InputStream is) throws IOException { + public static byte[] readFully(InputStream is) throws IOException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; diff --git a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java index 94b42265a..cbb361b62 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java @@ -3,7 +3,9 @@ package ru.vtosters.lite.utils; import static ru.vtosters.lite.f0x1d.VTVerifications.isPrometheus; import static ru.vtosters.lite.f0x1d.VTVerifications.isDeveloper; import static ru.vtosters.lite.f0x1d.VTVerifications.isVerified; +import static ru.vtosters.lite.utils.Preferences.getBoolValue; import static ru.vtosters.lite.utils.Preferences.hasVerification; +import static ru.vtosters.lite.utils.Preferences.preferences; import org.json.JSONException; import org.json.JSONObject; @@ -70,38 +72,12 @@ public class JsonInjectors{ if(Items != null) { for(int i = 0; i < Items.length(); i++){ var items = Items.optJSONObject(i); - var types = items.optString("type"); + var type = items.optString("type"); - switch(types){ - case "promo": - Items.remove(i); - case "vkpay_slim": - Items.remove(i); - case "greeting": - Items.remove(i); - case "sport": - Items.remove(i); - case "games": - Items.remove(i); - case "miniapps": - Items.remove(i); - case "informer": - Items.remove(i); - case "holiday": - Items.remove(i); - case "vk_run": - Items.remove(i); - case "weather": - Items.remove(i); - case "food": - Items.remove(i); - case "event": - Items.remove(i); - case "birthdays": - Items.remove(i); - case "music": - Items.remove(i); + if(getBoolValue("superapp_" + type, false)){ + Items.remove(i); } + } } diff --git a/app/src/main/java/ru/vtosters/lite/utils/Newsfeed.java b/app/src/main/java/ru/vtosters/lite/utils/Newsfeed.java index 95207e9e1..d54f8395f 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Newsfeed.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Newsfeed.java @@ -116,9 +116,7 @@ public class Newsfeed{ if(isGroupAds(obj)) return false; - if(injectFiltersReposts(obj)) return false; - - return true; + return !injectFiltersReposts(obj); } public static boolean injectFiltersReposts(JSONObject obj){ diff --git a/app/src/main/java/ru/vtosters/lite/utils/OTAHelper.java b/app/src/main/java/ru/vtosters/lite/utils/OTAHelper.java index fbd09596c..984b2d0c3 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/OTAHelper.java +++ b/app/src/main/java/ru/vtosters/lite/utils/OTAHelper.java @@ -18,7 +18,7 @@ public class OTAHelper{ private static final String LATEST_RELEASE_URL = "https://api.github.com/repositories/473685743/releases/latest"; private static final String LATEST_RELEASE_COMMIT_URL = "https://api.github.com/repositories/473685743/git/ref/tags/%s"; private final OkHttpClient mClient = new OkHttpClient(); - private OTAListener mListener; + private final OTAListener mListener; private JSONObject mReleaseJson; private JSONObject mCommitJson; diff --git a/app/src/main/java/ru/vtosters/lite/utils/Toggles.java b/app/src/main/java/ru/vtosters/lite/utils/Toggles.java index b4ec7a1c1..00e5d1498 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Toggles.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Toggles.java @@ -11,8 +11,8 @@ import com.vk.toggle.FeatureManager; import com.vk.toggle.Features; public class Toggles{ - public static boolean shouldPatch(Features.Type feature) { - switch (feature) { + public static boolean shouldPatch(Features.Type feature){ + switch(feature) { case AB_IM_LONGPOLL_MSG_BATCHING: case AB_IM_LP_ATTACHES: case AB_IM_VIEW_POOL: @@ -123,6 +123,7 @@ public class Toggles{ return false; } } + public static boolean redirect(Features.Type feature){ switch(feature) { case EXPERIMENT_NEWS_DISABLE_CACHE: