ImBanner cleanup code

This commit is contained in:
gdlbo
2022-12-30 15:58:10 +03:00
parent 8650124860
commit 2a6b9da4ef
@@ -1,30 +1,22 @@
package ru.vtosters.lite.ssfs;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.util.Log;
import com.vk.core.dialogs.alert.VkAlertDialog;
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.LifecycleUtils;
import ru.vtosters.lite.utils.Preferences;
import java.util.Objects;
import static ru.vtosters.lite.utils.Preferences.dev;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.VTVerifications.*;
import static ru.vtosters.lite.utils.VTVerifications.isVerified;
public class ImBanner {
public static JSONObject convBar(JSONObject orig) {
var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id");
private static final String TAG = "ImBanner";
if (!UsersList.hasBanner(peerid) || peerid == 0) {
public static JSONObject convBar(JSONObject orig) throws JSONException {
var user_id = orig.getJSONObject("peer").getInt("id");
if (!UsersList.hasBanner(user_id) || user_id == 0) {
if (getBoolValue("convBarRecomm", false)) {
return null;
} else {
@@ -32,66 +24,43 @@ public class ImBanner {
}
}
// var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null
// var text = AndroidUtils.getString(com.vtosters.lite.R.string.no_data_error);
// var link = "https://vtosters.app"; // can be null
// var linktitle = "Test button"; // can be null
//
// var hasIcon = !pic.isEmpty();
// var hasButton = !link.isEmpty();
// var isPicture = pic.endsWith(".png") || pic.endsWith(".jpg") || pic.endsWith(".jpeg") || pic.endsWith(".webp");
//
// if (isVerified(peerid))
// text = AndroidUtils.getString(com.vtosters.lite.R.string.i_bought) + " VTosters Premium";
// if (isPrometheus(peerid))
// text = AndroidUtils.getString(com.vtosters.lite.R.string.i_bought) + " VTosters Premium Gold Prime Pro Plus";
// if (isDeveloper(peerid)) text = AndroidUtils.getString(com.vtosters.lite.R.string.i_created_poop);
//
// if (!isVerified(peerid) || text.equals("") || peerid == AccountManagerUtils.getUserId() || peerid == 0) {
// if (getBoolValue("convBarRecomm", false)) {
// return null;
// } else {
// return orig.optJSONObject("conversation_bar");
// }
// }
//
// if (!dev()) return orig.optJSONObject("conversation_bar"); // for devs only
try {
var jsonBanner = Handler.getBanner(peerid);
var jsonBanner = Handler.getBanner(user_id);
var pic = jsonBanner.optString("picture");
var text = jsonBanner.optString("text");
var text = jsonBanner.getString("text");
var link = jsonBanner.optString("link");
var linktitle = jsonBanner.optString("link_text");
var link_text = jsonBanner.optString("link_text");
var hasIcon = !pic.isEmpty();
var hasButton = !link.isEmpty();
var isPicture = pic.endsWith(".png") || pic.endsWith(".jpg") || pic.endsWith(".jpeg") || pic.endsWith(".webp");
var json = new JSONObject();
var buttonsJson = new JSONObject();
buttonsJson.put("layout", "tertiary");
buttonsJson.put("text", linktitle);
buttonsJson.put("text", link_text);
buttonsJson.put("type", "link");
buttonsJson.put("link", link);
var buttonsjson = new JSONArray(); // max 3 buttons in array
if (hasButton) buttonsjson.put(buttonsJson);
var buttons = new JSONArray(); // max 3 buttons in array
if (hasButton) buttons.put(buttonsJson);
json.put("name", "group_admin_welcome");
json.put("text", text);
json.put("buttons", buttonsjson);
json.put("buttons", buttons);
if (hasIcon && isPicture) {
json.put("icon", pic);
}
return json;
} catch (JSONException e) {
e.printStackTrace();
Log.d(TAG, e.getMessage());
return null;
}
return null;
}
public static boolean showAlert() {