new btn injector for groups
This commit is contained in:
@@ -2,6 +2,7 @@ package ru.vtosters.lite.feature.groupslist;
|
||||
|
||||
import android.util.Log;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
|
||||
@@ -31,33 +32,46 @@ public class GroupsCatalogInjector {
|
||||
|
||||
public static void fixGroups(JSONObject section) {
|
||||
var blocks = section.optJSONArray("blocks");
|
||||
if (blocks == null) return;
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var block = blocks.optJSONObject(i);
|
||||
var actions = block.optJSONArray("buttons");
|
||||
if (actions == null) continue;
|
||||
var action = actions.optJSONObject(0);
|
||||
if (action == null) continue;
|
||||
var nestedAction = action.optJSONObject("action");
|
||||
if (nestedAction == null) continue;
|
||||
var type = nestedAction.optString("type");
|
||||
if (!type.contains("open_section")) continue;
|
||||
try {
|
||||
action.put("title", AndroidUtils.getGlobalContext().getString(com.vtosters.lite.R.string.catalog_button_show_all));
|
||||
block.put("data_type", "none");
|
||||
var layout = block.optJSONObject("layout");
|
||||
if (layout != null) {
|
||||
if (layout.optString("title").isEmpty()) layout.put("title", "");
|
||||
layout.put("name", "header");
|
||||
layout.remove("owner_id");
|
||||
layout.remove("style");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.d("CatalogButtonOpen", "Error: " + e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (blocks == null) return;
|
||||
|
||||
for (int i = 0; i < blocks.length(); i++) {
|
||||
var currBlock = blocks.optJSONObject(i);
|
||||
var badge = currBlock.optJSONObject("badge");
|
||||
|
||||
if (badge != null && badge.optString("type").equals("transparent")) {
|
||||
addNewButton(currBlock, blocks.optJSONObject(i + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addNewButton(JSONObject currBlock, JSONObject nextBlock) {
|
||||
try {
|
||||
var newButtons = new JSONArray();
|
||||
var newButton = createNewButton(nextBlock);
|
||||
|
||||
newButtons.put(newButton);
|
||||
currBlock.put("buttons", newButtons);
|
||||
} catch (JSONException e) {
|
||||
Log.d("CatalogButtonOpen", "Error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private static JSONObject createNewButton(JSONObject nextBlock) throws JSONException {
|
||||
var newButton = new JSONObject();
|
||||
|
||||
var type = new JSONObject();
|
||||
type.put("type", "open_section");
|
||||
|
||||
newButton.put("action", type);
|
||||
newButton.put("section_id", nextBlock.optString("id"));
|
||||
newButton.put("title", AndroidUtils.getGlobalContext().getString(com.vtosters.lite.R.string.catalog_button_show_all));
|
||||
newButton.put("ref_items_count", 30);
|
||||
newButton.put("ref_layout_name", "list");
|
||||
newButton.put("ref_data_type", "groups");
|
||||
|
||||
return newButton;
|
||||
}
|
||||
|
||||
public static ArrayList<String> injectIntoJsonParser(JSONObject jsonObject, String str) {
|
||||
|
||||
Reference in New Issue
Block a user