diff --git a/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java b/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java index 3f0b37bd..0ab31178 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/dialog/ApiDialog.java @@ -18,6 +18,7 @@ import com.github.tvbox.osc.server.ControlManager; import com.github.tvbox.osc.ui.adapter.ApiHistoryDialogAdapter; import com.github.tvbox.osc.ui.tv.QRCodeGen; import com.github.tvbox.osc.util.HawkConfig; +import com.github.tvbox.osc.util.HistoryHelper; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; @@ -68,13 +69,7 @@ public class ApiDialog extends BaseDialog { public void onClick(View v) { String newApi = inputApi.getText().toString().trim(); if (!newApi.isEmpty()) { - ArrayList history = Hawk.get(HawkConfig.API_HISTORY, new ArrayList()); - if (!history.contains(newApi)) - history.add(0, newApi); - if (history.size() > 30) - history.remove(30); - Hawk.put(HawkConfig.API_HISTORY, history); -// String newLiveApi = inputApi.getText().toString().trim(); + HistoryHelper.setApiHistory(newApi); if(!newApi.equals(Hawk.get(HawkConfig.API_URL, newApi))){ inputApiLive.setText(newApi); Hawk.put(HawkConfig.LIVE_API_URL, newApi); @@ -89,14 +84,7 @@ public class ApiDialog extends BaseDialog { public void onClick(View v) { String newApi = inputApiLive.getText().toString().trim(); if (!newApi.isEmpty()) { - ArrayList history = Hawk.get(HawkConfig.LIVE_API_HISTORY, new ArrayList()); - if (!history.contains(newApi)) { - history.add(0, newApi); - } - if (history.size() > 30) { - history.remove(30); - } - Hawk.put(HawkConfig.LIVE_API_HISTORY, history); + HistoryHelper.setLiveApiHistory(newApi); } Hawk.put(HawkConfig.LIVE_API_URL, newApi); dismiss(); @@ -167,12 +155,7 @@ public class ApiDialog extends BaseDialog { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { String newApi = inputApi.getText().toString().trim(); if (!newApi.isEmpty()) { - ArrayList history = Hawk.get(HawkConfig.API_HISTORY, new ArrayList()); - if (!history.contains(newApi)) - history.add(0, newApi); - if (history.size() > 30) - history.remove(30); - Hawk.put(HawkConfig.API_HISTORY, history); + HistoryHelper.setApiHistory(newApi); if(!newApi.equals(Hawk.get(HawkConfig.API_URL, newApi))){ inputApiLive.setText(newApi); diff --git a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java index 35a10e82..91b84e00 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/fragment/ModelSettingFragment.java @@ -325,14 +325,7 @@ public class ModelSettingFragment extends BaseLazyFragment { public void click(String value) { Hawk.put(HawkConfig.API_URL, value); Hawk.put(HawkConfig.LIVE_API_URL, value); - ArrayList history = Hawk.get(HawkConfig.LIVE_API_HISTORY, new ArrayList()); - if (!history.contains(value)) { - history.add(0, value); - } - if (history.size() > 30) { - history.remove(30); - } - Hawk.put(HawkConfig.LIVE_API_HISTORY, history); + HistoryHelper.setLiveApiHistory(value); tvApi.setText(value); dialog.dismiss(); } diff --git a/app/src/main/java/com/github/tvbox/osc/util/HistoryHelper.java b/app/src/main/java/com/github/tvbox/osc/util/HistoryHelper.java index 71b9eb92..0cf4a165 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/HistoryHelper.java +++ b/app/src/main/java/com/github/tvbox/osc/util/HistoryHelper.java @@ -32,4 +32,26 @@ public class HistoryHelper { } Hawk.put(HawkConfig.SEARCH_HISTORY, history); } + + public static void setLiveApiHistory(String value){ + ArrayList history = Hawk.get(HawkConfig.LIVE_API_HISTORY, new ArrayList()); + if (!history.contains(value)) { + history.add(0, value); + } + if (history.size() > 30) { + history.remove(30); + } + Hawk.put(HawkConfig.LIVE_API_HISTORY, history); + } + + public static void setApiHistory(String value){ + ArrayList history = Hawk.get(HawkConfig.API_HISTORY, new ArrayList()); + if (!history.contains(value)) { + history.add(0, value); + } + if (history.size() > 30) { + history.remove(30); + } + Hawk.put(HawkConfig.API_HISTORY, history); + } }