Added local caching appid names

This commit is contained in:
gdlbo
2022-07-10 01:07:55 +03:00
parent 9c9afa9925
commit cf3ecaa325
4 changed files with 60 additions and 5 deletions
@@ -1,8 +1,8 @@
package ru.vtosters.lite.dnr;
import static ru.vtosters.lite.net.Request.makeRequest;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Globals.getUserToken;
import static ru.vtosters.lite.utils.Proxy.getApi;
import com.vk.core.util.ToastUtils;
import com.vk.im.engine.commands.messages.SetUserActivityCmd;
@@ -51,7 +51,7 @@ public class DNRModule{
}
public static void hookRead(Dialog dialog){
makeRequest("https://" + getPrefsValue("proxyapi") + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.91&access_token=" + getUserToken(), response -> {
makeRequest("https://" + getApi() + "/method/messages.markAsRead?start_message_id=" + dialog.F1() + "&peer_id=" + dialog.getId() + "&v=5.91&access_token=" + getUserToken(), response -> {
ToastUtils.a("Чат помечен как прочитанный!");
});
}
@@ -3,9 +3,9 @@ package ru.vtosters.lite.foaf;
import static android.widget.Toast.LENGTH_SHORT;
import static android.widget.Toast.makeText;
import static ru.vtosters.lite.utils.Globals.getIdentifier;
import static ru.vtosters.lite.utils.Globals.getPrefsValue;
import static ru.vtosters.lite.utils.Globals.getString;
import static ru.vtosters.lite.utils.Proxy.apiproxy;
import static ru.vtosters.lite.utils.Proxy.getApi;
import android.app.ProgressDialog;
import android.content.Context;
@@ -51,7 +51,7 @@ public class FoafBase{
StringBuilder sb;
if(apiproxy()){
sb = new StringBuilder();
str = "https://" + getPrefsValue("proxyapi") + "/_/vk.com/foaf.php?id=";
str = "https://" + getApi() + "/_/vk.com/foaf.php?id=";
} else {
sb = new StringBuilder();
str = "https://vk.com/foaf.php?id=";
@@ -1,10 +1,29 @@
package ru.vtosters.lite.utils;
import static ru.vtosters.lite.net.Request.makeRequest;
import static ru.vtosters.lite.utils.Globals.getString;
import static ru.vtosters.lite.utils.Globals.getUserToken;
import static ru.vtosters.lite.utils.Globals.sendToast;
import static ru.vtosters.lite.utils.Preferences.dev;
import static ru.vtosters.lite.utils.Preferences.getPrefsFromFile;
import static ru.vtosters.lite.utils.Proxy.getApi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class OnlineFormatter{
private static String AppName;
public static String getAppName(int appid){ // thanks to egormetlitsky (vk mp3 mod) for helping with online ids
if(appid < 0) return "undefined";
switch(appid) {
case 0:
case 1:
case 2:
case 3:
return null;
case 2274003:
return "Android";
case 6328039:
@@ -79,8 +98,34 @@ public class OnlineFormatter{
case 6287487:
return "VK Web";
default:
return null;
return getAppNameFromOnline(appid);
}
}
public static String getAppNameFromOnline(int appid){
var appname = getPrefsFromFile("onlines").getString(String.valueOf(appid), null);
if(appname != null) return appname;
makeRequest("https://" + getApi() + "/method/apps.get?app_id=" + appid + "&v=5.99&access_token=" + getUserToken(),
response -> {
try {
JSONObject mainJson = new JSONObject(response);
JSONObject responseJson = mainJson.getJSONObject("response");
JSONArray itemsJson = responseJson.getJSONArray("items");
AppName = itemsJson.getJSONObject(0).optString("title", "");
getPrefsFromFile("onlines").edit().putString(String.valueOf(appid), AppName).apply();
if(dev()) sendToast("AppName: " + AppName + " for appid: " + appid);
} catch (JSONException e) {
e.printStackTrace();
}
});
return AppName;
}
public static String getOnline(int appid){
@@ -40,6 +40,16 @@ public class Proxy{
return link;
}
public static String getApi(){
var proxyapi = getPrefsValue("proxyapi");
if(apiproxy() & !proxyapi.isEmpty()){
return proxyapi;
}
return "api.vk.com";
}
public static String getAwayPhpCom(){
var proxyapi = getPrefsValue("proxyapi");