Revert "Multithreading verifs downloading"

This reverts commit 0e94efc4f7.
This commit is contained in:
gdlbo
2023-05-14 17:30:14 +03:00
parent 5a7a628117
commit 2e3b45a88f
@@ -5,19 +5,19 @@ import android.util.Log;
import com.vk.dto.common.VerifyInfo;
import com.vk.navigation.NavigatorKeys;
import okhttp3.*;
import okio.BufferedSink;
import okio.Okio;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Preferences.hasVerification;
public class VTVerifications {
public static final List<Integer> sVerifications = new ArrayList<>();
public static final List<Integer> sPrometheuses = new ArrayList<>();
@@ -28,7 +28,7 @@ public class VTVerifications {
public static void load(Context context) {
var prefs = context.getSharedPreferences("vt_another_data", 0);
if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || Preferences.getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
if ((!NetworkUtils.isNetworkConnected() && NetworkUtils.isInternetSlow() || getBoolValue("isRoamingState", false)) && prefs.contains("ids")) {
parseJson(prefs.getString("ids", "[]"));
return;
}
@@ -38,24 +38,27 @@ public class VTVerifications {
.a(RequestBody.a(MediaType.b("application/json; charset=UTF-8"), "{\"types\":[0,228,404,1337]}"))
.a();
sClient.a(request).a(new Callback() {
try (Response response = sClient.a(request).execute()) {
File file = new File(AndroidUtils.getGlobalContext().getCacheDir(), "response.json");
try (BufferedSink sink = Okio.a(Okio.b(file))) {
sink.a(response.a().f());
@Override
public void a(Call call, Response response) {
try {
var payload = response.a().g();
parseJson(payload);
prefs.edit()
.putString("ids", payload)
.apply();
} catch (Exception e) {
e.printStackTrace();
}
}
String r = IOUtils.readAllLines(file);
@Override
public void a(Call call, IOException e) {
Log.d("VTVerifications", String.valueOf(e));
}
parseJson(r);
prefs.edit()
.putString("ids", r)
.apply();
} catch (IOException e) {
if (prefs.contains("ids")) parseJson(prefs.getString("ids", "[]"));
Log.d("VTVerifications", e.getMessage());
}
});
}
/**
@@ -101,7 +104,7 @@ public class VTVerifications {
}
public static boolean vtverif() {
return Preferences.getBoolValue("VT_Verification", true);
return getBoolValue("VT_Verification", true);
}
private static int getId(JSONObject json) {
@@ -118,7 +121,7 @@ public class VTVerifications {
return true;
}
if (!Preferences.getBoolValue("VT_Verification", true)) {
if (!getBoolValue("VT_Verification", true)) {
return false;
}
@@ -130,7 +133,7 @@ public class VTVerifications {
return true;
}
if (!Preferences.getBoolValue("VT_Fire", true)) {
if (!getBoolValue("VT_Fire", true)) {
return false;
}
@@ -138,7 +141,7 @@ public class VTVerifications {
}
public static boolean hasDeveloper(JSONObject jSONObject) {
if (!Preferences.getBoolValue("VT_Dev", true)) {
if (!getBoolValue("VT_Dev", true)) {
return false;
}
@@ -150,6 +153,6 @@ public class VTVerifications {
}
public static boolean haveDonateButton() {
return Preferences.hasVerification() || new Random().nextInt(6) != 1;
return hasVerification() || new Random().nextInt(6) != 1;
}
}