refactored profile buttons injector

This commit is contained in:
gdlbo
2022-12-30 14:52:29 +03:00
parent 578f1a2221
commit 5e35a61473
6 changed files with 110 additions and 126 deletions
@@ -34,124 +34,6 @@ import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
public class JsonInjectors {
public static JSONObject profileButton(JSONObject orig) {
try {
int id = orig.getInt("id");
var newItem = new JSONArray();
if (orig.has("buttons")) {
newItem = orig.getJSONArray("buttons");
}
if (!haveDonateButton() && id == AccountManagerUtils.getUserId()) {
newItem.put(donateRecomm());
}
if (!orig.has("type") && AccountManagerUtils.isVKTester()) {
newItem.put(vktesters(id));
}
orig.put("buttons", newItem);
} catch (JSONException e) {
e.printStackTrace();
}
return orig;
}
public static JSONObject donateRecomm() {
try {
var title = AndroidUtils.getString(R.string.donate_to_vtl);
var link = "https://vk.com/vtosters_official";
var text_color = "2D81E0";
var json = new JSONObject();
var icons = new JSONArray();
var action = new JSONObject().put("target", "internal");
action.put("type", "open_url"); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
action.put("url", link);
json.put("action", action);
json.put("title", title);
var icon1 = new JSONObject();
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
icon1.put("width", "20");
icon1.put("height", "20");
icons.put(icon1);
var icon2 = new JSONObject();
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
icon2.put("width", "40");
icon2.put("height", "40");
icons.put(icon2);
var icon3 = new JSONObject();
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
icon3.put("width", "80");
icon3.put("height", "80");
icons.put(icon3);
json.put("icons", icons);
json.put("text_color", text_color);
return json;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public static JSONObject vktesters(int id) {
try {
var title = AndroidUtils.getString(R.string.tester_profile);
var text_color = "2D81E0";
var link = "https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id;
var json = new JSONObject();
var icons = new JSONArray();
var action = new JSONObject();
action.put("target", "internal");
action.put("type", "open_internal_vkui");
action.put("url", link);
json.put("action", action);
json.put("title", title);
var icon1 = new JSONObject();
icon1.put("url", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
icon1.put("width", "20");
icon1.put("height", "20");
icons.put(icon1);
var icon2 = new JSONObject();
icon2.put("url", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
icon2.put("width", "40");
icon2.put("height", "40");
icons.put(icon2);
var icon3 = new JSONObject();
icon3.put("url", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
icon3.put("width", "80");
icon3.put("height", "80");
icons.put(icon3);
json.put("icons", icons);
json.put("text_color", text_color);
return json;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static JSONObject menu(JSONObject orig) throws JSONException {
var Special = orig.optJSONArray("special");
var Main = orig.getJSONArray("main");
@@ -371,8 +253,4 @@ public class JsonInjectors {
return json;
}
public static boolean haveDonateButton() {
return hasVerification() || new Random().nextInt(6) != 1;
}
}
@@ -1,5 +1,6 @@
package ru.vtosters.lite.ssfs;
import android.util.Log;
import okhttp3.Request;
import org.json.JSONException;
import org.json.JSONObject;
@@ -8,6 +9,8 @@ import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import java.io.IOException;
public class Handler {
private static final String TAG = "SSFSHandler";
public static JSONObject getBanner(int id) {
Request request = new Request.a()
.b("https://ssfs.vtosters.app/api/getChatBanner" + "?user_id=" + id)
@@ -16,7 +19,7 @@ public class Handler {
try {
return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getJSONObject("response");
} catch (JSONException | IOException e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
return null;
}
}
@@ -29,7 +32,7 @@ public class Handler {
try {
return new JSONObject(VtOkHttpClient.getInstance().a(request).execute().a().g()).getString("response");
} catch (JSONException | IOException e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
return null;
}
}
@@ -0,0 +1,95 @@
package ru.vtosters.lite.ssfs;
import com.vk.core.util.LangUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.VTVerifications;
import java.util.HashMap;
import static ru.vtosters.lite.proxy.ProxyUtils.getStatic;
public class ProfileButtons {
public static JSONObject profileButton(JSONObject orig) {
try {
int id = orig.getInt("id");
var newItem = new JSONArray();
if (orig.has("buttons")) {
newItem = orig.getJSONArray("buttons");
}
if (!VTVerifications.haveDonateButton() && id == AccountManagerUtils.getUserId()) {
var map = new HashMap<>();
map.put("20", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
map.put("40", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
map.put("80", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.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<>();
map.put("20", "https://sun2-10.userapi.com/NLd_rNpGuSaBnPV6O-j5mqCGZk8BK8drAMd2LQ/5R-DEF37PFs.png");
map.put("40", "https://sun2-12.userapi.com/N8y9pU1meJq_eug-wB1u-HUuGyMqDfdq7A025w/A4Aio-xuLY8.png");
map.put("80", "https://sun2-9.userapi.com/3Hx4hff63_2Lt6wjjthJMF_3QLUswNNlQKoAXQ/oyzEu1NL9T8.png");
newItem.put(generateJsonObject(
AndroidUtils.getString(com.vtosters.lite.R.string.tester_profile),
"https://" + getStatic() + "/bugs?lang=" + LangUtils.a() + "#/reporter" + id,
"2D81E0",
"open_internal_vkui",
map
));
}
orig.put("buttons", newItem);
} catch (JSONException e) {
e.printStackTrace();
}
return orig;
}
public static JSONObject generateJsonObject(String title, String link, String text_color, String url_type, HashMap<Object, Object> iconsList) {
try {
var json = new JSONObject();
var icons = new JSONArray();
var action = new JSONObject().put("target", "internal");
action.put("type", url_type); // may be open_url, open_internal_vkui, open_game, help_hint, show_full_post, open_vkapp, show_recommendations_for_post and groups_advertisement
action.put("url", link);
json.put("action", action);
json.put("title", title);
for (var entry : iconsList.entrySet()) {
var icon = new JSONObject();
icon.put("url", entry.getValue());
icon.put("width", entry.getKey());
icon.put("height", entry.getKey());
icons.put(icon);
}
json.put("icons", icons);
json.put("text_color", text_color);
return json;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
@@ -10,6 +10,8 @@ import static ru.vtosters.lite.utils.AccountManagerUtils.getUserID;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
public class ProfileHider {
private static final String TAG = "ProfileHider";
public static boolean isService(Integer id) {
return UsersList.hasDescription(id) || id == 100 || id == 101 || id == 333;
}
@@ -21,7 +23,7 @@ public class ProfileHider {
try {
extendedUserProfile.z2 = Handler.getDescription(userID);
} catch (NullPointerException e) {
Log.e("ProfileHide", "null \"profiles\" node\n" + e);
Log.e(TAG, "null \"profiles\" node\n" + e);
}
}
}
@@ -1,6 +1,7 @@
package ru.vtosters.lite.utils;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Preferences.hasVerification;
import android.content.Context;
import android.util.Log;
@@ -15,6 +16,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import okhttp3.Call;
import okhttp3.Callback;
@@ -158,4 +160,8 @@ public class VTVerifications {
public static VerifyInfo VerifyInfo(JSONObject jSONObject) {
return new VerifyInfo(isVerified(jSONObject), hasPrometheus(jSONObject));
}
public static boolean haveDonateButton() {
return hasVerification() || new Random().nextInt(6) != 1;
}
}
@@ -1513,7 +1513,7 @@
iput-object v0, v15, Lcom/vtosters/lite/api/ExtendedUserProfile;->l1:Ljava/util/ArrayList;
:cond_22
invoke-static {v14}, Lru/vtosters/lite/hooks/JsonInjectors;->profileButton(Lorg/json/JSONObject;)Lorg/json/JSONObject;
invoke-static {v14}, Lru/vtosters/lite/ssfs/ProfileButtons;->profileButton(Lorg/json/JSONObject;)Lorg/json/JSONObject;
move-result-object v14