From 60e971f233afb91bc14dc8b3b1fb855be1513c70 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 19 Oct 2022 17:37:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8A=BD=E5=8F=96=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcontrol/base/ui/BaseActivity.java | 41 ++++++++++++++++- .../ui/powerswitch/PowerSwitchActivity.java | 45 ++++--------------- .../powerswitch/PowerSwitchSetActivity.java | 5 +-- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java index 1d7df01..33bf599 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java @@ -2,7 +2,11 @@ package cc.niushuai.project.devcontrol.base.ui; import androidx.appcompat.app.AppCompatActivity; +import java.util.Map; + +import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; +import cc.niushuai.project.devcontrol.base.util.ActivityUtil; import cc.niushuai.project.devcontrol.base.util.Keys; /** @@ -18,11 +22,46 @@ public abstract class BaseActivity extends AppCompatActivity { protected String getIntentDeviceId() { return getIntent().getStringExtra(Keys.ID); } + /** * 初始化方法 * * @author niushuai * @date: 2022/10/19 15:54 */ - public abstract void init(); + protected abstract void init(); + + /** + * 监听器事件统一设置入口 + * + * @author niushuai + * @date: 2022/10/19 17:31 + */ + protected void addListener() { + } + + /** + * 返回上一页 + * + * @param activity + * @author niushuai + * @date: 2022/10/19 14:46 + */ + protected void activityButtonBackClickListener(BaseActivity activity) { + findViewById(R.id.activity_title_back).setOnClickListener(view -> activity.finish()); + } + + /** + * 更多设置 打开新的activity + * + * @param activity 源activity + * @param clazz 目标activity + * @param withData activity之间传递数据 + * @author niushuai + * @date: 2022/10/19 14:47 + */ + protected void activityButtonMoreSetClickListener(BaseActivity activity, Class clazz, Map withData) { + findViewById(R.id.activity_title_more_set).setOnClickListener(view -> ActivityUtil.startActivity(activity, clazz, withData)); + } + } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java index 24c1e41..411cd59 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java @@ -1,18 +1,17 @@ package cc.niushuai.project.devcontrol.ui.powerswitch; -import android.annotation.SuppressLint; -import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView; import androidx.appcompat.widget.AppCompatImageView; +import java.util.HashMap; + import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; -import cc.niushuai.project.devcontrol.base.util.ActivityUtil; import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding; @@ -43,7 +42,7 @@ public class PowerSwitchActivity extends BaseActivity { * @date: 2022/10/19 11:18 */ @Override - public void init() { + protected void init() { DeviceInfo data = GlobalVariables.getDeviceInfo(getIntentDeviceId()); if (null != data) { @@ -68,46 +67,20 @@ public class PowerSwitchActivity extends BaseActivity { * @author niushuai * @date: 2022/10/19 11:49 */ - private void addListener() { + @Override + protected void addListener() { // 开关点击事件 binding.powerSwitchActivityContentSwitch.setOnClickListener(this::imageSwitchClickListener); // 标题栏 返回 - findViewById(R.id.activity_title_back).setOnClickListener(this::buttonBackClickListener); -// binding.powerSwitchActivityTitleBack.setOnClickListener(this::buttonBackClickListener); + super.activityButtonBackClickListener(this); // 标题栏 更多设置 - findViewById(R.id.activity_title_more_set).setOnClickListener(this::buttonMoreSetClickListener); -// binding.powerSwitchActivityTitleMoreSet.setOnClickListener(this::buttonMoreSetClickListener); + HashMap withData = new HashMap<>(1); + withData.put(Keys.ID, device.getId()); + super.activityButtonMoreSetClickListener(this, PowerSwitchSetActivity.class, withData); } - /** - * 更多设置 打开fragment - * - * @param view - * @author niushuai - * @date: 2022/10/19 14:47 - */ - private void buttonMoreSetClickListener(View view) { -// ActivityUtil.startActivity(this, PowerSwitchSetActivity.class); - - Intent intent = new Intent(this, PowerSwitchSetActivity.class); - - startActivity(intent); - - } - - /** - * 返回上一页 - * - * @param view - * @author niushuai - * @date: 2022/10/19 14:46 - */ - private void buttonBackClickListener(View view) { -// AppCompatImageButton buttonBack = (AppCompatImageButton) view; - PowerSwitchActivity.this.finish(); - } /** * 开关点击事件处理 diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java index 9eb88a6..57ee556 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchSetActivity.java @@ -23,10 +23,7 @@ public class PowerSwitchSetActivity extends BaseActivity { } @Override - public void init() { + protected void init() { device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); - - - } } \ No newline at end of file