From 0c187286057bf40528ba4d0d8fca4b1702ac2aa5 Mon Sep 17 00:00:00 2001 From: ourfor Date: Tue, 3 Dec 2024 20:03:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20useless=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/common/ScriptManageViewModel.java | 33 ------------------- .../common => web}/ScriptManageView.java | 29 ++++++++-------- .../page/web/ScriptManageViewModel.java | 19 +++++++++++ .../ourfor/app/iplayx/page/web/WebPage.java | 13 ++------ .../common => web}/WebScriptMessage.java | 2 +- .../app/src/main/res/layout/script_manage.xml | 2 +- 6 files changed, 38 insertions(+), 60 deletions(-) delete mode 100644 android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageViewModel.java rename android/app/src/main/java/top/ourfor/app/iplayx/page/{setting/common => web}/ScriptManageView.java (78%) create mode 100644 android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageViewModel.java rename android/app/src/main/java/top/ourfor/app/iplayx/page/{setting/common => web}/WebScriptMessage.java (83%) diff --git a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageViewModel.java b/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageViewModel.java deleted file mode 100644 index 703f5be3..00000000 --- a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageViewModel.java +++ /dev/null @@ -1,33 +0,0 @@ -package top.ourfor.app.iplayx.page.setting.common; - -import android.content.Context; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.LayoutInflater; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.constraintlayout.widget.ConstraintLayout; - -import java.util.function.Consumer; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.val; -import top.ourfor.app.iplayx.R; -import top.ourfor.app.iplayx.action.UpdateModelAction; -import top.ourfor.app.iplayx.databinding.ScriptManageBinding; -import top.ourfor.app.iplayx.util.DeviceUtil; - -@NoArgsConstructor -@AllArgsConstructor -public class ScriptManageViewModel { - @Getter @Setter - String value; - - @Getter @Setter - Consumer onClick; - -} diff --git a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageView.java b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageView.java similarity index 78% rename from android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageView.java rename to android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageView.java index db6b16c6..04fdaef8 100644 --- a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/ScriptManageView.java +++ b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageView.java @@ -1,41 +1,36 @@ -package top.ourfor.app.iplayx.page.setting.common; +package top.ourfor.app.iplayx.page.web; import static top.ourfor.app.iplayx.module.Bean.XGET; +import android.app.Dialog; import android.content.Context; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; -import com.google.android.flexbox.FlexboxLayout; - -import java.util.ArrayList; -import java.util.List; +import java.util.function.Consumer; import lombok.Getter; +import lombok.Setter; import lombok.val; import top.ourfor.app.iplayx.R; -import top.ourfor.app.iplayx.action.UpdateModelAction; import top.ourfor.app.iplayx.bean.KVStorage; import top.ourfor.app.iplayx.databinding.ScriptManageBinding; -import top.ourfor.app.iplayx.databinding.SettingCellBinding; import top.ourfor.app.iplayx.util.DeviceUtil; -import top.ourfor.app.iplayx.view.TagView; public class ScriptManageView extends ConstraintLayout { ScriptManageBinding binding = null; @Getter ScriptManageViewModel viewModel = new ScriptManageViewModel(); + @Getter @Setter + Consumer onSaveButtonClick; + public ScriptManageView(@NonNull Context context) { super(context); binding = ScriptManageBinding.inflate(LayoutInflater.from(context), this, true); @@ -48,8 +43,14 @@ private void bind() { viewModel.value = XGET(KVStorage.class).get("@script"); setupTextArea(); - binding.settingButton.setOnClickListener(v -> { - XGET(KVStorage.class).set("@script", viewModel.value); + binding.saveButton.setOnClickListener(v -> { + val kv = XGET(KVStorage.class); + if (kv != null) { + kv.set("@script", viewModel.value); + } + if (onSaveButtonClick != null) { + onSaveButtonClick.accept(v); + } }); if (!DeviceUtil.isTV) return; diff --git a/android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageViewModel.java b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageViewModel.java new file mode 100644 index 00000000..8ea07140 --- /dev/null +++ b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/ScriptManageViewModel.java @@ -0,0 +1,19 @@ +package top.ourfor.app.iplayx.page.web; + +import java.util.function.Consumer; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@NoArgsConstructor +@AllArgsConstructor +public class ScriptManageViewModel { + @Getter @Setter + String value; + + @Getter @Setter + Consumer onClick; + +} diff --git a/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebPage.java b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebPage.java index 7ce67238..615063c7 100644 --- a/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebPage.java +++ b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebPage.java @@ -13,15 +13,12 @@ import android.view.ViewGroup; import android.webkit.JavascriptInterface; import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.airbnb.lottie.LottieAnimationView; @@ -45,15 +42,10 @@ import top.ourfor.app.iplayx.databinding.WebPageBinding; import top.ourfor.app.iplayx.page.Activity; import top.ourfor.app.iplayx.page.Page; -import top.ourfor.app.iplayx.page.setting.common.ScriptManageView; -import top.ourfor.app.iplayx.page.setting.common.WebScriptMessage; import top.ourfor.app.iplayx.store.GlobalStore; import top.ourfor.app.iplayx.util.AnimationUtil; import top.ourfor.app.iplayx.util.DeviceUtil; import top.ourfor.app.iplayx.util.WindowUtil; -import top.ourfor.app.iplayx.view.infra.Button; -import top.ourfor.app.iplayx.view.infra.EditText; -import top.ourfor.app.iplayx.view.infra.TextView; import top.ourfor.app.iplayx.view.infra.Toolbar; import top.ourfor.app.iplayx.view.infra.ToolbarAction; @@ -211,11 +203,10 @@ void bind() { } void showScriptPanel() { - val drive = store.getDrive(); dialog = new BottomSheetDialog(getContext(), R.style.SiteBottomSheetDialog); - dialog.setOnDismissListener(dlg -> { - }); + dialog.setOnDismissListener(dlg -> { }); var view = new ScriptManageView(context); + view.setOnSaveButtonClick(v -> dialog.dismiss()); dialog.setContentView(view); var behavior = BottomSheetBehavior.from((View) view.getParent()); val height = (int) (DeviceUtil.screenSize(getContext()).getHeight() * 0.6); diff --git a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/WebScriptMessage.java b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebScriptMessage.java similarity index 83% rename from android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/WebScriptMessage.java rename to android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebScriptMessage.java index 08694b59..475d5513 100644 --- a/android/app/src/main/java/top/ourfor/app/iplayx/page/setting/common/WebScriptMessage.java +++ b/android/app/src/main/java/top/ourfor/app/iplayx/page/web/WebScriptMessage.java @@ -1,4 +1,4 @@ -package top.ourfor.app.iplayx.page.setting.common; +package top.ourfor.app.iplayx.page.web; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/android/app/src/main/res/layout/script_manage.xml b/android/app/src/main/res/layout/script_manage.xml index e2332499..59bc1636 100644 --- a/android/app/src/main/res/layout/script_manage.xml +++ b/android/app/src/main/res/layout/script_manage.xml @@ -37,7 +37,7 @@ />