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 f4792a6..1d7df01 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,11 +2,27 @@ package cc.niushuai.project.devcontrol.base.ui; import androidx.appcompat.app.AppCompatActivity; +import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; +import cc.niushuai.project.devcontrol.base.util.Keys; + /** * Activity基类 * * @author niushuai * @date: 2022/10/18 14:24 */ -public class BaseActivity extends AppCompatActivity { +public abstract class BaseActivity extends AppCompatActivity { + + protected DeviceInfo device; + + protected String getIntentDeviceId() { + return getIntent().getStringExtra(Keys.ID); + } + /** + * 初始化方法 + * + * @author niushuai + * @date: 2022/10/19 15:54 + */ + public abstract void init(); } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java index ca67353..8553677 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java @@ -15,7 +15,10 @@ public class GlobalVariables { public static final Map DEVICE_INFO_MAP = new HashMap<>(16); public static Class getDeviceOperateActivity(String deviceId) { - return DEVICE_INFO_MAP.get(deviceId).getDeviceType().getActivity(); + return getDeviceInfo(deviceId).getDeviceType().getActivity(); } + public static DeviceInfo getDeviceInfo(String deviceId) { + return DEVICE_INFO_MAP.get(deviceId); + } } 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 fea4f21..a01a4ec 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,6 +1,7 @@ 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; @@ -19,7 +20,6 @@ import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding; public class PowerSwitchActivity extends BaseActivity { private ActivityPowerSwitchBinding binding; - private DeviceInfo device; @Override public void onCreate(Bundle savedInstanceState) { @@ -42,10 +42,10 @@ public class PowerSwitchActivity extends BaseActivity { * @author niushuai * @date: 2022/10/19 11:18 */ + @Override public void init() { - String deviceId = getIntent().getStringExtra(Keys.ID); - DeviceInfo data = GlobalVariables.DEVICE_INFO_MAP.get(deviceId); + DeviceInfo data = GlobalVariables.getDeviceInfo(getIntentDeviceId()); if (null != data) { this.device = data; // 标题名称 @@ -87,7 +87,12 @@ public class PowerSwitchActivity extends BaseActivity { * @date: 2022/10/19 14:47 */ private void buttonMoreSetClickListener(View view) { - ActivityUtil.startActivity(this, PowerSwitchSetActivity.class); +// ActivityUtil.startActivity(this, PowerSwitchSetActivity.class); + + Intent intent = new Intent(this, PowerSwitchSetActivity.class); + + startActivity(intent); + } /** 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 40f7ba2..9eb88a6 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 @@ -1,17 +1,32 @@ package cc.niushuai.project.devcontrol.ui.powerswitch; -import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; -import cc.niushuai.project.devcontrol.R; +import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; +import cc.niushuai.project.devcontrol.base.util.GlobalVariables; +import cc.niushuai.project.devcontrol.base.util.Keys; +import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchBinding; +import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetBinding; public class PowerSwitchSetActivity extends BaseActivity { + private ActivityPowerSwitchSetBinding binding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_power_switch_set); + getSupportActionBar().hide(); + + binding = ActivityPowerSwitchSetBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + } + + @Override + public void init() { + device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); + + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_power_switch_set.xml b/app/src/main/res/layout/activity_power_switch_set.xml index a70323d..95294bd 100644 --- a/app/src/main/res/layout/activity_power_switch_set.xml +++ b/app/src/main/res/layout/activity_power_switch_set.xml @@ -6,13 +6,9 @@ android:layout_height="match_parent" tools:context=".ui.powerswitch.PowerSwitchSetActivity"> - - - \ No newline at end of file