This commit is contained in:
aliveoutside
2023-04-28 21:19:50 +03:00
parent 0d61904b19
commit f4d4c622eb
4 changed files with 79 additions and 70 deletions
@@ -0,0 +1,71 @@
package ru.vtosters.lite.feature.groupslist;
import android.util.Log;
import com.vk.catalog2.core.api.dto.buttons.CatalogButtonOpenSection;
import com.vk.core.serialize.Serializer;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
public class GroupsCatalogInjector {
public static JSONObject injectIntoGetGroups(JSONObject jsonObject) {
var sections = jsonObject.optJSONObject("catalog").optJSONArray("sections");
if (sections == null) return jsonObject;
var section = sections.optJSONObject(0);
var blocks = section.optJSONArray("blocks");
if (blocks == null) return jsonObject;
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", "Показать все");
block.put("data_type", "none");
var layout = block.optJSONObject("layout");
if (layout != null) {
Log.d("CatalogButtonOpen", "Layout: " + layout);
layout.put("title", "");
layout.put("name", "header");
layout.remove("owner_id");
layout.remove("style");
}
} catch (Exception e) {
Log.d("CatalogButtonOpen", "Error: " + e);
}
break;
}
return jsonObject;
}
public static ArrayList<String> injectIntoJsonParser(JSONObject jsonObject, String str) {
JSONArray optJSONArray = jsonObject.optJSONArray(str);
if (optJSONArray != null) {
int length = optJSONArray.length();
ArrayList<String> arrayList = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
String optString = optJSONArray.optString(i);
if (optString != null) {
arrayList.add(optString);
}
}
return arrayList;
}
return null;
}
public static CatalogButtonOpenSection injectIntoSerializer(Serializer serializer) {
serializer.v();
serializer.v();
serializer.v();
var title = serializer.v();
var id = serializer.v();
return new CatalogButtonOpenSection(title, id);
}
}
@@ -46,38 +46,9 @@
.end annotation
.line 2
new-instance v0, Lcom/vk/catalog2/core/api/dto/buttons/CatalogButtonOpenSection;
invoke-static { p1 }, Lru/vtosters/lite/feature/groupslist/GroupsCatalogInjector;->injectIntoSerializer(Lcom/vk/core/serialize/Serializer;)Lcom/vk/catalog2/core/api/dto/buttons/CatalogButtonOpenSection;
.line 3
invoke-virtual {p1}, Lcom/vk/core/serialize/Serializer;->v()Ljava/lang/String;
move-result-object v1
const-string v2, ""
if-eqz v1, :cond_0
goto :goto_0
:cond_0
move-object v1, v2
.line 4
:goto_0
invoke-virtual {p1}, Lcom/vk/core/serialize/Serializer;->v()Ljava/lang/String;
move-result-object p1
if-eqz p1, :cond_1
goto :goto_1
:cond_1
move-object p1, v2
.line 5
:goto_1
invoke-direct {v0, v1, p1}, Lcom/vk/catalog2/core/api/dto/buttons/CatalogButtonOpenSection;-><init>(Ljava/lang/String;Ljava/lang/String;)V
move-result-object v0
return-object v0
.end method
@@ -75,6 +75,10 @@
const-string v1, "r.getJSONObject(ServerKeys.RESPONSE)"
invoke-static { p1 }, Lru/vtosters/lite/feature/groupslist/GroupsCatalogInjector;->injectIntoGetGroups(Lorg/json/JSONObject;)Lorg/json/JSONObject;
move-result-object p1
invoke-static {p1, v1}, Lkotlin/jvm/internal/Intrinsics;->a(Ljava/lang/Object;Ljava/lang/String;)V
invoke-virtual {v0, p1}, Lcom/vk/catalog2/core/CatalogParser;->c(Lorg/json/JSONObject;)Lcom/vk/catalog2/core/api/dto/CatalogResponse;
@@ -165,47 +165,10 @@
">;"
}
.end annotation
invoke-static { p1, p2 }, Lru/vtosters/lite/feature/groupslist/GroupsCatalogInjector;->injectIntoJsonParser(Lorg/json/JSONObject;Ljava/lang/String;)Ljava/util/ArrayList;
.line 8
invoke-virtual {p1, p2}, Lorg/json/JSONObject;->optJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;
move-result-object v0
move-result-object p1
if-eqz p1, :cond_1
.line 9
invoke-virtual {p1}, Lorg/json/JSONArray;->length()I
move-result p2
.line 10
new-instance v0, Ljava/util/ArrayList;
invoke-direct {v0, p2}, Ljava/util/ArrayList;-><init>(I)V
const/4 v1, 0x0
:goto_0
if-ge v1, p2, :cond_2
.line 11
invoke-virtual {p1, v1}, Lorg/json/JSONArray;->optString(I)Ljava/lang/String;
move-result-object v2
if-eqz v2, :cond_0
invoke-virtual {v0, v2}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
:cond_0
add-int/lit8 v1, v1, 0x1
goto :goto_0
:cond_1
const/4 v0, 0x0
:cond_2
return-object v0
.end method