pull/605/head
jhengazuki 5 months ago
parent 4c2e699f2e
commit 72003f7efc
  1. 15
      app/src/main/java/com/fongmi/android/tv/api/config/LiveConfig.java
  2. 11
      app/src/main/java/com/fongmi/android/tv/api/config/VodConfig.java

@ -125,6 +125,7 @@ public class LiveConfig {
String text = Decoder.getJson(UrlUtil.convert(config.getUrl()));
if (!Json.isObj(text)) clear().parseText(text, callback);
else checkJson(Json.parse(text).getAsJsonObject(), callback);
config.update();
} catch (Throwable e) {
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e)));
@ -136,7 +137,7 @@ public class LiveConfig {
Live live = new Live(parseName(config.getUrl()), config.getUrl()).sync();
lives = new ArrayList<>(List.of(live));
LiveParser.text(live, text);
setHome(live, true);
setHome(live, false);
App.post(callback::success);
}
@ -186,14 +187,14 @@ public class LiveConfig {
setLives(Json.safeListElement(object, "lives").stream().map(element -> Live.objectFrom(element, spider)).distinct().collect(Collectors.toCollection(ArrayList::new)));
Map<String, Live> items = Live.findAll().stream().collect(Collectors.toMap(Live::getName, Function.identity()));
for (Live live : getLives()) {
if (live.getName().equals(config.getHome())) setHome(live, true);
if (live.getName().equals(config.getHome())) setHome(live, false);
Live item = items.get(live.getName());
if (item != null) live.sync(item);
}
}
private void initOther(JsonObject object) {
if (home == null) setHome(lives.isEmpty() ? new Live() : lives.get(0), true);
if (home == null) setHome(lives.isEmpty() ? new Live() : lives.get(0), false);
setHeaders(Header.arrayFrom(object.getAsJsonArray("headers")));
setProxy(Proxy.arrayFrom(object.getAsJsonArray("proxy")));
setRules(Rule.arrayFrom(object.getAsJsonArray("rules")));
@ -301,16 +302,16 @@ public class LiveConfig {
}
public void setHome(Live home) {
setHome(home, false);
setHome(home, true);
}
private void setHome(Live live, boolean check) {
private void setHome(Live live, boolean save) {
home = live;
home.setActivated(true);
config.home(home.getName());
if (!check) config.update();
if (save) config.save();
getLives().forEach(item -> item.setActivated(home));
if (App.activity() != null && App.activity() instanceof LiveActivity) return;
if (check) if (home.isBoot() || Setting.isBootLive()) App.post(this::bootLive);
if (!save && (home.isBoot() || Setting.isBootLive())) App.post(this::bootLive);
}
}

@ -126,6 +126,7 @@ public class VodConfig {
String json = Decoder.getJson(UrlUtil.convert(config.getUrl()));
JsonObject object = Json.parse(json).getAsJsonObject();
checkJson(object, callback);
config.update();
} catch (Throwable e) {
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e)));
@ -158,11 +159,9 @@ public class VodConfig {
initSite(object);
initParse(object);
initOther(object);
if (loadLive && !Json.isEmpty(object, "lives")) initLive(object);
String notice = Json.safeString(object, "notice");
config.logo(Json.safeString(object, "logo"));
config.json(object.toString()).update();
if (future.isCancelled()) return;
String notice = Json.safeString(object, "notice");
if (loadLive && !Json.isEmpty(object, "lives")) initLive(object);
App.post(() -> callback.success(notice));
App.post(callback::success);
} catch (Throwable e) {
@ -210,7 +209,7 @@ public class VodConfig {
private void initLive(JsonObject object) {
Config temp = Config.find(config, 1).save();
boolean sync = LiveConfig.get().needSync(config.getUrl());
if (sync) LiveConfig.get().config(temp).parse(object);
if (sync) LiveConfig.get().config(temp.update()).parse(object);
}
public List<Site> getSites() {
@ -337,8 +336,8 @@ public class VodConfig {
home = site;
home.setActivated(true);
config.home(home.getKey());
getSites().forEach(item -> item.setActivated(home));
if (save) config.save();
getSites().forEach(item -> item.setActivated(home));
}
private void setWall(String wall) {

Loading…
Cancel
Save