From ee1d6d5bb8c172c213b538895389685d648e0a60 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 19 Oct 2022 15:21:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../ui/nav/device/NavDeviceFragment.java | 5 +- .../PowerSwitchActivity.java} | 49 ++++++++++++++++--- .../PowerSwitchViewModel.java} | 6 +-- ...y.xml => device_power_switch_activity.xml} | 2 +- app/src/main/res/values/ids.xml | 4 +- 6 files changed, 50 insertions(+), 18 deletions(-) rename app/src/main/java/cc/niushuai/project/devcontrol/ui/{device/DeviceActivity.java => powerswitch/PowerSwitchActivity.java} (69%) rename app/src/main/java/cc/niushuai/project/devcontrol/ui/{device/DeviceViewModel.java => powerswitch/PowerSwitchViewModel.java} (74%) rename app/src/main/res/layout/{device_activity.xml => device_power_switch_activity.xml} (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1486a04..3921051 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,7 +20,7 @@ diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java index 411bd09..8743b62 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java @@ -11,7 +11,6 @@ import android.widget.AdapterView; import android.widget.GridView; import android.widget.SimpleAdapter; import android.widget.TextView; -import android.widget.Toast; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; @@ -25,7 +24,7 @@ import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; -import cc.niushuai.project.devcontrol.ui.device.DeviceActivity; +import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity; import cn.hutool.core.util.RandomUtil; /** @@ -117,7 +116,7 @@ public class NavDeviceFragment extends Fragment { private void onItemClick(AdapterView parent, View view, int position, long id) { TextView textId = view.findViewById(R.id.device_item_cardView_id); - Intent intent = new Intent(getActivity(), DeviceActivity.class); + Intent intent = new Intent(getActivity(), PowerSwitchActivity.class); intent.putExtra(Keys.ID, textId.getText()); startActivity(intent); } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java similarity index 69% rename from app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceActivity.java rename to app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java index c776c9b..535c265 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java @@ -1,5 +1,6 @@ -package cc.niushuai.project.devcontrol.ui.device; +package cc.niushuai.project.devcontrol.ui.powerswitch; +import android.annotation.SuppressLint; import android.os.Bundle; import android.view.View; import android.widget.TextView; @@ -7,16 +8,16 @@ import android.widget.TextView; import androidx.appcompat.widget.AppCompatImageView; import cc.niushuai.project.devcontrol.R; -import cc.niushuai.project.devcontrol.base.ui.BaseActivity; 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.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.Keys; -import cc.niushuai.project.devcontrol.databinding.DeviceActivityBinding; +import cc.niushuai.project.devcontrol.databinding.DevicePowerSwitchActivityBinding; -public class DeviceActivity extends BaseActivity { +public class PowerSwitchActivity extends BaseActivity { - private DeviceActivityBinding binding; + private DevicePowerSwitchActivityBinding binding; private DeviceInfo device; @Override @@ -25,7 +26,7 @@ public class DeviceActivity extends BaseActivity { // 隐藏自带的标题栏 getSupportActionBar().hide(); - binding = DeviceActivityBinding.inflate(getLayoutInflater()); + binding = DevicePowerSwitchActivityBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); // 初始化页面数据 @@ -67,8 +68,40 @@ public class DeviceActivity extends BaseActivity { * @date: 2022/10/19 11:49 */ private void addListener() { + // 开关点击事件 + binding.deviceActivityContentSwitch.setOnClickListener(this::imageSwitchClickListener); - binding.deviceActivityContentSwitch.setOnClickListener(this::switchClickListener); + // 标题栏 返回 + binding.deviceActivityTitleBack.setOnClickListener(this::buttonBackClickListener); + + // 标题栏 更多设置 + binding.deviceActivityTitleMoreSet.setOnClickListener(this::buttonMoreSetClickListener); + } + + /** + * 更多设置 打开fragment + * + * @param view + * @author niushuai + * @date: 2022/10/19 14:47 + */ + + private void buttonMoreSetClickListener(View view) { + + + + } + + /** + * 返回上一页 + * + * @param view + * @author niushuai + * @date: 2022/10/19 14:46 + */ + private void buttonBackClickListener(View view) { +// AppCompatImageButton buttonBack = (AppCompatImageButton) view; + PowerSwitchActivity.this.finish(); } /** @@ -78,7 +111,7 @@ public class DeviceActivity extends BaseActivity { * @author niushuai * @date: 2022/10/19 11:52 */ - private void switchClickListener(View view) { + private void imageSwitchClickListener(View view) { AppCompatImageView appCompatImageView = (AppCompatImageView) view; int switchImageId, iconImageId; diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceViewModel.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchViewModel.java similarity index 74% rename from app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceViewModel.java rename to app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchViewModel.java index 2f2413b..7818c7e 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/device/DeviceViewModel.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchViewModel.java @@ -1,15 +1,15 @@ -package cc.niushuai.project.devcontrol.ui.device; +package cc.niushuai.project.devcontrol.ui.powerswitch; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; -public class DeviceViewModel extends ViewModel { +public class PowerSwitchViewModel extends ViewModel { private MutableLiveData deviceInfo; - public DeviceViewModel() { + public PowerSwitchViewModel() { } public MutableLiveData getDeviceInfo() { diff --git a/app/src/main/res/layout/device_activity.xml b/app/src/main/res/layout/device_power_switch_activity.xml similarity index 97% rename from app/src/main/res/layout/device_activity.xml rename to app/src/main/res/layout/device_power_switch_activity.xml index 3343a70..dda27df 100644 --- a/app/src/main/res/layout/device_activity.xml +++ b/app/src/main/res/layout/device_power_switch_activity.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools" - tools:context=".ui.device.DeviceActivity"> + tools:context=".ui.powerswitch.PowerSwitchActivity"> - + @@ -31,7 +31,7 @@ - + \ No newline at end of file