Optimize config code

release
FongMi 3 weeks ago
parent a30ad7073b
commit 86f8ce9b92
  1. 24
      app/src/main/java/com/fongmi/android/tv/api/config/BaseConfig.java
  2. 61
      app/src/main/java/com/fongmi/android/tv/api/config/LiveConfig.java
  3. 62
      app/src/main/java/com/fongmi/android/tv/api/config/VodConfig.java
  4. 50
      app/src/main/java/com/fongmi/android/tv/api/config/WallConfig.java
  5. 28
      app/src/main/java/com/fongmi/android/tv/bean/Config.java
  6. 14
      app/src/main/java/com/fongmi/android/tv/event/ActionEvent.java
  7. 24
      app/src/main/java/com/fongmi/android/tv/event/CastEvent.java
  8. 33
      app/src/main/java/com/fongmi/android/tv/event/ConfigEvent.java
  9. 18
      app/src/main/java/com/fongmi/android/tv/event/PlayerEvent.java
  10. 20
      app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java
  11. 12
      app/src/main/java/com/fongmi/android/tv/event/ScanEvent.java
  12. 24
      app/src/main/java/com/fongmi/android/tv/event/ServerEvent.java
  13. 12
      app/src/main/java/com/fongmi/android/tv/event/StateEvent.java
  14. 5
      app/src/main/java/com/fongmi/android/tv/server/process/Action.java
  15. 6
      app/src/main/java/com/fongmi/android/tv/ui/custom/CustomWallView.java
  16. 1
      app/src/main/java/com/fongmi/android/tv/ui/dialog/DanmakuDialog.java
  17. 2
      app/src/main/java/com/fongmi/android/tv/utils/FileUtil.java
  18. 1
      app/src/main/res/values-zh-rCN/strings.xml
  19. 1
      app/src/main/res/values-zh-rTW/strings.xml
  20. 1
      app/src/main/res/values/strings.xml
  21. 26
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  22. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/KeepActivity.java
  23. 17
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  24. 20
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  25. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/dialog/CastDialog.java
  26. 13
      app/src/mobile/java/com/fongmi/android/tv/ui/dialog/ReceiveDialog.java
  27. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/dialog/SyncDialog.java
  28. 38
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/SettingFragment.java
  29. 17
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/VodFragment.java

@ -5,6 +5,7 @@ import android.text.TextUtils;
import com.fongmi.android.tv.App; import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R; import com.fongmi.android.tv.R;
import com.fongmi.android.tv.bean.Config; import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.server.Server; import com.fongmi.android.tv.server.Server;
import com.fongmi.android.tv.utils.Notify; import com.fongmi.android.tv.utils.Notify;
@ -30,7 +31,11 @@ abstract class BaseConfig {
protected abstract Config defaultConfig(); protected abstract Config defaultConfig();
protected abstract void doLoad(int id, Config config, Callback callback) throws Throwable; protected abstract void load(Config config) throws Throwable;
protected void postEvent() {
ConfigEvent.common();
}
public boolean needSync(String url) { public boolean needSync(String url) {
return sync || TextUtils.isEmpty(config.getUrl()) || url.equals(config.getUrl()); return sync || TextUtils.isEmpty(config.getUrl()) || url.equals(config.getUrl());
@ -59,26 +64,23 @@ abstract class BaseConfig {
try { try {
Server.get().start(); Server.get().start();
OkHttp.cancel(getTag()); OkHttp.cancel(getTag());
doLoad(id, config, callback); load(config);
if (taskId.get() == id && config.equals(this.config)) config.update(); if (taskId.get() != id) return;
if (config.equals(this.config)) config.update();
App.post(() -> Notify.show(config.getNotice()));
App.post(callback::success);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
if (isCanceled(e)) return; if (isCanceled(e)) return;
if (taskId.get() != id) return; if (taskId.get() != id) return;
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error("")); if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e))); else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e)));
} finally {
if (taskId.get() == id) postEvent();
} }
} }
protected boolean isCanceled(Throwable e) { protected boolean isCanceled(Throwable e) {
return "Canceled".equals(e.getMessage()) || e instanceof InterruptedException || e instanceof InterruptedIOException || e.getCause() instanceof InterruptedIOException; return "Canceled".equals(e.getMessage()) || e instanceof InterruptedException || e instanceof InterruptedIOException || e.getCause() instanceof InterruptedIOException;
} }
protected int getTaskId() {
return taskId.get();
}
protected int nextTaskId() {
return taskId.incrementAndGet();
}
} }

@ -1,7 +1,5 @@
package com.fongmi.android.tv.api.config; package com.fongmi.android.tv.api.config;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting; import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.api.Decoder; import com.fongmi.android.tv.api.Decoder;
import com.fongmi.android.tv.api.LiveParser; import com.fongmi.android.tv.api.LiveParser;
@ -14,9 +12,8 @@ import com.fongmi.android.tv.bean.Keep;
import com.fongmi.android.tv.bean.Live; import com.fongmi.android.tv.bean.Live;
import com.fongmi.android.tv.bean.Rule; import com.fongmi.android.tv.bean.Rule;
import com.fongmi.android.tv.db.AppDatabase; import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.UrlUtil; import com.fongmi.android.tv.utils.UrlUtil;
import com.github.catvod.bean.Header; import com.github.catvod.bean.Header;
import com.github.catvod.bean.Proxy; import com.github.catvod.bean.Proxy;
@ -94,10 +91,10 @@ public class LiveConfig extends BaseConfig {
} }
public LiveConfig clear() { public LiveConfig clear() {
ads = null;
home = null; home = null;
lives = null; lives = null;
rules = null; rules = null;
ads = null;
return this; return this;
} }
@ -112,10 +109,16 @@ public class LiveConfig extends BaseConfig {
} }
@Override @Override
protected void doLoad(int id, Config config, Callback callback) throws Throwable { protected void postEvent() {
super.postEvent();
ConfigEvent.live();
}
@Override
protected void load(Config config) throws Throwable {
String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG); String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG);
if (Json.isObj(json)) checkJson(id, config, callback, Json.parse(json).getAsJsonObject()); if (Json.isObj(json)) checkJson(config, Json.parse(json).getAsJsonObject());
else parseText(id, config, callback, json); else parseText(config, json);
} }
public void load() { public void load() {
@ -123,43 +126,38 @@ public class LiveConfig extends BaseConfig {
load(new Callback()); load(new Callback());
} }
private void parseText(int id, Config config, Callback callback, String text) { private void parseText(Config config, String text) {
Live live = new Live(UrlUtil.getName(config.getUrl()), config.getUrl()).sync(); Live live = new Live(UrlUtil.getName(config.getUrl()), config.getUrl()).sync();
lives = new ArrayList<>(List.of(live)); lives = new ArrayList<>(List.of(live));
LiveParser.text(live, text); LiveParser.text(live, text);
setHome(config, live, false); setHome(config, live, false);
if (getTaskId() == id) App.post(callback::success);
} }
private void checkJson(int id, Config config, Callback callback, JsonObject object) { private void checkJson(Config config, JsonObject object) throws Throwable {
if (object.has("msg")) { if (object.has("msg")) {
App.post(() -> callback.error(object.get("msg").getAsString())); throw new Exception(object.get("msg").getAsString());
} else if (object.has("urls")) { } else if (object.has("urls")) {
parseDepot(id, config, callback, object); parseDepot(config, object);
} else { } else {
parseConfig(id, config, callback, object); parseConfig(config, object);
} }
} }
private void parseDepot(int id, Config config, Callback callback, JsonObject object) { private void parseDepot(Config config, JsonObject object) throws Throwable {
List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString()); List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString());
List<Config> configs = new ArrayList<>(); List<Config> configs = new ArrayList<>();
for (Depot item : items) configs.add(Config.find(item, LIVE)); for (Depot item : items) configs.add(Config.find(item, LIVE));
loadConfig(id, this.config = configs.get(0), callback); load(this.config = configs.get(0));
Config.delete(config.getUrl()); Config.delete(config.getUrl());
} }
private void parseConfig(int id, Config config, Callback callback, JsonObject object) { private void parseConfig(Config config, JsonObject object) {
try { initList(object);
initList(object); initLive(config, object);
initLive(config, object); }
if (getTaskId() != id) return;
if (callback != null) App.post(callback::success); public void parse(JsonObject object) {
} catch (Throwable e) { parseConfig(getConfig(), object);
e.printStackTrace();
if (getTaskId() != id) return;
if (callback != null) App.post(() -> callback.error(Notify.getError(R.string.error_config_parse, e)));
}
} }
private void initList(JsonObject object) { private void initList(JsonObject object) {
@ -179,11 +177,6 @@ public class LiveConfig extends BaseConfig {
setHome(config, getLives().isEmpty() ? new Live() : getLives().stream().filter(item -> item.getName().equals(config.getHome())).findFirst().orElse(getLives().get(0)), false); setHome(config, getLives().isEmpty() ? new Live() : getLives().stream().filter(item -> item.getName().equals(config.getHome())).findFirst().orElse(getLives().get(0)), false);
} }
public void parse(JsonObject object) {
int id = nextTaskId();
parseConfig(id, getConfig(), null, object);
}
public void setKeep(Channel channel) { public void setKeep(Channel channel) {
if (home != null && !channel.getGroup().isHidden()) home.keep(channel).save(); if (home != null && !channel.getGroup().isHidden()) home.keep(channel).save();
} }
@ -272,9 +265,9 @@ public class LiveConfig extends BaseConfig {
private void setHome(Config config, Live live, boolean save) { private void setHome(Config config, Live live, boolean save) {
home = live; home = live;
home.setActivated(true); home.setActivated(true);
config.home(home.getName()); config.setHome(home.getName());
if (save) config.save(); if (save) config.save();
getLives().forEach(item -> item.setActivated(home)); getLives().forEach(item -> item.setActivated(home));
if (!save && (home.isBoot() || Setting.isBootLive())) RefreshEvent.boot(); if (!save && (home.isBoot() || Setting.isBootLive())) ConfigEvent.boot();
} }
} }

@ -3,7 +3,6 @@ package com.fongmi.android.tv.api.config;
import android.text.TextUtils; import android.text.TextUtils;
import com.fongmi.android.tv.App; import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.api.Decoder; import com.fongmi.android.tv.api.Decoder;
import com.fongmi.android.tv.api.loader.BaseLoader; import com.fongmi.android.tv.api.loader.BaseLoader;
import com.fongmi.android.tv.bean.Config; import com.fongmi.android.tv.bean.Config;
@ -11,8 +10,9 @@ import com.fongmi.android.tv.bean.Depot;
import com.fongmi.android.tv.bean.Parse; import com.fongmi.android.tv.bean.Parse;
import com.fongmi.android.tv.bean.Rule; import com.fongmi.android.tv.bean.Rule;
import com.fongmi.android.tv.bean.Site; import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.UrlUtil; import com.fongmi.android.tv.utils.UrlUtil;
import com.github.catvod.bean.Doh; import com.github.catvod.bean.Doh;
import com.github.catvod.bean.Header; import com.github.catvod.bean.Header;
@ -84,15 +84,15 @@ public class VodConfig extends BaseConfig {
} }
public VodConfig clear() { public VodConfig clear() {
ads = null;
doh = null;
home = null; home = null;
wall = null; wall = null;
parse = null; parse = null;
sites = null; sites = null;
parses = null;
rules = null;
ads = null;
doh = null;
flags = null; flags = null;
rules = null;
parses = null;
BaseLoader.get().clear(); BaseLoader.get().clear();
return this; return this;
} }
@ -108,44 +108,43 @@ public class VodConfig extends BaseConfig {
} }
@Override @Override
protected void doLoad(int id, Config config, Callback callback) throws Throwable { protected void postEvent() {
super.postEvent();
ConfigEvent.vod();
}
@Override
protected void load(Config config) throws Throwable {
String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG); String json = Decoder.getJson(UrlUtil.convert(config.getUrl()), TAG);
checkJson(id, config, callback, Json.parse(json).getAsJsonObject()); checkJson(config, Json.parse(json).getAsJsonObject());
} }
private void checkJson(int id, Config config, Callback callback, JsonObject object) { private void checkJson(Config config, JsonObject object) throws Throwable {
if (object.has("msg")) { if (object.has("msg")) {
App.post(() -> callback.error(object.get("msg").getAsString())); throw new Exception(object.get("msg").getAsString());
} else if (object.has("urls")) { } else if (object.has("urls")) {
parseDepot(id, config, callback, object); parseDepot(config, object);
} else { } else {
parseConfig(id, config, callback, object); parseConfig(config, object);
} }
} }
private void parseDepot(int id, Config config, Callback callback, JsonObject object) { private void parseDepot(Config config, JsonObject object) throws Throwable {
List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString()); List<Depot> items = Depot.arrayFrom(object.getAsJsonArray("urls").toString());
List<Config> configs = new ArrayList<>(); List<Config> configs = new ArrayList<>();
for (Depot item : items) configs.add(Config.find(item, VOD)); for (Depot item : items) configs.add(Config.find(item, VOD));
loadConfig(id, this.config = configs.get(0), callback); load(this.config = configs.get(0));
Config.delete(config.getUrl()); Config.delete(config.getUrl());
} }
private void parseConfig(int id, Config config, Callback callback, JsonObject object) { private void parseConfig(Config config, JsonObject object) {
try { initList(object);
initList(object); initLive(config, object);
initLive(config, object); initWall(config, object);
initWall(config, object); initSite(config, object);
initSite(config, object); initParse(config, object);
initParse(config, object); config.setLogo(Json.safeString(object, "logo"));
config.logo(Json.safeString(object, "logo")); config.setNotice(Json.safeString(object, "notice"));
if (getTaskId() != id) return;
App.post(callback::success);
} catch (Throwable e) {
e.printStackTrace();
if (getTaskId() != id) return;
App.post(() -> callback.error(Notify.getError(R.string.error_config_parse, e)));
}
} }
private void initList(JsonObject object) { private void initList(JsonObject object) {
@ -290,19 +289,20 @@ public class VodConfig extends BaseConfig {
private void setParse(Config config, Parse parse, boolean save) { private void setParse(Config config, Parse parse, boolean save) {
this.parse = parse; this.parse = parse;
this.parse.setActivated(true); this.parse.setActivated(true);
config.parse(parse.getName()); config.setParse(parse.getName());
getParses().forEach(item -> item.setActivated(parse)); getParses().forEach(item -> item.setActivated(parse));
if (save) config.save(); if (save) config.save();
} }
public void setHome(Site site) { public void setHome(Site site) {
setHome(getConfig(), site, true); setHome(getConfig(), site, true);
RefreshEvent.home();
} }
private void setHome(Config config, Site site, boolean save) { private void setHome(Config config, Site site, boolean save) {
home = site; home = site;
home.setActivated(true); home.setActivated(true);
config.home(home.getKey()); config.setHome(home.getKey());
if (save) config.save(); if (save) config.save();
getSites().forEach(item -> item.setActivated(home)); getSites().forEach(item -> item.setActivated(home));
} }

@ -3,22 +3,18 @@ package com.fongmi.android.tv.api.config;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever; import android.media.MediaMetadataRetriever;
import android.text.TextUtils;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.fongmi.android.tv.App; import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting; import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.bean.Config; import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.utils.Download; import com.fongmi.android.tv.utils.Download;
import com.fongmi.android.tv.utils.FileUtil; import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Notify;
import com.fongmi.android.tv.utils.ResUtil; import com.fongmi.android.tv.utils.ResUtil;
import com.fongmi.android.tv.utils.UrlUtil; import com.fongmi.android.tv.utils.UrlUtil;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.Path; import com.github.catvod.utils.Path;
import java.io.File; import java.io.File;
@ -76,57 +72,39 @@ public class WallConfig extends BaseConfig {
} }
@Override @Override
protected void doLoad(int id, Config config, Callback callback) throws Throwable { protected void postEvent() {
download(id, config.getUrl(), callback); super.postEvent();
ConfigEvent.wall();
} }
@Override @Override
protected void loadConfig(int id, Config config, Callback callback) { protected void load(Config config) throws Throwable {
try { File file = FileUtil.getWall(0);
OkHttp.cancel(TAG); checkUrl(config.getUrl(), file);
doLoad(id, config, callback); setWallType(file);
if (getTaskId() == id && config.equals(this.config)) config.update(); setSnapshot(file);
} catch (Throwable e) {
e.printStackTrace();
if (isCanceled(e)) return;
if (getTaskId() != id) return;
Setting.putWall(1);
RefreshEvent.wall();
if (TextUtils.isEmpty(config.getUrl())) App.post(() -> callback.error(""));
else App.post(() -> callback.error(Notify.getError(R.string.error_config_get, e)));
}
} }
private void download(int id, String url, Callback callback) throws Throwable { private void checkUrl(String url, File file) throws Throwable {
File file = FileUtil.getWall(0);
if (url.startsWith("file")) Path.copy(Path.local(url), file); if (url.startsWith("file")) Path.copy(Path.local(url), file);
else Download.create(UrlUtil.convert(url), file).tag(TAG).get(); else Download.create(UrlUtil.convert(url), file).tag(TAG).get();
if (!Path.exists(file)) throw new FileNotFoundException(); if (!Path.exists(file)) throw new FileNotFoundException();
if (getTaskId() != id) return;
process(file);
RefreshEvent.wall();
App.post(callback::success);
}
private static void process(File file) throws Throwable {
setWallType(file);
setSnapshot(file);
} }
private static void setWallType(File file) { private void setWallType(File file) {
Setting.putWallType(0); Setting.putWallType(0);
if (isGif(file)) Setting.putWallType(1); if (isGif(file)) Setting.putWallType(1);
else if (isVideo(file)) Setting.putWallType(2); else if (isVideo(file)) Setting.putWallType(2);
} }
private static void setSnapshot(File file) throws Throwable { private void setSnapshot(File file) throws Throwable {
Bitmap bitmap = Glide.with(App.get()).asBitmap().frame(0).load(file).override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit().get(); Bitmap bitmap = Glide.with(App.get()).asBitmap().frame(0).load(file).override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit().get();
try (FileOutputStream fos = new FileOutputStream(FileUtil.getWallCache())) { try (FileOutputStream fos = new FileOutputStream(FileUtil.getWallCache())) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} }
} }
private static boolean isVideo(File file) { private boolean isVideo(File file) {
try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) { try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) {
retriever.setDataSource(file.getAbsolutePath()); retriever.setDataSource(file.getAbsolutePath());
return "yes".equalsIgnoreCase(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO)); return "yes".equalsIgnoreCase(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO));
@ -135,7 +113,7 @@ public class WallConfig extends BaseConfig {
} }
} }
private static boolean isGif(File file) { private boolean isGif(File file) {
try { try {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;

@ -5,6 +5,7 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index; import androidx.room.Index;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -41,6 +42,10 @@ public class Config {
@SerializedName("parse") @SerializedName("parse")
private String parse; private String parse;
@Ignore
@SerializedName("notice")
private String notice;
public static List<Config> arrayFrom(String str) { public static List<Config> arrayFrom(String str) {
Type listType = new TypeToken<List<Config>>() {}.getType(); Type listType = new TypeToken<List<Config>>() {}.getType();
List<Config> items = App.gson().fromJson(str, listType); List<Config> items = App.gson().fromJson(str, listType);
@ -135,6 +140,14 @@ public class Config {
this.time = time; this.time = time;
} }
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice;
}
public Config type(int type) { public Config type(int type) {
setType(type); setType(type);
return this; return this;
@ -155,21 +168,6 @@ public class Config {
return this; return this;
} }
public Config logo(String logo) {
setLogo(logo);
return this;
}
public Config home(String home) {
setHome(home);
return this;
}
public Config parse(String parse) {
setParse(parse);
return this;
}
public boolean isEmpty() { public boolean isEmpty() {
return TextUtils.isEmpty(getUrl()); return TextUtils.isEmpty(getUrl());
} }

@ -4,7 +4,7 @@ import com.fongmi.android.tv.BuildConfig;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class ActionEvent { public record ActionEvent(String action) {
public static String STOP = BuildConfig.APPLICATION_ID.concat(".stop"); public static String STOP = BuildConfig.APPLICATION_ID.concat(".stop");
public static String PREV = BuildConfig.APPLICATION_ID.concat(".prev"); public static String PREV = BuildConfig.APPLICATION_ID.concat(".prev");
@ -16,8 +16,6 @@ public class ActionEvent {
public static String REPLAY = BuildConfig.APPLICATION_ID.concat(".replay"); public static String REPLAY = BuildConfig.APPLICATION_ID.concat(".replay");
public static String UPDATE = BuildConfig.APPLICATION_ID.concat(".update"); public static String UPDATE = BuildConfig.APPLICATION_ID.concat(".update");
private final String action;
public static void send(String action) { public static void send(String action) {
EventBus.getDefault().post(new ActionEvent(action)); EventBus.getDefault().post(new ActionEvent(action));
} }
@ -54,15 +52,7 @@ public class ActionEvent {
send(UPDATE); send(UPDATE);
} }
public ActionEvent(String action) {
this.action = action;
}
public String getAction() {
return action;
}
public boolean isUpdate() { public boolean isUpdate() {
return UPDATE.equals(getAction()); return UPDATE.equals(action());
} }
} }

@ -6,31 +6,9 @@ import com.fongmi.android.tv.bean.History;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class CastEvent { public record CastEvent(Config config, Device device, History history) {
private final Config config;
private final Device device;
private final History history;
public static void post(Config config, Device device, History history) { public static void post(Config config, Device device, History history) {
EventBus.getDefault().post(new CastEvent(config, device, history)); EventBus.getDefault().post(new CastEvent(config, device, history));
} }
public CastEvent(Config config, Device device, History history) {
this.config = config;
this.device = device;
this.history = history;
}
public History getHistory() {
return history;
}
public Device getDevice() {
return device;
}
public Config getConfig() {
return config;
}
} }

@ -0,0 +1,33 @@
package com.fongmi.android.tv.event;
import com.fongmi.android.tv.Setting;
import org.greenrobot.eventbus.EventBus;
public record ConfigEvent(Type type) {
public static void common() {
EventBus.getDefault().post(new ConfigEvent(Type.COMMON));
}
public static void vod() {
EventBus.getDefault().post(new ConfigEvent(Type.VOD));
}
public static void live() {
EventBus.getDefault().post(new ConfigEvent(Type.LIVE));
}
public static void wall() {
EventBus.getDefault().post(new ConfigEvent(Type.WALL));
}
public static void boot() {
EventBus.getDefault().post(new ConfigEvent(Type.BOOT));
Setting.putBootLive(false);
}
public enum Type {
COMMON, VOD, LIVE, WALL, BOOT
}
}

@ -2,16 +2,13 @@ package com.fongmi.android.tv.event;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class PlayerEvent { public record PlayerEvent(String tag, int state) {
public static final int PREPARE = 0; public static final int PREPARE = 0;
public static final int PLAYING = 10; public static final int PLAYING = 10;
public static final int TRACK = 11; public static final int TRACK = 11;
public static final int SIZE = 12; public static final int SIZE = 12;
private final String tag;
private final int state;
public static void prepare(String tag) { public static void prepare(String tag) {
EventBus.getDefault().post(new PlayerEvent(tag, PREPARE)); EventBus.getDefault().post(new PlayerEvent(tag, PREPARE));
} }
@ -31,17 +28,4 @@ public class PlayerEvent {
public static void state(String tag, int state) { public static void state(String tag, int state) {
EventBus.getDefault().post(new PlayerEvent(tag, state)); EventBus.getDefault().post(new PlayerEvent(tag, state));
} }
private PlayerEvent(String tag, int state) {
this.state = state;
this.tag = tag;
}
public String getTag() {
return tag;
}
public int getState() {
return state;
}
} }

@ -1,6 +1,5 @@
package com.fongmi.android.tv.event; package com.fongmi.android.tv.event;
import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.bean.Vod; import com.fongmi.android.tv.bean.Vod;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@ -11,12 +10,8 @@ public class RefreshEvent {
private String path; private String path;
private Vod vod; private Vod vod;
public static void config() { public static void home() {
EventBus.getDefault().post(new RefreshEvent(Type.CONFIG)); EventBus.getDefault().post(new RefreshEvent(Type.HOME));
}
public static void video() {
EventBus.getDefault().post(new RefreshEvent(Type.VIDEO));
} }
public static void history() { public static void history() {
@ -31,19 +26,10 @@ public class RefreshEvent {
EventBus.getDefault().post(new RefreshEvent(Type.SIZE)); EventBus.getDefault().post(new RefreshEvent(Type.SIZE));
} }
public static void wall() {
EventBus.getDefault().post(new RefreshEvent(Type.WALL));
}
public static void live() { public static void live() {
EventBus.getDefault().post(new RefreshEvent(Type.LIVE)); EventBus.getDefault().post(new RefreshEvent(Type.LIVE));
} }
public static void boot() {
EventBus.getDefault().post(new RefreshEvent(Type.BOOT));
Setting.putBootLive(false);
}
public static void detail() { public static void detail() {
EventBus.getDefault().post(new RefreshEvent(Type.DETAIL)); EventBus.getDefault().post(new RefreshEvent(Type.DETAIL));
} }
@ -91,6 +77,6 @@ public class RefreshEvent {
} }
public enum Type { public enum Type {
CONFIG, VIDEO, HISTORY, KEEP, SIZE, WALL, LIVE, BOOT, DETAIL, PLAYER, SUBTITLE, DANMAKU, VOD HOME, HISTORY, KEEP, SIZE, LIVE, DETAIL, PLAYER, SUBTITLE, DANMAKU, VOD
} }
} }

@ -2,19 +2,9 @@ package com.fongmi.android.tv.event;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class ScanEvent { public record ScanEvent(String address) {
private final String address;
public static void post(String address) { public static void post(String address) {
EventBus.getDefault().post(new ScanEvent(address)); EventBus.getDefault().post(new ScanEvent(address));
} }
public ScanEvent(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
} }

@ -2,11 +2,7 @@ package com.fongmi.android.tv.event;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class ServerEvent { public record ServerEvent(Type type, String text, String name) {
private final Type type;
private final String text;
private final String name;
public static void search(String text) { public static void search(String text) {
EventBus.getDefault().post(new ServerEvent(Type.SEARCH, text)); EventBus.getDefault().post(new ServerEvent(Type.SEARCH, text));
@ -28,24 +24,6 @@ public class ServerEvent {
this(type, text, ""); this(type, text, "");
} }
private ServerEvent(Type type, String text, String name) {
this.type = type;
this.text = text;
this.name = name;
}
public Type getType() {
return type;
}
public String getText() {
return text;
}
public String getName() {
return name;
}
public enum Type { public enum Type {
SEARCH, PUSH, SETTING SEARCH, PUSH, SETTING
} }

@ -2,9 +2,7 @@ package com.fongmi.android.tv.event;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
public class StateEvent { public record StateEvent(Type type) {
private final Type type;
public static void empty() { public static void empty() {
EventBus.getDefault().post(new StateEvent(Type.EMPTY)); EventBus.getDefault().post(new StateEvent(Type.EMPTY));
@ -18,14 +16,6 @@ public class StateEvent {
EventBus.getDefault().post(new StateEvent(Type.CONTENT)); EventBus.getDefault().post(new StateEvent(Type.CONTENT));
} }
private StateEvent(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
public enum Type { public enum Type {
EMPTY, PROGRESS, CONTENT EMPTY, PROGRESS, CONTENT
} }

@ -176,8 +176,6 @@ public class Action implements Process {
if (force) History.delete(cid); if (force) History.delete(cid);
History.sync(targets); History.sync(targets);
RefreshEvent.history(); RefreshEvent.history();
RefreshEvent.config();
RefreshEvent.video();
} }
@Override @Override
@ -205,9 +203,6 @@ public class Action implements Process {
public void success() { public void success() {
if (force) Keep.deleteAll(); if (force) Keep.deleteAll();
Keep.sync(configs, targets); Keep.sync(configs, targets);
RefreshEvent.history();
RefreshEvent.config();
RefreshEvent.video();
RefreshEvent.keep(); RefreshEvent.keep();
} }

@ -20,7 +20,7 @@ import androidx.media3.ui.PlayerView;
import com.fongmi.android.tv.R; import com.fongmi.android.tv.R;
import com.fongmi.android.tv.Setting; import com.fongmi.android.tv.Setting;
import com.fongmi.android.tv.databinding.ViewWallBinding; import com.fongmi.android.tv.databinding.ViewWallBinding;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.utils.FileUtil; import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.ResUtil; import com.fongmi.android.tv.utils.ResUtil;
@ -66,8 +66,8 @@ public class CustomWallView extends FrameLayout implements DefaultLifecycleObser
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onConfigEvent(ConfigEvent event) {
if (event.getType() == RefreshEvent.Type.WALL) refresh(); if (event.type() == ConfigEvent.Type.WALL) refresh();
} }
private void refresh() { private void refresh() {

@ -1,4 +1,3 @@
package com.fongmi.android.tv.ui.dialog; package com.fongmi.android.tv.ui.dialog;
import android.app.Activity; import android.app.Activity;

@ -97,7 +97,7 @@ public class FileUtil {
public static long getDirectorySize(File dir) { public static long getDirectorySize(File dir) {
long size = 0; long size = 0;
if (dir == null) return 0; if (dir == null) return 0;
if (dir.isDirectory()) for (File file: Path.list(dir)) size += getDirectorySize(file); if (dir.isDirectory()) for (File file : Path.list(dir)) size += getDirectorySize(file);
else size = dir.length(); else size = dir.length();
return size; return size;
} }

@ -125,7 +125,6 @@
<!-- Error --> <!-- Error -->
<string name="error_config_get">配置取得失败</string> <string name="error_config_get">配置取得失败</string>
<string name="error_config_parse">配置解析失败</string>
<string name="error_play_next">已经是最后一集了!</string> <string name="error_play_next">已经是最后一集了!</string>
<string name="error_play_prev">已经是第一集了!</string> <string name="error_play_prev">已经是第一集了!</string>
<string name="error_play_parse">播放地址解析失败</string> <string name="error_play_parse">播放地址解析失败</string>

@ -125,7 +125,6 @@
<!-- Error --> <!-- Error -->
<string name="error_config_get">配置取得失敗</string> <string name="error_config_get">配置取得失敗</string>
<string name="error_config_parse">配置解析失敗</string>
<string name="error_play_next">已經是最後一集了!</string> <string name="error_play_next">已經是最後一集了!</string>
<string name="error_play_prev">已經是第一集了!</string> <string name="error_play_prev">已經是第一集了!</string>
<string name="error_play_parse">播放網址解析失敗</string> <string name="error_play_parse">播放網址解析失敗</string>

@ -126,7 +126,6 @@
<!-- Error --> <!-- Error -->
<string name="error_config_get">Configuration get failed</string> <string name="error_config_get">Configuration get failed</string>
<string name="error_config_parse">Configuration parse failed</string>
<string name="error_play_next">It\'s the last episode!</string> <string name="error_play_next">It\'s the last episode!</string>
<string name="error_play_prev">It\'s the first episode!</string> <string name="error_play_prev">It\'s the first episode!</string>
<string name="error_play_parse">Unable to parse url</string> <string name="error_play_parse">Unable to parse url</string>

@ -24,6 +24,7 @@ import com.fongmi.android.tv.api.config.WallConfig;
import com.fongmi.android.tv.bean.Config; import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.databinding.ActivityHomeBinding; import com.fongmi.android.tv.databinding.ActivityHomeBinding;
import com.fongmi.android.tv.db.AppDatabase; import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.ServerEvent; import com.fongmi.android.tv.event.ServerEvent;
import com.fongmi.android.tv.event.StateEvent; import com.fongmi.android.tv.event.StateEvent;
@ -122,22 +123,14 @@ public class HomeActivity extends BaseActivity implements NavigationBarView.OnIt
private Callback getCallback() { private Callback getCallback() {
return new Callback() { return new Callback() {
@Override
public void success(String result) {
Notify.show(result);
}
@Override @Override
public void success() { public void success() {
checkAction(getIntent()); checkAction(getIntent());
RefreshEvent.config();
RefreshEvent.video();
} }
@Override @Override
public void error(String msg) { public void error(String msg) {
checkAction(getIntent()); checkAction(getIntent());
RefreshEvent.config();
StateEvent.empty(); StateEvent.empty();
Notify.show(msg); Notify.show(msg);
} }
@ -176,15 +169,20 @@ public class HomeActivity extends BaseActivity implements NavigationBarView.OnIt
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onConfigEvent(ConfigEvent event) {
if (event.getType().equals(RefreshEvent.Type.CONFIG)) setNavigation(); if (event.type() == ConfigEvent.Type.VOD) {
if (event.getType().equals(RefreshEvent.Type.BOOT)) LiveActivity.start(this); RefreshEvent.home();
} else if (event.type() == ConfigEvent.Type.COMMON) {
setNavigation();
} else if (event.type() == ConfigEvent.Type.BOOT) {
LiveActivity.start(this);
}
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onServerEvent(ServerEvent event) { public void onServerEvent(ServerEvent event) {
if (event.getType() != ServerEvent.Type.PUSH) return; if (event.type() != ServerEvent.Type.PUSH) return;
VideoActivity.push(this, event.getText()); VideoActivity.push(this, event.text());
} }
@Override @Override
@ -205,7 +203,7 @@ public class HomeActivity extends BaseActivity implements NavigationBarView.OnIt
private void checkOrientation(Configuration newConfig) { private void checkOrientation(Configuration newConfig) {
if (orientation != newConfig.orientation) { if (orientation != newConfig.orientation) {
orientation = newConfig.orientation; orientation = newConfig.orientation;
RefreshEvent.video(); RefreshEvent.home();
} }
} }

@ -84,8 +84,6 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis
@Override @Override
public void success() { public void success() {
VideoActivity.start(getActivity(), item.getSiteKey(), item.getVodId(), item.getVodName(), item.getVodPic()); VideoActivity.start(getActivity(), item.getSiteKey(), item.getVodId(), item.getVodName(), item.getVodPic());
RefreshEvent.config();
RefreshEvent.video();
} }
@Override @Override

@ -733,7 +733,6 @@ public class LiveActivity extends BaseActivity implements CustomKeyDown.Listener
@Override @Override
public void success() { public void success() {
RefreshEvent.config();
setLive(getHome()); setLive(getHome());
} }
@ -783,18 +782,18 @@ public class LiveActivity extends BaseActivity implements CustomKeyDown.Listener
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (ActionEvent.PLAY.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.action())) {
onPlay(); onPlay();
} else if (ActionEvent.PAUSE.equals(event.getAction())) { } else if (ActionEvent.PAUSE.equals(event.action())) {
onPaused(); onPaused();
} else if (ActionEvent.NEXT.equals(event.getAction())) { } else if (ActionEvent.NEXT.equals(event.action())) {
nextChannel(); nextChannel();
} else if (ActionEvent.PREV.equals(event.getAction())) { } else if (ActionEvent.PREV.equals(event.action())) {
prevChannel(); prevChannel();
} else if (ActionEvent.AUDIO.equals(event.getAction())) { } else if (ActionEvent.AUDIO.equals(event.action())) {
moveTaskToBack(true); moveTaskToBack(true);
setAudioOnly(true); setAudioOnly(true);
} else if (ActionEvent.STOP.equals(event.getAction())) { } else if (ActionEvent.STOP.equals(event.action())) {
finish(); finish();
} }
} }
@ -813,8 +812,8 @@ public class LiveActivity extends BaseActivity implements CustomKeyDown.Listener
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (!event.getTag().equals(tag)) return; if (!event.tag().equals(tag)) return;
switch (event.getState()) { switch (event.state()) {
case PlayerEvent.PREPARE: case PlayerEvent.PREPARE:
setDecode(); setDecode();
break; break;

@ -1172,22 +1172,22 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onActionEvent(ActionEvent event) { public void onActionEvent(ActionEvent event) {
if (isRedirect()) return; if (isRedirect()) return;
if (ActionEvent.PLAY.equals(event.getAction())) { if (ActionEvent.PLAY.equals(event.action())) {
onPlay(); onPlay();
} else if (ActionEvent.PAUSE.equals(event.getAction())) { } else if (ActionEvent.PAUSE.equals(event.action())) {
onPaused(); onPaused();
} else if (ActionEvent.NEXT.equals(event.getAction())) { } else if (ActionEvent.NEXT.equals(event.action())) {
checkNext(); checkNext();
} else if (ActionEvent.PREV.equals(event.getAction())) { } else if (ActionEvent.PREV.equals(event.action())) {
checkPrev(); checkPrev();
} else if (ActionEvent.LOOP.equals(event.getAction())) { } else if (ActionEvent.LOOP.equals(event.action())) {
onLoop(); onLoop();
} else if (ActionEvent.REPLAY.equals(event.getAction())) { } else if (ActionEvent.REPLAY.equals(event.action())) {
onReplay(); onReplay();
} else if (ActionEvent.AUDIO.equals(event.getAction())) { } else if (ActionEvent.AUDIO.equals(event.action())) {
moveTaskToBack(true); moveTaskToBack(true);
setAudioOnly(true); setAudioOnly(true);
} else if (ActionEvent.STOP.equals(event.getAction())) { } else if (ActionEvent.STOP.equals(event.action())) {
finish(); finish();
} }
} }
@ -1204,8 +1204,8 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onPlayerEvent(PlayerEvent event) { public void onPlayerEvent(PlayerEvent event) {
if (!event.getTag().equals(tag)) return; if (!event.tag().equals(tag)) return;
switch (event.getState()) { switch (event.state()) {
case PlayerEvent.PREPARE: case PlayerEvent.PREPARE:
setDecode(); setDecode();
setPosition(); setPosition();

@ -156,7 +156,7 @@ public class CastDialog extends BaseDialog implements DeviceAdapter.OnClickListe
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onScanEvent(ScanEvent event) { public void onScanEvent(ScanEvent event) {
scanTask.start(event.getAddress()); scanTask.start(event.address());
} }
@Override @Override

@ -14,7 +14,6 @@ import com.fongmi.android.tv.api.config.VodConfig;
import com.fongmi.android.tv.bean.History; import com.fongmi.android.tv.bean.History;
import com.fongmi.android.tv.databinding.DialogReceiveBinding; import com.fongmi.android.tv.databinding.DialogReceiveBinding;
import com.fongmi.android.tv.event.CastEvent; import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.ui.activity.VideoActivity; import com.fongmi.android.tv.ui.activity.VideoActivity;
import com.fongmi.android.tv.utils.ImgUtil; import com.fongmi.android.tv.utils.ImgUtil;
@ -52,9 +51,9 @@ public class ReceiveDialog extends BaseDialog {
@Override @Override
protected void initView() { protected void initView() {
History item = event.getHistory(); History item = event.history();
binding.name.setText(item.getVodName()); binding.name.setText(item.getVodName());
binding.from.setText(event.getDevice().getName()); binding.from.setText(event.device().getName());
ImgUtil.load(item.getVodName(), item.getVodPic(), binding.image); ImgUtil.load(item.getVodName(), item.getVodPic(), binding.image);
} }
@ -76,12 +75,12 @@ public class ReceiveDialog extends BaseDialog {
} }
private void onReceiveCast() { private void onReceiveCast() {
if (VodConfig.get().getConfig().equals(event.getConfig())) { if (VodConfig.get().getConfig().equals(event.config())) {
VideoActivity.cast(requireActivity(), event.getHistory().save(VodConfig.getCid())); VideoActivity.cast(requireActivity(), event.history().save(VodConfig.getCid()));
dismiss(); dismiss();
} else { } else {
showProgress(); showProgress();
VodConfig.load(event.getConfig(), getCallback()); VodConfig.load(event.config(), getCallback());
} }
} }
@ -89,8 +88,6 @@ public class ReceiveDialog extends BaseDialog {
return new Callback() { return new Callback() {
@Override @Override
public void success() { public void success() {
RefreshEvent.config();
RefreshEvent.video();
onReceiveCast(); onReceiveCast();
hideProgress(); hideProgress();
} }

@ -151,7 +151,7 @@ public class SyncDialog extends BaseDialog implements DeviceAdapter.OnClickListe
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onScanEvent(ScanEvent event) { public void onScanEvent(ScanEvent event) {
scanTask.start(event.getAddress()); scanTask.start(event.address());
} }
@Override @Override

@ -24,6 +24,7 @@ import com.fongmi.android.tv.bean.Live;
import com.fongmi.android.tv.bean.Site; import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.databinding.FragmentSettingBinding; import com.fongmi.android.tv.databinding.FragmentSettingBinding;
import com.fongmi.android.tv.db.AppDatabase; import com.fongmi.android.tv.db.AppDatabase;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
import com.fongmi.android.tv.impl.ConfigCallback; import com.fongmi.android.tv.impl.ConfigCallback;
@ -149,54 +150,42 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
private void load(Config config) { private void load(Config config) {
switch (config.getType()) { switch (config.getType()) {
case 0: case 0:
VodConfig.load(config, getCallback(0)); VodConfig.load(config, getCallback());
break; break;
case 1: case 1:
LiveConfig.load(config, getCallback(1)); LiveConfig.load(config, getCallback());
break; break;
case 2: case 2:
Setting.putWall(0); Setting.putWall(0);
WallConfig.load(config, getCallback(2)); WallConfig.load(config, getCallback());
break; break;
} }
} }
private Callback getCallback(int type) { private Callback getCallback() {
return new Callback() { return new Callback() {
@Override @Override
public void start() { public void start() {
Notify.progress(requireActivity()); Notify.progress(requireActivity());
} }
@Override
public void success(String result) {
Notify.show(result);
}
@Override @Override
public void success() { public void success() {
setConfig(type); Notify.dismiss();
setCacheText();
} }
@Override @Override
public void error(String msg) { public void error(String msg) {
Notify.dismiss();
Notify.show(msg); Notify.show(msg);
setConfig(type);
} }
}; };
} }
private void setConfig(int type) {
setCacheText();
Notify.dismiss();
RefreshEvent.config();
if (type == 0) RefreshEvent.video();
}
@Override @Override
public void setSite(Site item) { public void setSite(Site item) {
VodConfig.get().setHome(item); VodConfig.get().setHome(item);
RefreshEvent.video();
} }
@Override @Override
@ -257,12 +246,13 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
private void setWallDefault(View view) { private void setWallDefault(View view) {
Setting.putWall(Setting.getWall() == 4 ? 1 : Setting.getWall() + 1); Setting.putWall(Setting.getWall() == 4 ? 1 : Setting.getWall() + 1);
RefreshEvent.wall(); Setting.putWallType(0);
ConfigEvent.wall();
} }
private void setWallRefresh(View view) { private void setWallRefresh(View view) {
Setting.putWall(0); Setting.putWall(0);
WallConfig.get().load(getCallback(2)); WallConfig.get().load(getCallback());
} }
private boolean onWallHistory(View view) { private boolean onWallHistory(View view) {
@ -337,14 +327,14 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
} }
private void initConfig() { private void initConfig() {
VodConfig.get().init().load(getCallback(0)); VodConfig.get().init().load(getCallback());
LiveConfig.get().init().load(); LiveConfig.get().init().load();
WallConfig.get().init().load(); WallConfig.get().init().load();
} }
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onConfigEvent(ConfigEvent event) {
if (event.getType() != RefreshEvent.Type.CONFIG) return; if (event.type() != ConfigEvent.Type.COMMON) return;
mBinding.vodUrl.setText(VodConfig.getDesc()); mBinding.vodUrl.setText(VodConfig.getDesc());
mBinding.liveUrl.setText(LiveConfig.getDesc()); mBinding.liveUrl.setText(LiveConfig.getDesc());
mBinding.wallUrl.setText(WallConfig.getDesc()); mBinding.wallUrl.setText(WallConfig.getDesc());

@ -28,6 +28,7 @@ import com.fongmi.android.tv.bean.Site;
import com.fongmi.android.tv.bean.Value; import com.fongmi.android.tv.bean.Value;
import com.fongmi.android.tv.databinding.FragmentVodBinding; import com.fongmi.android.tv.databinding.FragmentVodBinding;
import com.fongmi.android.tv.event.CastEvent; import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.ConfigEvent;
import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.StateEvent; import com.fongmi.android.tv.event.StateEvent;
import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.Callback;
@ -233,19 +234,21 @@ public class VodFragment extends BaseFragment implements ConfigCallback, SiteCal
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) { public void onRefreshEvent(RefreshEvent event) {
switch (event.getType()) { switch (event.getType()) {
case CONFIG: case HOME:
setLogo();
break;
case VIDEO:
case SIZE: case SIZE:
homeContent(); homeContent();
break; break;
} }
} }
@Subscribe(threadMode = ThreadMode.MAIN)
public void onConfigEvent(ConfigEvent event) {
if (event.type() == ConfigEvent.Type.VOD) setLogo();
}
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onStateEvent(StateEvent event) { public void onStateEvent(StateEvent event) {
switch (event.getType()) { switch (event.type()) {
case EMPTY: case EMPTY:
hideProgress(); hideProgress();
break; break;
@ -273,9 +276,8 @@ public class VodFragment extends BaseFragment implements ConfigCallback, SiteCal
@Override @Override
public void success() { public void success() {
RefreshEvent.config();
RefreshEvent.video();
showContent(); showContent();
setLogo();
} }
@Override @Override
@ -289,7 +291,6 @@ public class VodFragment extends BaseFragment implements ConfigCallback, SiteCal
@Override @Override
public void setSite(Site item) { public void setSite(Site item) {
VodConfig.get().setHome(item); VodConfig.get().setHome(item);
homeContent();
} }
@Override @Override

Loading…
Cancel
Save