adfree + free from server connection (#1481)

This commit is contained in:
gdlbo
2023-09-28 16:10:30 +03:00
committed by GitHub
parent aac86a9952
commit bf4cf2be53
14 changed files with 71 additions and 255 deletions
@@ -23,14 +23,12 @@ import ru.vtosters.lite.utils.NavigatorUtils;
import ru.vtosters.lite.utils.VTVerifications;
import static ru.vtosters.hooks.other.Preferences.checkupdates;
import static ru.vtosters.lite.ui.dialogs.ServerDialog.sendRequest;
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
public class MainActivityInjector {
public static void inject(Activity activity) {
SystemThemeChangerHook.themeOnStart(activity);
sendRequest();
UsersList.getUsersList();
VTVerifications.load(activity);
@@ -20,7 +20,7 @@ public class VerificationsHook {
return true;
}
if (!getBoolValue("VT_Verification", true)) {
if (!getBoolValue("VT_Verification", true) || getBoolValue("serverFeaturesDisable", false)) {
return false;
}
@@ -32,7 +32,7 @@ public class VerificationsHook {
return true;
}
if (!getBoolValue("VT_Fire", true)) {
if (!getBoolValue("VT_Fire", true) || getBoolValue("serverFeaturesDisable", false)) {
return false;
}
@@ -40,10 +40,6 @@ public class VerificationsHook {
}
public static boolean hasDeveloper(JSONObject jSONObject) {
if (!getBoolValue("VT_Dev", true)) {
return false;
}
return VTVerifications.isDeveloper(VTVerifications.getId(jSONObject));
}
@@ -26,20 +26,20 @@ public class ProfileButtons {
newItem = orig.getJSONArray("buttons");
}
if (!VTVerifications.haveDonateButton() && id == AccountManagerUtils.getUserId()) {
var map = new HashMap<>();
map.put("20", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/20.png");
map.put("40", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/40.png");
map.put("80", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/80.png");
newItem.put(generateJsonObject(
AndroidUtils.getString(com.vtosters.lite.R.string.donate_to_vtl),
"https://vk.com/vtosters_official",
"2D81E0",
"open_url",
map
));
}
// if (!VTVerifications.haveDonateButton() && id == AccountManagerUtils.getUserId()) {
// var map = new HashMap<>();
// map.put("20", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/20.png");
// map.put("40", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/40.png");
// map.put("80", "https://raw.githubusercontent.com/vtosters/lite/main/.github/images/donate_icon/80.png");
//
// newItem.put(generateJsonObject(
// AndroidUtils.getString(com.vtosters.lite.R.string.donate_to_vtl),
// "https://vk.com/vtosters_official",
// "2D81E0",
// "open_url",
// map
// ));
// }
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
var map = new HashMap<>();
@@ -17,6 +17,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
public class UsersList {
private static final String TAG = "UsersList";
private static final List<Integer> descriptionsList = new ArrayList<>();
@@ -25,7 +27,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")) {
if ((!NetworkUtils.isNetworkConnected() || NetworkUtils.isInternetSlow()) && prefs.contains("ids") || getBoolValue("serverFeaturesDisable", false)) {
return;
}
@@ -39,11 +39,11 @@ public class IconManager {
);
public static List<String> icons() {
return Preferences.hasVerification() && Preferences.isValidSignature() ? sIconsPlusNames : sIconsNames; // delete later sdk check
return sIconsPlusNames; // delete later sdk check
}
public static List<String> iconsValues() {
return Preferences.hasVerification() && Preferences.isValidSignature() ? sIconsPlus : sIcons; // delete later sdk check
return sIconsPlus; // delete later sdk check
}
public static void switchComponent(String icon, String appName) {
@@ -55,7 +55,7 @@ public class IconManager {
Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appName);
List<String> iconsList = (Preferences.hasVerification() && Preferences.isValidSignature()) ? sIconsPlus : sIcons;
List<String> iconsList = sIconsPlus;
List<String> labelsList = sLabels;
// check if icon is exist
@@ -1,108 +0,0 @@
package ru.vtosters.lite.ui.dialogs;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import com.vk.core.dialogs.alert.VkAlertDialog;
import okhttp3.*;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import ru.vtosters.lite.utils.LifecycleUtils;
import java.io.IOException;
import java.util.Random;
import static android.content.ContentValues.TAG;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
import static ru.vtosters.hooks.other.Preferences.hasVerification;
public class ServerDialog {
private static final OkHttpClient client = VtOkHttpClient.getInstance();
public static Boolean showAlert;
private static String title;
private static String message;
private static String positiveButton;
private static String neutralButton;
private static String link;
private static String key;
private static Boolean cancelable;
private static Boolean isNotForVerified;
public static void sendRequest() {
if (getBoolValue("dialogrecomm", false)) return;
if (!getBoolValue("isRoamingState", false)) {
Request request = new Request.a()
.b("https://vtosters.app/dialog.json")
.a();
client.a(request).a(new Callback() {
@Override
public void a(Call call, IOException e) {
Log.d(TAG, e.getMessage());
showAlert = false;
}
@Override
public void a(Call call, Response response) {
try {
getResponse(response.a().g());
} catch (Exception e) {
showAlert = false;
}
}
});
}
}
private static Boolean showForNotVerified() {
int random = new Random().nextInt(6);
if (isNotForVerified) {
return !hasVerification() && random != 0;
}
return true;
}
private static void getResponse(String body) throws Exception {
JSONObject jSONObject = new JSONObject(body);
if (jSONObject.getString("title").equals("")) {
showAlert = false;
return;
}
title = jSONObject.getString("title");
message = jSONObject.getString("message");
positiveButton = jSONObject.getString("positiveButton");
neutralButton = jSONObject.getString("neutralButton");
link = jSONObject.getString("link");
key = jSONObject.getString("key");
cancelable = jSONObject.getBoolean("cancelable");
isNotForVerified = jSONObject.getBoolean("isNotForVerified");
showAlert = true;
Activity activity = LifecycleUtils.getCurrentActivity();
if (getBoolValue(key, true) && showForNotVerified() && showAlert) {
activity.runOnUiThread(() -> {
new VkAlertDialog.Builder(activity)
.setTitle(title)
.setMessage(message)
.setCancelable(cancelable)
.setPositiveButton(positiveButton,
(dialogInterface, i) -> Preferences.getPreferences().edit().putBoolean(key, false).apply())
.setNeutralButton(neutralButton, (dialogInterface, i) -> {
Preferences.getPreferences().edit().putBoolean(key, false).apply();
Intent intent = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(link));
activity.startActivity(intent);
})
.show();
});
}
}
}
@@ -301,6 +301,20 @@ public class DataSettingsFragment extends TrackedMaterialPreferenceToolbarFragme
}
);
PreferenceFragmentUtils.addMaterialSwitchPreference(
getPreferenceScreen(),
"serverFeaturesDisable",
"Отключить всю работу с сервером",
"Отключает галочки и все дополнительные функции связанные с получением данных с сервера ВТостерс",
null,
false,
(preference, o) -> {
Preferences.getPreferences().edit().putBoolean("serverFeaturesDisable", (boolean) o).apply();
LifecycleUtils.restartApplicationWithTimer();
return true;
}
);
findPreference("analyticsDisabled").setVisible(Preferences.isValidSignature());
}
@@ -92,13 +92,6 @@ public class IconsFragment extends TrackedMaterialPreferenceToolbarFragment {
this.addPreferencesFromResource(R.xml.empty);
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), "", requireContext().getString(R.string.icons_warning), requireContext().getString(R.string.icons_warning_info), R.drawable.ic_about_outline_28, preference -> {
getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://vtosters.app/donate/")));
return false;
});
}
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), requireContext().getString(R.string.icons_title));
for (var i = 0; i < IconManager.icons().size(); i++) {
@@ -128,37 +121,5 @@ public class IconsFragment extends TrackedMaterialPreferenceToolbarFragment {
return false;
});
}
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), requireContext().getString(R.string.unavailable_icons));
for (var i = 2; i < IconManager.sIconsPlusNames.size(); i++) {
if (IconManager.sIconsPlusNames.get(i) == null || IconManager.sIconsPlus.get(i) == null) return;
String iconname = IconManager.sIconsPlusNames.get(i);
String icon = IconManager.sIconsPlus.get(i);
int iconRes;
if (icon.equals("vt")) {
iconRes = R.mipmap.vt_launcher_round;
} else if (icon.contains("standard")) {
iconRes = R.mipmap.ic_launcher_round;
} else {
iconRes = AndroidUtils.getIdentifier("ic_launcher_" + icon, "mipmap");
}
Drawable drawable = ResourcesCompat.getDrawable(getResources(), iconRes, null);
if (drawable == null) {
drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_bug_outline_28, null);
}
PreferenceFragmentUtils.addPreference(getPreferenceScreen(), icon, iconname, "", drawable, preference -> {
AndroidUtils.sendToast(requireContext().getString(R.string.unavailable_icon_warning));
return false;
});
}
}
}
}
@@ -16,6 +16,8 @@ import ru.vtosters.lite.ssfs.UsersList;
import ru.vtosters.lite.ui.activities.VKAdminTokenActivity;
import ru.vtosters.lite.utils.*;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
public class OtherFragment extends TrackedMaterialPreferenceToolbarFragment {
private static final int VK_ADMIN_TOKEN_REQUEST_CODE = 1;
@@ -110,6 +112,10 @@ 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));
var vkAdminTokenPref = findPreference("vk_admin_token");
vkAdminTokenPref.setVisible(Preferences.getPreferences().getBoolean("new_music_downloading_way", false));
if (vkAdminTokenPref.isVisible()) {
@@ -142,18 +142,20 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
});
});
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
requireContext().getString(R.string.vtssfs),
getSSFSsumm(),
R.drawable.ic_link_circle_outline_28,
preference -> {
VKUIwrapper.setLink(Utils.getVKUILink());
NavigatorUtils.switchFragment(requireContext(), VKUIwrapper.class);
return false;
}
);
if (Preferences.hasSpecialVerif()) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
requireContext().getString(R.string.vtssfs),
getSSFSsumm(),
R.drawable.ic_link_circle_outline_28,
preference -> {
VKUIwrapper.setLink(Utils.getVKUILink());
NavigatorUtils.switchFragment(requireContext(), VKUIwrapper.class);
return false;
}
);
}
}
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), R.string.appearance_theme_use_system);
@@ -649,20 +651,6 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment {
}
);
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
"Помочь проекту",
"За донат можно получить приятные бонусы на аккаунт",
R.drawable.ic_money_circle_outline_28,
preference -> {
requireContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://vtosters.app/donate")));
return false;
}
);
}
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
@@ -11,8 +11,7 @@ import java.nio.ByteBuffer;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
enum ImageEffects {
Blur(true,
AndroidUtils.getArray(R.array.filter_types),
Blur(AndroidUtils.getArray(R.array.filter_types),
new String[]{"disabled", "low", "med", "high"},
getGlobalContext().getString(R.string.filter_blur)
) {
@@ -40,8 +39,7 @@ enum ImageEffects {
};
}
},
Dim(true,
AndroidUtils.getArray(R.array.filter_dim_types),
Dim(AndroidUtils.getArray(R.array.filter_dim_types),
new String[]{"disabled", "dim_black", "dim_white"},
getGlobalContext().getString(R.string.filter_dim)) {
@Override
@@ -66,8 +64,7 @@ enum ImageEffects {
};
}
},
Mosaic(true,
AndroidUtils.getArray(R.array.filter_types),
Mosaic(AndroidUtils.getArray(R.array.filter_types),
new String[]{"disabled", "low", "med", "high"},
getGlobalContext().getString(R.string.filter_mosaic)) {
@Override
@@ -94,7 +91,7 @@ enum ImageEffects {
};
}
},
Monochrome(false, null, null,
Monochrome(null, null,
getGlobalContext().getString(R.string.filter_monochrome)) {
@Override
public void applyEffect(ByteBuffer bitmap, int height, int width) {
@@ -103,7 +100,7 @@ enum ImageEffects {
}
}
},
Invert(false, null, null,
Invert(null, null,
getGlobalContext().getString(R.string.filter_invert_colors)) {
@Override
public void applyEffect(ByteBuffer bitmap, int height, int width) {
@@ -112,7 +109,7 @@ enum ImageEffects {
}
}
},
Sepia(false, null, null,
Sepia(null, null,
getGlobalContext().getString(R.string.filter_sepia)) {
@Override
public void applyEffect(ByteBuffer bitmap, int height, int width) {
@@ -121,7 +118,7 @@ enum ImageEffects {
}
}
},
Emboss(false, null, null,
Emboss(null, null,
getGlobalContext().getString(R.string.filter_emboss)) {
@Override
public String getSummary() {
@@ -135,7 +132,7 @@ enum ImageEffects {
}
}
},
Engrave(false, null, null,
Engrave(null, null,
getGlobalContext().getString(R.string.filter_engrave)) {
@Override
public String getSummary() {
@@ -149,7 +146,7 @@ enum ImageEffects {
}
}
},
Flea(false, null, null,
Flea(null, null,
getGlobalContext().getString(R.string.filter_flea)) {
@Override
public void applyEffect(ByteBuffer bitmap, int height, int width) {
@@ -158,7 +155,7 @@ enum ImageEffects {
}
}
},
Snow(false, null, null,
Snow(null, null,
getGlobalContext().getString(R.string.filter_snow)) {
@Override
public void applyEffect(ByteBuffer bitmap, int height, int width) {
@@ -168,15 +165,13 @@ enum ImageEffects {
}
};
private final boolean free;
private final String title;
@Nullable
private final String[] entryValues;
@Nullable
private final String[] entries;
ImageEffects(boolean free, @Nullable String[] entries, @Nullable String[] entryValues, String title) {
this.free = free;
ImageEffects(@Nullable String[] entries, @Nullable String[] entryValues, String title) {
this.entries = entries;
this.entryValues = entryValues;
this.title = title;
@@ -207,10 +202,6 @@ enum ImageEffects {
return entryValues != null && entryValues.length > 0;
}
public boolean isFree() {
return free;
}
@Nullable
public String[] getEntries() {
return entries;
@@ -80,24 +80,7 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment {
PreferenceFragmentUtils.addPreferenceCategory(getPreferenceScreen(), requireContext().getString(R.string.vtlfilters));
if (!Preferences.hasVerification() && !Preferences.getBoolValue("dialogrecomm", false)) {
PreferenceFragmentUtils.addPreference(
getPreferenceScreen(),
"",
requireContext().getString(R.string.filters_warning),
requireContext().getString(R.string.icons_warning_info),
0,
preference -> {
requireContext().startActivity(
new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("https://vtosters.app/donate/"))
);
return false;
});
}
Arrays.stream(ImageEffects.values())
.filter(imageEffects -> imageEffects.isFree() || Preferences.hasVerification())
.forEach(it -> {
if (it.isList()) {
var pref = PreferenceFragmentUtils.addListPreference(
@@ -12,10 +12,8 @@ import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static ru.vtosters.hooks.other.Preferences.getBoolValue;
import static ru.vtosters.hooks.other.Preferences.hasVerification;
public class VTVerifications {
public static final List<Integer> sVerifications = new ArrayList<>();
@@ -33,7 +31,7 @@ public class VTVerifications {
return;
}
if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids") || getBoolValue("serverFeaturesDisable", false)) {
parseJson(prefs.getString("ids", "[]"));
Log.d("VTVerifications", "load from memory. Roaming or Network issues");
isLoaded = true;
@@ -129,7 +127,7 @@ public class VTVerifications {
return -id;
}
public static boolean haveDonateButton() {
return hasVerification() || new Random().nextInt(6) != 1;
}
// public static boolean haveDonateButton() {
// return hasVerification() || new Random().nextInt(6) != 1;
// }
}
-13
View File
@@ -10,25 +10,12 @@
android:title="@string/microgsett"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/vtverify">
<Preference
android:enabled="false"
android:summary="@string/vtverifyinfosum"
android:title="@string/vtverifyinfo"/>
<Preference
android:persistent="false"
android:summary="vtosters.app/donate"
android:title="@string/getvtverify">
<intent
android:action="android.intent.action.VIEW"
android:data="https://vtosters.app/donate"/>
</Preference>
<Preference
android:key="updateverifdata"
android:summary="@string/updateverifdata_summ"
android:title="@string/updateverifdata_title"/>
<Preference
android:key="copyownlink"
android:summary="@string/copyownlink_summ"
android:title="@string/copyownlink_title"/>
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="true"