ServerDialog impl
This commit is contained in:
@@ -5,6 +5,8 @@ import static ru.vtosters.lite.utils.CacheUtils.getInstance;
|
||||
import static ru.vtosters.lite.utils.Preferences.checkupdates;
|
||||
import static ru.vtosters.lite.utils.Preferences.getLocale;
|
||||
import static ru.vtosters.lite.utils.Preferences.preferences;
|
||||
import static ru.vtosters.lite.utils.ServerDialog.sendRequest;
|
||||
import static ru.vtosters.lite.utils.ServerDialog.showAlert;
|
||||
import static ru.vtosters.lite.utils.Themes.isDarkTheme;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -69,14 +71,15 @@ public class Globals{
|
||||
}
|
||||
|
||||
public static void MainActivityInit(Activity activity){
|
||||
if(checkupdates())
|
||||
OTADialog.checkUpdates(activity);
|
||||
sendRequest();
|
||||
if(checkupdates()) OTADialog.checkUpdates(activity);
|
||||
Start.alert(activity);
|
||||
InstallGMS.alert(activity);
|
||||
DisableBattery.alert(activity);
|
||||
edit().putBoolean("isdark", isDarkTheme()).commit();
|
||||
getInstance().autoCleaningCache();
|
||||
// VKIDProtection.alert(activity);
|
||||
if(showAlert) ServerDialog.alert(activity);
|
||||
}
|
||||
|
||||
public static void componentSwitcher(String component, Boolean enabled){
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package ru.vtosters.lite.utils;
|
||||
import static android.content.ContentValues.TAG;
|
||||
import static ru.vtosters.lite.utils.Globals.edit;
|
||||
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
|
||||
import static ru.vtosters.lite.utils.Preferences.hasVerification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.vk.navigation.Navigator;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class ServerDialog{
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static String title;
|
||||
private static String message;
|
||||
private static String positiveButton;
|
||||
private static String negativeButton;
|
||||
private static String link;
|
||||
private static String key;
|
||||
private static Boolean cancelable;
|
||||
private static Boolean isNotForVerified;
|
||||
|
||||
public static Boolean showAlert = true;
|
||||
|
||||
public static void alert(final Activity activity){
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
builder.setCancelable(cancelable);
|
||||
builder.setPositiveButton(positiveButton, (dialogInterface, i) -> edit().putBoolean(key, false).apply());
|
||||
builder.setNeutralButton(negativeButton, (dialogInterface, i) -> {
|
||||
edit().putBoolean(key, false).apply();
|
||||
VKUIwrapper.setLink(link);
|
||||
Intent a2 = new Navigator(VKUIwrapper.class).b(activity);
|
||||
activity.startActivity(a2);
|
||||
});
|
||||
if(getBoolValue(key, true) && showForNotVerified()){
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendRequest(){
|
||||
Request request = new Request.a()
|
||||
.b("https://192.168.1.6/test.json")
|
||||
.a();
|
||||
|
||||
client.a(request).a(new Callback(){
|
||||
@Override
|
||||
public void a(Call call, IOException e){
|
||||
Log.d(TAG, "" + e);
|
||||
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.has("title")){
|
||||
showAlert = false;
|
||||
return;
|
||||
}
|
||||
|
||||
title = jSONObject.getString("title");
|
||||
message = jSONObject.getString("message");
|
||||
positiveButton = jSONObject.getString("positiveButton");
|
||||
negativeButton = jSONObject.getString("negativeButton");
|
||||
link = jSONObject.getString("link");
|
||||
key = jSONObject.getString("key");
|
||||
cancelable = jSONObject.getBoolean("cancelable");
|
||||
isNotForVerified = jSONObject.getBoolean("isNotForVerified");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user