From 0079082f80435a51c235a597d2ba60b479c56da1 Mon Sep 17 00:00:00 2001 From: FongMi Date: Mon, 5 Jun 2023 14:52:44 +0800 Subject: [PATCH] Clean code --- .../server/process/ActionRequestProcess.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/fongmi/android/tv/server/process/ActionRequestProcess.java b/app/src/main/java/com/fongmi/android/tv/server/process/ActionRequestProcess.java index c012695bf..e51efaaa3 100644 --- a/app/src/main/java/com/fongmi/android/tv/server/process/ActionRequestProcess.java +++ b/app/src/main/java/com/fongmi/android/tv/server/process/ActionRequestProcess.java @@ -36,13 +36,13 @@ public class ActionRequestProcess implements RequestProcess { Map params = session.getParms(); switch (Objects.requireNonNullElse(params.get("do"), "")) { case "search": - onSearch(params.get("word").trim()); + onSearch(params); break; case "push": - onPush(params.get("url").trim()); + onPush(params); break; case "api": - onApi(params.get("url").trim()); + onApi(params); break; case "cast": onCast(params); @@ -54,15 +54,18 @@ public class ActionRequestProcess implements RequestProcess { return Nano.createSuccessResponse(); } - public void onSearch(String word) { + public void onSearch(Map params) { + String word = Objects.requireNonNullElse(params.get("word"), ""); if (word.length() > 0) ServerEvent.search(word); } - public void onPush(String url) { + public void onPush(Map params) { + String url = Objects.requireNonNullElse(params.get("url"), ""); if (url.length() > 0) ServerEvent.push(url); } - public void onApi(String url) { + public void onApi(Map params) { + String url = Objects.requireNonNullElse(params.get("url"), ""); if (url.length() > 0) ServerEvent.api(url); } @@ -74,9 +77,9 @@ public class ActionRequestProcess implements RequestProcess { } public void onSync(Map params) { - boolean sync = params.get("mode").equals("0"); - boolean keep = params.get("type").equals("keep"); - boolean history = params.get("type").equals("history"); + boolean sync = Objects.equals(params.get("mode"), "0"); + boolean keep = Objects.equals(params.get("type"), "keep"); + boolean history = Objects.equals(params.get("type"), "history"); Device device = Device.objectFrom(params.get("device")); if (params.get("device") != null && sync) { if (history) sendHistory(device, params); @@ -116,7 +119,7 @@ public class ActionRequestProcess implements RequestProcess { String url = params.get("url"); if (TextUtils.isEmpty(url)) return; Config config = Config.find(url, 0); - boolean replace = params.get("mode").equals("1"); + boolean replace = Objects.equals(params.get("mode"), "1"); List targets = History.arrayFrom(params.get("targets")); if (ApiConfig.get().getConfig().equals(config)) { if (replace) History.delete(config.getId()); @@ -145,7 +148,7 @@ public class ActionRequestProcess implements RequestProcess { public void syncKeep(Map params) { List configs = Config.arrayFrom(params.get("configs")); List targets = Keep.arrayFrom(params.get("targets")); - boolean replace = params.get("mode").equals("1"); + boolean replace = Objects.equals(params.get("mode"), "1"); if (ApiConfig.getUrl() == null && configs.size() > 0) { ApiConfig.load(Config.find(configs.get(0), 0), getCallback(configs, targets)); } else {