Files
LihonT-Store/src/lihonstore/app/ItemPage.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

139 lines
6.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package lihonstore.app;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.json.JSONObject;
/** One item: a large preview, the description, the author (a tap opens their profile) and the "+" that adds it to the account's library. */
final class ItemPage {
private final MainActivity host;
private final Item item;
private final TextView action;
private final TextView meta;
ItemPage(MainActivity host, Item item) {
this.host = host;
this.item = item;
Theme theme = host.theme();
action = theme.button(host, "", true);
meta = theme.text(host, "", 13f, theme.muted, false);
}
View view() {
final Theme theme = host.theme();
ScrollView scroll = new ScrollView(host);
LinearLayout page = theme.column(host);
page.setPadding(theme.dp(20), theme.dp(8), theme.dp(20), theme.dp(24));
scroll.addView(page);
TextView back = theme.text(host, "← Назад", 15f, theme.accent, true);
back.setPadding(0, theme.dp(8), 0, theme.dp(12));
back.setClickable(true);
back.setOnClickListener(v -> host.back());
page.addView(back);
ArtView art = new ArtView(host, theme);
art.show(item.id, item.isFrame());
page.addView(art, new LinearLayout.LayoutParams(-1, theme.dp(280)));
TextView name = theme.text(host, item.name, 24f, theme.onSurface, true);
name.setPadding(0, theme.dp(16), 0, 0);
page.addView(name);
TextView kind = theme.text(host, Texts.kind(item.kind), 13f, theme.muted, false);
page.addView(kind);
if (item.description.length() > 0) {
TextView about = theme.text(host, item.description, 16f, theme.onSurface, false);
about.setPadding(0, theme.dp(12), 0, 0);
page.addView(about);
}
if (item.authorUid.length() > 0) {
TextView author = theme.text(host, "Автор: " + item.author(), 15f, theme.accent, true);
author.setPadding(0, theme.dp(16), 0, 0);
author.setClickable(true);
author.setOnClickListener(v -> host.openProfile(item.authorUid, item.authorName));
page.addView(author);
}
meta.setPadding(0, theme.dp(4), 0, theme.dp(20));
page.addView(meta);
if (item.status.length() > 0) {
TextView state = theme.text(host, Texts.status(item.status) + (item.reason.length() > 0 ? ": " + Texts.reason(item.reason) : ""),
14f, "rejected".equals(item.status) ? theme.danger : theme.muted, false);
state.setPadding(0, 0, 0, theme.dp(16));
page.addView(state);
}
if ("approved".equals(item.status) || item.status.length() == 0) {
page.addView(action, new LinearLayout.LayoutParams(-1, -2));
refresh();
action.setOnClickListener(v -> toggle());
}
Account account = host.account();
if (account != null && account.uid.equals(item.authorUid) && item.listed && "approved".equals(item.status)) {
TextView off = theme.button(host, "Снять с публикации", false);
off.setOnClickListener(v -> unpublish());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-1, -2);
params.topMargin = theme.dp(12);
page.addView(off, params);
}
return scroll;
}
private void refresh() {
boolean added = host.library().contains(item.id);
action.setText(added ? "Убрать из моих" : "+ Добавить в мои");
Theme theme = host.theme();
action.setTextColor(added ? theme.onAccentSoft : theme.onAccent);
action.setBackground(theme.round(added ? theme.accentSoft : theme.accent, 24));
meta.setText("Добавили: " + item.installs + " · " + (item.isFrame() ? "в приложении LihonT её можно выбрать как рамку" : "в приложении LihonT её можно выбрать как пузырь"));
}
private void toggle() {
final boolean add = !host.library().contains(item.id);
action.setEnabled(false);
host.proven(() -> Work.run(() -> {
JSONObject request = host.body();
try {
request.put("id", item.id);
} catch (org.json.JSONException impossible) {
throw new IllegalStateException(impossible);
}
return Api.post(add ? "library_add" : "library_remove", request);
}, new Work.Done<JSONObject>() {
@Override public void ok(JSONObject reply) {
action.setEnabled(true);
if (add) host.library().add(item.id); else host.library().remove(item.id);
refresh();
host.toast(add ? "Добавлено. Откройте выбор в TikTok: она уже там" : "Убрано");
}
@Override public void failed(String message) {
action.setEnabled(true);
host.toast(message);
}
}));
// the proof dialog may be shown instead: the button must not stay dead
action.postDelayed(() -> action.setEnabled(true), 3000L);
}
private void unpublish() {
Work.run(() -> {
JSONObject request = host.body();
try {
request.put("id", item.id);
} catch (org.json.JSONException impossible) {
throw new IllegalStateException(impossible);
}
return Api.post("unpublish", request);
}, new Work.Done<JSONObject>() {
@Override public void ok(JSONObject reply) {
host.toast("Снято с публикации");
host.back();
}
@Override public void failed(String message) {
host.toast(message);
}
});
}
}