diff --git a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index c7f3d91b6..ab65f2a6c 100644 --- a/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -760,6 +760,18 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, GroupP } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRefreshEvent(RefreshEvent event) { + switch (event.getType()) { + case LIVE: + setLive(getHome()); + break; + case PLAYER: + fetch(); + break; + } + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onPlayerEvent(PlayerEvent event) { switch (event.getState()) { diff --git a/app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java b/app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java index ea24eca6f..30224a6f7 100644 --- a/app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java +++ b/app/src/main/java/com/fongmi/android/tv/event/RefreshEvent.java @@ -35,6 +35,10 @@ public class RefreshEvent { EventBus.getDefault().post(new RefreshEvent(Type.WALL)); } + public static void live() { + EventBus.getDefault().post(new RefreshEvent(Type.LIVE)); + } + public static void detail() { EventBus.getDefault().post(new RefreshEvent(Type.DETAIL)); } @@ -69,6 +73,6 @@ public class RefreshEvent { } public enum Type { - CONFIG, IMAGE, VIDEO, HISTORY, KEEP, SIZE, WALL, DETAIL, PLAYER, SUBTITLE, DANMAKU + CONFIG, IMAGE, VIDEO, HISTORY, KEEP, SIZE, WALL, LIVE, DETAIL, PLAYER, SUBTITLE, DANMAKU } } diff --git a/app/src/main/java/com/fongmi/android/tv/server/process/Action.java b/app/src/main/java/com/fongmi/android/tv/server/process/Action.java index 3be8bcb05..b3114c8ae 100644 --- a/app/src/main/java/com/fongmi/android/tv/server/process/Action.java +++ b/app/src/main/java/com/fongmi/android/tv/server/process/Action.java @@ -44,34 +44,16 @@ public class Action implements Process { @Override public NanoHTTPD.Response doResponse(NanoHTTPD.IHTTPSession session, String path, Map files) { Map params = session.getParms(); - switch (Objects.requireNonNullElse(params.get("do"), "")) { - case "search": - onSearch(params); - return Nano.success(); - case "push": - onPush(params); - return Nano.success(); - case "setting": - onSetting(params); - return Nano.success(); - case "file": - onFile(params); - return Nano.success(); - case "refresh": - onRefresh(params); - return Nano.success(); - case "cast": - onCast(params); - return Nano.success(); - case "sync": - onSync(params); - return Nano.success(); - case "transmit": - onTransmit(params, files); - return Nano.success(); - default: - return Nano.error(null); - } + String param = params.get("do"); + if ("file".equals(param)) onFile(params); + else if ("push".equals(param)) onPush(params); + else if ("cast".equals(param)) onCast(params); + else if ("sync".equals(param)) onSync(params); + else if ("search".equals(param)) onSearch(params); + else if ("setting".equals(param)) onSetting(params); + else if ("refresh".equals(param)) onRefresh(params); + else if ("transmit".equals(param)) onTransmit(params, files); + return Nano.success(); } private void onSearch(Map params) { @@ -106,20 +88,11 @@ public class Action implements Process { String type = params.get("type"); String path = params.get("path"); if (TextUtils.isEmpty(type)) return; - switch (type) { - case "detail": - RefreshEvent.detail(); - break; - case "player": - RefreshEvent.player(); - break; - case "danmaku": - RefreshEvent.danmaku(path); - break; - case "subtitle": - RefreshEvent.subtitle(path); - break; - } + if ("live".equals(type)) RefreshEvent.live(); + else if ("detail".equals(type)) RefreshEvent.detail(); + else if ("player".equals(type)) RefreshEvent.player(); + else if ("danmaku".equals(type)) RefreshEvent.danmaku(path); + else if ("subtitle".equals(type)) RefreshEvent.subtitle(path); } private void onCast(Map params) { @@ -147,25 +120,11 @@ public class Action implements Process { private void onTransmit(Map params, Map files) { String type = params.get("type"); - switch (type) { - case "apk": - apk(params, files); - break; - case "vod_config": - vodConfig(params); - break; - case "wall_config": - wallConfig(params, files); - break; - case "push_restore": - pushRestore(params, files); - break; - case "pull_restore": - pullRestore(params, files); - break; - default: - break; - } + if ("apk".equals(type)) apk(params, files); + else if ("vod_config".equals(type)) vodConfig(params); + else if ("wall_config".equals(type)) wallConfig(params, files); + else if ("push_restore".equals(type)) pushRestore(params, files); + else if ("pull_restore".equals(type)) pullRestore(params, files); } private void sendHistory(Device device, Map params) { diff --git a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java index 4da4f325c..199ea5588 100644 --- a/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java +++ b/app/src/mobile/java/com/fongmi/android/tv/ui/activity/LiveActivity.java @@ -40,6 +40,7 @@ import com.fongmi.android.tv.databinding.ActivityLiveBinding; import com.fongmi.android.tv.event.ActionEvent; import com.fongmi.android.tv.event.ErrorEvent; import com.fongmi.android.tv.event.PlayerEvent; +import com.fongmi.android.tv.event.RefreshEvent; import com.fongmi.android.tv.impl.Callback; import com.fongmi.android.tv.impl.LiveCallback; import com.fongmi.android.tv.impl.PassCallback; @@ -825,6 +826,18 @@ public class LiveActivity extends BaseActivity implements Clock.Callback, Custom } } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onRefreshEvent(RefreshEvent event) { + switch (event.getType()) { + case LIVE: + setLive(getHome()); + break; + case PLAYER: + fetch(); + break; + } + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onPlayerEvent(PlayerEvent event) { switch (event.getState()) {