Files
LihonT-Store/src/lihonstore/app/Item.java
cheb0chik e8277bb7e8 LihonT Store 0.1
A catalog app for the LihonT mod: avatar frames and chat bubbles made by members. Browse, add with the plus button, author profiles,
publishing with a check before anything is shown. Signs in through the TikTok that carries the mod, which hands over only the public
account data to an app signed with the same key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 15:40:01 +03:00

59 lines
1.9 KiB
Java

package lihonstore.app;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/** One catalog item as the service describes it (a public one, or one of the account's own with its state). */
final class Item {
final String id;
final String kind;
final String name;
final String description;
final String authorUid;
final String authorName;
final int installs;
/** For the account's own items: approved, new, review or rejected; empty for the public ones. */
final String status;
final String reason;
final boolean listed;
private Item(JSONObject json) {
id = json.optString("id", "");
kind = json.optString("kind", "frame");
name = json.optString("name", "");
description = json.optString("description", "");
JSONObject author = json.optJSONObject("author");
authorUid = author == null ? "" : author.optString("uid", "");
authorName = author == null || author.isNull("name") ? "" : author.optString("name", "");
installs = json.optInt("installs", 0);
status = json.optString("status", "");
reason = json.optString("reason", "");
listed = json.optBoolean("listed", true);
}
static Item of(JSONObject json) {
return new Item(json);
}
static List<Item> list(JSONArray array) {
List<Item> items = new ArrayList<Item>();
if (array == null) return items;
for (int i = 0; i < array.length(); i++) {
JSONObject json = array.optJSONObject(i);
if (json != null && json.optString("id", "").matches("[0-9a-f]{24}")) items.add(new Item(json));
}
return items;
}
boolean isFrame() {
return "frame".equals(kind);
}
String author() {
return authorName.length() == 0 ? "автор" : "@" + authorName;
}
}