更新
This commit is contained in:
@@ -108,9 +108,9 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
||||
goTo(mContext, DevicePreviewActivity.class, null));
|
||||
String name = getString(R.string.device_home_sample_name);
|
||||
List<HomeDeviceEntity> devices = new ArrayList<>();
|
||||
devices.add(new HomeDeviceEntity("demo-device-1", name, true, 1200, 180));
|
||||
devices.add(new HomeDeviceEntity("demo-device-2", name, true, 1000, 160));
|
||||
devices.add(new HomeDeviceEntity("demo-device-3", name, true, 800, 140));
|
||||
devices.add(new HomeDeviceEntity("demo-device-1", name, true, 1200, 180, "128.6"));
|
||||
devices.add(new HomeDeviceEntity("demo-device-2", name, true, 1000, 160, "96.4"));
|
||||
devices.add(new HomeDeviceEntity("demo-device-3", name, true, 800, 140, "64.2"));
|
||||
devices.add(new HomeDeviceEntity("demo-device-4", name, false, 0, 0));
|
||||
adapter.setNewData(devices);
|
||||
// 复用现有观察器;列表有数据时显示宫格,清空后仍可恢复原来的空状态。
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.ckkj.griddle.device.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
@@ -19,16 +21,29 @@ public class HomeDeviceAdapter extends BaseQuickAdapter<HomeDeviceEntity, BaseVi
|
||||
boolean online = item.isOnline();
|
||||
helper.setText(R.id.tv_device_name, item.getName());
|
||||
helper.setText(R.id.tv_device_power, mContext.getString(
|
||||
R.string.device_home_power_value, item.getPower()));
|
||||
R.string.home_index_power, item.getPower()));
|
||||
helper.setText(R.id.tv_device_temperature, mContext.getString(
|
||||
R.string.device_home_temperature_value, item.getTemperature()));
|
||||
R.string.home_index_temperature, item.getTemperature()));
|
||||
helper.setText(R.id.tv_device_carbon, mContext.getString(
|
||||
R.string.home_index_carbon, item.getCarbonReduction()));
|
||||
// 每次绑定都重置可见性,避免离线卡片复用时残留在线功率和温度。
|
||||
helper.setGone(R.id.ll_device_online, online);
|
||||
helper.setGone(R.id.tv_device_offline, !online);
|
||||
ImageView icon = helper.getView(R.id.iv_device);
|
||||
View status = helper.getView(R.id.view_device_status);
|
||||
// 现有 selector 使用 activated=true 表示离线,图标、底色和状态点保持一致。
|
||||
icon.setActivated(!online);
|
||||
// 原切图自带绿色底色;按原图绿色通道将底色和图形映射为稿中的离线灰色。
|
||||
icon.clearColorFilter();
|
||||
if (!online) {
|
||||
float scale = (245f - 153f) / (245f - 164f);
|
||||
float offset = 245f - 245f * scale;
|
||||
ColorMatrix offline = new ColorMatrix(new float[]{
|
||||
0, scale, 0, 0, offset,
|
||||
0, scale, 0, 0, offset,
|
||||
0, scale, 0, 0, offset,
|
||||
0, 0, 0, 1, 0
|
||||
});
|
||||
icon.setColorFilter(new ColorMatrixColorFilter(offline));
|
||||
}
|
||||
status.setActivated(!online);
|
||||
status.setContentDescription(mContext.getString(online
|
||||
? R.string.device_home_online : R.string.device_home_offline));
|
||||
|
||||
@@ -35,13 +35,16 @@ public class DevicePreviewActivity extends BaseActivity<DevicePreviewBinding, De
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
super.initData(savedInstanceState);
|
||||
ImmersionBar.with(this)
|
||||
.statusBarColor(R.color.device_home_background)
|
||||
.statusBarColor(R.color.white)
|
||||
.statusBarDarkFont(true)
|
||||
.init();
|
||||
// 当前沿用静态示例数据;积分环按设计稿显示 72%,不代表设备实时数据。
|
||||
findViewById(R.id.preview_points_progress).getBackground().setLevel(7200);
|
||||
}
|
||||
|
||||
@OnClick({R.id.img_back, R.id.cv_preview_device, R.id.cv_preview_carbon, R.id.ll_preview_stats,
|
||||
R.id.tv_carbon_status, R.id.ll_preview_carbon_points, R.id.tv_carbon_points})
|
||||
R.id.tv_carbon_status, R.id.ll_preview_control,
|
||||
R.id.ll_preview_carbon_points, R.id.tv_carbon_points})
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.img_back:
|
||||
@@ -50,12 +53,13 @@ public class DevicePreviewActivity extends BaseActivity<DevicePreviewBinding, De
|
||||
|
||||
case R.id.cv_preview_device:
|
||||
case R.id.ll_preview_stats:
|
||||
// 设备卡片和统计入口均进入设备数据页。
|
||||
case R.id.tv_carbon_status:
|
||||
case R.id.ll_preview_control:
|
||||
// 设备卡片、统计和控制入口复用现有设备数据页。
|
||||
goTo(mContext, DeviceDataViewActivity.class, null);
|
||||
break;
|
||||
|
||||
case R.id.cv_preview_carbon:
|
||||
case R.id.tv_carbon_status:
|
||||
// 今日碳减排整张卡片进入碳排放统计页。
|
||||
goTo(mContext, CarbonActivity.class, null);
|
||||
break;
|
||||
|
||||
@@ -10,13 +10,21 @@ public class HomeDeviceEntity {
|
||||
private final int power;
|
||||
/** 当前温度,单位摄氏度。 */
|
||||
private final int temperature;
|
||||
/** 累计碳减排,单位为 kg CO₂e;使用十进制文本保留接口精度。 */
|
||||
private final String carbonReduction;
|
||||
|
||||
public HomeDeviceEntity(String id, String name, boolean online, int power, int temperature) {
|
||||
this(id, name, online, power, temperature, "0");
|
||||
}
|
||||
|
||||
public HomeDeviceEntity(String id, String name, boolean online, int power, int temperature,
|
||||
String carbonReduction) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.online = online;
|
||||
this.power = power;
|
||||
this.temperature = temperature;
|
||||
this.carbonReduction = carbonReduction;
|
||||
}
|
||||
|
||||
public String getId() { return id; }
|
||||
@@ -28,4 +36,6 @@ public class HomeDeviceEntity {
|
||||
public int getPower() { return power; }
|
||||
|
||||
public int getTemperature() { return temperature; }
|
||||
|
||||
public String getCarbonReduction() { return carbonReduction; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user