设备,碳排,个人中心
This commit is contained in:
15
AGENTS.md
Normal file
15
AGENTS.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 项目代码约定
|
||||||
|
|
||||||
|
## Activity 点击事件
|
||||||
|
|
||||||
|
- 所有新增或修改的 Activity,布局控件点击事件统一参考 `LoginActivity`:使用 ButterKnife `@OnClick({R.id.xxx, ...})`,集中到 `public void onClick(View v)`,通过 `switch (v.getId())` 分发。
|
||||||
|
- 各 `case` 保留清晰的 `break`,相同行为可以合并 `case`;复杂业务提取为独立方法,点击分支负责调用。
|
||||||
|
- 不在 `initData` 等方法中分散注册布局控件的 `setOnClickListener` 或点击 lambda。
|
||||||
|
- `BaseActivity` 已统一调用 `ButterKnife.bind(this)`,子 Activity 不重复绑定。
|
||||||
|
- 开关状态变化、文本输入、图表触摸、列表条目等专用回调继续使用对应接口,不替换成普通点击事件。
|
||||||
|
|
||||||
|
## 页面跳转
|
||||||
|
|
||||||
|
- Activity 和 Fragment 跳转到项目内的 Activity 时,统一复用各自父类提供的 `goTo(mContext, TargetActivity.class, bundle)`,无参数时传 `null`;不在业务页面直接使用 `startActivity(new Intent(...))`。
|
||||||
|
- 页面参数通过 `Bundle` 传递。Activity 中使用 Activity Result API 的跳转,调用父类 `goTo(mContext, TargetActivity.class, bundle, launcher)` 重载,保留原有返回结果回调。
|
||||||
|
- 系统蓝牙、定位、应用设置等通过 action 启动的系统页面,继续使用对应系统 Intent 和返回回调。
|
||||||
@@ -92,6 +92,8 @@ android {
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// 原生折线图:设备数据页的温度、功率和使用时长趋势。
|
||||||
|
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
|
||||||
// Espressif 官方 ESP32 配网 SDK(BLE / SoftAP)
|
// Espressif 官方 ESP32 配网 SDK(BLE / SoftAP)
|
||||||
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.4.4'
|
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.4.4'
|
||||||
// 官方配网 SDK 的连接事件使用新版 EventBus;与框架现有的 de.greenrobot 包并存。
|
// 官方配网 SDK 的连接事件使用新版 EventBus;与框架现有的 de.greenrobot 包并存。
|
||||||
|
|||||||
@@ -137,10 +137,54 @@
|
|||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
|
<activity
|
||||||
|
android:name=".device.control.DevicePreviewActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".device.control.DeviceDataViewActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".device.control.DeviceInfoActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".device.control.DeviceTimerActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".device.DeviceConnectingActivity"
|
android:name=".device.DeviceConnectingActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:screenOrientation="portrait" />
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".mine.MyDevicesActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".mine.PointsHistoryActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".mine.PersonalInfoActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".carbon.CarbonPointsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".carbon.CarbonActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".carbon.CarbonTrendActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
|
<activity
|
||||||
|
android:name=".carbon.CarbonReductionDetailsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:screenOrientation="portrait" />
|
||||||
<activity
|
<activity
|
||||||
android:name="com.ckkj.griddle.main.activity.MainActivity"
|
android:name="com.ckkj.griddle.main.activity.MainActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.viewbinding.ViewBinding;
|
import androidx.viewbinding.ViewBinding;
|
||||||
|
|
||||||
@@ -395,6 +396,17 @@ public abstract class BaseActivity<T extends ViewBinding, P extends IPresenter>
|
|||||||
from.startActivity(i);
|
from.startActivity(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要处理返回结果的页面跳转,复用页面已注册的 Activity Result 回调。
|
||||||
|
*/
|
||||||
|
protected void goTo(Context from, Class<? extends BaseActivity> to, Bundle data,
|
||||||
|
ActivityResultLauncher<Intent> launcher) {
|
||||||
|
Intent i = new Intent();
|
||||||
|
i.setClass(from, to);
|
||||||
|
if (data != null) i.putExtras(data);
|
||||||
|
launcher.launch(i);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* activity跳转
|
* activity跳转
|
||||||
*/
|
*/
|
||||||
|
|||||||
116
app/src/main/java/com/ckkj/griddle/carbon/CarbonActivity.java
Normal file
116
app/src/main/java/com/ckkj/griddle/carbon/CarbonActivity.java
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package com.ckkj.griddle.carbon;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonStatsEntity;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonContract;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonImpl;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonPresenter;
|
||||||
|
import com.ckkj.griddle.databinding.CarbonLayoutBinding;
|
||||||
|
import com.ckkj.griddle.databinding.ItemCarbonMetricBinding;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 碳排放统计页:累计环保贡献、核心指标及后续统计入口。 */
|
||||||
|
public class CarbonActivity extends BaseActivity<CarbonLayoutBinding, CarbonPresenter>
|
||||||
|
implements CarbonContract.CarbonView {
|
||||||
|
@Override
|
||||||
|
public CarbonPresenter createPresenter() {
|
||||||
|
return new CarbonPresenter(new CarbonImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.carbon_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
mPresenter.getCarbonStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.ll_carbon_trend, R.id.ll_carbon_details})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_carbon_trend:
|
||||||
|
goTo(mContext, CarbonTrendActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_carbon_details:
|
||||||
|
goTo(mContext, CarbonReductionDetailsActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonStatsSuccess(CarbonStatsEntity data) {
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat decimal = NumberFormat.getNumberInstance(locale);
|
||||||
|
decimal.setMinimumFractionDigits(1);
|
||||||
|
decimal.setMaximumFractionDigits(1);
|
||||||
|
NumberFormat money = NumberFormat.getNumberInstance(locale);
|
||||||
|
money.setMinimumFractionDigits(2);
|
||||||
|
money.setMaximumFractionDigits(2);
|
||||||
|
NumberFormat integer = NumberFormat.getIntegerInstance(locale);
|
||||||
|
NumberFormat percent = NumberFormat.getPercentInstance(locale);
|
||||||
|
percent.setMaximumFractionDigits(0);
|
||||||
|
String growth = (data.getGrowthRate() > 0 ? "+" : "") + percent.format(data.getGrowthRate());
|
||||||
|
|
||||||
|
viewBinding.tvCarbonTotalReduction.setText(decimal.format(data.getTotalCarbonReduction()));
|
||||||
|
viewBinding.tvCarbonTotalCharcoal.setText(decimal.format(data.getTotalCharcoalSaved()));
|
||||||
|
viewBinding.tvCarbonTotalMoney.setText(getString(R.string.carbon_money_value,
|
||||||
|
decimal.format(data.getTotalMoneySaved())));
|
||||||
|
viewBinding.tvCarbonTreeHint.setText(getString(R.string.carbon_tree_hint,
|
||||||
|
integer.format(data.getTotalTreeEquivalent())));
|
||||||
|
viewBinding.tvCarbonDrivingHint.setText(getString(R.string.carbon_driving_hint,
|
||||||
|
integer.format(data.getLessDrivingKm())));
|
||||||
|
|
||||||
|
bindMetric(viewBinding.metricPower, getString(R.string.carbon_kwh_value,
|
||||||
|
decimal.format(data.getPowerUsed())), growth);
|
||||||
|
bindMetric(viewBinding.metricReduction, getString(R.string.carbon_kg_value,
|
||||||
|
decimal.format(data.getCarbonReduction())), growth);
|
||||||
|
bindMetric(viewBinding.metricCharcoal, getString(R.string.carbon_kg_value,
|
||||||
|
decimal.format(data.getCharcoalSaved())), growth);
|
||||||
|
bindMetric(viewBinding.metricMoney, getString(R.string.carbon_money_value,
|
||||||
|
money.format(data.getElectricitySaved())), growth);
|
||||||
|
bindMetric(viewBinding.metricCoal, getString(R.string.carbon_kg_value,
|
||||||
|
decimal.format(data.getStandardCoalSaved())), growth);
|
||||||
|
bindMetric(viewBinding.metricTrees, getString(R.string.carbon_trees_value,
|
||||||
|
decimal.format(data.getTreeEquivalent())), growth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 六个固定指标共用展示布局,数值与单位按当前语言格式化。 */
|
||||||
|
private void bindMetric(ItemCarbonMetricBinding binding, String value, String growth) {
|
||||||
|
binding.tvMetricValue.setText(value);
|
||||||
|
binding.tvMetricGrowth.setText(growth);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
package com.ckkj.griddle.carbon;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.carbon.adapter.CarbonPointsAdapter;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity.Period;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity.RecordFilter;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonContract;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonImpl;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonPresenter;
|
||||||
|
import com.ckkj.griddle.databinding.CarbonPointsLayoutBinding;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 减排积分页:复用 Carbon MVP,支持收支、时间筛选以及流水分页。 */
|
||||||
|
public class CarbonPointsActivity extends BaseActivity<CarbonPointsLayoutBinding, CarbonPresenter>
|
||||||
|
implements CarbonContract.CarbonView {
|
||||||
|
private static final int PAGE_SIZE = 5;
|
||||||
|
private static final String STATE_FILTER = "points_filter";
|
||||||
|
private static final String STATE_PERIOD = "points_period";
|
||||||
|
private static final String STATE_COUNT = "points_count";
|
||||||
|
private RecordFilter filter = RecordFilter.ALL;
|
||||||
|
private Period period = Period.THIS_MONTH;
|
||||||
|
private CarbonPointsAdapter adapter;
|
||||||
|
private boolean loading;
|
||||||
|
private boolean hasMore = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarbonPresenter createPresenter() {
|
||||||
|
return new CarbonPresenter(new CarbonImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.carbon_points_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
filter = RecordFilter.values()[Math.max(0, Math.min(RecordFilter.values().length - 1,
|
||||||
|
savedInstanceState.getInt(STATE_FILTER, 0)))];
|
||||||
|
period = Period.values()[Math.max(0, Math.min(Period.values().length - 1,
|
||||||
|
savedInstanceState.getInt(STATE_PERIOD, Period.THIS_MONTH.ordinal())))];
|
||||||
|
}
|
||||||
|
adapter = new CarbonPointsAdapter();
|
||||||
|
viewBinding.rvCarbonPoints.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
viewBinding.rvCarbonPoints.setNestedScrollingEnabled(false);
|
||||||
|
viewBinding.rvCarbonPoints.setItemAnimator(null);
|
||||||
|
viewBinding.rvCarbonPoints.setAdapter(adapter);
|
||||||
|
renderFilters();
|
||||||
|
int count = savedInstanceState == null ? PAGE_SIZE
|
||||||
|
: Math.max(PAGE_SIZE, savedInstanceState.getInt(STATE_COUNT, PAGE_SIZE));
|
||||||
|
loadPoints(0, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.tv_points_all, R.id.tv_points_earned, R.id.tv_points_spent,
|
||||||
|
R.id.tv_points_today, R.id.tv_points_week, R.id.tv_points_month, R.id.tv_points_more})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_all:
|
||||||
|
changeFilter(RecordFilter.ALL, period);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_earned:
|
||||||
|
changeFilter(RecordFilter.EARNED, period);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_spent:
|
||||||
|
changeFilter(RecordFilter.SPENT, period);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_today:
|
||||||
|
changeFilter(filter, Period.TODAY);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_week:
|
||||||
|
changeFilter(filter, Period.THIS_WEEK);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_month:
|
||||||
|
changeFilter(filter, Period.THIS_MONTH);
|
||||||
|
break;
|
||||||
|
case R.id.tv_points_more:
|
||||||
|
if (hasMore) loadPoints(adapter.getData().size(), PAGE_SIZE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeFilter(RecordFilter newFilter, Period newPeriod) {
|
||||||
|
if (loading || (filter == newFilter && period == newPeriod)) return;
|
||||||
|
filter = newFilter;
|
||||||
|
period = newPeriod;
|
||||||
|
adapter.setNewData(new ArrayList<>());
|
||||||
|
viewBinding.tvPointsEmpty.setVisibility(View.GONE);
|
||||||
|
hasMore = true;
|
||||||
|
renderFilters();
|
||||||
|
loadPoints(0, PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderFilters() {
|
||||||
|
viewBinding.tvPointsAll.setSelected(filter == RecordFilter.ALL);
|
||||||
|
viewBinding.tvPointsEarned.setSelected(filter == RecordFilter.EARNED);
|
||||||
|
viewBinding.tvPointsSpent.setSelected(filter == RecordFilter.SPENT);
|
||||||
|
viewBinding.tvPointsToday.setSelected(period == Period.TODAY);
|
||||||
|
viewBinding.tvPointsWeek.setSelected(period == Period.THIS_WEEK);
|
||||||
|
viewBinding.tvPointsMonth.setSelected(period == Period.THIS_MONTH);
|
||||||
|
viewBinding.tvPointsRecordsTitle.setText(filter == RecordFilter.ALL ? R.string.carbon_points_all_records
|
||||||
|
: filter == RecordFilter.EARNED ? R.string.carbon_points_earned_records : R.string.carbon_points_spent_records);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadPoints(int offset, int count) {
|
||||||
|
if (loading) return;
|
||||||
|
loading = true;
|
||||||
|
renderFooter();
|
||||||
|
mPresenter.getCarbonPoints(filter, period, offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonPointsSuccess(CarbonPointsPageEntity data) {
|
||||||
|
// 防止后续接入异步接口时,旧筛选结果覆盖当前列表。
|
||||||
|
if (data.getFilter() != filter || data.getPeriod() != period) return;
|
||||||
|
loading = false;
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat number = NumberFormat.getIntegerInstance(locale);
|
||||||
|
viewBinding.tvPointsBalance.setText(getString(R.string.carbon_points_value, number.format(data.getBalance())));
|
||||||
|
String net = (data.getMonthlyNet() > 0 ? "+" : "") + number.format(data.getMonthlyNet());
|
||||||
|
viewBinding.tvPointsMonthlyNet.setText(getString(R.string.carbon_points_value, net));
|
||||||
|
viewBinding.tvPointsMonthlyNet.setTextColor(getResources().getColor(data.getMonthlyNet() < 0
|
||||||
|
? R.color.carbon_points_red : R.color.carbon_green));
|
||||||
|
viewBinding.tvPointsCount.setText(getString(R.string.carbon_points_record_count, number.format(data.getTotalCount())));
|
||||||
|
if (data.getOffset() == 0) {
|
||||||
|
// Adapter 持有可变副本,后续加载更多才能安全追加。
|
||||||
|
adapter.setNewData(new ArrayList<>(data.getRecords()));
|
||||||
|
} else {
|
||||||
|
int previousLast = adapter.getData().size() - 1;
|
||||||
|
adapter.addData(data.getRecords());
|
||||||
|
if (previousLast >= 0 && !data.getRecords().isEmpty()) adapter.notifyItemChanged(previousLast);
|
||||||
|
}
|
||||||
|
hasMore = data.hasMore();
|
||||||
|
viewBinding.tvPointsEmpty.setVisibility(adapter.getData().isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
|
renderFooter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderFooter() {
|
||||||
|
viewBinding.tvPointsMore.setEnabled(!loading && hasMore);
|
||||||
|
viewBinding.tvPointsMore.setText(loading ? R.string.carbon_loading
|
||||||
|
: hasMore ? R.string.carbon_points_load_more : R.string.carbon_all_loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putInt(STATE_FILTER, filter.ordinal());
|
||||||
|
outState.putInt(STATE_PERIOD, period.ordinal());
|
||||||
|
if (adapter != null) outState.putInt(STATE_COUNT, adapter.getData().size());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
loading = false;
|
||||||
|
renderFooter();
|
||||||
|
ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用父类统一处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package com.ckkj.griddle.carbon;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.carbon.adapter.CarbonReductionAdapter;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonReductionPageEntity;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonContract;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonImpl;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonPresenter;
|
||||||
|
import com.ckkj.griddle.databinding.CarbonReductionDetailsLayoutBinding;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 减排明细页:月度汇总及分页列表,复用 Carbon MVP 和 BaseQuickAdapter。 */
|
||||||
|
public class CarbonReductionDetailsActivity
|
||||||
|
extends BaseActivity<CarbonReductionDetailsLayoutBinding, CarbonPresenter>
|
||||||
|
implements CarbonContract.CarbonView {
|
||||||
|
private static final int PAGE_SIZE = 8;
|
||||||
|
private static final String STATE_VISIBLE_COUNT = "carbon_details_visible_count";
|
||||||
|
private CarbonReductionAdapter adapter;
|
||||||
|
private boolean loading;
|
||||||
|
private boolean hasMore = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarbonPresenter createPresenter() {
|
||||||
|
return new CarbonPresenter(new CarbonImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.carbon_reduction_details_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
adapter = new CarbonReductionAdapter();
|
||||||
|
viewBinding.rvCarbonReduction.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
viewBinding.rvCarbonReduction.setNestedScrollingEnabled(false);
|
||||||
|
viewBinding.rvCarbonReduction.setItemAnimator(null);
|
||||||
|
viewBinding.rvCarbonReduction.setAdapter(adapter);
|
||||||
|
int count = savedInstanceState == null ? PAGE_SIZE
|
||||||
|
: Math.max(PAGE_SIZE, savedInstanceState.getInt(STATE_VISIBLE_COUNT, PAGE_SIZE));
|
||||||
|
loadDetails(0, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.tv_reduction_more})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_reduction_more:
|
||||||
|
if (hasMore) loadDetails(adapter.getData().size(), PAGE_SIZE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDetails(int offset, int count) {
|
||||||
|
if (loading) return;
|
||||||
|
loading = true;
|
||||||
|
renderFooter();
|
||||||
|
mPresenter.getCarbonReductionDetails(offset, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonReductionDetailsSuccess(CarbonReductionPageEntity data) {
|
||||||
|
loading = false;
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
String pattern = DateFormat.getBestDateTimePattern(locale, "yMMMM");
|
||||||
|
String month = new SimpleDateFormat(pattern, locale).format(new Date(data.getSummaryMonth()));
|
||||||
|
viewBinding.tvReductionSummaryMonth.setText(getString(R.string.carbon_month_summary, month));
|
||||||
|
NumberFormat number = NumberFormat.getNumberInstance(locale);
|
||||||
|
number.setMinimumFractionDigits(1);
|
||||||
|
number.setMaximumFractionDigits(1);
|
||||||
|
viewBinding.tvReductionSummary.setText(getString(R.string.carbon_reduction_summary,
|
||||||
|
number.format(data.getTotalPower()), number.format(data.getTotalReduction())));
|
||||||
|
if (data.getOffset() == 0) {
|
||||||
|
adapter.setNewData(new ArrayList<>(data.getRecords()));
|
||||||
|
} else {
|
||||||
|
int previousLast = adapter.getData().size() - 1;
|
||||||
|
adapter.addData(data.getRecords());
|
||||||
|
// 追加后原来的末行也要显示分隔线。
|
||||||
|
if (previousLast >= 0 && !data.getRecords().isEmpty()) adapter.notifyItemChanged(previousLast);
|
||||||
|
}
|
||||||
|
hasMore = data.hasMore();
|
||||||
|
renderFooter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderFooter() {
|
||||||
|
viewBinding.tvReductionMore.setEnabled(!loading && hasMore);
|
||||||
|
viewBinding.tvReductionMore.setText(loading ? R.string.carbon_loading
|
||||||
|
: hasMore ? R.string.carbon_view_more : R.string.carbon_all_loaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
if (adapter != null) outState.putInt(STATE_VISIBLE_COUNT, adapter.getData().size());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
loading = false;
|
||||||
|
renderFooter();
|
||||||
|
ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,432 @@
|
|||||||
|
package com.ckkj.griddle.carbon;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity.Metric;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity.Period;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonContract;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonImpl;
|
||||||
|
import com.ckkj.griddle.carbon.mvp.CarbonPresenter;
|
||||||
|
import com.ckkj.griddle.carbon.view.CarbonRoundedBarRenderer;
|
||||||
|
import com.ckkj.griddle.databinding.CarbonTrendLayoutBinding;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.github.mikephil.charting.charts.CombinedChart;
|
||||||
|
import com.github.mikephil.charting.charts.PieChart;
|
||||||
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
|
import com.github.mikephil.charting.data.BarData;
|
||||||
|
import com.github.mikephil.charting.data.BarDataSet;
|
||||||
|
import com.github.mikephil.charting.data.BarEntry;
|
||||||
|
import com.github.mikephil.charting.data.CombinedData;
|
||||||
|
import com.github.mikephil.charting.data.Entry;
|
||||||
|
import com.github.mikephil.charting.data.LineData;
|
||||||
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
|
import com.github.mikephil.charting.data.PieData;
|
||||||
|
import com.github.mikephil.charting.data.PieDataSet;
|
||||||
|
import com.github.mikephil.charting.data.PieEntry;
|
||||||
|
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
||||||
|
import com.github.mikephil.charting.renderer.BarChartRenderer;
|
||||||
|
import com.github.mikephil.charting.renderer.CombinedChartRenderer;
|
||||||
|
import com.github.mikephil.charting.renderer.DataRenderer;
|
||||||
|
import com.github.mikephil.charting.utils.MPPointD;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 碳排放趋势页:复用 Carbon MVP,展示占比、周期筛选及可滑动查值的组合图。 */
|
||||||
|
public class CarbonTrendActivity extends BaseActivity<CarbonTrendLayoutBinding, CarbonPresenter>
|
||||||
|
implements CarbonContract.CarbonView {
|
||||||
|
private static final String STATE_PERIOD = "carbon_trend_period";
|
||||||
|
private static final String STATE_METRIC = "carbon_trend_metric";
|
||||||
|
private static final String STATE_INDEX = "carbon_trend_index";
|
||||||
|
private static final String STATE_INSPECTED = "carbon_trend_inspected";
|
||||||
|
private Period selectedPeriod = Period.MONTH;
|
||||||
|
private Metric selectedMetric = Metric.POWER;
|
||||||
|
private CarbonTrendEntity trendData;
|
||||||
|
private BarDataSet barDataSet;
|
||||||
|
private int selectedIndex = 2;
|
||||||
|
private boolean inspected;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CarbonPresenter createPresenter() {
|
||||||
|
return new CarbonPresenter(new CarbonImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.carbon_trend_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
try {
|
||||||
|
selectedPeriod = Period.valueOf(savedInstanceState.getString(STATE_PERIOD, Period.MONTH.name()));
|
||||||
|
selectedMetric = Metric.valueOf(savedInstanceState.getString(STATE_METRIC, Metric.POWER.name()));
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
selectedPeriod = Period.MONTH;
|
||||||
|
selectedMetric = Metric.POWER;
|
||||||
|
}
|
||||||
|
selectedIndex = savedInstanceState.getInt(STATE_INDEX, 2);
|
||||||
|
inspected = savedInstanceState.getBoolean(STATE_INSPECTED);
|
||||||
|
}
|
||||||
|
initCompositionChart();
|
||||||
|
initTrendChart();
|
||||||
|
requestTrend();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.tv_carbon_period_day, R.id.tv_carbon_period_week,
|
||||||
|
R.id.tv_carbon_period_month, R.id.tv_carbon_period_year, R.id.tv_carbon_metric_power,
|
||||||
|
R.id.tv_carbon_metric_reduction, R.id.tv_carbon_metric_charcoal, R.id.tv_carbon_metric_savings})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_period_day:
|
||||||
|
selectPeriod(Period.DAY);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_period_week:
|
||||||
|
selectPeriod(Period.WEEK);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_period_month:
|
||||||
|
selectPeriod(Period.MONTH);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_period_year:
|
||||||
|
selectPeriod(Period.YEAR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_metric_power:
|
||||||
|
selectMetric(Metric.POWER);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_metric_reduction:
|
||||||
|
selectMetric(Metric.REDUCTION);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_metric_charcoal:
|
||||||
|
selectMetric(Metric.CHARCOAL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.tv_carbon_metric_savings:
|
||||||
|
selectMetric(Metric.SAVINGS);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectPeriod(Period period) {
|
||||||
|
if (selectedPeriod == period) return;
|
||||||
|
selectedPeriod = period;
|
||||||
|
selectedIndex = 2;
|
||||||
|
inspected = false;
|
||||||
|
requestTrend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectMetric(Metric metric) {
|
||||||
|
if (selectedMetric == metric) return;
|
||||||
|
selectedMetric = metric;
|
||||||
|
inspected = false;
|
||||||
|
requestTrend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void requestTrend() {
|
||||||
|
View[] periods = {viewBinding.tvCarbonPeriodDay, viewBinding.tvCarbonPeriodWeek,
|
||||||
|
viewBinding.tvCarbonPeriodMonth, viewBinding.tvCarbonPeriodYear};
|
||||||
|
View[] metrics = {viewBinding.tvCarbonMetricPower, viewBinding.tvCarbonMetricReduction,
|
||||||
|
viewBinding.tvCarbonMetricCharcoal, viewBinding.tvCarbonMetricSavings};
|
||||||
|
for (int i = 0; i < periods.length; i++) periods[i].setSelected(i == selectedPeriod.ordinal());
|
||||||
|
for (int i = 0; i < metrics.length; i++) metrics[i].setSelected(i == selectedMetric.ordinal());
|
||||||
|
mPresenter.getCarbonTrend(selectedPeriod, selectedMetric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCompositionChart() {
|
||||||
|
PieChart chart = viewBinding.chartCarbonComposition;
|
||||||
|
chart.getDescription().setEnabled(false);
|
||||||
|
chart.getLegend().setEnabled(false);
|
||||||
|
chart.setDrawEntryLabels(false);
|
||||||
|
chart.setTouchEnabled(false);
|
||||||
|
chart.setRotationEnabled(false);
|
||||||
|
chart.setRotationAngle(270f);
|
||||||
|
chart.setHoleRadius(65f);
|
||||||
|
chart.setTransparentCircleRadius(65f);
|
||||||
|
chart.setHoleColor(color(android.R.color.white));
|
||||||
|
chart.setCenterText(getString(R.string.carbon_composition_center));
|
||||||
|
chart.setCenterTextSize(12f);
|
||||||
|
chart.setCenterTextColor(color(R.color.carbon_total_text));
|
||||||
|
chart.setCenterTextTypeface(Typeface.DEFAULT_BOLD);
|
||||||
|
chart.setMinOffset(0);
|
||||||
|
chart.setExtraOffsets(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTrendChart() {
|
||||||
|
CombinedChart chart = viewBinding.chartCarbonTrend;
|
||||||
|
chart.getDescription().setEnabled(false);
|
||||||
|
chart.getLegend().setEnabled(false);
|
||||||
|
chart.setDrawOrder(new CombinedChart.DrawOrder[]{CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.LINE});
|
||||||
|
chart.setDrawGridBackground(false);
|
||||||
|
chart.setDrawBorders(false);
|
||||||
|
chart.setDrawBarShadow(false);
|
||||||
|
chart.setScaleEnabled(false);
|
||||||
|
chart.setDragEnabled(false);
|
||||||
|
chart.setDoubleTapToZoomEnabled(false);
|
||||||
|
chart.setHighlightPerTapEnabled(false);
|
||||||
|
chart.setHighlightPerDragEnabled(false);
|
||||||
|
chart.setMinOffset(0);
|
||||||
|
chart.setExtraOffsets(0, 8, 0, 8);
|
||||||
|
chart.getAxisLeft().setEnabled(false);
|
||||||
|
chart.getAxisLeft().setAxisMinimum(0f);
|
||||||
|
chart.getAxisRight().setEnabled(false);
|
||||||
|
XAxis axis = chart.getXAxis();
|
||||||
|
axis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||||
|
axis.setDrawGridLines(false);
|
||||||
|
axis.setDrawAxisLine(false);
|
||||||
|
axis.setGranularity(1f);
|
||||||
|
axis.setTextSize(11f);
|
||||||
|
axis.setTextColor(color(R.color.carbon_muted));
|
||||||
|
axis.setYOffset(8f);
|
||||||
|
initChartTouch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonTrendSuccess(CarbonTrendEntity data) {
|
||||||
|
// 快速切换筛选项时不使用已经过期的返回结果。
|
||||||
|
if (data.getPeriod() != selectedPeriod || data.getMetric() != selectedMetric) return;
|
||||||
|
trendData = data;
|
||||||
|
PieDataSet composition = new PieDataSet(Arrays.asList(
|
||||||
|
new PieEntry(data.getCharcoalShare()), new PieEntry(data.getPowerShare())), "");
|
||||||
|
composition.setColors(color(R.color.device_data_orange), color(R.color.carbon_chart_light));
|
||||||
|
composition.setDrawValues(false);
|
||||||
|
composition.setSliceSpace(0);
|
||||||
|
composition.setSelectionShift(0);
|
||||||
|
viewBinding.chartCarbonComposition.setData(new PieData(composition));
|
||||||
|
viewBinding.chartCarbonComposition.invalidate();
|
||||||
|
NumberFormat percent = NumberFormat.getPercentInstance(locale());
|
||||||
|
percent.setMaximumFractionDigits(0);
|
||||||
|
viewBinding.tvTrendPowerShare.setText(percent.format(data.getPowerShare() / 100f));
|
||||||
|
viewBinding.tvTrendCharcoalShare.setText(percent.format(data.getCharcoalShare() / 100f));
|
||||||
|
|
||||||
|
List<BarEntry> bars = new ArrayList<>();
|
||||||
|
List<Entry> lines = new ArrayList<>();
|
||||||
|
List<String> labels = new ArrayList<>();
|
||||||
|
float maximum = 0;
|
||||||
|
for (int i = 0; i < data.getPoints().size(); i++) {
|
||||||
|
CarbonTrendEntity.Point point = data.getPoints().get(i);
|
||||||
|
bars.add(new BarEntry(i, point.getBarValue()));
|
||||||
|
lines.add(new Entry(i, point.getLineValue()));
|
||||||
|
labels.add(formatLabel(point.getLabelValue()));
|
||||||
|
maximum = Math.max(maximum, Math.max(point.getBarValue(), point.getLineValue()));
|
||||||
|
}
|
||||||
|
barDataSet = new BarDataSet(bars, getString(metricTitle()));
|
||||||
|
barDataSet.setDrawValues(false);
|
||||||
|
barDataSet.setHighlightEnabled(false);
|
||||||
|
BarData barData = new BarData(barDataSet);
|
||||||
|
barData.setBarWidth(0.44f);
|
||||||
|
LineDataSet line = new LineDataSet(lines, "");
|
||||||
|
line.setColor(color(R.color.carbon_total_text));
|
||||||
|
line.setLineWidth(1.8545455f);
|
||||||
|
line.setCircleColor(color(R.color.carbon_total_text));
|
||||||
|
line.setCircleRadius(3f);
|
||||||
|
line.setDrawCircleHole(false);
|
||||||
|
line.setDrawValues(false);
|
||||||
|
line.setHighlightEnabled(false);
|
||||||
|
CombinedData combined = new CombinedData();
|
||||||
|
combined.setData(barData);
|
||||||
|
combined.setData(new LineData(line));
|
||||||
|
CombinedChart chart = viewBinding.chartCarbonTrend;
|
||||||
|
chart.setData(combined);
|
||||||
|
chart.getXAxis().setAxisMinimum(-0.6f);
|
||||||
|
chart.getXAxis().setAxisMaximum(Math.max(0, labels.size() - 1) + 0.6f);
|
||||||
|
chart.getXAxis().setLabelCount(Math.max(2, labels.size()), false);
|
||||||
|
chart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
|
||||||
|
chart.getAxisLeft().setAxisMaximum(Math.max(1f, maximum * 1.12f));
|
||||||
|
// setData 会重建组合图内部 renderer,因此每次绑定后替换圆角柱绘制器。
|
||||||
|
CombinedChartRenderer renderer = (CombinedChartRenderer) chart.getRenderer();
|
||||||
|
List<DataRenderer> renderers = new ArrayList<>(renderer.getSubRenderers());
|
||||||
|
for (int i = 0; i < renderers.size(); i++) {
|
||||||
|
if (renderers.get(i) instanceof BarChartRenderer) {
|
||||||
|
renderers.set(i, new CarbonRoundedBarRenderer(chart, chart.getAnimator(), chart.getViewPortHandler()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renderer.setSubRenderers(renderers);
|
||||||
|
renderer.initBuffers();
|
||||||
|
chart.notifyDataSetChanged();
|
||||||
|
chart.setContentDescription(getString(R.string.carbon_chart_accessibility, getString(metricTitle())));
|
||||||
|
selectPoint(selectedIndex, inspected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 横向拖动选择最近数据点,纵向拖动交还外层滚动容器。 */
|
||||||
|
private void initChartTouch() {
|
||||||
|
CombinedChart chart = viewBinding.chartCarbonTrend;
|
||||||
|
int slop = ViewConfiguration.get(this).getScaledTouchSlop();
|
||||||
|
chart.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
private float downX;
|
||||||
|
private float downY;
|
||||||
|
private boolean tracking;
|
||||||
|
private boolean horizontal;
|
||||||
|
private boolean vertical;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
|
if (event.getActionMasked() != MotionEvent.ACTION_DOWN && !tracking) return false;
|
||||||
|
switch (event.getActionMasked()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
if (trendData == null || trendData.getPoints().isEmpty()
|
||||||
|
|| !chart.getViewPortHandler().isInBoundsX(event.getX())
|
||||||
|
|| !chart.getViewPortHandler().isInBoundsY(event.getY())) return false;
|
||||||
|
tracking = true;
|
||||||
|
horizontal = false;
|
||||||
|
vertical = false;
|
||||||
|
downX = event.getX();
|
||||||
|
downY = event.getY();
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
selectTouchPoint(event.getX(), event.getY());
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if (!horizontal && !vertical) {
|
||||||
|
float dx = Math.abs(event.getX() - downX);
|
||||||
|
float dy = Math.abs(event.getY() - downY);
|
||||||
|
if (Math.max(dx, dy) > slop) {
|
||||||
|
horizontal = dx >= dy;
|
||||||
|
vertical = !horizontal;
|
||||||
|
if (vertical) view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (horizontal) selectTouchPoint(event.getX(), event.getY());
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
tracking = false;
|
||||||
|
if (!vertical) {
|
||||||
|
selectTouchPoint(event.getX(), event.getY());
|
||||||
|
if (!horizontal) view.performClick();
|
||||||
|
}
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
|
vertical = true;
|
||||||
|
horizontal = false;
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
tracking = false;
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectTouchPoint(float x, float y) {
|
||||||
|
MPPointD point = viewBinding.chartCarbonTrend.getTransformer(YAxis.AxisDependency.LEFT)
|
||||||
|
.getValuesByTouchPoint(x, y);
|
||||||
|
int index = (int) Math.round(point.x);
|
||||||
|
MPPointD.recycleInstance(point);
|
||||||
|
selectPoint(index, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectPoint(int index, boolean showValue) {
|
||||||
|
if (trendData == null || trendData.getPoints().isEmpty()) return;
|
||||||
|
selectedIndex = Math.max(0, Math.min(index, trendData.getPoints().size() - 1));
|
||||||
|
inspected = showValue;
|
||||||
|
List<Integer> colors = new ArrayList<>();
|
||||||
|
for (int i = 0; i < trendData.getPoints().size(); i++) {
|
||||||
|
colors.add(color(i == selectedIndex ? R.color.device_data_orange : R.color.carbon_chart_bar_light));
|
||||||
|
}
|
||||||
|
barDataSet.setColors(colors);
|
||||||
|
viewBinding.chartCarbonTrend.invalidate();
|
||||||
|
if (showValue) {
|
||||||
|
CarbonTrendEntity.Point point = trendData.getPoints().get(selectedIndex);
|
||||||
|
viewBinding.tvTrendHint.setText(getString(R.string.carbon_chart_selected,
|
||||||
|
formatLabel(point.getLabelValue()), getString(metricTitle()),
|
||||||
|
formatValue(point.getBarValue()), formatValue(point.getLineValue())));
|
||||||
|
} else {
|
||||||
|
viewBinding.tvTrendHint.setText(R.string.carbon_chart_hint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatLabel(int value) {
|
||||||
|
switch (selectedPeriod) {
|
||||||
|
case DAY:
|
||||||
|
return String.format(locale(), "%02d:00", value);
|
||||||
|
case WEEK:
|
||||||
|
return getString(R.string.carbon_chart_day, value);
|
||||||
|
case MONTH:
|
||||||
|
return "zh".equals(locale().getLanguage()) ? getString(R.string.carbon_chart_month, value)
|
||||||
|
: new DateFormatSymbols(locale()).getShortMonths()[value - 1];
|
||||||
|
default:
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int metricTitle() {
|
||||||
|
switch (selectedMetric) {
|
||||||
|
case REDUCTION: return R.string.carbon_metric_reduction;
|
||||||
|
case CHARCOAL: return R.string.carbon_metric_charcoal;
|
||||||
|
case SAVINGS: return R.string.carbon_metric_savings;
|
||||||
|
default: return R.string.carbon_metric_power;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatValue(float value) {
|
||||||
|
NumberFormat number = NumberFormat.getNumberInstance(locale());
|
||||||
|
number.setMinimumFractionDigits(selectedMetric == Metric.SAVINGS ? 2 : 1);
|
||||||
|
number.setMaximumFractionDigits(selectedMetric == Metric.SAVINGS ? 2 : 1);
|
||||||
|
int format;
|
||||||
|
switch (selectedMetric) {
|
||||||
|
case REDUCTION: format = R.string.carbon_chart_co2_value; break;
|
||||||
|
case CHARCOAL: format = R.string.carbon_kg_value; break;
|
||||||
|
case SAVINGS: format = R.string.carbon_money_value; break;
|
||||||
|
default: format = R.string.carbon_kwh_value; break;
|
||||||
|
}
|
||||||
|
return getString(format, number.format(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Locale locale() { return getResources().getConfiguration().getLocales().get(0); }
|
||||||
|
private int color(int resId) { return ContextCompat.getColor(this, resId); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putString(STATE_PERIOD, selectedPeriod.name());
|
||||||
|
outState.putString(STATE_METRIC, selectedMetric.name());
|
||||||
|
outState.putInt(STATE_INDEX, selectedIndex);
|
||||||
|
outState.putBoolean(STATE_INSPECTED, inspected);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) { ToastUtil.showShort(this, message); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.ckkj.griddle.carbon.adapter;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 积分流水使用 BaseQuickAdapter,按收入/支出显示不同图标和颜色。 */
|
||||||
|
public class CarbonPointsAdapter extends BaseQuickAdapter<CarbonPointsPageEntity.Record, BaseViewHolder> {
|
||||||
|
public CarbonPointsAdapter() {
|
||||||
|
super(R.layout.item_carbon_points);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, CarbonPointsPageEntity.Record item) {
|
||||||
|
int title;
|
||||||
|
int icon;
|
||||||
|
switch (item.getKind()) {
|
||||||
|
case REDEEM:
|
||||||
|
title = R.string.carbon_points_redeem;
|
||||||
|
icon = R.drawable.ic_carbon_points_bag;
|
||||||
|
break;
|
||||||
|
case INVITE:
|
||||||
|
title = R.string.carbon_points_invite;
|
||||||
|
icon = R.drawable.ic_carbon_points_invite;
|
||||||
|
break;
|
||||||
|
case COOKING:
|
||||||
|
title = R.string.carbon_points_cooking;
|
||||||
|
icon = R.drawable.ic_carbon_points_flame;
|
||||||
|
break;
|
||||||
|
case ACTIVATION:
|
||||||
|
title = R.string.carbon_points_activation;
|
||||||
|
icon = R.drawable.ic_carbon_points_device;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
title = R.string.carbon_points_registration;
|
||||||
|
icon = R.drawable.ic_carbon_points_gift;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
boolean spent = item.getPoints() < 0;
|
||||||
|
Locale locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm", locale).format(new Date(item.getTimestamp()));
|
||||||
|
String type = mContext.getString(spent ? R.string.carbon_points_spent : R.string.carbon_points_earned);
|
||||||
|
String points = NumberFormat.getIntegerInstance(locale).format(item.getPoints());
|
||||||
|
helper.setText(R.id.tv_point_record_title, mContext.getString(title));
|
||||||
|
helper.setText(R.id.tv_point_record_meta, mContext.getString(R.string.carbon_points_record_meta, type, date));
|
||||||
|
helper.setText(R.id.tv_point_record_amount, spent
|
||||||
|
? mContext.getString(R.string.carbon_points_record_spent, points) : "+" + points);
|
||||||
|
helper.setTextColor(R.id.tv_point_record_amount, mContext.getResources().getColor(spent
|
||||||
|
? R.color.carbon_points_red : R.color.carbon_green));
|
||||||
|
ImageView image = helper.getView(R.id.iv_point_record_icon);
|
||||||
|
image.setImageResource(icon);
|
||||||
|
image.setColorFilter(mContext.getResources().getColor(spent
|
||||||
|
? R.color.carbon_points_red : R.color.device_data_orange));
|
||||||
|
image.setBackgroundResource(spent ? R.drawable.carbon_points_spent_bg : R.drawable.carbon_points_earned_bg);
|
||||||
|
helper.getView(R.id.view_point_record_divider).setVisibility(
|
||||||
|
helper.getLayoutPosition() - getHeaderLayoutCount() == getData().size() - 1
|
||||||
|
? View.INVISIBLE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.ckkj.griddle.carbon.adapter;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonReductionPageEntity;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 减排明细沿用项目 BaseQuickAdapter 写法,四列权重与表头一致。 */
|
||||||
|
public class CarbonReductionAdapter
|
||||||
|
extends BaseQuickAdapter<CarbonReductionPageEntity.Record, BaseViewHolder> {
|
||||||
|
public CarbonReductionAdapter() {
|
||||||
|
super(R.layout.item_carbon_reduction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, CarbonReductionPageEntity.Record item) {
|
||||||
|
Locale locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat power = NumberFormat.getNumberInstance(locale);
|
||||||
|
power.setMinimumFractionDigits(1);
|
||||||
|
power.setMaximumFractionDigits(1);
|
||||||
|
NumberFormat money = NumberFormat.getNumberInstance(locale);
|
||||||
|
money.setMinimumFractionDigits(2);
|
||||||
|
money.setMaximumFractionDigits(2);
|
||||||
|
helper.setText(R.id.tv_reduction_date, item.getDate());
|
||||||
|
helper.setText(R.id.tv_reduction_type, mContext.getString(R.string.carbon_record_power));
|
||||||
|
helper.setText(R.id.tv_reduction_amount, mContext.getString(R.string.carbon_record_kwh,
|
||||||
|
power.format(item.getPowerSaved())));
|
||||||
|
helper.setText(R.id.tv_reduction_bill, mContext.getString(R.string.carbon_record_saved,
|
||||||
|
money.format(item.getMoneySaved())));
|
||||||
|
// 最后一条记录不绘制分隔线,追加数据时页面会重新绑定旧的末行。
|
||||||
|
helper.getView(R.id.view_reduction_divider).setVisibility(
|
||||||
|
helper.getLayoutPosition() - getHeaderLayoutCount() == getData().size() - 1
|
||||||
|
? View.INVISIBLE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.ckkj.griddle.carbon.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 积分汇总与流水分页,积分使用有符号整数,汇总不随筛选改变。 */
|
||||||
|
public class CarbonPointsPageEntity {
|
||||||
|
public enum RecordFilter { ALL, EARNED, SPENT }
|
||||||
|
public enum Period { TODAY, THIS_WEEK, THIS_MONTH }
|
||||||
|
public enum Kind { REDEEM, INVITE, COOKING, ACTIVATION, REGISTRATION }
|
||||||
|
|
||||||
|
private final RecordFilter filter;
|
||||||
|
private final Period period;
|
||||||
|
private final int balance;
|
||||||
|
private final int monthlyNet;
|
||||||
|
private final int totalCount;
|
||||||
|
private final int offset;
|
||||||
|
private final boolean hasMore;
|
||||||
|
private final List<Record> records;
|
||||||
|
|
||||||
|
public CarbonPointsPageEntity(RecordFilter filter, Period period, int balance, int monthlyNet,
|
||||||
|
int totalCount, int offset, boolean hasMore, List<Record> records) {
|
||||||
|
this.filter = filter;
|
||||||
|
this.period = period;
|
||||||
|
this.balance = balance;
|
||||||
|
this.monthlyNet = monthlyNet;
|
||||||
|
this.totalCount = totalCount;
|
||||||
|
this.offset = offset;
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.records = Collections.unmodifiableList(new ArrayList<>(records));
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecordFilter getFilter() { return filter; }
|
||||||
|
public Period getPeriod() { return period; }
|
||||||
|
public int getBalance() { return balance; }
|
||||||
|
public int getMonthlyNet() { return monthlyNet; }
|
||||||
|
public int getTotalCount() { return totalCount; }
|
||||||
|
public int getOffset() { return offset; }
|
||||||
|
public boolean hasMore() { return hasMore; }
|
||||||
|
public List<Record> getRecords() { return records; }
|
||||||
|
|
||||||
|
public static class Record {
|
||||||
|
private final long id;
|
||||||
|
private final long timestamp;
|
||||||
|
private final Kind kind;
|
||||||
|
private final int points;
|
||||||
|
|
||||||
|
public Record(long id, long timestamp, Kind kind, int points) {
|
||||||
|
this.id = id;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.kind = kind;
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() { return id; }
|
||||||
|
public long getTimestamp() { return timestamp; }
|
||||||
|
public Kind getKind() { return kind; }
|
||||||
|
public int getPoints() { return points; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.ckkj.griddle.carbon.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 明细分页与月度汇总;月汇总独立于当前分页,金额单位元、节电量单位 kWh。 */
|
||||||
|
public class CarbonReductionPageEntity {
|
||||||
|
private final long summaryMonth;
|
||||||
|
private final double totalPower;
|
||||||
|
private final double totalReduction;
|
||||||
|
private final int offset;
|
||||||
|
private final boolean hasMore;
|
||||||
|
private final List<Record> records;
|
||||||
|
|
||||||
|
public CarbonReductionPageEntity(long summaryMonth, double totalPower, double totalReduction,
|
||||||
|
int offset, boolean hasMore, List<Record> records) {
|
||||||
|
this.summaryMonth = summaryMonth;
|
||||||
|
this.totalPower = totalPower;
|
||||||
|
this.totalReduction = totalReduction;
|
||||||
|
this.offset = offset;
|
||||||
|
this.hasMore = hasMore;
|
||||||
|
this.records = Collections.unmodifiableList(new ArrayList<>(records));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSummaryMonth() { return summaryMonth; }
|
||||||
|
public double getTotalPower() { return totalPower; }
|
||||||
|
public double getTotalReduction() { return totalReduction; }
|
||||||
|
public int getOffset() { return offset; }
|
||||||
|
public boolean hasMore() { return hasMore; }
|
||||||
|
public List<Record> getRecords() { return records; }
|
||||||
|
|
||||||
|
public static class Record {
|
||||||
|
private final String date;
|
||||||
|
private final double powerSaved;
|
||||||
|
private final double moneySaved;
|
||||||
|
|
||||||
|
public Record(String date, double powerSaved, double moneySaved) {
|
||||||
|
this.date = date;
|
||||||
|
this.powerSaved = powerSaved;
|
||||||
|
this.moneySaved = moneySaved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDate() { return date; }
|
||||||
|
public double getPowerSaved() { return powerSaved; }
|
||||||
|
public double getMoneySaved() { return moneySaved; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.ckkj.griddle.carbon.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 碳统计展示数据。重量单位 kg、用电单位 kWh、金额单位元。
|
||||||
|
* 等效树木及少开车里程由数据层提供,不在页面中自行推算减排系数。
|
||||||
|
* growthRate 使用小数比例,例如 0.12 表示增长 12%。
|
||||||
|
*/
|
||||||
|
public class CarbonStatsEntity {
|
||||||
|
private final double totalCarbonReduction;
|
||||||
|
private final double totalCharcoalSaved;
|
||||||
|
private final double totalMoneySaved;
|
||||||
|
private final int totalTreeEquivalent;
|
||||||
|
private final int lessDrivingKm;
|
||||||
|
private final double powerUsed;
|
||||||
|
private final double carbonReduction;
|
||||||
|
private final double charcoalSaved;
|
||||||
|
private final double electricitySaved;
|
||||||
|
private final double standardCoalSaved;
|
||||||
|
private final double treeEquivalent;
|
||||||
|
private final double growthRate;
|
||||||
|
|
||||||
|
public CarbonStatsEntity(double totalCarbonReduction,
|
||||||
|
double totalCharcoalSaved,
|
||||||
|
double totalMoneySaved,
|
||||||
|
int totalTreeEquivalent,
|
||||||
|
int lessDrivingKm,
|
||||||
|
double powerUsed,
|
||||||
|
double carbonReduction,
|
||||||
|
double charcoalSaved,
|
||||||
|
double electricitySaved,
|
||||||
|
double standardCoalSaved,
|
||||||
|
double treeEquivalent,
|
||||||
|
double growthRate) {
|
||||||
|
this.totalCarbonReduction = totalCarbonReduction;
|
||||||
|
this.totalCharcoalSaved = totalCharcoalSaved;
|
||||||
|
this.totalMoneySaved = totalMoneySaved;
|
||||||
|
this.totalTreeEquivalent = totalTreeEquivalent;
|
||||||
|
this.lessDrivingKm = lessDrivingKm;
|
||||||
|
this.powerUsed = powerUsed;
|
||||||
|
this.carbonReduction = carbonReduction;
|
||||||
|
this.charcoalSaved = charcoalSaved;
|
||||||
|
this.electricitySaved = electricitySaved;
|
||||||
|
this.standardCoalSaved = standardCoalSaved;
|
||||||
|
this.treeEquivalent = treeEquivalent;
|
||||||
|
this.growthRate = growthRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTotalCarbonReduction() { return totalCarbonReduction; }
|
||||||
|
public double getTotalCharcoalSaved() { return totalCharcoalSaved; }
|
||||||
|
public double getTotalMoneySaved() { return totalMoneySaved; }
|
||||||
|
public int getTotalTreeEquivalent() { return totalTreeEquivalent; }
|
||||||
|
public int getLessDrivingKm() { return lessDrivingKm; }
|
||||||
|
public double getPowerUsed() { return powerUsed; }
|
||||||
|
public double getCarbonReduction() { return carbonReduction; }
|
||||||
|
public double getCharcoalSaved() { return charcoalSaved; }
|
||||||
|
public double getElectricitySaved() { return electricitySaved; }
|
||||||
|
public double getStandardCoalSaved() { return standardCoalSaved; }
|
||||||
|
public double getTreeEquivalent() { return treeEquivalent; }
|
||||||
|
public double getGrowthRate() { return growthRate; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.ckkj.griddle.carbon.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 趋势页数据,保留数值和周期,由页面按当前语言格式化标签及单位。 */
|
||||||
|
public class CarbonTrendEntity {
|
||||||
|
public enum Period { DAY, WEEK, MONTH, YEAR }
|
||||||
|
public enum Metric { POWER, REDUCTION, CHARCOAL, SAVINGS }
|
||||||
|
|
||||||
|
private final Period period;
|
||||||
|
private final Metric metric;
|
||||||
|
private final float powerShare;
|
||||||
|
private final float charcoalShare;
|
||||||
|
private final List<Point> points;
|
||||||
|
|
||||||
|
public CarbonTrendEntity(Period period, Metric metric, float powerShare,
|
||||||
|
float charcoalShare, List<Point> points) {
|
||||||
|
this.period = period;
|
||||||
|
this.metric = metric;
|
||||||
|
this.powerShare = powerShare;
|
||||||
|
this.charcoalShare = charcoalShare;
|
||||||
|
this.points = Collections.unmodifiableList(new ArrayList<>(points));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Period getPeriod() { return period; }
|
||||||
|
public Metric getMetric() { return metric; }
|
||||||
|
public float getPowerShare() { return powerShare; }
|
||||||
|
public float getCharcoalShare() { return charcoalShare; }
|
||||||
|
public List<Point> getPoints() { return points; }
|
||||||
|
|
||||||
|
/** 柱值与折线值为相同单位的两组演示趋势,标签含义由周期决定。 */
|
||||||
|
public static class Point {
|
||||||
|
private final int labelValue;
|
||||||
|
private final float barValue;
|
||||||
|
private final float lineValue;
|
||||||
|
|
||||||
|
public Point(int labelValue, float barValue, float lineValue) {
|
||||||
|
this.labelValue = labelValue;
|
||||||
|
this.barValue = barValue;
|
||||||
|
this.lineValue = lineValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLabelValue() { return labelValue; }
|
||||||
|
public float getBarValue() { return barValue; }
|
||||||
|
public float getLineValue() { return lineValue; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.ckkj.griddle.carbon.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.base.IView;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonStatsEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonReductionPageEntity;
|
||||||
|
|
||||||
|
/** 碳排放统计模块协议,后续真实接口沿用该数据回调。 */
|
||||||
|
public final class CarbonContract {
|
||||||
|
private CarbonContract() { }
|
||||||
|
|
||||||
|
public interface CallBack<T> {
|
||||||
|
void success(T data);
|
||||||
|
void fail(String message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DataModel {
|
||||||
|
/** 按收支类型、时间范围加载积分流水,汇总独立于列表筛选。 */
|
||||||
|
void getCarbonPoints(CarbonPointsPageEntity.RecordFilter filter, CarbonPointsPageEntity.Period period,
|
||||||
|
int offset, int limit, CallBack<CarbonPointsPageEntity> callback);
|
||||||
|
|
||||||
|
/** 获取累计环保贡献和六项核心指标。 */
|
||||||
|
void getCarbonStats(CallBack<CarbonStatsEntity> callback);
|
||||||
|
|
||||||
|
/** 按周期和指标获取趋势图及能源占比,目前为演示数据。 */
|
||||||
|
void getCarbonTrend(CarbonTrendEntity.Period period, CarbonTrendEntity.Metric metric,
|
||||||
|
CallBack<CarbonTrendEntity> callback);
|
||||||
|
|
||||||
|
/** 按偏移量加载减排明细,月度汇总不随分页改变。 */
|
||||||
|
void getCarbonReductionDetails(int offset, int limit,
|
||||||
|
CallBack<CarbonReductionPageEntity> callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface CarbonView extends IView {
|
||||||
|
default void getCarbonPointsSuccess(CarbonPointsPageEntity data) { }
|
||||||
|
|
||||||
|
default void getCarbonStatsSuccess(CarbonStatsEntity data) { }
|
||||||
|
|
||||||
|
default void getCarbonTrendSuccess(CarbonTrendEntity data) { }
|
||||||
|
|
||||||
|
default void getCarbonReductionDetailsSuccess(CarbonReductionPageEntity data) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
109
app/src/main/java/com/ckkj/griddle/carbon/mvp/CarbonImpl.java
Normal file
109
app/src/main/java/com/ckkj/griddle/carbon/mvp/CarbonImpl.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package com.ckkj.griddle.carbon.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonStatsEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonReductionPageEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 碳统计数据层;当前返回设计稿示例,尚未接入真实统计接口。 */
|
||||||
|
public class CarbonImpl implements CarbonContract.DataModel {
|
||||||
|
@Override
|
||||||
|
public void getCarbonPoints(CarbonPointsPageEntity.RecordFilter filter, CarbonPointsPageEntity.Period period,
|
||||||
|
int offset, int limit, CarbonContract.CallBack<CarbonPointsPageEntity> callback) {
|
||||||
|
if (filter == null || period == null || offset < 0 || limit <= 0) {
|
||||||
|
callback.fail("积分筛选或分页参数无效");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 固定在设计稿的 2026-06-30 演示,避免模拟的“今日”流水随运行日期变空。
|
||||||
|
Calendar reference = new GregorianCalendar(2026, Calendar.JUNE, 30, 14, 32, 0);
|
||||||
|
reference.set(Calendar.MILLISECOND, 0);
|
||||||
|
Calendar begin = (Calendar) reference.clone();
|
||||||
|
begin.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
begin.set(Calendar.MINUTE, 0);
|
||||||
|
begin.set(Calendar.SECOND, 0);
|
||||||
|
if (period == CarbonPointsPageEntity.Period.THIS_MONTH) {
|
||||||
|
begin.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
} else if (period == CarbonPointsPageEntity.Period.THIS_WEEK) {
|
||||||
|
int daysSinceMonday = (begin.get(Calendar.DAY_OF_WEEK) + 5) % 7;
|
||||||
|
begin.add(Calendar.DAY_OF_MONTH, -daysSinceMonday);
|
||||||
|
}
|
||||||
|
List<CarbonPointsPageEntity.Record> filtered = new ArrayList<>();
|
||||||
|
int[] firstPoints = {-1000, 100, 5, 100, 100};
|
||||||
|
CarbonPointsPageEntity.Kind[] kinds = CarbonPointsPageEntity.Kind.values();
|
||||||
|
int monthlyNet = 0;
|
||||||
|
for (int i = 0; i < 75; i++) {
|
||||||
|
int points = i < 5 ? firstPoints[i] : i == 74 ? 80 : 15;
|
||||||
|
long time = reference.getTimeInMillis() - Math.max(0, i - 4) * 9L * 60 * 60 * 1000;
|
||||||
|
monthlyNet += points;
|
||||||
|
boolean matchesType = filter == CarbonPointsPageEntity.RecordFilter.ALL
|
||||||
|
|| (filter == CarbonPointsPageEntity.RecordFilter.EARNED && points > 0)
|
||||||
|
|| (filter == CarbonPointsPageEntity.RecordFilter.SPENT && points < 0);
|
||||||
|
if (time >= begin.getTimeInMillis() && matchesType) {
|
||||||
|
CarbonPointsPageEntity.Kind kind = i < 5 ? kinds[i] : kinds[1 + (i - 5) % 4];
|
||||||
|
filtered.add(new CarbonPointsPageEntity.Record(i + 1L, time, kind, points));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int start = Math.min(offset, filtered.size());
|
||||||
|
int end = start + Math.min(limit, filtered.size() - start);
|
||||||
|
// 期初 2440 + 当月净增 420 = 当前余额 2860,模拟账目保持一致。
|
||||||
|
callback.success(new CarbonPointsPageEntity(filter, period, 2440 + monthlyNet, monthlyNet,
|
||||||
|
filtered.size(), offset, end < filtered.size(), filtered.subList(start, end)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonTrend(CarbonTrendEntity.Period period, CarbonTrendEntity.Metric metric,
|
||||||
|
CarbonContract.CallBack<CarbonTrendEntity> callback) {
|
||||||
|
if (period == null || metric == null) {
|
||||||
|
callback.fail("周期或指标不能为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int[][] labels = {{8, 10, 12, 14, 16}, {26, 27, 28, 29, 30},
|
||||||
|
{1, 2, 3, 4, 5}, {2022, 2023, 2024, 2025, 2026}};
|
||||||
|
float[] bars = {3.4f, 4.3f, 7.1f, 3.7f, 2.9f};
|
||||||
|
float[] lines = {3.0f, 3.7f, 5.9f, 4.1f, 3.0f};
|
||||||
|
float[] periodScale = {0.12f, 0.6f, 1f, 12f};
|
||||||
|
float[] metricScale = {1f, 0.78f, 0.62f, 1.52f};
|
||||||
|
float scale = periodScale[period.ordinal()] * metricScale[metric.ordinal()];
|
||||||
|
List<CarbonTrendEntity.Point> points = new ArrayList<>();
|
||||||
|
for (int i = 0; i < bars.length; i++) {
|
||||||
|
points.add(new CarbonTrendEntity.Point(labels[period.ordinal()][i],
|
||||||
|
bars[i] * scale, lines[i] * scale));
|
||||||
|
}
|
||||||
|
// 比例和转换系数仅用于 UI 演示,不作为真实减排计算依据。
|
||||||
|
callback.success(new CarbonTrendEntity(period, metric, 45, 55, points));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonReductionDetails(int offset, int limit,
|
||||||
|
CarbonContract.CallBack<CarbonReductionPageEntity> callback) {
|
||||||
|
if (offset < 0 || limit <= 0) {
|
||||||
|
callback.fail("分页参数无效");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int[] days = {30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25, 24};
|
||||||
|
int start = Math.min(offset, days.length);
|
||||||
|
int end = start + Math.min(limit, days.length - start);
|
||||||
|
List<CarbonReductionPageEntity.Record> records = new ArrayList<>();
|
||||||
|
for (int i = start; i < end; i++) {
|
||||||
|
records.add(new CarbonReductionPageEntity.Record(
|
||||||
|
String.format(Locale.ROOT, "2026-06-%02d", days[i]), 2.1, 3.20));
|
||||||
|
}
|
||||||
|
// 汇总和行数据均采用设计稿示例,独立模拟后台汇总、分页两个口径。
|
||||||
|
long month = new GregorianCalendar(2026, Calendar.JUNE, 1).getTimeInMillis();
|
||||||
|
callback.success(new CarbonReductionPageEntity(month, 16.4, 3.6,
|
||||||
|
offset, end < days.length, records));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getCarbonStats(CarbonContract.CallBack<CarbonStatsEntity> callback) {
|
||||||
|
// 累计数据与核心指标分别对应设计稿两个区块,不视为同一统计周期。
|
||||||
|
callback.success(new CarbonStatsEntity(156.8, 112.3, 156.8, 12, 780,
|
||||||
|
45.2, 28.6, 20.5, 32.80, 18.2, 1.2, 0.12));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.ckkj.griddle.carbon.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.base.BasePresenter;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonPointsPageEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonStatsEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonTrendEntity;
|
||||||
|
import com.ckkj.griddle.carbon.entity.CarbonReductionPageEntity;
|
||||||
|
|
||||||
|
/** 碳统计协调层:持有具体 Impl,并在页面仍绑定时回传结果。 */
|
||||||
|
public class CarbonPresenter extends BasePresenter<CarbonContract.CarbonView> {
|
||||||
|
private final CarbonImpl mImpl;
|
||||||
|
|
||||||
|
public CarbonPresenter(CarbonImpl mImpl) {
|
||||||
|
this.mImpl = mImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCarbonPoints(CarbonPointsPageEntity.RecordFilter filter, CarbonPointsPageEntity.Period period,
|
||||||
|
int offset, int limit) {
|
||||||
|
mImpl.getCarbonPoints(filter, period, offset, limit,
|
||||||
|
new CarbonContract.CallBack<CarbonPointsPageEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(CarbonPointsPageEntity data) {
|
||||||
|
if (getView() != null) getView().getCarbonPointsSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCarbonTrend(CarbonTrendEntity.Period period, CarbonTrendEntity.Metric metric) {
|
||||||
|
mImpl.getCarbonTrend(period, metric, new CarbonContract.CallBack<CarbonTrendEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(CarbonTrendEntity data) {
|
||||||
|
if (getView() != null) getView().getCarbonTrendSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCarbonReductionDetails(int offset, int limit) {
|
||||||
|
mImpl.getCarbonReductionDetails(offset, limit,
|
||||||
|
new CarbonContract.CallBack<CarbonReductionPageEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(CarbonReductionPageEntity data) {
|
||||||
|
if (getView() != null) getView().getCarbonReductionDetailsSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getCarbonStats() {
|
||||||
|
mImpl.getCarbonStats(new CarbonContract.CallBack<CarbonStatsEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(CarbonStatsEntity data) {
|
||||||
|
if (getView() != null) getView().getCarbonStatsSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.ckkj.griddle.carbon.view;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
|
||||||
|
import com.github.mikephil.charting.animation.ChartAnimator;
|
||||||
|
import com.github.mikephil.charting.charts.CombinedChart;
|
||||||
|
import com.github.mikephil.charting.data.BarEntry;
|
||||||
|
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
||||||
|
import com.github.mikephil.charting.renderer.BarChartRenderer;
|
||||||
|
import com.github.mikephil.charting.utils.Transformer;
|
||||||
|
import com.github.mikephil.charting.utils.Utils;
|
||||||
|
import com.github.mikephil.charting.utils.ViewPortHandler;
|
||||||
|
|
||||||
|
/** 在原生组合图中绘制顶部圆角的非堆叠正值柱;坐标仍由图表 Transformer 计算。 */
|
||||||
|
public class CarbonRoundedBarRenderer extends BarChartRenderer {
|
||||||
|
private final RectF barRect = new RectF();
|
||||||
|
|
||||||
|
public CarbonRoundedBarRenderer(CombinedChart chart, ChartAnimator animator,
|
||||||
|
ViewPortHandler viewPortHandler) {
|
||||||
|
super(chart, animator, viewPortHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawDataSet(Canvas canvas, IBarDataSet dataSet, int index) {
|
||||||
|
Transformer transformer = mChart.getTransformer(dataSet.getAxisDependency());
|
||||||
|
float halfWidth = mChart.getBarData().getBarWidth() / 2f;
|
||||||
|
int count = Math.min(dataSet.getEntryCount(),
|
||||||
|
(int) Math.ceil(dataSet.getEntryCount() * mAnimator.getPhaseX()));
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
BarEntry entry = dataSet.getEntryForIndex(i);
|
||||||
|
float value = entry.getY() * mAnimator.getPhaseY();
|
||||||
|
barRect.set(entry.getX() - halfWidth, value, entry.getX() + halfWidth, 0);
|
||||||
|
transformer.rectValueToPixel(barRect);
|
||||||
|
if (!mViewPortHandler.isInBoundsLeft(barRect.right)) continue;
|
||||||
|
if (!mViewPortHandler.isInBoundsRight(barRect.left)) break;
|
||||||
|
mRenderPaint.setColor(dataSet.getColor(i));
|
||||||
|
float radius = Math.min(Utils.convertDpToPixel(6),
|
||||||
|
Math.min(barRect.width() / 2f, barRect.height() / 2f));
|
||||||
|
canvas.drawRoundRect(barRect, radius, radius, mRenderPaint);
|
||||||
|
// 底部覆盖为直角,使柱子与零基线贴合。
|
||||||
|
canvas.drawRect(barRect.left, barRect.bottom - radius,
|
||||||
|
barRect.right, barRect.bottom, mRenderPaint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.ckkj.griddle.custom.view;
|
|||||||
|
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
@@ -9,7 +10,9 @@ import android.util.AttributeSet;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
|
|
||||||
/** 配网进度环:浅橙色完整底环,叠加两端为半圆的橙色进度弧。 */
|
import com.ckkj.griddle.R;
|
||||||
|
|
||||||
|
/** 浅橙色完整底环,叠加两端为半圆的橙色进度弧;配网与设备预览页共用。 */
|
||||||
public class ProvisionProgressView extends View {
|
public class ProvisionProgressView extends View {
|
||||||
private static final int PROGRESS_COLOR = 0xFFFF6900;
|
private static final int PROGRESS_COLOR = 0xFFFF6900;
|
||||||
private static final int TRACK_COLOR = 0xFFFFE3CC;
|
private static final int TRACK_COLOR = 0xFFFFE3CC;
|
||||||
@@ -28,16 +31,18 @@ public class ProvisionProgressView extends View {
|
|||||||
public ProvisionProgressView(Context context, AttributeSet attrs) {
|
public ProvisionProgressView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
float density = getResources().getDisplayMetrics().density;
|
float density = getResources().getDisplayMetrics().density;
|
||||||
strokeWidth = 12f * density;
|
// 默认值保持配网页面不变;预览页可在 XML 中配置细环及示例进度。
|
||||||
inset = 3f * density;
|
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ProvisionProgressView);
|
||||||
|
strokeWidth = attributes.getDimension(R.styleable.ProvisionProgressView_provisionStrokeWidth,
|
||||||
|
12f * density);
|
||||||
|
inset = attributes.getDimension(R.styleable.ProvisionProgressView_provisionInset, 3f * density);
|
||||||
|
progress = Math.max(0, Math.min(100, attributes.getInt(
|
||||||
|
R.styleable.ProvisionProgressView_provisionProgress, isInEditMode() ? 70 : 0)));
|
||||||
|
displayedProgress = progress;
|
||||||
|
attributes.recycle();
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
paint.setStrokeWidth(strokeWidth);
|
paint.setStrokeWidth(strokeWidth);
|
||||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
// 只在布局预览中显示示例进度,运行时仍从真实设备阶段开始。
|
|
||||||
if (isInEditMode()) {
|
|
||||||
progress = 70;
|
|
||||||
displayedProgress = progress;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package com.ckkj.griddle.custom.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.LinearSnapHelper;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 平面三行时间滚轮:56dp 行高,停下后吸附,中间数字高亮。 */
|
||||||
|
public class TimerWheelView extends RecyclerView {
|
||||||
|
private final LinearLayoutManager layoutManager;
|
||||||
|
private final LinearSnapHelper snapHelper = new LinearSnapHelper();
|
||||||
|
private final WheelAdapter wheelAdapter;
|
||||||
|
private int valueCount = 24;
|
||||||
|
private int selectedPosition;
|
||||||
|
|
||||||
|
public TimerWheelView(@NonNull Context context) { this(context, null); }
|
||||||
|
|
||||||
|
public TimerWheelView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimerWheelView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
layoutManager = new LinearLayoutManager(context);
|
||||||
|
setLayoutManager(layoutManager);
|
||||||
|
setClipToPadding(false);
|
||||||
|
setPadding(0, getResources().getDimensionPixelSize(R.dimen.device_timer_wheel_row),
|
||||||
|
0, getResources().getDimensionPixelSize(R.dimen.device_timer_wheel_row));
|
||||||
|
setOverScrollMode(OVER_SCROLL_NEVER);
|
||||||
|
setVerticalScrollBarEnabled(false);
|
||||||
|
setNestedScrollingEnabled(false);
|
||||||
|
setItemAnimator(null);
|
||||||
|
wheelAdapter = new WheelAdapter();
|
||||||
|
setAdapter(wheelAdapter);
|
||||||
|
snapHelper.attachToRecyclerView(this);
|
||||||
|
wheelAdapter.setOnItemClickListener((adapter, view, position) ->
|
||||||
|
smoothScrollBy(0, (view.getTop() + view.getBottom() - getHeight()) / 2));
|
||||||
|
addOnScrollListener(new OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
|
updateSelectedRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||||
|
if (newState != SCROLL_STATE_IDLE) return;
|
||||||
|
updateSelectedRow();
|
||||||
|
View selected = snapHelper.findSnapView(layoutManager);
|
||||||
|
int[] distance = selected == null ? null : snapHelper.calculateDistanceToFinalSnap(layoutManager, selected);
|
||||||
|
// 回到中间一组,支持 23→00、59→00 的循环,同时保持当前画面不跳动。
|
||||||
|
if (distance != null && distance[1] == 0
|
||||||
|
&& (selectedPosition < valueCount || selectedPosition >= valueCount * 2)) {
|
||||||
|
setSelectedValue(selectedPosition % valueCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setValueCount(24);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueCount(int count) {
|
||||||
|
if (count <= 0) throw new IllegalArgumentException("Value count must be positive");
|
||||||
|
stopScroll();
|
||||||
|
valueCount = count;
|
||||||
|
List<Integer> values = new ArrayList<>();
|
||||||
|
for (int i = 0; i < count * 3; i++) values.add(i % count);
|
||||||
|
wheelAdapter.setNewData(values);
|
||||||
|
setSelectedValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedValue(int value) {
|
||||||
|
if (value < 0 || value >= valueCount) throw new IllegalArgumentException("Value out of range");
|
||||||
|
selectedPosition = valueCount + value;
|
||||||
|
layoutManager.scrollToPositionWithOffset(selectedPosition, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 确认时取视觉上最接近中线的值,即使用户刚刚快速甩动滚轮也可准确提交。 */
|
||||||
|
public int getSelectedValue() {
|
||||||
|
updateSelectedRow();
|
||||||
|
int value = selectedPosition % valueCount;
|
||||||
|
stopScroll();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
updateSelectedRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSelectedRow() {
|
||||||
|
View selected = snapHelper.findSnapView(layoutManager);
|
||||||
|
if (selected == null) return;
|
||||||
|
int position = layoutManager.getPosition(selected);
|
||||||
|
if (position == NO_POSITION) return;
|
||||||
|
selectedPosition = position;
|
||||||
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
|
View child = getChildAt(i);
|
||||||
|
boolean checked = layoutManager.getPosition(child) == selectedPosition;
|
||||||
|
child.setSelected(checked);
|
||||||
|
TextView value = child.findViewById(R.id.tv_timer_wheel_value);
|
||||||
|
value.setTextColor(ContextCompat.getColor(getContext(), checked
|
||||||
|
? R.color.device_timer_wheel_selected : R.color.device_timer_wheel_unselected));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 与项目其他列表一致,滚轮条目也通过 BaseQuickAdapter 绑定。 */
|
||||||
|
private static class WheelAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {
|
||||||
|
WheelAdapter() { super(R.layout.item_device_timer_wheel); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, Integer value) {
|
||||||
|
Locale locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
helper.setText(R.id.tv_timer_wheel_value, String.format(locale, "%02d", value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,8 @@ import com.ckkj.griddle.device.mvp.BltDeviceListPresenter;
|
|||||||
import com.ckkj.griddle.network.BaseBean;
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
import com.ckkj.griddle.utils.show.ToastUtil;
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电饼铛蓝牙扫描列表:负责扫描前置条件、页面状态和扫描结果展示。
|
* 电饼铛蓝牙扫描列表:负责扫描前置条件、页面状态和扫描结果展示。
|
||||||
* 动态权限由设备首页申请;先建立 BLE 连接,再进入下一页展示连接状态及设备能力。
|
* 动态权限由设备首页申请;先建立 BLE 连接,再进入下一页展示连接状态及设备能力。
|
||||||
@@ -115,7 +117,6 @@ public class BltDeviceListActivity
|
|||||||
viewBinding.rvDevices.setAdapter(deviceAdapter);
|
viewBinding.rvDevices.setAdapter(deviceAdapter);
|
||||||
// RSSI 持续变化时避免列表项反复闪烁。
|
// RSSI 持续变化时避免列表项反复闪烁。
|
||||||
viewBinding.rvDevices.setItemAnimator(null);
|
viewBinding.rvDevices.setItemAnimator(null);
|
||||||
viewBinding.llSearchAgain.setOnClickListener(v -> requestScan());
|
|
||||||
provisioning = GriddleProvisioningSession.get(this);
|
provisioning = GriddleProvisioningSession.get(this);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
connectionToken = savedInstanceState.getString("connection_token");
|
connectionToken = savedInstanceState.getString("connection_token");
|
||||||
@@ -124,6 +125,18 @@ public class BltDeviceListActivity
|
|||||||
deviceAdapter.setOnDeviceClickListener(this::connectDevice);
|
deviceAdapter.setOnDeviceClickListener(this::connectDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.ll_search_again})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.ll_search_again:
|
||||||
|
requestScan();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@@ -302,10 +315,10 @@ public class BltDeviceListActivity
|
|||||||
} else if (provisioning.isConnected() && !openingWifi) {
|
} else if (provisioning.isConnected() && !openingWifi) {
|
||||||
hideDialogLoading();
|
hideDialogLoading();
|
||||||
openingWifi = true;
|
openingWifi = true;
|
||||||
Intent intent = new Intent(this, WifiListActivity.class);
|
Bundle bundle = new Bundle();
|
||||||
intent.putExtra(WifiListActivity.EXTRA_SESSION_TOKEN, connectionToken);
|
bundle.putString(WifiListActivity.EXTRA_SESSION_TOKEN, connectionToken);
|
||||||
// 会话所有权交给 Wi-Fi 页面;当前页留在返回栈,离开前台时只停止扫描。
|
// 会话所有权交给 Wi-Fi 页面;当前页留在返回栈,离开前台时只停止扫描。
|
||||||
wifiLauncher.launch(intent);
|
goTo(mContext, WifiListActivity.class, bundle, wifiLauncher);
|
||||||
} else if (provisioning.getState() == GriddleProvisioningSession.State.FAILED) {
|
} else if (provisioning.getState() == GriddleProvisioningSession.State.FAILED) {
|
||||||
hideDialogLoading();
|
hideDialogLoading();
|
||||||
int error = provisioning.getErrorRes();
|
int error = provisioning.getErrorRes();
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.ckkj.griddle.network.BaseBean;
|
|||||||
import com.ckkj.griddle.utils.show.ToastUtil;
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
import com.gyf.immersionbar.ImmersionBar;
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
/** 配网过渡页面:复用已提交的会话,通过 SDK 回调更新现有进度环和步骤。 */
|
/** 配网过渡页面:复用已提交的会话,通过 SDK 回调更新现有进度环和步骤。 */
|
||||||
public class DeviceConnectingActivity extends BaseActivity<DeviceWifiConnectBinding, BltDeviceListPresenter>
|
public class DeviceConnectingActivity extends BaseActivity<DeviceWifiConnectBinding, BltDeviceListPresenter>
|
||||||
implements BltDeviceListContract.BltDeviceListView {
|
implements BltDeviceListContract.BltDeviceListView {
|
||||||
@@ -35,7 +37,6 @@ public class DeviceConnectingActivity extends BaseActivity<DeviceWifiConnectBind
|
|||||||
provisioning = GriddleProvisioningSession.get(this);
|
provisioning = GriddleProvisioningSession.get(this);
|
||||||
connectionToken = getIntent().getStringExtra(WifiListActivity.EXTRA_SESSION_TOKEN);
|
connectionToken = getIntent().getStringExtra(WifiListActivity.EXTRA_SESSION_TOKEN);
|
||||||
viewBinding.tvCancelSetup.setPaintFlags(viewBinding.tvCancelSetup.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
viewBinding.tvCancelSetup.setPaintFlags(viewBinding.tvCancelSetup.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
viewBinding.tvCancelSetup.setOnClickListener(v -> cancelProvisioning());
|
|
||||||
// 同时兼容按键与手势返回,不能仅关闭页面而留下正在执行的配网任务。
|
// 同时兼容按键与手势返回,不能仅关闭页面而留下正在执行的配网任务。
|
||||||
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||||
@Override public void handleOnBackPressed() {
|
@Override public void handleOnBackPressed() {
|
||||||
@@ -48,6 +49,18 @@ public class DeviceConnectingActivity extends BaseActivity<DeviceWifiConnectBind
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.tv_cancel_setup})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.tv_cancel_setup:
|
||||||
|
cancelProvisioning();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package com.ckkj.griddle.device;
|
package com.ckkj.griddle.device;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
@@ -15,12 +20,16 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.ckkj.griddle.R;
|
import com.ckkj.griddle.R;
|
||||||
import com.ckkj.griddle.base.BaseFragment;
|
import com.ckkj.griddle.base.BaseFragment;
|
||||||
import com.ckkj.griddle.databinding.DeviceIndexFragmentBinding;
|
import com.ckkj.griddle.databinding.DeviceIndexFragmentBinding;
|
||||||
|
import com.ckkj.griddle.device.adapter.HomeDeviceAdapter;
|
||||||
|
import com.ckkj.griddle.device.control.DevicePreviewActivity;
|
||||||
|
import com.ckkj.griddle.device.entity.HomeDeviceEntity;
|
||||||
import com.ckkj.griddle.device.mvp.DeviceContract;
|
import com.ckkj.griddle.device.mvp.DeviceContract;
|
||||||
import com.ckkj.griddle.device.mvp.DeviceImpl;
|
import com.ckkj.griddle.device.mvp.DeviceImpl;
|
||||||
import com.ckkj.griddle.device.mvp.DevicePresenter;
|
import com.ckkj.griddle.device.mvp.DevicePresenter;
|
||||||
import com.ckkj.griddle.network.BaseBean;
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
import com.ckkj.griddle.utils.show.ToastUtil;
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pub.devrel.easypermissions.EasyPermissions;
|
import pub.devrel.easypermissions.EasyPermissions;
|
||||||
@@ -35,6 +44,22 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
private RecyclerView.Adapter<?> mObservedAdapter;
|
private RecyclerView.Adapter<?> mObservedAdapter;
|
||||||
// 从系统权限请求发起到结果回调之间保持为 true,防止连续点击重复申请。
|
// 从系统权限请求发起到结果回调之间保持为 true,防止连续点击重复申请。
|
||||||
private boolean bluetoothPermissionRequestInFlight;
|
private boolean bluetoothPermissionRequestInFlight;
|
||||||
|
private static final int REQUEST_HOME_LOCATION = 10004;
|
||||||
|
// 定位授权与蓝牙授权分开记录,避免两种权限回调互相触发业务。
|
||||||
|
private boolean locationPermissionRequestInFlight;
|
||||||
|
private boolean waitingForLocationSettings;
|
||||||
|
private final ActivityResultLauncher<Intent> locationSettingsLauncher =
|
||||||
|
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||||
|
if (!waitingForLocationSettings) return;
|
||||||
|
waitingForLocationSettings = false;
|
||||||
|
if (!canUpdateLocationDemo()) return;
|
||||||
|
// 设置返回后只检查授权状态并展示模拟城市,不读取真实位置。
|
||||||
|
if (!hasLocationPermission()) {
|
||||||
|
ToastUtil.showShort(requireContext(), getString(R.string.device_home_location_permission_required));
|
||||||
|
} else {
|
||||||
|
showLocationDemo();
|
||||||
|
}
|
||||||
|
});
|
||||||
private final RecyclerView.AdapterDataObserver mDeviceDataObserver =
|
private final RecyclerView.AdapterDataObserver mDeviceDataObserver =
|
||||||
new RecyclerView.AdapterDataObserver() {
|
new RecyclerView.AdapterDataObserver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -60,13 +85,112 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initData(Bundle state) {
|
public void initData(Bundle state) {
|
||||||
|
if (mDeviceAdapter == null) {
|
||||||
|
initDemoDevices();
|
||||||
|
} else {
|
||||||
bindDeviceAdapter();
|
bindDeviceAdapter();
|
||||||
|
}
|
||||||
// 首页标题、右上角添加图标和空状态入口共用授权检查,避免某个入口绕过授权。
|
// 首页标题、右上角添加图标和空状态入口共用授权检查,避免某个入口绕过授权。
|
||||||
View.OnClickListener openDeviceList = v -> openBluetoothDeviceList();
|
View.OnClickListener openDeviceList = v -> openBluetoothDeviceList();
|
||||||
viewBinding.tvHomeTitle.setOnClickListener(openDeviceList);
|
viewBinding.tvHomeTitle.setOnClickListener(openDeviceList);
|
||||||
viewBinding.ivEmptyDevices.setOnClickListener(openDeviceList);
|
viewBinding.ivEmptyDevices.setOnClickListener(openDeviceList);
|
||||||
viewBinding.ivAddDevice.setOnClickListener(openDeviceList);
|
viewBinding.ivAddDevice.setOnClickListener(openDeviceList);
|
||||||
viewBinding.btnEmptyAddDevice.setOnClickListener(openDeviceList);
|
viewBinding.btnEmptyAddDevice.setOnClickListener(openDeviceList);
|
||||||
|
// 进入首页不申请位置权限;点击定位区域后才说明用途并申请。
|
||||||
|
viewBinding.llHomeLocation.setOnClickListener(v -> requestHomeLocationPermission());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅供首页展示:三台在线、一台离线;后续接口接入时替换此方法中的数据来源。 */
|
||||||
|
private void initDemoDevices() {
|
||||||
|
HomeDeviceAdapter adapter = new HomeDeviceAdapter();
|
||||||
|
// 点击模拟设备卡片进入预览页,在线和离线设备均可查看。
|
||||||
|
adapter.setOnItemChildClickListener((baseAdapter, view, position) ->
|
||||||
|
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-4", name, false, 0, 0));
|
||||||
|
adapter.setNewData(devices);
|
||||||
|
// 复用现有观察器;列表有数据时显示宫格,清空后仍可恢复原来的空状态。
|
||||||
|
setDeviceAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canUpdateLocationDemo() {
|
||||||
|
return isAdded() && getView() != null && viewBinding != null && !isHidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 授权演示接受大致位置权限,实际不调用任何定位服务。 */
|
||||||
|
private boolean hasLocationPermission() {
|
||||||
|
return isAdded() && (ContextCompat.checkSelfPermission(requireContext(),
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
||||||
|
|| ContextCompat.checkSelfPermission(requireContext(),
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 沿用添加设备入口的权限说明弹窗和顶部提示,授权后仅展示模拟结果。 */
|
||||||
|
private void requestHomeLocationPermission() {
|
||||||
|
if (!canUpdateLocationDemo() || locationPermissionRequestInFlight
|
||||||
|
|| bluetoothPermissionRequestInFlight || (dialog != null && dialog.isShowing())) return;
|
||||||
|
if (hasLocationPermission()) {
|
||||||
|
showLocationDemo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String title = getString(R.string.device_home_location_permission_title);
|
||||||
|
String description = getString(R.string.device_home_location_permission_description);
|
||||||
|
showDialogtext(null, false, false, title, description,
|
||||||
|
getString(R.string.bl_device_permission_deny),
|
||||||
|
getString(R.string.bl_device_permission_allow), new OnDialogClick() {
|
||||||
|
@Override public void onCancelClick() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfirmClick() {
|
||||||
|
if (!canUpdateLocationDemo()) return;
|
||||||
|
if (hasLocationPermission()) {
|
||||||
|
showLocationDemo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
locationPermissionRequestInFlight = true;
|
||||||
|
showPermissionDialog(ContextCompat.getDrawable(requireContext(),
|
||||||
|
R.mipmap.img_location), true, title, description);
|
||||||
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
|
dialog.setCancelable(false);
|
||||||
|
// 成对申请以兼容 Android 12+ 的精确/大致位置选择;大致位置也视为成功。
|
||||||
|
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_HOME_LOCATION);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 仅模拟授权后的城市展示,后续接入真实服务时再替换此处。 */
|
||||||
|
private void showLocationDemo() {
|
||||||
|
if (!canUpdateLocationDemo() || !hasLocationPermission()) return;
|
||||||
|
viewBinding.tvHomeLocation.setText(R.string.device_home_location_demo);
|
||||||
|
ToastUtil.showShort(requireContext(), getString(R.string.device_home_location_demo_hint));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 永久拒绝后引导用户打开应用权限设置,返回后继续授权演示。 */
|
||||||
|
private void showLocationSettingsDialog(int messageResId, Intent intent) {
|
||||||
|
showDialogtext(null, false, false,
|
||||||
|
getString(R.string.device_home_location_permission_title), getString(messageResId),
|
||||||
|
getString(R.string.bl_device_permission_deny),
|
||||||
|
getString(R.string.bl_device_open_settings), new OnDialogClick() {
|
||||||
|
@Override public void onCancelClick() { }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfirmClick() {
|
||||||
|
if (!canUpdateLocationDemo()) return;
|
||||||
|
try {
|
||||||
|
waitingForLocationSettings = true;
|
||||||
|
locationSettingsLauncher.launch(intent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
waitingForLocationSettings = false;
|
||||||
|
ToastUtil.showShort(requireContext(),
|
||||||
|
getString(R.string.device_home_location_settings_unavailable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 添加入口:已有权限直接跳转;缺少权限时先通过基类弹窗说明用途。 */
|
/** 添加入口:已有权限直接跳转;缺少权限时先通过基类弹窗说明用途。 */
|
||||||
@@ -114,7 +238,7 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
/** 只由已有完整权限或完整授权成功的分支调用,不在此方法中再申请权限。 */
|
/** 只由已有完整权限或完整授权成功的分支调用,不在此方法中再申请权限。 */
|
||||||
private void navigateToBluetoothDeviceList() {
|
private void navigateToBluetoothDeviceList() {
|
||||||
if (!isAdded() || getView() == null) return;
|
if (!isAdded() || getView() == null) return;
|
||||||
startActivity(new Intent(requireContext(), BltDeviceListActivity.class));
|
goTo(mContext, BltDeviceListActivity.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -157,6 +281,8 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
// 避免首页视图销毁后遗留顶部说明框或授权等待状态。
|
// 避免首页视图销毁后遗留顶部说明框或授权等待状态。
|
||||||
bluetoothPermissionRequestInFlight = false;
|
bluetoothPermissionRequestInFlight = false;
|
||||||
|
locationPermissionRequestInFlight = false;
|
||||||
|
waitingForLocationSettings = false;
|
||||||
hidePermissionDialog();
|
hidePermissionDialog();
|
||||||
unregisterDeviceObserver();
|
unregisterDeviceObserver();
|
||||||
if (viewBinding != null) {
|
if (viewBinding != null) {
|
||||||
@@ -185,7 +311,7 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||||
@NonNull int[] grantResults) {
|
@NonNull int[] grantResults) {
|
||||||
// 先关闭顶部说明框,再分发结果;通过、拒绝和取消都需要结束说明展示。
|
// 先关闭顶部说明框,再分发结果;通过、拒绝和取消都需要结束说明展示。
|
||||||
if (requestCode == REQUEST_EVENT_CODE_10003) {
|
if (requestCode == REQUEST_EVENT_CODE_10003 || requestCode == REQUEST_HOME_LOCATION) {
|
||||||
hidePermissionDialog();
|
hidePermissionDialog();
|
||||||
}
|
}
|
||||||
// BaseFragment 将结果分发给 EasyPermissions,包含部分授权和拒绝的回调。
|
// BaseFragment 将结果分发给 EasyPermissions,包含部分授权和拒绝的回调。
|
||||||
@@ -194,10 +320,18 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
// 系统取消请求时可能返回空结果,同样需要清理等待状态。
|
// 系统取消请求时可能返回空结果,同样需要清理等待状态。
|
||||||
bluetoothPermissionRequestInFlight = false;
|
bluetoothPermissionRequestInFlight = false;
|
||||||
}
|
}
|
||||||
|
if (requestCode == REQUEST_HOME_LOCATION) locationPermissionRequestInFlight = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||||
|
if (requestCode == REQUEST_HOME_LOCATION) {
|
||||||
|
if (locationPermissionRequestInFlight && canUpdateLocationDemo() && hasLocationPermission()) {
|
||||||
|
locationPermissionRequestInFlight = false;
|
||||||
|
showLocationDemo();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
// EasyPermissions 在部分授权时也可能回调此方法,必须复查整组权限才能跳转。
|
// EasyPermissions 在部分授权时也可能回调此方法,必须复查整组权限才能跳转。
|
||||||
if (requestCode == REQUEST_EVENT_CODE_10003 && bluetoothPermissionRequestInFlight
|
if (requestCode == REQUEST_EVENT_CODE_10003 && bluetoothPermissionRequestInFlight
|
||||||
&& isAdded() && getView() != null
|
&& isAdded() && getView() != null
|
||||||
@@ -209,6 +343,19 @@ public class DeviceFragment extends BaseFragment<DeviceIndexFragmentBinding, Dev
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||||
|
if (requestCode == REQUEST_HOME_LOCATION) {
|
||||||
|
// 仅拒绝精确位置但允许大致位置时,也视为授权演示成功。
|
||||||
|
if (!locationPermissionRequestInFlight || !canUpdateLocationDemo() || hasLocationPermission()) return;
|
||||||
|
locationPermissionRequestInFlight = false;
|
||||||
|
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
|
||||||
|
showLocationSettingsDialog(R.string.device_home_location_permission_settings,
|
||||||
|
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||||
|
Uri.parse("package:" + requireContext().getPackageName())));
|
||||||
|
} else {
|
||||||
|
ToastUtil.showShort(requireContext(), getString(R.string.device_home_location_permission_required));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (requestCode != REQUEST_EVENT_CODE_10003 || !isAdded() || getView() == null) return;
|
if (requestCode != REQUEST_EVENT_CODE_10003 || !isAdded() || getView() == null) return;
|
||||||
bluetoothPermissionRequestInFlight = false;
|
bluetoothPermissionRequestInFlight = false;
|
||||||
// 永久拒绝后无法再次弹出系统授权框,使用基类弹窗引导用户自行前往应用设置。
|
// 永久拒绝后无法再次弹出系统授权框,使用基类弹窗引导用户自行前往应用设置。
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import com.ckkj.griddle.network.BaseBean;
|
|||||||
import com.ckkj.griddle.utils.show.ToastUtil;
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
import com.gyf.immersionbar.ImmersionBar;
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
/** 先展示上一页已建立的 BLE 连接;配网能力独立判断,Wi-Fi 扫描仅由用户手动触发。 */
|
/** 先展示上一页已建立的 BLE 连接;配网能力独立判断,Wi-Fi 扫描仅由用户手动触发。 */
|
||||||
public class WifiListActivity extends BaseActivity<WifiListLayoutBinding, DevicePresenter>
|
public class WifiListActivity extends BaseActivity<WifiListLayoutBinding, DevicePresenter>
|
||||||
implements DeviceContract.DeviceView {
|
implements DeviceContract.DeviceView {
|
||||||
@@ -60,17 +62,8 @@ public class WifiListActivity extends BaseActivity<WifiListLayoutBinding, Device
|
|||||||
// 网络较多时列表内部滚动,不再只显示设计稿中的三个示例网络。
|
// 网络较多时列表内部滚动,不再只显示设计稿中的三个示例网络。
|
||||||
viewBinding.rvWifiNetworks.setNestedScrollingEnabled(true);
|
viewBinding.rvWifiNetworks.setNestedScrollingEnabled(true);
|
||||||
viewBinding.tvOtherNetworks.setText(R.string.wifi_setup_refresh_networks);
|
viewBinding.tvOtherNetworks.setText(R.string.wifi_setup_refresh_networks);
|
||||||
viewBinding.tvOtherNetworks.setOnClickListener(v -> {
|
|
||||||
if (!provisioning.matches(connectionToken) || !provisioning.isConnected()) {
|
|
||||||
showMessage(getString(R.string.wifi_setup_reconnect_required));
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
provisioning.scanNetworks(connectionToken);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
viewBinding.btnStartSetup.setEnabled(false);
|
viewBinding.btnStartSetup.setEnabled(false);
|
||||||
viewBinding.btnStartSetup.setAlpha(0.5f);
|
viewBinding.btnStartSetup.setAlpha(0.5f);
|
||||||
viewBinding.btnStartSetup.setOnClickListener(v -> startProvisioning());
|
|
||||||
viewBinding.etWifiPassword.setEnabled(false);
|
viewBinding.etWifiPassword.setEnabled(false);
|
||||||
// 禁止系统跨页面重建保存 Wi-Fi 密码;切换 SSID 时也会主动清空输入。
|
// 禁止系统跨页面重建保存 Wi-Fi 密码;切换 SSID 时也会主动清空输入。
|
||||||
viewBinding.etWifiPassword.setSaveEnabled(false);
|
viewBinding.etWifiPassword.setSaveEnabled(false);
|
||||||
@@ -81,6 +74,28 @@ public class WifiListActivity extends BaseActivity<WifiListLayoutBinding, Device
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.tv_other_networks, R.id.btn_start_setup})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.tv_other_networks:
|
||||||
|
// 刷新前检查蓝牙会话,已断开时提示用户重新连接。
|
||||||
|
if (!provisioning.matches(connectionToken) || !provisioning.isConnected()) {
|
||||||
|
showMessage(getString(R.string.wifi_setup_reconnect_required));
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
provisioning.scanNetworks(connectionToken);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.btn_start_setup:
|
||||||
|
startProvisioning();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -212,9 +227,9 @@ public class WifiListActivity extends BaseActivity<WifiListLayoutBinding, Device
|
|||||||
if (keyboard != null) keyboard.hideSoftInputFromWindow(viewBinding.etWifiPassword.getWindowToken(), 0);
|
if (keyboard != null) keyboard.hideSoftInputFromWindow(viewBinding.etWifiPassword.getWindowToken(), 0);
|
||||||
// 只传会话标识,不通过 Intent 传递密码,也不重复发起配网。
|
// 只传会话标识,不通过 Intent 传递密码,也不重复发起配网。
|
||||||
openingConnecting = true;
|
openingConnecting = true;
|
||||||
Intent intent = new Intent(this, DeviceConnectingActivity.class);
|
Bundle bundle = new Bundle();
|
||||||
intent.putExtra(EXTRA_SESSION_TOKEN, connectionToken);
|
bundle.putString(EXTRA_SESSION_TOKEN, connectionToken);
|
||||||
connectingLauncher.launch(intent);
|
goTo(mContext, DeviceConnectingActivity.class, bundle, connectingLauncher);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resizeNetworkList() {
|
private void resizeNetworkList() {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.ckkj.griddle.device.adapter;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.device.entity.HomeDeviceEntity;
|
||||||
|
|
||||||
|
/** 首页设备宫格,沿用项目 BaseQuickAdapter 的绑定与点击方式。 */
|
||||||
|
public class HomeDeviceAdapter extends BaseQuickAdapter<HomeDeviceEntity, BaseViewHolder> {
|
||||||
|
public HomeDeviceAdapter() {
|
||||||
|
super(R.layout.device_index_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, HomeDeviceEntity item) {
|
||||||
|
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()));
|
||||||
|
helper.setText(R.id.tv_device_temperature, mContext.getString(
|
||||||
|
R.string.device_home_temperature_value, item.getTemperature()));
|
||||||
|
// 每次绑定都重置可见性,避免离线卡片复用时残留在线功率和温度。
|
||||||
|
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);
|
||||||
|
status.setActivated(!online);
|
||||||
|
status.setContentDescription(mContext.getString(online
|
||||||
|
? R.string.device_home_online : R.string.device_home_offline));
|
||||||
|
helper.addOnClickListener(R.id.cv_device);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,353 @@
|
|||||||
|
package com.ckkj.griddle.device.control;
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.databinding.DeviceDataViewLayoutBinding;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceDataEntity;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlContract;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlImpl;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlPresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
|
import com.github.mikephil.charting.components.XAxis;
|
||||||
|
import com.github.mikephil.charting.components.YAxis;
|
||||||
|
import com.github.mikephil.charting.components.LimitLine;
|
||||||
|
import com.github.mikephil.charting.data.Entry;
|
||||||
|
import com.github.mikephil.charting.data.LineData;
|
||||||
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
|
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
||||||
|
import com.github.mikephil.charting.utils.MPPointD;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 设备数据页:展示模拟指标和原生折线图,后续通过 MVP 接入真实数据。 */
|
||||||
|
public class DeviceDataViewActivity
|
||||||
|
extends BaseActivity<DeviceDataViewLayoutBinding, DeviceControlPresenter>
|
||||||
|
implements DeviceControlContract.DeviceControlView {
|
||||||
|
private static final String STATE_RUNNING = "device_data_running";
|
||||||
|
private static final String STATE_CHART_INDEX = "device_data_chart_index";
|
||||||
|
private boolean running = true;
|
||||||
|
private List<DeviceDataEntity.TrendPoint> chartPoints = Collections.emptyList();
|
||||||
|
private List<String> chartLabels = Collections.emptyList();
|
||||||
|
private int selectedChartIndex = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceControlPresenter createPresenter() {
|
||||||
|
return new DeviceControlPresenter(new DeviceControlImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.device_data_view_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
initChart();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
running = savedInstanceState.getBoolean(STATE_RUNNING, true);
|
||||||
|
selectedChartIndex = savedInstanceState.getInt(STATE_CHART_INDEX, -1);
|
||||||
|
}
|
||||||
|
mPresenter.getDeviceData(running);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.ll_data_timer, R.id.ll_data_info,
|
||||||
|
R.id.cv_data_today, R.id.ll_data_diagnosis, R.id.btn_data_power})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_data_timer:
|
||||||
|
goTo(mContext, DeviceTimerActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_data_info:
|
||||||
|
case R.id.cv_data_today:
|
||||||
|
// 设备信息入口和今日统计卡片共用设备信息页。
|
||||||
|
goTo(mContext, DeviceInfoActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_data_diagnosis:
|
||||||
|
showActionHint(R.string.device_data_diagnosis);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.btn_data_power:
|
||||||
|
// 演示状态交由数据层重新生成,不调用真实设备控制接口。
|
||||||
|
mPresenter.getDeviceData(!running);
|
||||||
|
ToastUtil.showShort(this, getString(running
|
||||||
|
? R.string.device_data_demo_on : R.string.device_data_demo_off));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 允许横向滑动查值,关闭图表缩放和平移,避免手指移动后坐标轴偏移。 */
|
||||||
|
private void initChart() {
|
||||||
|
LineChart chart = viewBinding.chartDeviceData;
|
||||||
|
chart.getDescription().setEnabled(false);
|
||||||
|
chart.getLegend().setEnabled(false);
|
||||||
|
chart.setTouchEnabled(true);
|
||||||
|
chart.setDragEnabled(false);
|
||||||
|
chart.setScaleEnabled(false);
|
||||||
|
chart.setDoubleTapToZoomEnabled(false);
|
||||||
|
chart.setHighlightPerTapEnabled(false);
|
||||||
|
chart.setHighlightPerDragEnabled(false);
|
||||||
|
initChartTouch(chart);
|
||||||
|
chart.setDrawGridBackground(false);
|
||||||
|
chart.setDrawBorders(false);
|
||||||
|
chart.setExtraOffsets(0, 6, 4, 2);
|
||||||
|
chart.getAxisRight().setEnabled(false);
|
||||||
|
XAxis xAxis = chart.getXAxis();
|
||||||
|
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||||
|
xAxis.setDrawGridLines(false);
|
||||||
|
xAxis.setDrawAxisLine(false);
|
||||||
|
xAxis.setGranularity(1f);
|
||||||
|
xAxis.setTextSize(9.5f);
|
||||||
|
xAxis.setTextColor(color(R.color.device_data_muted));
|
||||||
|
xAxis.setYOffset(7f);
|
||||||
|
xAxis.setAvoidFirstLastClipping(true);
|
||||||
|
xAxis.setDrawLimitLinesBehindData(true);
|
||||||
|
YAxis yAxis = chart.getAxisLeft();
|
||||||
|
yAxis.setAxisMinimum(0f);
|
||||||
|
yAxis.setAxisMaximum(250f);
|
||||||
|
yAxis.setLabelCount(6, true);
|
||||||
|
yAxis.setDrawAxisLine(false);
|
||||||
|
yAxis.setGridColor(color(R.color.device_data_grid));
|
||||||
|
yAxis.setGridLineWidth(1f);
|
||||||
|
yAxis.setTextColor(color(R.color.device_data_muted));
|
||||||
|
yAxis.setTextSize(9.5f);
|
||||||
|
yAxis.setXOffset(7f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 横向手势交给图表查值,纵向手势交还外层页面滚动。 */
|
||||||
|
private void initChartTouch(LineChart chart) {
|
||||||
|
final int touchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
|
||||||
|
chart.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
private float downX;
|
||||||
|
private float downY;
|
||||||
|
private boolean horizontal;
|
||||||
|
private boolean vertical;
|
||||||
|
private boolean tracking;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
|
if (event.getActionMasked() != MotionEvent.ACTION_DOWN && !tracking) return false;
|
||||||
|
switch (event.getActionMasked()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
tracking = false;
|
||||||
|
if (chartPoints.isEmpty()
|
||||||
|
|| !chart.getViewPortHandler().isInBoundsX(event.getX())
|
||||||
|
|| !chart.getViewPortHandler().isInBoundsY(event.getY())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
downX = event.getX();
|
||||||
|
downY = event.getY();
|
||||||
|
horizontal = false;
|
||||||
|
vertical = false;
|
||||||
|
tracking = true;
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
selectChartPosition(event.getX(), event.getY());
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if (!horizontal && !vertical) {
|
||||||
|
float dx = Math.abs(event.getX() - downX);
|
||||||
|
float dy = Math.abs(event.getY() - downY);
|
||||||
|
if (Math.max(dx, dy) > touchSlop) {
|
||||||
|
horizontal = dx >= dy;
|
||||||
|
vertical = !horizontal;
|
||||||
|
if (vertical) view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (horizontal) selectChartPosition(event.getX(), event.getY());
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
tracking = false;
|
||||||
|
if (!vertical) {
|
||||||
|
selectChartPosition(event.getX(), event.getY());
|
||||||
|
if (!horizontal) view.performClick();
|
||||||
|
}
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
|
// 多指操作不执行查值或缩放,避免双指变成意外的单点选择。
|
||||||
|
vertical = true;
|
||||||
|
horizontal = false;
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
tracking = false;
|
||||||
|
view.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 只根据横坐标吸附到最近月份,不要求手指精确碰到某一条线。 */
|
||||||
|
private void selectChartPosition(float x, float y) {
|
||||||
|
if (chartPoints.isEmpty()) return;
|
||||||
|
MPPointD point = viewBinding.chartDeviceData.getValuesByTouchPoint(x, y, YAxis.AxisDependency.LEFT);
|
||||||
|
int index = (int) Math.max(0, Math.min(chartPoints.size() - 1, Math.round(point.x)));
|
||||||
|
MPPointD.recycleInstance(point);
|
||||||
|
if (index != selectedChartIndex) showChartSelection(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同步选中月份的三项数值和竖向指示线,松手后继续保留当前选中结果。 */
|
||||||
|
private void showChartSelection(int index) {
|
||||||
|
selectedChartIndex = index;
|
||||||
|
DeviceDataEntity.TrendPoint point = chartPoints.get(index);
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat format = NumberFormat.getNumberInstance(locale);
|
||||||
|
format.setMaximumFractionDigits(1);
|
||||||
|
viewBinding.tvDataChartPeriod.setText(getString(R.string.device_data_selected_month, chartLabels.get(index)));
|
||||||
|
viewBinding.tvDataChartTemperature.setText(getString(R.string.device_data_selected_temperature,
|
||||||
|
format.format(point.getTemperature())));
|
||||||
|
viewBinding.tvDataChartPower.setText(getString(R.string.device_data_selected_power,
|
||||||
|
format.format(point.getPower())));
|
||||||
|
viewBinding.tvDataChartUsage.setText(getString(R.string.device_data_selected_usage,
|
||||||
|
format.format(point.getUsageMinutes())));
|
||||||
|
XAxis axis = viewBinding.chartDeviceData.getXAxis();
|
||||||
|
axis.removeAllLimitLines();
|
||||||
|
LimitLine cursor = new LimitLine(index);
|
||||||
|
cursor.setLineColor(color(R.color.device_data_muted));
|
||||||
|
cursor.setLineWidth(1f);
|
||||||
|
cursor.enableDashedLine(4f, 4f, 0f);
|
||||||
|
axis.addLimitLine(cursor);
|
||||||
|
viewBinding.chartDeviceData.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getDeviceDataSuccess(DeviceDataEntity data) {
|
||||||
|
running = data.isRunning();
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
viewBinding.tvDataPower.setText(NumberFormat.getIntegerInstance(locale).format(data.getPower()));
|
||||||
|
viewBinding.tvDataTemperature.setText(NumberFormat.getIntegerInstance(locale).format(data.getTemperature()));
|
||||||
|
viewBinding.tvDataElectricity.setText(getString(R.string.device_data_decimal, data.getTodayElectricity()));
|
||||||
|
viewBinding.tvDataCharcoal.setText(getString(R.string.device_data_decimal, data.getTodayCharcoal()));
|
||||||
|
viewBinding.tvDataRuntime.setText(getString(R.string.device_data_decimal, data.getTodayRuntime()));
|
||||||
|
viewBinding.tvDataSince.setText(getString(R.string.device_data_since, data.getStartTime()));
|
||||||
|
viewBinding.llDataStatus.setActivated(running);
|
||||||
|
viewBinding.tvDataStatus.setText(running ? R.string.device_data_running : R.string.device_data_stopped);
|
||||||
|
int statusColor = color(running ? R.color.device_data_green : R.color.device_data_muted);
|
||||||
|
viewBinding.tvDataStatus.setTextColor(statusColor);
|
||||||
|
viewBinding.viewDataStatusDot.setBackgroundTintList(ColorStateList.valueOf(statusColor));
|
||||||
|
viewBinding.btnDataPower.setActivated(running);
|
||||||
|
viewBinding.btnDataPower.setContentDescription(getString(R.string.device_data_switch)
|
||||||
|
+ ", " + getString(running ? R.string.device_data_running : R.string.device_data_stopped));
|
||||||
|
renderChart(data.getTrend(), locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 线段和空心圆点均由图表库绘制,不使用图片或手工拼接坐标。 */
|
||||||
|
private void renderChart(List<DeviceDataEntity.TrendPoint> points, Locale locale) {
|
||||||
|
chartPoints = points;
|
||||||
|
if (points.isEmpty()) {
|
||||||
|
selectedChartIndex = -1;
|
||||||
|
chartLabels = Collections.emptyList();
|
||||||
|
viewBinding.chartDeviceData.getXAxis().removeAllLimitLines();
|
||||||
|
viewBinding.chartDeviceData.clear();
|
||||||
|
viewBinding.tvDataChartPeriod.setText(R.string.device_data_period);
|
||||||
|
viewBinding.tvDataChartTemperature.setText(R.string.device_data_chart_empty);
|
||||||
|
viewBinding.tvDataChartPower.setText(R.string.device_data_chart_empty);
|
||||||
|
viewBinding.tvDataChartUsage.setText(R.string.device_data_chart_empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Entry> temperature = new ArrayList<>();
|
||||||
|
List<Entry> power = new ArrayList<>();
|
||||||
|
List<Entry> usage = new ArrayList<>();
|
||||||
|
List<String> labels = new ArrayList<>();
|
||||||
|
String[] months = DateFormatSymbols.getInstance(locale).getShortMonths();
|
||||||
|
StringBuilder description = new StringBuilder(getString(R.string.device_data_chart_description));
|
||||||
|
float maximum = 250f;
|
||||||
|
for (int i = 0; i < points.size(); i++) {
|
||||||
|
DeviceDataEntity.TrendPoint point = points.get(i);
|
||||||
|
temperature.add(new Entry(i, point.getTemperature()));
|
||||||
|
power.add(new Entry(i, point.getPower()));
|
||||||
|
usage.add(new Entry(i, point.getUsageMinutes()));
|
||||||
|
labels.add(months[point.getMonth()]);
|
||||||
|
maximum = Math.max(maximum, Math.max(point.getTemperature(),
|
||||||
|
Math.max(point.getPower(), point.getUsageMinutes())));
|
||||||
|
description.append(' ').append(getString(R.string.device_data_chart_point,
|
||||||
|
labels.get(i), point.getTemperature(), point.getPower(), point.getUsageMinutes()));
|
||||||
|
}
|
||||||
|
LineChart chart = viewBinding.chartDeviceData;
|
||||||
|
chartLabels = labels;
|
||||||
|
chart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(labels));
|
||||||
|
chart.getXAxis().setLabelCount(Math.max(2, labels.size()), false);
|
||||||
|
chart.getXAxis().setAxisMinimum(-0.25f);
|
||||||
|
chart.getXAxis().setAxisMaximum(Math.max(1, labels.size() - 1) + 0.25f);
|
||||||
|
// 保留设计稿的 0~250 刻度;后续数据超出时按 50 向上扩展,避免截断峰值。
|
||||||
|
chart.getAxisLeft().setAxisMaximum((float) Math.ceil(maximum / 50f) * 50f);
|
||||||
|
chart.setData(new LineData(
|
||||||
|
createLine(temperature, R.string.device_data_legend_temperature, R.color.device_data_orange),
|
||||||
|
createLine(power, R.string.device_data_legend_power, R.color.device_data_power_line),
|
||||||
|
createLine(usage, R.string.device_data_legend_usage, R.color.device_data_usage_line)));
|
||||||
|
chart.setContentDescription(description.toString());
|
||||||
|
// 首次展示最近一个月;刷新数据或切换演示电源状态时保留已有选择。
|
||||||
|
showChartSelection(selectedChartIndex >= 0 && selectedChartIndex < points.size()
|
||||||
|
? selectedChartIndex : points.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LineDataSet createLine(List<Entry> entries, int labelResId, int colorResId) {
|
||||||
|
LineDataSet line = new LineDataSet(entries, getString(labelResId));
|
||||||
|
line.setMode(LineDataSet.Mode.LINEAR);
|
||||||
|
line.setColor(color(colorResId));
|
||||||
|
line.setLineWidth(2f);
|
||||||
|
line.setCircleColor(color(colorResId));
|
||||||
|
line.setCircleRadius(3.5f);
|
||||||
|
line.setDrawCircleHole(true);
|
||||||
|
line.setCircleHoleColor(color(android.R.color.white));
|
||||||
|
line.setCircleHoleRadius(1.8f);
|
||||||
|
line.setDrawValues(false);
|
||||||
|
line.setDrawFilled(false);
|
||||||
|
line.setHighlightEnabled(false);
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int color(int resId) { return ContextCompat.getColor(this, resId); }
|
||||||
|
|
||||||
|
private void showActionHint(int actionResId) {
|
||||||
|
ToastUtil.showShort(this, getString(R.string.device_data_action_hint, getString(actionResId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putBoolean(STATE_RUNNING, running);
|
||||||
|
outState.putInt(STATE_CHART_INDEX, selectedChartIndex);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) { ToastUtil.showShort(this, message); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效由 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package com.ckkj.griddle.device.control;
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.text.style.RelativeSizeSpan;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.databinding.DeviceInfoLayoutBinding;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceInfoEntity;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlContract;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlImpl;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlPresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 设备信息与今日数据页:复用公共标题栏,通过 MVP 加载当前演示数据。 */
|
||||||
|
public class DeviceInfoActivity extends BaseActivity<DeviceInfoLayoutBinding, DeviceControlPresenter>
|
||||||
|
implements DeviceControlContract.DeviceControlView {
|
||||||
|
@Override
|
||||||
|
public DeviceControlPresenter createPresenter() {
|
||||||
|
return new DeviceControlPresenter(new DeviceControlImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.device_info_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
mPresenter.getDeviceInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getDeviceInfoSuccess(DeviceInfoEntity data) {
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat decimal = NumberFormat.getNumberInstance(locale);
|
||||||
|
decimal.setMinimumFractionDigits(1);
|
||||||
|
decimal.setMaximumFractionDigits(1);
|
||||||
|
viewBinding.tvInfoDate.setText(formatDate(data.getDataTime(), "EEEdMMM", locale));
|
||||||
|
setValueWithUnit(viewBinding.tvInfoTodayPower, decimal.format(data.getTodayElectricity()),
|
||||||
|
R.string.device_data_unit_kwh);
|
||||||
|
setValueWithUnit(viewBinding.tvInfoCharcoal, decimal.format(data.getTodayCharcoal()),
|
||||||
|
R.string.device_data_unit_kg);
|
||||||
|
setValueWithUnit(viewBinding.tvInfoCarbon, decimal.format(data.getCarbonReduction()),
|
||||||
|
R.string.device_info_unit_carbon);
|
||||||
|
NumberFormat money = NumberFormat.getNumberInstance(locale);
|
||||||
|
money.setMinimumFractionDigits(2);
|
||||||
|
money.setMaximumFractionDigits(2);
|
||||||
|
viewBinding.tvInfoElectricitySaved.setText(getString(R.string.device_info_money_value,
|
||||||
|
money.format(data.getElectricitySaved())));
|
||||||
|
viewBinding.tvInfoSerial.setText(data.getSerialNumber());
|
||||||
|
viewBinding.tvInfoFirmware.setText(data.getFirmware());
|
||||||
|
setValueWithUnit(viewBinding.tvInfoTotalPower, decimal.format(data.getTotalElectricity()),
|
||||||
|
R.string.device_data_unit_kwh);
|
||||||
|
setValueWithUnit(viewBinding.tvInfoTotalRuntime,
|
||||||
|
NumberFormat.getIntegerInstance(locale).format(data.getTotalRuntime()), R.string.device_data_unit_h);
|
||||||
|
viewBinding.tvInfoWarranty.setText(formatDate(data.getWarrantyUntil(), "yMMM", locale));
|
||||||
|
viewBinding.tvInfoLastService.setText(formatDate(data.getLastServiceTime(), "dMMMy", locale));
|
||||||
|
viewBinding.llInfoStatus.setActivated(data.isOnline());
|
||||||
|
viewBinding.tvInfoStatus.setText(data.isOnline()
|
||||||
|
? R.string.device_home_online : R.string.device_home_offline);
|
||||||
|
int statusColor = ContextCompat.getColor(this, data.isOnline()
|
||||||
|
? R.color.device_data_green : R.color.device_data_muted);
|
||||||
|
viewBinding.tvInfoStatus.setTextColor(statusColor);
|
||||||
|
viewBinding.viewInfoStatusDot.setBackgroundTintList(ColorStateList.valueOf(statusColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 单位使用小号灰色字体,数值继续沿用布局中的黑色或减排绿色。 */
|
||||||
|
private void setValueWithUnit(TextView view, String value, int unitResId) {
|
||||||
|
SpannableStringBuilder text = new SpannableStringBuilder(value).append(' ');
|
||||||
|
int unitStart = text.length();
|
||||||
|
text.append(getString(unitResId));
|
||||||
|
text.setSpan(new RelativeSizeSpan(10.5f / 12.5f), unitStart, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
text.setSpan(new ForegroundColorSpan(ContextCompat.getColor(this, R.color.device_data_muted)),
|
||||||
|
unitStart, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
view.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 使用当前语言的日期排列方式,避免英文格式出现在中文界面。 */
|
||||||
|
private String formatDate(long timestamp, String skeleton, Locale locale) {
|
||||||
|
String pattern = DateFormat.getBestDateTimePattern(locale, skeleton);
|
||||||
|
return new SimpleDateFormat(pattern, locale).format(new Date(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) { ToastUtil.showShort(this, message); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.ckkj.griddle.device.control;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.carbon.CarbonActivity;
|
||||||
|
import com.ckkj.griddle.carbon.CarbonPointsActivity;
|
||||||
|
import com.ckkj.griddle.databinding.DevicePreviewBinding;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlContract;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlImpl;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlPresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备预览
|
||||||
|
*/
|
||||||
|
public class DevicePreviewActivity extends BaseActivity<DevicePreviewBinding, DeviceControlPresenter>
|
||||||
|
implements DeviceControlContract.DeviceControlView {
|
||||||
|
@Override
|
||||||
|
public DeviceControlPresenter createPresenter() {
|
||||||
|
return new DeviceControlPresenter(new DeviceControlImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.device_preview;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this)
|
||||||
|
.statusBarColor(R.color.device_home_background)
|
||||||
|
.statusBarDarkFont(true)
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.cv_preview_device:
|
||||||
|
case R.id.ll_preview_stats:
|
||||||
|
// 设备卡片和统计入口均进入设备数据页。
|
||||||
|
goTo(mContext, DeviceDataViewActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.cv_preview_carbon:
|
||||||
|
case R.id.tv_carbon_status:
|
||||||
|
// 今日碳减排整张卡片进入碳排放统计页。
|
||||||
|
goTo(mContext, CarbonActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_preview_carbon_points:
|
||||||
|
case R.id.tv_carbon_points:
|
||||||
|
// 积分快捷入口进入减排积分流水页。
|
||||||
|
goTo(mContext, CarbonPointsActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
package com.ckkj.griddle.device.control;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.databinding.DeviceTimerLayoutBinding;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlContract;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlImpl;
|
||||||
|
import com.ckkj.griddle.device.mvp.DeviceControlPresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 设备定时页:当前只演示时间选择与开关状态,不创建真实定时任务。 */
|
||||||
|
public class DeviceTimerActivity extends BaseActivity<DeviceTimerLayoutBinding, DeviceControlPresenter>
|
||||||
|
implements DeviceControlContract.DeviceControlView {
|
||||||
|
private static final String STATE_START_HOUR = "timer_start_hour";
|
||||||
|
private static final String STATE_START_MINUTE = "timer_start_minute";
|
||||||
|
private static final String STATE_OFF_HOUR = "timer_off_hour";
|
||||||
|
private static final String STATE_OFF_MINUTE = "timer_off_minute";
|
||||||
|
private static final String STATE_START_ENABLED = "timer_start_enabled";
|
||||||
|
private static final String STATE_OFF_ENABLED = "timer_off_enabled";
|
||||||
|
private static final String STATE_START_REPEAT = "timer_start_repeat";
|
||||||
|
private static final String STATE_OFF_REPEAT = "timer_off_repeat";
|
||||||
|
private int startHour = 18;
|
||||||
|
private int startMinute;
|
||||||
|
private int offHour = 20;
|
||||||
|
private int offMinute;
|
||||||
|
private boolean startEnabled = true;
|
||||||
|
private boolean offEnabled;
|
||||||
|
private int startRepeatDays = DeviceTimerPickerDialog.REPEAT_DAILY;
|
||||||
|
private int offRepeatDays = DeviceTimerPickerDialog.REPEAT_DAILY;
|
||||||
|
private DeviceTimerPickerDialog timePickerDialog;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceControlPresenter createPresenter() {
|
||||||
|
return new DeviceControlPresenter(new DeviceControlImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.device_timer_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
startHour = savedInstanceState.getInt(STATE_START_HOUR, 18);
|
||||||
|
startMinute = savedInstanceState.getInt(STATE_START_MINUTE, 0);
|
||||||
|
offHour = savedInstanceState.getInt(STATE_OFF_HOUR, 20);
|
||||||
|
offMinute = savedInstanceState.getInt(STATE_OFF_MINUTE, 0);
|
||||||
|
startEnabled = savedInstanceState.getBoolean(STATE_START_ENABLED, true);
|
||||||
|
offEnabled = savedInstanceState.getBoolean(STATE_OFF_ENABLED, false);
|
||||||
|
startRepeatDays = savedInstanceState.getInt(STATE_START_REPEAT, DeviceTimerPickerDialog.REPEAT_DAILY);
|
||||||
|
offRepeatDays = savedInstanceState.getInt(STATE_OFF_REPEAT, DeviceTimerPickerDialog.REPEAT_DAILY);
|
||||||
|
}
|
||||||
|
// 使用已有开关组件的无事件初始化,避免页面恢复时触发业务回调。
|
||||||
|
viewBinding.switchTimerStart.setCheckedImmediatelyNoEvent(startEnabled);
|
||||||
|
viewBinding.switchTimerOff.setCheckedImmediatelyNoEvent(offEnabled);
|
||||||
|
viewBinding.switchTimerStart.setOnCheckedChangeListener((button, checked) -> {
|
||||||
|
startEnabled = checked;
|
||||||
|
renderTimerState();
|
||||||
|
});
|
||||||
|
viewBinding.switchTimerOff.setOnCheckedChangeListener((button, checked) -> {
|
||||||
|
offEnabled = checked;
|
||||||
|
renderTimerState();
|
||||||
|
});
|
||||||
|
renderTimerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.fl_timer_start_time, R.id.fl_timer_off_time})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.fl_timer_start_time:
|
||||||
|
showTimePicker(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.fl_timer_off_time:
|
||||||
|
showTimePicker(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 两个时间均可编辑;更改时间不会自动启用对应的定时开关。 */
|
||||||
|
private void showTimePicker(boolean start) {
|
||||||
|
if (timePickerDialog != null && timePickerDialog.isShowing()) return;
|
||||||
|
timePickerDialog = new DeviceTimerPickerDialog(this,
|
||||||
|
start ? startHour : offHour, start ? startMinute : offMinute,
|
||||||
|
start ? startRepeatDays : offRepeatDays, (hour, minute, repeatDays) -> {
|
||||||
|
if (start) {
|
||||||
|
startHour = hour;
|
||||||
|
startMinute = minute;
|
||||||
|
startRepeatDays = repeatDays;
|
||||||
|
} else {
|
||||||
|
offHour = hour;
|
||||||
|
offMinute = minute;
|
||||||
|
offRepeatDays = repeatDays;
|
||||||
|
}
|
||||||
|
// 只在右上角确认后回填对应时间;取消不修改页面,也不自动开启开关。
|
||||||
|
renderTimerState();
|
||||||
|
});
|
||||||
|
timePickerDialog.setOnDismissListener(dialog -> timePickerDialog = null);
|
||||||
|
timePickerDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 时间块随启用状态变为绿色或灰色,开关本身保持设计稿的橙色和浅灰色。 */
|
||||||
|
private void renderTimerState() {
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
String startTime = String.format(locale, "%02d:%02d", startHour, startMinute);
|
||||||
|
String offTime = String.format(locale, "%02d:%02d", offHour, offMinute);
|
||||||
|
viewBinding.tvTimerStartTime.setText(startTime);
|
||||||
|
viewBinding.tvTimerOffTime.setText(offTime);
|
||||||
|
viewBinding.tvTimerStartTime.setActivated(startEnabled);
|
||||||
|
viewBinding.tvTimerOffTime.setActivated(offEnabled);
|
||||||
|
viewBinding.flTimerStartTime.setContentDescription(getString(R.string.device_timer_pick_start, startTime));
|
||||||
|
viewBinding.flTimerOffTime.setContentDescription(getString(R.string.device_timer_pick_off, offTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putInt(STATE_START_HOUR, startHour);
|
||||||
|
outState.putInt(STATE_START_MINUTE, startMinute);
|
||||||
|
outState.putInt(STATE_OFF_HOUR, offHour);
|
||||||
|
outState.putInt(STATE_OFF_MINUTE, offMinute);
|
||||||
|
outState.putBoolean(STATE_START_ENABLED, startEnabled);
|
||||||
|
outState.putBoolean(STATE_OFF_ENABLED, offEnabled);
|
||||||
|
outState.putInt(STATE_START_REPEAT, startRepeatDays);
|
||||||
|
outState.putInt(STATE_OFF_REPEAT, offRepeatDays);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (timePickerDialog != null) timePickerDialog.dismiss();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) { ToastUtil.showShort(this, message); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一事件处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
package com.ckkj.griddle.device.control;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatDialog;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.databinding.DialogDeviceTimerPickerBinding;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 底部设置定时弹窗,编辑期间只修改草稿,点击右上角确认后才回传。 */
|
||||||
|
public class DeviceTimerPickerDialog extends AppCompatDialog {
|
||||||
|
public static final int REPEAT_DAILY = 0x7F;
|
||||||
|
private static final int REPEAT_WEEKDAYS = 0x1F;
|
||||||
|
private static final int REPEAT_WEEKENDS = 0x60;
|
||||||
|
private final DialogDeviceTimerPickerBinding binding;
|
||||||
|
private final OnConfirmListener listener;
|
||||||
|
private int repeatDays;
|
||||||
|
private AlertDialog customDaysDialog;
|
||||||
|
|
||||||
|
public interface OnConfirmListener {
|
||||||
|
/** repeatDays 的低七位依次表示周一至周日。 */
|
||||||
|
void onConfirm(int hour, int minute, int repeatDays);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceTimerPickerDialog(Context context, int hour, int minute, int repeatDays,
|
||||||
|
OnConfirmListener listener) {
|
||||||
|
super(context, R.style.DeviceTimerPickerDialogTheme);
|
||||||
|
this.listener = listener;
|
||||||
|
this.repeatDays = repeatDays == 0 ? REPEAT_DAILY : repeatDays;
|
||||||
|
binding = DialogDeviceTimerPickerBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
setCanceledOnTouchOutside(true);
|
||||||
|
binding.wheelTimerHour.setValueCount(24);
|
||||||
|
binding.wheelTimerMinute.setValueCount(60);
|
||||||
|
binding.wheelTimerHour.setSelectedValue(hour);
|
||||||
|
binding.wheelTimerMinute.setSelectedValue(minute);
|
||||||
|
binding.btnTimerPickerCancel.setOnClickListener(v -> dismiss());
|
||||||
|
binding.btnTimerPickerConfirm.setOnClickListener(v -> {
|
||||||
|
listener.onConfirm(binding.wheelTimerHour.getSelectedValue(),
|
||||||
|
binding.wheelTimerMinute.getSelectedValue(), this.repeatDays);
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
binding.tvRepeatDaily.setOnClickListener(v -> selectRepeat(REPEAT_DAILY));
|
||||||
|
binding.tvRepeatWeekdays.setOnClickListener(v -> selectRepeat(REPEAT_WEEKDAYS));
|
||||||
|
binding.tvRepeatWeekends.setOnClickListener(v -> selectRepeat(REPEAT_WEEKENDS));
|
||||||
|
binding.tvRepeatCustom.setOnClickListener(v -> showCustomDays());
|
||||||
|
renderRepeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show() {
|
||||||
|
super.show();
|
||||||
|
Window window = getWindow();
|
||||||
|
if (window == null) return;
|
||||||
|
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
window.setGravity(Gravity.BOTTOM);
|
||||||
|
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
||||||
|
window.setDimAmount(0.32f);
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||||
|
window.setNavigationBarColor(ContextCompat.getColor(getContext(), R.color.device_preview_background));
|
||||||
|
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectRepeat(int days) {
|
||||||
|
repeatDays = days;
|
||||||
|
renderRepeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRepeat() {
|
||||||
|
binding.tvRepeatDaily.setSelected(repeatDays == REPEAT_DAILY);
|
||||||
|
binding.tvRepeatWeekdays.setSelected(repeatDays == REPEAT_WEEKDAYS);
|
||||||
|
binding.tvRepeatWeekends.setSelected(repeatDays == REPEAT_WEEKENDS);
|
||||||
|
binding.tvRepeatCustom.setSelected(repeatDays != REPEAT_DAILY
|
||||||
|
&& repeatDays != REPEAT_WEEKDAYS && repeatDays != REPEAT_WEEKENDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 自定义选择独立草稿,取消星期弹窗不会覆盖原来的重复规则。 */
|
||||||
|
private void showCustomDays() {
|
||||||
|
if (customDaysDialog != null && customDaysDialog.isShowing()) return;
|
||||||
|
Locale locale = getContext().getResources().getConfiguration().getLocales().get(0);
|
||||||
|
String[] weekdays = DateFormatSymbols.getInstance(locale).getWeekdays();
|
||||||
|
String[] labels = new String[7];
|
||||||
|
boolean[] selected = new boolean[7];
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
labels[i] = weekdays[i == 6 ? Calendar.SUNDAY : Calendar.MONDAY + i];
|
||||||
|
selected[i] = (repeatDays & (1 << i)) != 0;
|
||||||
|
}
|
||||||
|
customDaysDialog = new AlertDialog.Builder(getContext())
|
||||||
|
.setTitle(R.string.device_timer_repeat_custom)
|
||||||
|
.setMultiChoiceItems(labels, selected, (dialog, which, checked) -> selected[which] = checked)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.create();
|
||||||
|
customDaysDialog.setOnDismissListener(dialog -> customDaysDialog = null);
|
||||||
|
customDaysDialog.setOnShowListener(dialog -> customDaysDialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||||
|
.setOnClickListener(v -> {
|
||||||
|
int days = 0;
|
||||||
|
for (int i = 0; i < 7; i++) if (selected[i]) days |= 1 << i;
|
||||||
|
if (days == 0) {
|
||||||
|
ToastUtil.showShort(getContext(), getContext().getString(R.string.device_timer_repeat_required));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectRepeat(days);
|
||||||
|
customDaysDialog.dismiss();
|
||||||
|
}));
|
||||||
|
customDaysDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismiss() {
|
||||||
|
if (customDaysDialog != null) customDaysDialog.dismiss();
|
||||||
|
super.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.ckkj.griddle.device.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 设备数据预览;数值保留原始单位,格式化和图表样式由页面处理。 */
|
||||||
|
public class DeviceDataEntity {
|
||||||
|
private final boolean running;
|
||||||
|
private final int power;
|
||||||
|
private final int temperature;
|
||||||
|
private final float todayElectricity;
|
||||||
|
private final float todayCharcoal;
|
||||||
|
private final float todayRuntime;
|
||||||
|
private final String startTime;
|
||||||
|
private final List<TrendPoint> trend;
|
||||||
|
|
||||||
|
public DeviceDataEntity(boolean running, int power, int temperature,
|
||||||
|
float todayElectricity, float todayCharcoal, float todayRuntime,
|
||||||
|
String startTime, List<TrendPoint> trend) {
|
||||||
|
this.running = running;
|
||||||
|
this.power = power;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.todayElectricity = todayElectricity;
|
||||||
|
this.todayCharcoal = todayCharcoal;
|
||||||
|
this.todayRuntime = todayRuntime;
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.trend = Collections.unmodifiableList(new ArrayList<>(trend));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() { return running; }
|
||||||
|
public int getPower() { return power; }
|
||||||
|
public int getTemperature() { return temperature; }
|
||||||
|
public float getTodayElectricity() { return todayElectricity; }
|
||||||
|
public float getTodayCharcoal() { return todayCharcoal; }
|
||||||
|
public float getTodayRuntime() { return todayRuntime; }
|
||||||
|
public String getStartTime() { return startTime; }
|
||||||
|
public List<TrendPoint> getTrend() { return trend; }
|
||||||
|
|
||||||
|
/** 同一个月份的三项演示指标:温度 °C、平均功率 W、使用时长 min。 */
|
||||||
|
public static class TrendPoint {
|
||||||
|
private final int month;
|
||||||
|
private final float temperature;
|
||||||
|
private final float power;
|
||||||
|
private final float usageMinutes;
|
||||||
|
|
||||||
|
public TrendPoint(int month, float temperature, float power, float usageMinutes) {
|
||||||
|
this.month = month;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.power = power;
|
||||||
|
this.usageMinutes = usageMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMonth() { return month; }
|
||||||
|
public float getTemperature() { return temperature; }
|
||||||
|
public float getPower() { return power; }
|
||||||
|
public float getUsageMinutes() { return usageMinutes; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.ckkj.griddle.device.entity;
|
||||||
|
|
||||||
|
/** 设备信息页数据;日期保存时间戳,数值保留原始单位,由页面统一格式化。 */
|
||||||
|
public class DeviceInfoEntity {
|
||||||
|
private final long dataTime;
|
||||||
|
private final float todayElectricity;
|
||||||
|
private final float todayCharcoal;
|
||||||
|
private final float carbonReduction;
|
||||||
|
private final float electricitySaved;
|
||||||
|
private final boolean online;
|
||||||
|
private final String serialNumber;
|
||||||
|
private final String firmware;
|
||||||
|
private final float totalElectricity;
|
||||||
|
private final int totalRuntime;
|
||||||
|
private final long warrantyUntil;
|
||||||
|
private final long lastServiceTime;
|
||||||
|
|
||||||
|
public DeviceInfoEntity(long dataTime, float todayElectricity, float todayCharcoal,
|
||||||
|
float carbonReduction, float electricitySaved, boolean online,
|
||||||
|
String serialNumber, String firmware, float totalElectricity,
|
||||||
|
int totalRuntime, long warrantyUntil, long lastServiceTime) {
|
||||||
|
this.dataTime = dataTime;
|
||||||
|
this.todayElectricity = todayElectricity;
|
||||||
|
this.todayCharcoal = todayCharcoal;
|
||||||
|
this.carbonReduction = carbonReduction;
|
||||||
|
this.electricitySaved = electricitySaved;
|
||||||
|
this.online = online;
|
||||||
|
this.serialNumber = serialNumber;
|
||||||
|
this.firmware = firmware;
|
||||||
|
this.totalElectricity = totalElectricity;
|
||||||
|
this.totalRuntime = totalRuntime;
|
||||||
|
this.warrantyUntil = warrantyUntil;
|
||||||
|
this.lastServiceTime = lastServiceTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDataTime() { return dataTime; }
|
||||||
|
public float getTodayElectricity() { return todayElectricity; }
|
||||||
|
public float getTodayCharcoal() { return todayCharcoal; }
|
||||||
|
public float getCarbonReduction() { return carbonReduction; }
|
||||||
|
public float getElectricitySaved() { return electricitySaved; }
|
||||||
|
public boolean isOnline() { return online; }
|
||||||
|
public String getSerialNumber() { return serialNumber; }
|
||||||
|
public String getFirmware() { return firmware; }
|
||||||
|
public float getTotalElectricity() { return totalElectricity; }
|
||||||
|
public int getTotalRuntime() { return totalRuntime; }
|
||||||
|
public long getWarrantyUntil() { return warrantyUntil; }
|
||||||
|
public long getLastServiceTime() { return lastServiceTime; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.ckkj.griddle.device.entity;
|
||||||
|
|
||||||
|
/** 首页设备卡片数据;当前使用模拟数据,后续可替换为接口返回内容。 */
|
||||||
|
public class HomeDeviceEntity {
|
||||||
|
/** 模拟编号仅用于区分列表条目,不用于连接设备。 */
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
private final boolean online;
|
||||||
|
/** 当前功率,单位 W。 */
|
||||||
|
private final int power;
|
||||||
|
/** 当前温度,单位摄氏度。 */
|
||||||
|
private final int temperature;
|
||||||
|
|
||||||
|
public HomeDeviceEntity(String id, String name, boolean online, int power, int temperature) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.online = online;
|
||||||
|
this.power = power;
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() { return id; }
|
||||||
|
|
||||||
|
public String getName() { return name; }
|
||||||
|
|
||||||
|
public boolean isOnline() { return online; }
|
||||||
|
|
||||||
|
public int getPower() { return power; }
|
||||||
|
|
||||||
|
public int getTemperature() { return temperature; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ckkj.griddle.device.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.base.IView;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceDataEntity;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceInfoEntity;
|
||||||
|
|
||||||
|
/** 设备控制模块统一协议,供预览、设备数据和设备信息页面共用。 */
|
||||||
|
public final class DeviceControlContract {
|
||||||
|
private DeviceControlContract() { }
|
||||||
|
|
||||||
|
public interface CallBack<T> {
|
||||||
|
void success(T data);
|
||||||
|
void fail(String message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DataModel {
|
||||||
|
/** 获取设备即时指标和趋势数据,目前使用模拟数据。 */
|
||||||
|
void getDeviceData(boolean running, CallBack<DeviceDataEntity> callback);
|
||||||
|
|
||||||
|
/** 获取设备信息、今日统计和保修记录,目前使用模拟数据。 */
|
||||||
|
void getDeviceInfo(CallBack<DeviceInfoEntity> callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 各页面只重写自身使用的成功回调,避免添加其他页面的空实现。 */
|
||||||
|
public interface DeviceControlView extends IView {
|
||||||
|
default void getDeviceDataSuccess(DeviceDataEntity data) { }
|
||||||
|
|
||||||
|
default void getDeviceInfoSuccess(DeviceInfoEntity data) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.ckkj.griddle.device.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceDataEntity;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceInfoEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 设备控制模块共用数据层;目前仅用于演示,不执行真实设备查询和控制。 */
|
||||||
|
public class DeviceControlImpl implements DeviceControlContract.DataModel {
|
||||||
|
@Override
|
||||||
|
public void getDeviceData(boolean running,
|
||||||
|
DeviceControlContract.CallBack<DeviceDataEntity> callback) {
|
||||||
|
callback.success(createDemoData(running));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getDeviceInfo(DeviceControlContract.CallBack<DeviceInfoEntity> callback) {
|
||||||
|
// 序列号、固件版本、保修和维修日期均为设计稿示例,不代表真实设备状态。
|
||||||
|
long warrantyUntil = new GregorianCalendar(2027, Calendar.MARCH, 1).getTimeInMillis();
|
||||||
|
long lastService = new GregorianCalendar(2026, Calendar.AUGUST, 14).getTimeInMillis();
|
||||||
|
callback.success(new DeviceInfoEntity(System.currentTimeMillis(), 1.8f, 2.3f,
|
||||||
|
3.1f, 3.56f, true, "CHS-4F2A-0917", "V2.1.0",
|
||||||
|
156.8f, 320, warrantyUntil, lastService));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 最近五个月的固定示例曲线,避免每次重绘时随机变化。 */
|
||||||
|
private DeviceDataEntity createDemoData(boolean running) {
|
||||||
|
float[] temperature = {100, 120, 235, 95, 135};
|
||||||
|
float[] power = {155, 100, 205, 105, 145};
|
||||||
|
float[] usage = {150, 142, 118, 112, 138};
|
||||||
|
Calendar month = Calendar.getInstance();
|
||||||
|
month.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
month.add(Calendar.MONTH, -4);
|
||||||
|
List<DeviceDataEntity.TrendPoint> trend = new ArrayList<>();
|
||||||
|
for (int i = 0; i < temperature.length; i++) {
|
||||||
|
trend.add(new DeviceDataEntity.TrendPoint(month.get(Calendar.MONTH),
|
||||||
|
temperature[i], power[i], usage[i]));
|
||||||
|
month.add(Calendar.MONTH, 1);
|
||||||
|
}
|
||||||
|
// 停止演示仅将即时功率归零,历史统计和余温不随之清空。
|
||||||
|
return new DeviceDataEntity(running, running ? 1200 : 0, 185,
|
||||||
|
1.8f, 2.3f, 2.4f, "08:10", trend);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ckkj.griddle.device.mvp;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.base.BasePresenter;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceDataEntity;
|
||||||
|
import com.ckkj.griddle.device.entity.DeviceInfoEntity;
|
||||||
|
|
||||||
|
/** 设备控制模块共用协调层,每个页面创建自己的实例并绑定自身视图。 */
|
||||||
|
public class DeviceControlPresenter extends BasePresenter<DeviceControlContract.DeviceControlView> {
|
||||||
|
private final DeviceControlImpl mImpl;
|
||||||
|
|
||||||
|
public DeviceControlPresenter(DeviceControlImpl mImpl) {
|
||||||
|
this.mImpl = mImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDeviceData(boolean running) {
|
||||||
|
mImpl.getDeviceData(running, new DeviceControlContract.CallBack<DeviceDataEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(DeviceDataEntity data) {
|
||||||
|
if (getView() != null) getView().getDeviceDataSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getDeviceInfo() {
|
||||||
|
mImpl.getDeviceInfo(new DeviceControlContract.CallBack<DeviceInfoEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(DeviceInfoEntity data) {
|
||||||
|
if (getView() != null) getView().getDeviceInfoSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,9 +7,9 @@ import com.ckkj.griddle.base.BasePresenter;
|
|||||||
*/
|
*/
|
||||||
public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
public class DevicePresenter extends BasePresenter<DeviceContract.DeviceView> {
|
||||||
|
|
||||||
private final DeviceContract.DataModel impl;
|
private final DeviceImpl mImpl;
|
||||||
|
|
||||||
public DevicePresenter(DeviceContract.DataModel impl) {
|
public DevicePresenter(DeviceImpl mImpl) {
|
||||||
this.impl = impl;
|
this.mImpl = mImpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ckkj.griddle.mine;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -18,6 +19,8 @@ import com.ckkj.griddle.utils.show.ToastUtil;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
/** 新项目个人中心,业务入口保留独立 ID,后续接入对应页面。 */
|
/** 新项目个人中心,业务入口保留独立 ID,后续接入对应页面。 */
|
||||||
public class MineFragment extends BaseFragment<MineFragmentLayoutBinding, MinePresenter>
|
public class MineFragment extends BaseFragment<MineFragmentLayoutBinding, MinePresenter>
|
||||||
implements MineContract.MineView {
|
implements MineContract.MineView {
|
||||||
@@ -27,6 +30,27 @@ public class MineFragment extends BaseFragment<MineFragmentLayoutBinding, MinePr
|
|||||||
return new MinePresenter(new MineImpl());
|
return new MinePresenter(new MineImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.cv_mine_profile, R.id.ll_mine_devices, R.id.ll_credit_history})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.cv_mine_profile:
|
||||||
|
// 顶部整张个人资料卡片进入个人信息编辑页。
|
||||||
|
goTo(mContext, PersonalInfoActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_mine_devices:
|
||||||
|
goTo(mContext, MyDevicesActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_credit_history:
|
||||||
|
goTo(mContext, PointsHistoryActivity.class, null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initData(Bundle state) {
|
public void initData(Bundle state) {
|
||||||
viewBinding.tvMinePoints.setText(getString(R.string.mine_points, "0"));
|
viewBinding.tvMinePoints.setText(getString(R.string.mine_points, "0"));
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.ckkj.griddle.mine;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.databinding.MyDevicesLayoutBinding;
|
||||||
|
import com.ckkj.griddle.mine.adapter.MyDevicesAdapter;
|
||||||
|
import com.ckkj.griddle.mine.entity.MyDevicesEntity;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineContract;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineImpl;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MinePresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 我的设备:顶部汇总与设备在线状态列表,复用个人中心 MVP。 */
|
||||||
|
public class MyDevicesActivity extends BaseActivity<MyDevicesLayoutBinding, MinePresenter>
|
||||||
|
implements MineContract.MineView {
|
||||||
|
private MyDevicesAdapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinePresenter createPresenter() {
|
||||||
|
return new MinePresenter(new MineImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.my_devices_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
viewBinding.includeTitle.tvTitle.setTypeface(viewBinding.includeTitle.tvTitle.getTypeface(), Typeface.BOLD);
|
||||||
|
adapter = new MyDevicesAdapter();
|
||||||
|
viewBinding.rvMyDevices.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
viewBinding.rvMyDevices.setNestedScrollingEnabled(false);
|
||||||
|
viewBinding.rvMyDevices.setItemAnimator(null);
|
||||||
|
viewBinding.rvMyDevices.setAdapter(adapter);
|
||||||
|
mPresenter.getMyDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getMyDevicesSuccess(MyDevicesEntity data) {
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat count = NumberFormat.getIntegerInstance(locale);
|
||||||
|
NumberFormat reduction = NumberFormat.getNumberInstance(locale);
|
||||||
|
reduction.setMinimumFractionDigits(1);
|
||||||
|
reduction.setMaximumFractionDigits(1);
|
||||||
|
viewBinding.tvMyDevicesTotal.setText(count.format(data.getTotalCount()));
|
||||||
|
viewBinding.tvMyDevicesOnline.setText(count.format(data.getOnlineCount()));
|
||||||
|
viewBinding.tvMyDevicesOffline.setText(count.format(data.getOfflineCount()));
|
||||||
|
viewBinding.tvMyDevicesReduction.setText(getString(R.string.mine_devices_kg, reduction.format(data.getReductionKg())));
|
||||||
|
adapter.setNewData(new ArrayList<>(data.getDevices()));
|
||||||
|
viewBinding.tvMyDevicesEmpty.setVisibility(data.getDevices().isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用父类统一处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package com.ckkj.griddle.mine;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatDialog;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.databinding.DialogPersonalNicknameBinding;
|
||||||
|
|
||||||
|
/** 个人信息页的昵称弹窗,保存后回传本页草稿,不直接修改服务端资料。 */
|
||||||
|
public class NicknameEditDialog extends AppCompatDialog implements View.OnClickListener {
|
||||||
|
private final DialogPersonalNicknameBinding binding;
|
||||||
|
private final OnSaveListener listener;
|
||||||
|
|
||||||
|
public interface OnSaveListener {
|
||||||
|
void onSave(String nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NicknameEditDialog(Context context, String nickname, OnSaveListener listener) {
|
||||||
|
super(context, R.style.PersonalNicknameDialogTheme);
|
||||||
|
this.listener = listener;
|
||||||
|
binding = DialogPersonalNicknameBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
setCanceledOnTouchOutside(true);
|
||||||
|
binding.etNickname.setText(nickname == null ? "" : nickname);
|
||||||
|
binding.etNickname.setSelection(binding.etNickname.length());
|
||||||
|
binding.btnNicknameSave.setOnClickListener(this);
|
||||||
|
// 输入法的“完成”与保存按钮走同一个校验和回传流程。
|
||||||
|
binding.etNickname.setOnEditorActionListener((view, actionId, event) -> {
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||||
|
saveNickname();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.btn_nickname_save:
|
||||||
|
saveNickname();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveNickname() {
|
||||||
|
String nickname = binding.etNickname.getText().toString().trim();
|
||||||
|
if (TextUtils.isEmpty(nickname)) {
|
||||||
|
binding.etNickname.setError(getContext().getString(R.string.personal_info_nickname_required));
|
||||||
|
binding.etNickname.requestFocus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listener != null) listener.onSave(nickname);
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show() {
|
||||||
|
super.show();
|
||||||
|
Window window = getWindow();
|
||||||
|
if (window == null) return;
|
||||||
|
// 设计稿宽 322dp,窄屏保留两侧最少 24dp,键盘弹出时窗口随可用区域调整。
|
||||||
|
float density = getContext().getResources().getDisplayMetrics().density;
|
||||||
|
int availableWidth = getContext().getResources().getDisplayMetrics().widthPixels - Math.round(48 * density);
|
||||||
|
window.setLayout(Math.min(Math.round(322 * density), availableWidth),
|
||||||
|
WindowManager.LayoutParams.WRAP_CONTENT);
|
||||||
|
window.setGravity(Gravity.CENTER);
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||||||
|
window.setDimAmount(0.8f);
|
||||||
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
||||||
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
package com.ckkj.griddle.mine;
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.InputFilter;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Patterns;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.base.entity.UserInfoEntity;
|
||||||
|
import com.ckkj.griddle.databinding.PersonalInfoLayoutBinding;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineContract;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineImpl;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MinePresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 个人信息编辑页,复用 Mine MVP 读取资料;编辑内容暂为本页草稿。 */
|
||||||
|
public class PersonalInfoActivity extends BaseActivity<PersonalInfoLayoutBinding, MinePresenter>
|
||||||
|
implements MineContract.MineView {
|
||||||
|
private static final String STATE_NICKNAME = "personal_info_nickname";
|
||||||
|
private static final String STATE_PHONE = "personal_info_phone";
|
||||||
|
private static final String STATE_EMAIL = "personal_info_email";
|
||||||
|
private static final String STATE_AVATAR = "personal_info_avatar";
|
||||||
|
private String nickname = "";
|
||||||
|
private String phone = "";
|
||||||
|
private String email = "";
|
||||||
|
private String avatar = "";
|
||||||
|
private AlertDialog editDialog;
|
||||||
|
private NicknameEditDialog nicknameDialog;
|
||||||
|
|
||||||
|
// 系统图片选择器仅授予所选图片的访问权,无需申请整个相册权限。
|
||||||
|
private final ActivityResultLauncher<String> avatarLauncher = registerForActivityResult(
|
||||||
|
new ActivityResultContracts.GetContent(), uri -> {
|
||||||
|
if (uri != null) {
|
||||||
|
avatar = uri.toString();
|
||||||
|
renderAvatar();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinePresenter createPresenter() {
|
||||||
|
return new MinePresenter(new MineImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.personal_info_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
viewBinding.includeTitle.tvTitle.setTypeface(viewBinding.includeTitle.tvTitle.getTypeface(), Typeface.BOLD);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.personal_info_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
mPresenter.loadProfile();
|
||||||
|
} else {
|
||||||
|
// 页面重建时恢复用户尚未提交的编辑,避免重新读缓存覆盖草稿。
|
||||||
|
nickname = savedInstanceState.getString(STATE_NICKNAME, "");
|
||||||
|
phone = savedInstanceState.getString(STATE_PHONE, "");
|
||||||
|
email = savedInstanceState.getString(STATE_EMAIL, "");
|
||||||
|
avatar = savedInstanceState.getString(STATE_AVATAR, "");
|
||||||
|
renderProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showProfile(@Nullable UserInfoEntity userInfo) {
|
||||||
|
if (userInfo != null) {
|
||||||
|
nickname = safeText(TextUtils.isEmpty(userInfo.getNickname())
|
||||||
|
? userInfo.getUsername() : userInfo.getNickname());
|
||||||
|
phone = safeText(userInfo.getMobile());
|
||||||
|
email = safeText(userInfo.getEmail());
|
||||||
|
avatar = safeText(userInfo.getAvatar());
|
||||||
|
}
|
||||||
|
renderProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.cv_personal_avatar, R.id.tv_personal_avatar_hint,
|
||||||
|
R.id.ll_personal_nickname, R.id.ll_personal_phone, R.id.ll_personal_email,
|
||||||
|
R.id.btn_personal_save})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.cv_personal_avatar:
|
||||||
|
case R.id.tv_personal_avatar_hint:
|
||||||
|
selectAvatar();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_personal_nickname:
|
||||||
|
showNicknameEditor();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_personal_phone:
|
||||||
|
showEditor(R.id.ll_personal_phone);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.ll_personal_email:
|
||||||
|
showEditor(R.id.ll_personal_email);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.btn_personal_save:
|
||||||
|
// 尚未提供保存/绑定接口,不修改登录资料,也不模拟服务端保存成功。
|
||||||
|
ToastUtil.showShort(this, getString(R.string.personal_info_save_pending));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectAvatar() {
|
||||||
|
try {
|
||||||
|
avatarLauncher.launch("image/*");
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
showError(getString(R.string.personal_info_picker_unavailable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 昵称使用设计稿对应的居中自定义 Dialog,保存时回填本页草稿。 */
|
||||||
|
private void showNicknameEditor() {
|
||||||
|
if (nicknameDialog != null && nicknameDialog.isShowing()) return;
|
||||||
|
if (editDialog != null && editDialog.isShowing()) return;
|
||||||
|
nicknameDialog = new NicknameEditDialog(this, nickname, value -> {
|
||||||
|
nickname = value;
|
||||||
|
viewBinding.tvPersonalNickname.setText(nickname);
|
||||||
|
});
|
||||||
|
nicknameDialog.setOnDismissListener(dialog -> nicknameDialog = null);
|
||||||
|
nicknameDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 手机号和邮箱沿用通用编辑框,确认后仅更新本页草稿。 */
|
||||||
|
private void showEditor(int fieldId) {
|
||||||
|
if (editDialog != null && editDialog.isShowing()) return;
|
||||||
|
if (nicknameDialog != null && nicknameDialog.isShowing()) return;
|
||||||
|
boolean isPhone = fieldId == R.id.ll_personal_phone;
|
||||||
|
EditText input = new EditText(this);
|
||||||
|
input.setSingleLine(true);
|
||||||
|
input.setInputType(isPhone ? InputType.TYPE_CLASS_PHONE
|
||||||
|
: InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||||
|
input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(isPhone ? 32 : 254)});
|
||||||
|
input.setText(isPhone ? phone : email);
|
||||||
|
input.setSelection(input.length());
|
||||||
|
int inset = Math.round(24 * getResources().getDisplayMetrics().density);
|
||||||
|
int title = isPhone ? R.string.personal_info_phone : R.string.personal_info_email;
|
||||||
|
input.setHint(title);
|
||||||
|
editDialog = new AlertDialog.Builder(this)
|
||||||
|
.setTitle(title)
|
||||||
|
.setView(input, inset, inset / 2, inset, 0)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.create();
|
||||||
|
editDialog.setOnShowListener(dialog -> {
|
||||||
|
// 对话框专用按钮回调,校验失败时保留输入内容。
|
||||||
|
editDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> {
|
||||||
|
String value = input.getText().toString().trim();
|
||||||
|
if (isPhone && !TextUtils.isEmpty(value) && !value.matches("\\+?[0-9]{6,15}")) {
|
||||||
|
input.setError(getString(R.string.personal_info_phone_invalid));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isPhone && !TextUtils.isEmpty(value)
|
||||||
|
&& !Patterns.EMAIL_ADDRESS.matcher(value).matches()) {
|
||||||
|
input.setError(getString(R.string.personal_info_email_invalid));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPhone) phone = value;
|
||||||
|
else email = value;
|
||||||
|
renderProfile();
|
||||||
|
editDialog.dismiss();
|
||||||
|
});
|
||||||
|
input.requestFocus();
|
||||||
|
if (editDialog.getWindow() != null) {
|
||||||
|
editDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderProfile() {
|
||||||
|
viewBinding.tvPersonalNickname.setText(nickname);
|
||||||
|
viewBinding.tvPersonalPhone.setText(phone);
|
||||||
|
viewBinding.tvPersonalEmail.setText(email);
|
||||||
|
renderAvatar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderAvatar() {
|
||||||
|
Glide.with(this).load(TextUtils.isEmpty(avatar) ? null : Uri.parse(avatar))
|
||||||
|
.placeholder(R.mipmap.icon_mine_user_head_defaul)
|
||||||
|
.error(R.mipmap.icon_mine_user_head_defaul).circleCrop()
|
||||||
|
.into(viewBinding.ivPersonalAvatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String safeText(String text) {
|
||||||
|
return text == null ? "" : text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putString(STATE_NICKNAME, nickname);
|
||||||
|
outState.putString(STATE_PHONE, phone);
|
||||||
|
outState.putString(STATE_EMAIL, email);
|
||||||
|
outState.putString(STATE_AVATAR, avatar);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (nicknameDialog != null) nicknameDialog.dismiss();
|
||||||
|
if (editDialog != null) editDialog.dismiss();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
if (!TextUtils.isEmpty(message)) ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用 BaseActivity 的统一处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package com.ckkj.griddle.mine;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.base.BaseActivity;
|
||||||
|
import com.ckkj.griddle.databinding.PointsHistoryLayoutBinding;
|
||||||
|
import com.ckkj.griddle.main.activity.MainActivity;
|
||||||
|
import com.ckkj.griddle.mine.adapter.PointsHistoryMonthAdapter;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineContract;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MineImpl;
|
||||||
|
import com.ckkj.griddle.mine.mvp.MinePresenter;
|
||||||
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
|
import com.ckkj.griddle.utils.show.ToastUtil;
|
||||||
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
/** 历史积分记录:可用余额、收支筛选及月份分组,余额不随筛选变化。 */
|
||||||
|
public class PointsHistoryActivity extends BaseActivity<PointsHistoryLayoutBinding, MinePresenter>
|
||||||
|
implements MineContract.MineView {
|
||||||
|
private static final String STATE_FILTER = "points_history_filter";
|
||||||
|
private PointsHistoryEntity.Filter filter = PointsHistoryEntity.Filter.ALL;
|
||||||
|
private PointsHistoryMonthAdapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MinePresenter createPresenter() {
|
||||||
|
return new MinePresenter(new MineImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLayoutResId(Bundle savedInstanceState) {
|
||||||
|
return R.layout.points_history_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData(Bundle savedInstanceState) {
|
||||||
|
super.initData(savedInstanceState);
|
||||||
|
ImmersionBar.with(this).statusBarColor(R.color.device_preview_background)
|
||||||
|
.statusBarDarkFont(true).init();
|
||||||
|
viewBinding.includeTitle.tvTitle.setTypeface(viewBinding.includeTitle.tvTitle.getTypeface(), Typeface.BOLD);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
int value = savedInstanceState.getInt(STATE_FILTER, 0);
|
||||||
|
filter = PointsHistoryEntity.Filter.values()[Math.max(0,
|
||||||
|
Math.min(PointsHistoryEntity.Filter.values().length - 1, value))];
|
||||||
|
}
|
||||||
|
adapter = new PointsHistoryMonthAdapter();
|
||||||
|
viewBinding.rvPointsHistory.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
viewBinding.rvPointsHistory.setNestedScrollingEnabled(false);
|
||||||
|
viewBinding.rvPointsHistory.setItemAnimator(null);
|
||||||
|
viewBinding.rvPointsHistory.setAdapter(adapter);
|
||||||
|
renderFilter();
|
||||||
|
mPresenter.getPointsHistory(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnClick({R.id.img_back, R.id.btn_history_redeem, R.id.tv_history_all,
|
||||||
|
R.id.tv_history_earned, R.id.tv_history_spent})
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.img_back:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
case R.id.btn_history_redeem:
|
||||||
|
// 复用首页已有的商城定位参数,仅跳转商城,不执行兑换交易。
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putBoolean("goto_index_fragment", true);
|
||||||
|
goTo(mContext, MainActivity.class, bundle);
|
||||||
|
break;
|
||||||
|
case R.id.tv_history_all:
|
||||||
|
selectFilter(PointsHistoryEntity.Filter.ALL);
|
||||||
|
break;
|
||||||
|
case R.id.tv_history_earned:
|
||||||
|
selectFilter(PointsHistoryEntity.Filter.EARNED);
|
||||||
|
break;
|
||||||
|
case R.id.tv_history_spent:
|
||||||
|
selectFilter(PointsHistoryEntity.Filter.SPENT);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectFilter(PointsHistoryEntity.Filter selected) {
|
||||||
|
if (filter == selected) return;
|
||||||
|
filter = selected;
|
||||||
|
renderFilter();
|
||||||
|
mPresenter.getPointsHistory(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderFilter() {
|
||||||
|
viewBinding.tvHistoryAll.setSelected(filter == PointsHistoryEntity.Filter.ALL);
|
||||||
|
viewBinding.tvHistoryEarned.setSelected(filter == PointsHistoryEntity.Filter.EARNED);
|
||||||
|
viewBinding.tvHistorySpent.setSelected(filter == PointsHistoryEntity.Filter.SPENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPointsHistorySuccess(PointsHistoryEntity data) {
|
||||||
|
// 后续异步请求返回时,旧筛选结果不覆盖当前列表。
|
||||||
|
if (data.getFilter() != filter) return;
|
||||||
|
Locale locale = getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat number = NumberFormat.getNumberInstance(locale);
|
||||||
|
number.setMinimumFractionDigits(2);
|
||||||
|
number.setMaximumFractionDigits(2);
|
||||||
|
viewBinding.tvHistoryBalance.setText(getString(R.string.mine_history_balance_value,
|
||||||
|
number.format(data.getAvailablePoints())));
|
||||||
|
adapter.setNewData(new ArrayList<>(data.getMonths()));
|
||||||
|
viewBinding.tvHistoryEmpty.setVisibility(data.getMonths().isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
outState.putInt(STATE_FILTER, filter.ordinal());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showError(String message) {
|
||||||
|
ToastUtil.showShort(this, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut(BaseBean bean) {
|
||||||
|
// 登录失效沿用父类统一处理。
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.ckkj.griddle.mine.adapter;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.mine.entity.MyDevicesEntity;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 我的设备卡片,复用时完整重置在线/离线颜色、图标及最近减排日期。 */
|
||||||
|
public class MyDevicesAdapter extends BaseQuickAdapter<MyDevicesEntity.Device, BaseViewHolder> {
|
||||||
|
public MyDevicesAdapter() {
|
||||||
|
super(R.layout.item_my_device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, MyDevicesEntity.Device item) {
|
||||||
|
boolean online = item.isOnline();
|
||||||
|
int color = ContextCompat.getColor(mContext, online ? R.color.mine_device_green : R.color.device_home_orange);
|
||||||
|
helper.setText(R.id.tv_my_device_name, TextUtils.isEmpty(item.getName())
|
||||||
|
? mContext.getString(R.string.mine_devices_default_name) : item.getName());
|
||||||
|
helper.setText(R.id.tv_my_device_status, mContext.getString(online
|
||||||
|
? R.string.mine_devices_online : R.string.mine_devices_offline));
|
||||||
|
helper.setTextColor(R.id.tv_my_device_status, color);
|
||||||
|
helper.getView(R.id.tv_my_device_status).setBackgroundResource(online
|
||||||
|
? R.drawable.mine_device_online_pill : R.drawable.mine_device_offline_pill);
|
||||||
|
ImageView icon = helper.getView(R.id.iv_my_device);
|
||||||
|
icon.setImageResource(online ? R.drawable.ic_mine_device_online : R.drawable.ic_mine_device_offline);
|
||||||
|
icon.setBackgroundResource(online ? R.drawable.mine_device_online_bg : R.drawable.mine_device_offline_bg);
|
||||||
|
|
||||||
|
Locale locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
NumberFormat number = NumberFormat.getNumberInstance(locale);
|
||||||
|
number.setMinimumFractionDigits(2);
|
||||||
|
number.setMaximumFractionDigits(2);
|
||||||
|
String label = mContext.getString(item.isReductionToday()
|
||||||
|
? R.string.mine_devices_today_reduction : R.string.mine_devices_yesterday_reduction);
|
||||||
|
String amount = mContext.getString(R.string.mine_devices_kg, number.format(item.getRecentReductionKg()));
|
||||||
|
SpannableStringBuilder summary = new SpannableStringBuilder(label).append(" ");
|
||||||
|
int start = summary.length();
|
||||||
|
summary.append(amount);
|
||||||
|
summary.setSpan(new ForegroundColorSpan(color), start, summary.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
summary.setSpan(new StyleSpan(Typeface.BOLD), start, summary.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
helper.setText(R.id.tv_my_device_reduction, summary);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.ckkj.griddle.mine.adapter;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/** 月份分组保留独立白色卡片,月内列表关闭嵌套滚动,整页统一滚动。 */
|
||||||
|
public class PointsHistoryMonthAdapter extends BaseQuickAdapter<PointsHistoryEntity.MonthGroup, BaseViewHolder> {
|
||||||
|
public PointsHistoryMonthAdapter() {
|
||||||
|
super(R.layout.item_points_history_month);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, PointsHistoryEntity.MonthGroup item) {
|
||||||
|
helper.setText(R.id.tv_history_month, item.getMonth());
|
||||||
|
RecyclerView records = helper.getView(R.id.rv_history_month_records);
|
||||||
|
PointsHistoryRecordAdapter adapter = (PointsHistoryRecordAdapter) records.getAdapter();
|
||||||
|
if (adapter == null) {
|
||||||
|
adapter = new PointsHistoryRecordAdapter();
|
||||||
|
records.setLayoutManager(new LinearLayoutManager(mContext));
|
||||||
|
records.setNestedScrollingEnabled(false);
|
||||||
|
records.setItemAnimator(null);
|
||||||
|
records.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
adapter.setNewData(new ArrayList<>(item.getRecords()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.ckkj.griddle.mine.adapter;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 月内积分流水,收入为绿色,支出为深色,末行隐藏分隔线。 */
|
||||||
|
public class PointsHistoryRecordAdapter extends BaseQuickAdapter<PointsHistoryEntity.Record, BaseViewHolder> {
|
||||||
|
public PointsHistoryRecordAdapter() {
|
||||||
|
super(R.layout.item_points_history_record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, PointsHistoryEntity.Record item) {
|
||||||
|
boolean earned = item.getPoints() > 0;
|
||||||
|
Locale locale = mContext.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
helper.setText(R.id.tv_history_record_type, mContext.getString(earned
|
||||||
|
? R.string.mine_history_earned : R.string.mine_history_spent));
|
||||||
|
helper.setText(R.id.tv_history_record_date, new SimpleDateFormat("yyyy-M-dd HH:mm:ss", locale)
|
||||||
|
.format(new Date(item.getTimestamp())));
|
||||||
|
String amount = NumberFormat.getIntegerInstance(locale).format(Math.abs((long) item.getPoints()));
|
||||||
|
helper.setText(R.id.tv_history_record_amount, (earned ? "+" : "−") + amount);
|
||||||
|
helper.setTextColor(R.id.tv_history_record_amount, ContextCompat.getColor(mContext,
|
||||||
|
earned ? R.color.mine_device_green : R.color.mine_history_amount));
|
||||||
|
helper.getView(R.id.view_history_record_divider).setVisibility(
|
||||||
|
helper.getLayoutPosition() - getHeaderLayoutCount() == getData().size() - 1
|
||||||
|
? View.INVISIBLE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.ckkj.griddle.mine.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 我的设备汇总与列表,减排单位 kg;汇总和单台最近日数据采用各自统计口径。 */
|
||||||
|
public class MyDevicesEntity {
|
||||||
|
private final double reductionKg;
|
||||||
|
private final List<Device> devices;
|
||||||
|
|
||||||
|
public MyDevicesEntity(double reductionKg, List<Device> devices) {
|
||||||
|
this.reductionKg = reductionKg;
|
||||||
|
this.devices = Collections.unmodifiableList(new ArrayList<>(devices));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getReductionKg() { return reductionKg; }
|
||||||
|
public List<Device> getDevices() { return devices; }
|
||||||
|
public int getTotalCount() { return devices.size(); }
|
||||||
|
public int getOnlineCount() {
|
||||||
|
int online = 0;
|
||||||
|
for (Device device : devices) if (device.isOnline()) online++;
|
||||||
|
return online;
|
||||||
|
}
|
||||||
|
public int getOfflineCount() { return getTotalCount() - getOnlineCount(); }
|
||||||
|
|
||||||
|
public static class Device {
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
private final boolean online;
|
||||||
|
private final double recentReductionKg;
|
||||||
|
private final boolean reductionToday;
|
||||||
|
|
||||||
|
public Device(String id, String name, boolean online, double recentReductionKg, boolean reductionToday) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.online = online;
|
||||||
|
this.recentReductionKg = recentReductionKg;
|
||||||
|
this.reductionToday = reductionToday;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() { return id; }
|
||||||
|
public String getName() { return name; }
|
||||||
|
public boolean isOnline() { return online; }
|
||||||
|
public double getRecentReductionKg() { return recentReductionKg; }
|
||||||
|
public boolean isReductionToday() { return reductionToday; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.ckkj.griddle.mine.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 历史积分记录:余额独立于筛选,月份及组内流水均按时间倒序返回。 */
|
||||||
|
public class PointsHistoryEntity {
|
||||||
|
public enum Filter { ALL, EARNED, SPENT }
|
||||||
|
|
||||||
|
private final int availablePoints;
|
||||||
|
private final Filter filter;
|
||||||
|
private final List<MonthGroup> months;
|
||||||
|
|
||||||
|
public PointsHistoryEntity(int availablePoints, Filter filter, List<MonthGroup> months) {
|
||||||
|
this.availablePoints = availablePoints;
|
||||||
|
this.filter = filter;
|
||||||
|
this.months = Collections.unmodifiableList(new ArrayList<>(months));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAvailablePoints() { return availablePoints; }
|
||||||
|
public Filter getFilter() { return filter; }
|
||||||
|
public List<MonthGroup> getMonths() { return months; }
|
||||||
|
|
||||||
|
public static class MonthGroup {
|
||||||
|
private final String month;
|
||||||
|
private final List<Record> records;
|
||||||
|
|
||||||
|
public MonthGroup(String month, List<Record> records) {
|
||||||
|
this.month = month;
|
||||||
|
this.records = Collections.unmodifiableList(new ArrayList<>(records));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMonth() { return month; }
|
||||||
|
public List<Record> getRecords() { return records; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Record {
|
||||||
|
private final long id;
|
||||||
|
private final long timestamp;
|
||||||
|
private final int points;
|
||||||
|
|
||||||
|
public Record(long id, long timestamp, int points) {
|
||||||
|
this.id = id;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() { return id; }
|
||||||
|
public long getTimestamp() { return timestamp; }
|
||||||
|
public int getPoints() { return points; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import com.ckkj.griddle.base.IView;
|
import com.ckkj.griddle.base.IView;
|
||||||
import com.ckkj.griddle.base.entity.UserInfoEntity;
|
import com.ckkj.griddle.base.entity.UserInfoEntity;
|
||||||
|
import com.ckkj.griddle.mine.entity.MyDevicesEntity;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
|
|
||||||
/** 个人中心页面与数据层协议。 */
|
/** 个人中心页面与数据层协议。 */
|
||||||
public class MineContract {
|
public class MineContract {
|
||||||
@@ -17,9 +19,19 @@ public class MineContract {
|
|||||||
public interface DataModel {
|
public interface DataModel {
|
||||||
@Nullable
|
@Nullable
|
||||||
UserInfoEntity getCachedProfile();
|
UserInfoEntity getCachedProfile();
|
||||||
|
|
||||||
|
/** 获取我的设备列表与汇总,目前使用设计稿演示数据。 */
|
||||||
|
void getMyDevices(CallBack<MyDevicesEntity> callback);
|
||||||
|
|
||||||
|
/** 按收入/支出筛选积分流水并保留月份分组。 */
|
||||||
|
void getPointsHistory(PointsHistoryEntity.Filter filter, CallBack<PointsHistoryEntity> callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MineView extends IView {
|
public interface MineView extends IView {
|
||||||
void showProfile(@Nullable UserInfoEntity userInfo);
|
default void showProfile(@Nullable UserInfoEntity userInfo) { }
|
||||||
|
|
||||||
|
default void getMyDevicesSuccess(MyDevicesEntity data) { }
|
||||||
|
|
||||||
|
default void getPointsHistorySuccess(PointsHistoryEntity data) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,59 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import com.ckkj.griddle.AppConfig;
|
import com.ckkj.griddle.AppConfig;
|
||||||
import com.ckkj.griddle.base.entity.UserInfoEntity;
|
import com.ckkj.griddle.base.entity.UserInfoEntity;
|
||||||
|
import com.ckkj.griddle.mine.entity.MyDevicesEntity;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
import com.ckkj.griddle.utils.manager.MingDengUserInfoManager;
|
import com.ckkj.griddle.utils.manager.MingDengUserInfoManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/** 读取已缓存的用户资料,后续在此接入新个人中心接口。 */
|
/** 读取已缓存的用户资料,后续在此接入新个人中心接口。 */
|
||||||
public class MineImpl implements MineContract.DataModel {
|
public class MineImpl implements MineContract.DataModel {
|
||||||
|
@Override
|
||||||
|
public void getMyDevices(MineContract.CallBack<MyDevicesEntity> callback) {
|
||||||
|
// 仅用于布局演示,不代表已绑定真实设备;空名称由界面使用本地化默认名称。
|
||||||
|
List<MyDevicesEntity.Device> devices = Arrays.asList(
|
||||||
|
new MyDevicesEntity.Device("demo-mine-1", "", true, 1.24, true),
|
||||||
|
new MyDevicesEntity.Device("demo-mine-2", "", true, 1.24, true),
|
||||||
|
new MyDevicesEntity.Device("demo-mine-3", "", false, 1.24, false));
|
||||||
|
// 汇总值与日数据分别采用设计稿示例,后续由真实统计接口提供。
|
||||||
|
callback.success(new MyDevicesEntity(3.6, devices));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPointsHistory(PointsHistoryEntity.Filter filter,
|
||||||
|
MineContract.CallBack<PointsHistoryEntity> callback) {
|
||||||
|
if (filter == null) {
|
||||||
|
callback.fail("积分筛选条件不能为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<PointsHistoryEntity.MonthGroup> months = new ArrayList<>();
|
||||||
|
int[] points = {-200, -200, 200, 200};
|
||||||
|
// 演示 2026 年 9 月、8 月的流水;日期归属实际月份,不照抄稿中重复的 9 月日期。
|
||||||
|
for (int month : new int[]{Calendar.SEPTEMBER, Calendar.AUGUST}) {
|
||||||
|
List<PointsHistoryEntity.Record> records = new ArrayList<>();
|
||||||
|
long timestamp = new GregorianCalendar(2026, month, 28, 10, 50, 24).getTimeInMillis();
|
||||||
|
for (int i = 0; i < points.length; i++) {
|
||||||
|
if (filter == PointsHistoryEntity.Filter.ALL
|
||||||
|
|| (filter == PointsHistoryEntity.Filter.EARNED && points[i] > 0)
|
||||||
|
|| (filter == PointsHistoryEntity.Filter.SPENT && points[i] < 0)) {
|
||||||
|
records.add(new PointsHistoryEntity.Record((month + 1) * 10L + i, timestamp, points[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!records.isEmpty()) {
|
||||||
|
months.add(new PointsHistoryEntity.MonthGroup(
|
||||||
|
String.format(Locale.ROOT, "2026-%02d", month + 1), records));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 两个月流水净额为 0,期初与当前可用余额均为 200,余额不随筛选变化。
|
||||||
|
callback.success(new PointsHistoryEntity(200, filter, months));
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public UserInfoEntity getCachedProfile() {
|
public UserInfoEntity getCachedProfile() {
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package com.ckkj.griddle.mine.mvp;
|
package com.ckkj.griddle.mine.mvp;
|
||||||
|
|
||||||
import com.ckkj.griddle.base.BasePresenter;
|
import com.ckkj.griddle.base.BasePresenter;
|
||||||
|
import com.ckkj.griddle.mine.entity.MyDevicesEntity;
|
||||||
|
import com.ckkj.griddle.mine.entity.PointsHistoryEntity;
|
||||||
|
|
||||||
/** 个人中心业务协调层。 */
|
/** 个人中心业务协调层。 */
|
||||||
public class MinePresenter extends BasePresenter<MineContract.MineView> {
|
public class MinePresenter extends BasePresenter<MineContract.MineView> {
|
||||||
private final MineContract.DataModel impl;
|
private final MineImpl impl;
|
||||||
|
|
||||||
public MinePresenter(MineContract.DataModel impl) {
|
public MinePresenter(MineImpl impl) {
|
||||||
this.impl = impl;
|
this.impl = impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,4 +17,32 @@ public class MinePresenter extends BasePresenter<MineContract.MineView> {
|
|||||||
getView().showProfile(impl.getCachedProfile());
|
getView().showProfile(impl.getCachedProfile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getMyDevices() {
|
||||||
|
impl.getMyDevices(new MineContract.CallBack<MyDevicesEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(MyDevicesEntity data) {
|
||||||
|
if (getView() != null) getView().getMyDevicesSuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPointsHistory(PointsHistoryEntity.Filter filter) {
|
||||||
|
impl.getPointsHistory(filter, new MineContract.CallBack<PointsHistoryEntity>() {
|
||||||
|
@Override
|
||||||
|
public void success(PointsHistoryEntity data) {
|
||||||
|
if (getView() != null) getView().getPointsHistorySuccess(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fail(String message) {
|
||||||
|
if (getView() != null) getView().showError(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.ckkj.griddle.plate.entity.BaziSaveSuccessEntity;
|
|||||||
import com.ckkj.griddle.plate.entity.PaipanHistoryEntity;
|
import com.ckkj.griddle.plate.entity.PaipanHistoryEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsPageEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -106,5 +107,11 @@ public interface Request {
|
|||||||
*/
|
*/
|
||||||
@GET("app/elicacy/categories")
|
@GET("app/elicacy/categories")
|
||||||
Observable<BaseBean<List<ShopCategoryEntity>>> getShopCategories(@HeaderMap Map<String, String> headMap);
|
Observable<BaseBean<List<ShopCategoryEntity>>> getShopCategories(@HeaderMap Map<String, String> headMap);
|
||||||
|
/**
|
||||||
|
* 按分类分页查询商品,参数包含 categoryId、page 和 size。
|
||||||
|
*/
|
||||||
|
@GET("app/elicacy/list")
|
||||||
|
Observable<BaseBean<ShopGoodsPageEntity>> getShopGoods(@HeaderMap Map<String, String> headMap,
|
||||||
|
@QueryMap Map<String, Object> map);
|
||||||
/***************************钱包********************************/
|
/***************************钱包********************************/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.ckkj.griddle.shop.adapter.ShopCategoryAdapter;
|
|||||||
import com.ckkj.griddle.shop.adapter.ShopFoodAdapter;
|
import com.ckkj.griddle.shop.adapter.ShopFoodAdapter;
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsPageEntity;
|
||||||
import com.ckkj.griddle.shop.mvp.ShopContract;
|
import com.ckkj.griddle.shop.mvp.ShopContract;
|
||||||
import com.ckkj.griddle.shop.mvp.ShopImpl;
|
import com.ckkj.griddle.shop.mvp.ShopImpl;
|
||||||
import com.ckkj.griddle.shop.mvp.ShopPresenter;
|
import com.ckkj.griddle.shop.mvp.ShopPresenter;
|
||||||
@@ -40,9 +42,9 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
private static final long BANNER_SWITCH_INTERVAL = 3500L;
|
private static final long BANNER_SWITCH_INTERVAL = 3500L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商城首页下拉刷新时等待的网络请求数量。
|
* 分类商品列表默认加载第一页,每页 20 条。
|
||||||
*/
|
*/
|
||||||
private static final int SHOP_NETWORK_REQUEST_COUNT = 2;
|
private static final int SHOP_GOODS_PAGE_SIZE = 20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用主线程 Handler 控制 Banner 自动轮播。
|
* 使用主线程 Handler 控制 Banner 自动轮播。
|
||||||
@@ -71,17 +73,19 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
private ShopFoodAdapter breakfastAdapter;
|
private ShopFoodAdapter breakfastAdapter;
|
||||||
private ShopFoodAdapter recommendationAdapter;
|
private ShopFoodAdapter recommendationAdapter;
|
||||||
/**
|
/**
|
||||||
* 保存商品分类接口结果,当前暂不用于页面展示。
|
* 当前选中分类的真实 ID,下拉刷新后尽量保持选中项。
|
||||||
*/
|
*/
|
||||||
private List<ShopCategoryEntity> shopCategories = Collections.emptyList();
|
private Long selectedCategoryId;
|
||||||
/**
|
/**
|
||||||
* 标记当前是否由用户下拉触发了数据刷新。
|
* 标记当前是否由用户下拉触发了数据刷新。
|
||||||
*/
|
*/
|
||||||
private boolean shopRefreshing;
|
private boolean shopRefreshing;
|
||||||
/**
|
/**
|
||||||
* 当前仍未结束的商城网络请求数量。
|
* 分别跟踪三个请求,分类返回后新增的商品请求也要参与下拉刷新。
|
||||||
*/
|
*/
|
||||||
private int pendingShopRequests;
|
private boolean bannersLoading;
|
||||||
|
private boolean categoriesLoading;
|
||||||
|
private boolean goodsLoading;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShopPresenter createPresenter() {
|
public ShopPresenter createPresenter() {
|
||||||
@@ -90,9 +94,11 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initData(Bundle state) {
|
public void initData(Bundle state) {
|
||||||
|
selectedCategoryId = null;
|
||||||
initRecyclerViews();
|
initRecyclerViews();
|
||||||
initBanner();
|
initBanner();
|
||||||
initRefresh();
|
initRefresh();
|
||||||
|
viewBinding.tvFoodSectionTitle.setText("");
|
||||||
loadShopData();
|
loadShopData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +115,15 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
viewBinding.rvFoodRecommend.setLayoutManager(new GridLayoutManager(mContext, 2));
|
viewBinding.rvFoodRecommend.setLayoutManager(new GridLayoutManager(mContext, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryAdapter = new ShopCategoryAdapter(this::showCategory);
|
categoryAdapter = new ShopCategoryAdapter();
|
||||||
|
categoryAdapter.setOnItemClickListener((adapter, view, position) -> {
|
||||||
|
// 重复点击当前分类不重复请求,切换分类后保持选中高亮并重新加载商品。
|
||||||
|
if (position == categoryAdapter.getSelectedPosition()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
categoryAdapter.select(position);
|
||||||
|
showCategory(categoryAdapter.getItem(position));
|
||||||
|
});
|
||||||
breakfastAdapter = new ShopFoodAdapter(R.layout.food_breakfast_item);
|
breakfastAdapter = new ShopFoodAdapter(R.layout.food_breakfast_item);
|
||||||
recommendationAdapter = new ShopFoodAdapter(R.layout.food_recommend_item);
|
recommendationAdapter = new ShopFoodAdapter(R.layout.food_recommend_item);
|
||||||
viewBinding.rvFoodCategories.setAdapter(categoryAdapter);
|
viewBinding.rvFoodCategories.setAdapter(categoryAdapter);
|
||||||
@@ -133,13 +147,15 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载商城 Banner 和页面内容。
|
* 加载 Banner 和真实分类,再由分类结果触发商品列表请求。
|
||||||
*/
|
*/
|
||||||
private void loadShopData() {
|
private void loadShopData() {
|
||||||
pendingShopRequests = SHOP_NETWORK_REQUEST_COUNT;
|
mPresenter.cancelGoodsRequest();
|
||||||
mPresenter.loadContent();
|
bannersLoading = true;
|
||||||
mPresenter.getShopCategories();
|
categoriesLoading = true;
|
||||||
|
goodsLoading = false;
|
||||||
mPresenter.getShopBanners();
|
mPresenter.getShopBanners();
|
||||||
|
mPresenter.getShopCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,22 +168,28 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每完成一个网络请求就更新计数,全部结束后收起下拉刷新头。
|
* 分类请求可能继续触发商品请求,必须等待最新请求全部结束后收起刷新头。
|
||||||
*/
|
*/
|
||||||
private void completeShopNetworkRequest() {
|
private void finishShopRefreshIfReady() {
|
||||||
if (!shopRefreshing) {
|
if (!shopRefreshing || bannersLoading || categoriesLoading || goodsLoading) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (pendingShopRequests > 0) {
|
|
||||||
pendingShopRequests--;
|
|
||||||
}
|
|
||||||
if (pendingShopRequests > 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shopRefreshing = false;
|
shopRefreshing = false;
|
||||||
if (viewBinding != null) {
|
if (viewBinding != null) {
|
||||||
viewBinding.refreshShop.finishRefresh(300);
|
viewBinding.refreshShop.finishRefresh(300);
|
||||||
}
|
}
|
||||||
|
startBannerAutoPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShopRequestFinished(ShopContract.RequestType type) {
|
||||||
|
switch (type) {
|
||||||
|
case BANNERS: bannersLoading = false; break;
|
||||||
|
case CATEGORIES: categoriesLoading = false; break;
|
||||||
|
case GOODS: goodsLoading = false; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
finishShopRefreshIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -176,48 +198,67 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
List<ShopBannerEntity> bannerList = banners == null
|
List<ShopBannerEntity> bannerList = banners == null
|
||||||
? Collections.emptyList()
|
? Collections.emptyList()
|
||||||
: banners;
|
: banners;
|
||||||
bannerAdapter.submitList(bannerList);
|
bannerAdapter.setNewData(bannerList);
|
||||||
if (!bannerList.isEmpty()) {
|
if (!bannerList.isEmpty()) {
|
||||||
// 新数据到达后从第一张开始展示。
|
// 新数据到达后从第一张开始展示。
|
||||||
viewBinding.vpFoodBanner.setCurrentItem(0, false);
|
viewBinding.vpFoodBanner.setCurrentItem(0, false);
|
||||||
}
|
}
|
||||||
startBannerAutoPlay();
|
startBannerAutoPlay();
|
||||||
completeShopNetworkRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getShopCategoriesSuccess(List<ShopCategoryEntity> categories) {
|
public void getShopCategoriesSuccess(List<ShopCategoryEntity> categories) {
|
||||||
// 暂不展示商品分类,只保存接口返回结果,后续接入分类 UI 时直接使用。
|
List<ShopCategoryEntity> categoryList = categories == null
|
||||||
shopCategories = categories == null ? Collections.emptyList() : categories;
|
? Collections.emptyList() : categories;
|
||||||
completeShopNetworkRequest();
|
categoryAdapter.setNewData(categoryList);
|
||||||
}
|
if (categoryList.isEmpty()) {
|
||||||
|
selectedCategoryId = null;
|
||||||
@Override
|
mPresenter.cancelGoodsRequest();
|
||||||
public void showShopContent(ShopContract.ShopContent content) {
|
goodsLoading = false;
|
||||||
if (content == null) {
|
viewBinding.tvFoodSectionTitle.setText("");
|
||||||
categoryAdapter.submitList(Collections.emptyList());
|
showGoods(Collections.emptyList());
|
||||||
breakfastAdapter.submitList(Collections.emptyList());
|
|
||||||
recommendationAdapter.submitList(Collections.emptyList());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryAdapter.submitList(content.getCategories());
|
// 刷新后保留原分类;原分类已被删除时,回退到接口的第一项。
|
||||||
recommendationAdapter.submitList(content.getRecommendations());
|
int selectedPosition = 0;
|
||||||
|
if (selectedCategoryId != null) {
|
||||||
List<ShopContract.Category> categories = content.getCategories();
|
for (int index = 0; index < categoryList.size(); index++) {
|
||||||
if (categories.isEmpty()) {
|
if (categoryList.get(index).getId() == selectedCategoryId.longValue()) {
|
||||||
breakfastAdapter.submitList(Collections.emptyList());
|
selectedPosition = index;
|
||||||
} else {
|
break;
|
||||||
showCategory(categories.get(0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
categoryAdapter.select(selectedPosition);
|
||||||
|
viewBinding.rvFoodCategories.scrollToPosition(selectedPosition);
|
||||||
|
showCategory(categoryList.get(selectedPosition));
|
||||||
|
}
|
||||||
|
|
||||||
private void showCategory(ShopContract.Category category) {
|
/** 首次选中或切换分类时,用分类 ID 重新查询商品。 */
|
||||||
|
private void showCategory(ShopCategoryEntity category) {
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
viewBinding.tvFoodSectionTitle.setText(category.getTitleRes());
|
selectedCategoryId = category.getId();
|
||||||
breakfastAdapter.submitList(category.getFoods());
|
viewBinding.tvFoodSectionTitle.setText(category.getCategoryName());
|
||||||
|
// 请求期间清掉前一分类的商品,避免标题和列表不一致。
|
||||||
|
showGoods(Collections.emptyList());
|
||||||
|
viewBinding.rvFoodBreakfast.scrollToPosition(0);
|
||||||
|
viewBinding.rvFoodRecommend.scrollToPosition(0);
|
||||||
|
goodsLoading = true;
|
||||||
|
mPresenter.getShopGoods(category.getId(), 1, SHOP_GOODS_PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getShopGoodsSuccess(ShopGoodsPageEntity data) {
|
||||||
|
showGoods(data == null ? Collections.emptyList() : data.getRows());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 两个展示区使用当前选中分类的同一份接口商品,不再填充模拟数据。 */
|
||||||
|
private void showGoods(List<ShopGoodsEntity> goods) {
|
||||||
|
breakfastAdapter.setNewData(goods);
|
||||||
|
recommendationAdapter.setNewData(goods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -229,7 +270,7 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
private void startBannerAutoPlay() {
|
private void startBannerAutoPlay() {
|
||||||
// 页面不可见或只有一条数据时停止自动轮播,避免无效切换。
|
// 页面不可见或只有一条数据时停止自动轮播,避免无效切换。
|
||||||
bannerHandler.removeCallbacks(bannerSwitchTask);
|
bannerHandler.removeCallbacks(bannerSwitchTask);
|
||||||
if (!isResumed() || bannerAdapter == null || bannerAdapter.getItemCount() <= 1) {
|
if (shopRefreshing || !isResumed() || bannerAdapter == null || bannerAdapter.getItemCount() <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bannerHandler.postDelayed(bannerSwitchTask, BANNER_SWITCH_INTERVAL);
|
bannerHandler.postDelayed(bannerSwitchTask, BANNER_SWITCH_INTERVAL);
|
||||||
@@ -249,7 +290,10 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
stopBannerAutoPlay();
|
stopBannerAutoPlay();
|
||||||
shopRefreshing = false;
|
shopRefreshing = false;
|
||||||
pendingShopRequests = 0;
|
bannersLoading = false;
|
||||||
|
categoriesLoading = false;
|
||||||
|
goodsLoading = false;
|
||||||
|
mPresenter.cancelRequests();
|
||||||
// 主动解除 RecyclerView 对适配器的引用,避免视图销毁后继续持有页面对象。
|
// 主动解除 RecyclerView 对适配器的引用,避免视图销毁后继续持有页面对象。
|
||||||
if (viewBinding != null) {
|
if (viewBinding != null) {
|
||||||
viewBinding.vpFoodBanner.setAdapter(null);
|
viewBinding.vpFoodBanner.setAdapter(null);
|
||||||
@@ -274,7 +318,6 @@ public class ShopFragment extends BaseFragment<ShopFragmentBinding, ShopPresente
|
|||||||
if (mContext != null && !TextUtils.isEmpty(message)) {
|
if (mContext != null && !TextUtils.isEmpty(message)) {
|
||||||
ToastUtil.showShort(mContext, message);
|
ToastUtil.showShort(mContext, message);
|
||||||
}
|
}
|
||||||
completeShopNetworkRequest();
|
|
||||||
startBannerAutoPlay();
|
startBannerAutoPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,121 +1,73 @@
|
|||||||
package com.ckkj.griddle.shop.adapter;
|
package com.ckkj.griddle.shop.adapter;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
import com.ckkj.griddle.R;
|
import com.ckkj.griddle.R;
|
||||||
import com.ckkj.griddle.databinding.FoodBannerItemBinding;
|
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商城顶部轮播适配器。
|
* 商城顶部轮播适配器。
|
||||||
*/
|
*/
|
||||||
public class ShopBannerAdapter extends RecyclerView.Adapter<ShopBannerAdapter.BannerViewHolder> {
|
public class ShopBannerAdapter extends BaseQuickAdapter<ShopBannerEntity, BaseViewHolder> {
|
||||||
|
|
||||||
private final List<ShopBannerEntity> items = new ArrayList<>();
|
public ShopBannerAdapter() {
|
||||||
|
super(R.layout.food_banner_item);
|
||||||
/**
|
|
||||||
* 提交接口返回的轮播商品列表。
|
|
||||||
*/
|
|
||||||
public void submitList(List<ShopBannerEntity> banners) {
|
|
||||||
items.clear();
|
|
||||||
if (banners != null) {
|
|
||||||
items.addAll(banners);
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public BannerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
FoodBannerItemBinding binding = FoodBannerItemBinding.inflate(
|
|
||||||
LayoutInflater.from(parent.getContext()), parent, false);
|
|
||||||
return new BannerViewHolder(binding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull BannerViewHolder holder, int position) {
|
protected void convert(BaseViewHolder helper, ShopBannerEntity item) {
|
||||||
holder.bind(items.get(position), position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return items.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
class BannerViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
private final FoodBannerItemBinding binding;
|
|
||||||
|
|
||||||
BannerViewHolder(FoodBannerItemBinding binding) {
|
|
||||||
super(binding.getRoot());
|
|
||||||
this.binding = binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bind(ShopBannerEntity item, int position) {
|
|
||||||
// 接口只返回商品图、名称和价格,标题直接使用商品名称。
|
// 接口只返回商品图、名称和价格,标题直接使用商品名称。
|
||||||
String goodsName = item.getGoodsName();
|
String goodsName = item.getGoodsName();
|
||||||
binding.tvFoodBannerTitle.setText(goodsName);
|
helper.setText(R.id.tv_food_banner_title, goodsName);
|
||||||
binding.ivFoodBanner.setContentDescription(goodsName);
|
ImageView cover = helper.getView(R.id.iv_food_banner);
|
||||||
|
cover.setContentDescription(goodsName);
|
||||||
|
|
||||||
// 根据接口返回的积分价和现金价,组合出需要展示的价格文案。
|
String priceText = getPriceText(helper.itemView, item);
|
||||||
String priceText = getPriceText(item);
|
helper.setText(R.id.tv_food_banner_subtitle, priceText);
|
||||||
binding.tvFoodBannerSubtitle.setText(priceText);
|
helper.getView(R.id.tv_food_banner_subtitle).setVisibility(
|
||||||
binding.tvFoodBannerSubtitle.setVisibility(
|
|
||||||
TextUtils.isEmpty(priceText) ? View.GONE : View.VISIBLE);
|
TextUtils.isEmpty(priceText) ? View.GONE : View.VISIBLE);
|
||||||
|
|
||||||
// 统一交给 Glide 加载,空地址也会替换旧请求,避免复用时显示上一件商品图。
|
// 空地址也通过 Glide 替换旧请求,避免复用时显示上一件商品图。
|
||||||
String goodsImg = item.getGoodsImg();
|
String goodsImg = item.getGoodsImg();
|
||||||
Glide.with(binding.ivFoodBanner)
|
Glide.with(cover)
|
||||||
.load(TextUtils.isEmpty(goodsImg) ? null : goodsImg.trim())
|
.load(TextUtils.isEmpty(goodsImg) ? null : goodsImg.trim())
|
||||||
.placeholder(R.drawable.food_cover_placeholder)
|
.placeholder(R.drawable.food_cover_placeholder)
|
||||||
.fallback(R.drawable.food_cover_placeholder)
|
.fallback(R.drawable.food_cover_placeholder)
|
||||||
.error(R.drawable.food_cover_placeholder)
|
.error(R.drawable.food_cover_placeholder)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(binding.ivFoodBanner);
|
.into(cover);
|
||||||
bindIndicators(position);
|
bindIndicators(helper.getView(R.id.ll_banner_indicators),
|
||||||
|
helper.getLayoutPosition() - getHeaderLayoutCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 根据积分价和现金价生成展示文案。 */
|
||||||
* 根据接口返回的价格字段生成展示文案。
|
private String getPriceText(View view, ShopBannerEntity item) {
|
||||||
*/
|
|
||||||
private String getPriceText(ShopBannerEntity item) {
|
|
||||||
String pointPrice = formatPrice(item.getPointPrice());
|
String pointPrice = formatPrice(item.getPointPrice());
|
||||||
String cashPrice = formatPrice(item.getCashPrice());
|
String cashPrice = formatPrice(item.getCashPrice());
|
||||||
boolean hasPointPrice = !TextUtils.isEmpty(pointPrice);
|
boolean hasPointPrice = !TextUtils.isEmpty(pointPrice);
|
||||||
boolean hasCashPrice = !TextUtils.isEmpty(cashPrice);
|
boolean hasCashPrice = !TextUtils.isEmpty(cashPrice);
|
||||||
if (hasPointPrice && hasCashPrice) {
|
if (hasPointPrice && hasCashPrice) {
|
||||||
return binding.getRoot().getContext().getString(
|
return view.getContext().getString(R.string.food_banner_price_both,
|
||||||
R.string.food_banner_price_both,
|
pointPrice, cashPrice);
|
||||||
pointPrice,
|
|
||||||
cashPrice);
|
|
||||||
}
|
}
|
||||||
if (hasPointPrice) {
|
if (hasPointPrice) {
|
||||||
return binding.getRoot().getContext().getString(
|
return view.getContext().getString(R.string.food_banner_point_price, pointPrice);
|
||||||
R.string.food_banner_point_price,
|
|
||||||
pointPrice);
|
|
||||||
}
|
}
|
||||||
if (hasCashPrice) {
|
if (hasCashPrice) {
|
||||||
return binding.getRoot().getContext().getString(
|
return view.getContext().getString(R.string.food_banner_cash_price, cashPrice);
|
||||||
R.string.food_banner_cash_price,
|
|
||||||
cashPrice);
|
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 直接解析价格字符串,去掉多余的 0;空值或异常价格不展示。 */
|
||||||
* 直接解析接口价格字符串,去掉末尾多余的 0;空值或异常价格不展示。
|
|
||||||
*/
|
|
||||||
private String formatPrice(String price) {
|
private String formatPrice(String price) {
|
||||||
if (TextUtils.isEmpty(price)) {
|
if (TextUtils.isEmpty(price)) {
|
||||||
return "";
|
return "";
|
||||||
@@ -128,13 +80,10 @@ public class ShopBannerAdapter extends RecyclerView.Adapter<ShopBannerAdapter.Ba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** 根据 Banner 数据数量生成指示器,并高亮当前页。 */
|
||||||
* 根据 Banner 数量动态生成指示器,并高亮当前页。
|
private void bindIndicators(LinearLayout indicators, int selectedPosition) {
|
||||||
*/
|
|
||||||
private void bindIndicators(int selectedPosition) {
|
|
||||||
LinearLayout indicators = binding.llBannerIndicators;
|
|
||||||
indicators.removeAllViews();
|
indicators.removeAllViews();
|
||||||
int count = getItemCount();
|
int count = getData().size();
|
||||||
if (count <= 1) {
|
if (count <= 1) {
|
||||||
indicators.setVisibility(View.GONE);
|
indicators.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
@@ -159,5 +108,4 @@ public class ShopBannerAdapter extends RecyclerView.Adapter<ShopBannerAdapter.Ba
|
|||||||
private int dp(View view, int value) {
|
private int dp(View view, int value) {
|
||||||
return Math.round(value * view.getResources().getDisplayMetrics().density);
|
return Math.round(value * view.getResources().getDisplayMetrics().density);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.ckkj.griddle.shop.adapter;
|
package com.ckkj.griddle.shop.adapter;
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import androidx.annotation.Nullable;
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.ckkj.griddle.databinding.FoodCategoryItemBinding;
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
import com.ckkj.griddle.shop.mvp.ShopContract;
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.griddle.R;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -15,80 +14,41 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 商城美食分类适配器。
|
* 商城美食分类适配器。
|
||||||
*/
|
*/
|
||||||
public class ShopCategoryAdapter extends RecyclerView.Adapter<ShopCategoryAdapter.CategoryViewHolder> {
|
public class ShopCategoryAdapter extends BaseQuickAdapter<ShopCategoryEntity, BaseViewHolder> {
|
||||||
|
|
||||||
public interface OnCategorySelectedListener {
|
|
||||||
void onCategorySelected(ShopContract.Category category);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final List<ShopContract.Category> items = new ArrayList<>();
|
|
||||||
private final OnCategorySelectedListener listener;
|
|
||||||
private int selectedPosition = RecyclerView.NO_POSITION;
|
private int selectedPosition = RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
public ShopCategoryAdapter(OnCategorySelectedListener listener) {
|
public ShopCategoryAdapter() {
|
||||||
this.listener = listener;
|
super(R.layout.food_category_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submitList(List<ShopContract.Category> categories) {
|
/** 替换分类时重置选中位置,刷新后由页面恢复原选中分类。 */
|
||||||
items.clear();
|
@Override
|
||||||
if (categories != null) {
|
public void setNewData(@Nullable List<ShopCategoryEntity> data) {
|
||||||
items.addAll(categories);
|
selectedPosition = data == null || data.isEmpty() ? RecyclerView.NO_POSITION : 0;
|
||||||
}
|
super.setNewData(data == null ? new ArrayList<>() : new ArrayList<>(data));
|
||||||
selectedPosition = items.isEmpty() ? RecyclerView.NO_POSITION : 0;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void select(int position) {
|
public void select(int position) {
|
||||||
if (position < 0 || position >= items.size() || position == selectedPosition) {
|
if (position < 0 || position >= getData().size() || position == selectedPosition) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int previousPosition = selectedPosition;
|
int previousPosition = selectedPosition;
|
||||||
selectedPosition = position;
|
selectedPosition = position;
|
||||||
if (previousPosition != RecyclerView.NO_POSITION) {
|
if (previousPosition != RecyclerView.NO_POSITION) {
|
||||||
notifyItemChanged(previousPosition);
|
notifyItemChanged(previousPosition + getHeaderLayoutCount());
|
||||||
}
|
}
|
||||||
notifyItemChanged(selectedPosition);
|
notifyItemChanged(selectedPosition + getHeaderLayoutCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
public int getSelectedPosition() {
|
||||||
@Override
|
return selectedPosition;
|
||||||
public CategoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
FoodCategoryItemBinding binding = FoodCategoryItemBinding.inflate(
|
|
||||||
LayoutInflater.from(parent.getContext()), parent, false);
|
|
||||||
return new CategoryViewHolder(binding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull CategoryViewHolder holder, int position) {
|
protected void convert(BaseViewHolder helper, ShopCategoryEntity item) {
|
||||||
holder.bind(items.get(position), position == selectedPosition);
|
helper.setText(R.id.tv_food_category, item.getCategoryName());
|
||||||
}
|
helper.itemView.setSelected(
|
||||||
|
helper.getLayoutPosition() - getHeaderLayoutCount() == selectedPosition);
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return items.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
class CategoryViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
private final FoodCategoryItemBinding binding;
|
|
||||||
|
|
||||||
CategoryViewHolder(FoodCategoryItemBinding binding) {
|
|
||||||
super(binding.getRoot());
|
|
||||||
this.binding = binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bind(ShopContract.Category item, boolean selected) {
|
|
||||||
binding.tvFoodCategory.setText(item.getTitleRes());
|
|
||||||
binding.getRoot().setSelected(selected);
|
|
||||||
binding.getRoot().setOnClickListener(view -> {
|
|
||||||
int position = getBindingAdapterPosition();
|
|
||||||
if (position == RecyclerView.NO_POSITION) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
select(position);
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onCategorySelected(items.get(position));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +1,39 @@
|
|||||||
package com.ckkj.griddle.shop.adapter;
|
package com.ckkj.griddle.shop.adapter;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
import com.ckkj.griddle.R;
|
import com.ckkj.griddle.R;
|
||||||
import com.ckkj.griddle.shop.mvp.ShopContract;
|
import com.ckkj.griddle.shop.entity.ShopGoodsEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商城横向列表和推荐宫格共用的美食适配器。
|
* 商城横向列表和推荐宫格共用的美食适配器。
|
||||||
*/
|
*/
|
||||||
public class ShopFoodAdapter extends RecyclerView.Adapter<ShopFoodAdapter.FoodViewHolder> {
|
public class ShopFoodAdapter extends BaseQuickAdapter<ShopGoodsEntity, BaseViewHolder> {
|
||||||
|
|
||||||
@LayoutRes
|
|
||||||
private final int layoutResId;
|
|
||||||
private final List<ShopContract.Food> items = new ArrayList<>();
|
|
||||||
|
|
||||||
public ShopFoodAdapter(@LayoutRes int layoutResId) {
|
public ShopFoodAdapter(@LayoutRes int layoutResId) {
|
||||||
this.layoutResId = layoutResId;
|
super(layoutResId);
|
||||||
}
|
|
||||||
|
|
||||||
public void submitList(List<ShopContract.Food> foods) {
|
|
||||||
items.clear();
|
|
||||||
if (foods != null) {
|
|
||||||
items.addAll(foods);
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(layoutResId, parent, false);
|
|
||||||
return new FoodViewHolder(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull FoodViewHolder holder, int position) {
|
protected void convert(BaseViewHolder helper, ShopGoodsEntity item) {
|
||||||
holder.bind(items.get(position));
|
String title = item.getGoodsName();
|
||||||
}
|
helper.setText(R.id.tv_food_name, title);
|
||||||
|
ImageView cover = helper.getView(R.id.iv_food_cover);
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return items.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class FoodViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
private final ImageView cover;
|
|
||||||
private final TextView name;
|
|
||||||
|
|
||||||
FoodViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
cover = itemView.findViewById(R.id.iv_food_cover);
|
|
||||||
name = itemView.findViewById(R.id.tv_food_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bind(ShopContract.Food item) {
|
|
||||||
String title = itemView.getContext().getString(item.getTitleRes());
|
|
||||||
name.setText(item.getTitleRes());
|
|
||||||
cover.setContentDescription(title);
|
cover.setContentDescription(title);
|
||||||
if (!TextUtils.isEmpty(item.getImageUrl())) {
|
// 空图片同样交给 Glide,防止复用时旧的网络图片请求覆盖新商品。
|
||||||
|
String imageUrl = item.getGoodsImg();
|
||||||
Glide.with(cover)
|
Glide.with(cover)
|
||||||
.load(item.getImageUrl())
|
.load(TextUtils.isEmpty(imageUrl) ? null : imageUrl.trim())
|
||||||
.placeholder(item.getImageRes())
|
.placeholder(R.drawable.food_cover_placeholder)
|
||||||
.error(item.getImageRes())
|
.fallback(R.drawable.food_cover_placeholder)
|
||||||
|
.error(R.drawable.food_cover_placeholder)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(cover);
|
.into(cover);
|
||||||
} else {
|
|
||||||
cover.setImageResource(item.getImageRes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.ckkj.griddle.shop.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/** 商品列表中的单个商品,对应 data.rows 中的数据。 */
|
||||||
|
public class ShopGoodsEntity implements Serializable {
|
||||||
|
/** 商品编号按字符串保存,兼容接口返回的长整型或字符串 ID。 */
|
||||||
|
private String id;
|
||||||
|
/** 商品名称。 */
|
||||||
|
private String goodsName;
|
||||||
|
/** 商品主图地址。 */
|
||||||
|
private String goodsImg;
|
||||||
|
/** 积分价格,使用字符串保留接口精度。 */
|
||||||
|
private String pointPrice;
|
||||||
|
/** 现金价格,使用字符串保留接口精度。 */
|
||||||
|
private String cashPrice;
|
||||||
|
/** 库存数量。 */
|
||||||
|
private int stockNum;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodsName() {
|
||||||
|
return goodsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsName(String goodsName) {
|
||||||
|
this.goodsName = goodsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodsImg() {
|
||||||
|
return goodsImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsImg(String goodsImg) {
|
||||||
|
this.goodsImg = goodsImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPointPrice() {
|
||||||
|
return pointPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPointPrice(String pointPrice) {
|
||||||
|
this.pointPrice = pointPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCashPrice() {
|
||||||
|
return cashPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCashPrice(String cashPrice) {
|
||||||
|
this.cashPrice = cashPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStockNum() {
|
||||||
|
return stockNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStockNum(int stockNum) {
|
||||||
|
this.stockNum = stockNum;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ckkj.griddle.shop.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 商品列表分页数据,外层 code、msg 继续由 BaseBean 接收。 */
|
||||||
|
public class ShopGoodsPageEntity implements Serializable {
|
||||||
|
/** 当前分类下的商品总数。 */
|
||||||
|
private long total;
|
||||||
|
/** 当前页的商品列表。 */
|
||||||
|
private List<ShopGoodsEntity> rows;
|
||||||
|
|
||||||
|
public long getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(long total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopGoodsEntity> getRows() {
|
||||||
|
return rows == null ? Collections.emptyList() : rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRows(List<ShopGoodsEntity> rows) {
|
||||||
|
this.rows = rows;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.ckkj.griddle.shop.mvp;
|
package com.ckkj.griddle.shop.mvp;
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
|
|
||||||
import com.ckkj.griddle.base.IView;
|
import com.ckkj.griddle.base.IView;
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsPageEntity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商城页面与数据层协议。
|
* 商城页面与数据层协议。
|
||||||
@@ -41,7 +39,10 @@ public final class ShopContract {
|
|||||||
*/
|
*/
|
||||||
void getShopCategories(CallBack<List<ShopCategoryEntity>> callback);
|
void getShopCategories(CallBack<List<ShopCategoryEntity>> callback);
|
||||||
|
|
||||||
void loadContent(CallBack<ShopContent> callback);
|
/**
|
||||||
|
* 按分类和分页参数获取商品列表。
|
||||||
|
*/
|
||||||
|
void getShopGoods(Map<String, Object> map, CallBack<ShopGoodsPageEntity> callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,77 +59,15 @@ public final class ShopContract {
|
|||||||
*/
|
*/
|
||||||
void getShopCategoriesSuccess(List<ShopCategoryEntity> categories);
|
void getShopCategoriesSuccess(List<ShopCategoryEntity> categories);
|
||||||
|
|
||||||
void showShopContent(ShopContent content);
|
/** 商品获取成功,将当前分类的数据交给两个商品列表展示。 */
|
||||||
|
void getShopGoodsSuccess(ShopGoodsPageEntity data);
|
||||||
|
|
||||||
|
/** 各请求成功或失败后均通知页面,便于准确结束下拉刷新。 */
|
||||||
|
void onShopRequestFinished(RequestType type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class ShopContent {
|
/** 商城页面参与刷新的三个请求类型。 */
|
||||||
private final List<Category> categories;
|
public enum RequestType {
|
||||||
private final List<Food> recommendations;
|
BANNERS, CATEGORIES, GOODS
|
||||||
|
|
||||||
public ShopContent(List<Category> categories, List<Food> recommendations) {
|
|
||||||
this.categories = immutableCopy(categories);
|
|
||||||
this.recommendations = immutableCopy(recommendations);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Category> getCategories() {
|
|
||||||
return categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Food> getRecommendations() {
|
|
||||||
return recommendations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Category {
|
|
||||||
@StringRes
|
|
||||||
private final int titleRes;
|
|
||||||
private final List<Food> foods;
|
|
||||||
|
|
||||||
public Category(@StringRes int titleRes, List<Food> foods) {
|
|
||||||
this.titleRes = titleRes;
|
|
||||||
this.foods = immutableCopy(foods);
|
|
||||||
}
|
|
||||||
|
|
||||||
@StringRes
|
|
||||||
public int getTitleRes() {
|
|
||||||
return titleRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Food> getFoods() {
|
|
||||||
return foods;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Food {
|
|
||||||
@StringRes
|
|
||||||
private final int titleRes;
|
|
||||||
private final String imageUrl;
|
|
||||||
private final int imageRes;
|
|
||||||
|
|
||||||
public Food(@StringRes int titleRes, String imageUrl, int imageRes) {
|
|
||||||
this.titleRes = titleRes;
|
|
||||||
this.imageUrl = imageUrl;
|
|
||||||
this.imageRes = imageRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@StringRes
|
|
||||||
public int getTitleRes() {
|
|
||||||
return titleRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getImageUrl() {
|
|
||||||
return imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getImageRes() {
|
|
||||||
return imageRes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> List<T> immutableCopy(List<T> source) {
|
|
||||||
if (source == null || source.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableList(new ArrayList<>(source));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.ckkj.griddle.shop.mvp;
|
package com.ckkj.griddle.shop.mvp;
|
||||||
|
|
||||||
import com.ckkj.griddle.R;
|
|
||||||
import com.ckkj.griddle.network.BaseBean;
|
import com.ckkj.griddle.network.BaseBean;
|
||||||
import com.ckkj.griddle.network.NetWorkManager;
|
import com.ckkj.griddle.network.NetWorkManager;
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsPageEntity;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.reactivex.Observer;
|
import io.reactivex.Observer;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
@@ -84,7 +84,7 @@ public class ShopImpl implements ShopContract.DataModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(@NonNull BaseBean<List<ShopCategoryEntity>> bean) {
|
public void onNext(@NonNull BaseBean<List<ShopCategoryEntity>> bean) {
|
||||||
if (bean != null && bean.isSuccess()) {
|
if (bean != null && (bean.getCode() == 200 || bean.isSuccess())) {
|
||||||
// 分类接口未返回数据时统一转成空列表。
|
// 分类接口未返回数据时统一转成空列表。
|
||||||
List<ShopCategoryEntity> categories = bean.getData();
|
List<ShopCategoryEntity> categories = bean.getData();
|
||||||
callback.success(categories == null
|
callback.success(categories == null
|
||||||
@@ -110,40 +110,43 @@ public class ShopImpl implements ShopContract.DataModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 请求分类商品,继续沿用商城其他接口的 RxJava 和 BaseBean 写法。 */
|
||||||
@Override
|
@Override
|
||||||
public void loadContent(ShopContract.CallBack<ShopContract.ShopContent> callback) {
|
public void getShopGoods(Map<String, Object> map,
|
||||||
List<ShopContract.Category> categories = Arrays.asList(
|
ShopContract.CallBack<ShopGoodsPageEntity> callback) {
|
||||||
category(R.string.food_category_breakfast,
|
try {
|
||||||
food(R.string.food_item_injera_firfir),
|
NetWorkManager.getRequest().getShopGoods(NetWorkManager.getToken(), map)
|
||||||
food(R.string.food_item_chechebsa),
|
.subscribeOn(Schedulers.io())
|
||||||
food(R.string.food_item_firfir)),
|
.unsubscribeOn(Schedulers.io())
|
||||||
category(R.string.food_category_main_dishes,
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
food(R.string.food_item_doro_wat),
|
.subscribe(new Observer<BaseBean<ShopGoodsPageEntity>>() {
|
||||||
food(R.string.food_item_kitfo),
|
@Override
|
||||||
food(R.string.food_item_tibs)),
|
public void onSubscribe(@NonNull Disposable d) {
|
||||||
category(R.string.food_category_drinks,
|
|
||||||
food(R.string.food_item_ethiopian_coffee),
|
|
||||||
food(R.string.food_item_spiced_tea)),
|
|
||||||
category(R.string.food_category_snack,
|
|
||||||
food(R.string.food_item_sambusa),
|
|
||||||
food(R.string.food_item_kolo))
|
|
||||||
);
|
|
||||||
|
|
||||||
List<ShopContract.Food> recommendations = Arrays.asList(
|
|
||||||
food(R.string.food_item_doro_wat),
|
|
||||||
food(R.string.food_item_kitfo),
|
|
||||||
food(R.string.food_item_beyaynetu),
|
|
||||||
food(R.string.food_item_shiro)
|
|
||||||
);
|
|
||||||
|
|
||||||
callback.success(new ShopContract.ShopContent(categories, recommendations));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShopContract.Category category(int titleRes, ShopContract.Food... foods) {
|
@Override
|
||||||
return new ShopContract.Category(titleRes, Arrays.asList(foods));
|
public void onNext(@NonNull BaseBean<ShopGoodsPageEntity> bean) {
|
||||||
|
if (bean != null && (bean.getCode() == 200 || bean.isSuccess())) {
|
||||||
|
// 空 data 也作为空列表处理,及时清掉上一分类的商品。
|
||||||
|
callback.success(bean.getData() == null
|
||||||
|
? new ShopGoodsPageEntity() : bean.getData());
|
||||||
|
} else {
|
||||||
|
callback.fail(bean == null ? "商品列表获取失败" : bean.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShopContract.Food food(int titleRes) {
|
@Override
|
||||||
return new ShopContract.Food(titleRes, null, R.drawable.food_cover_placeholder);
|
public void onError(@NonNull Throwable e) {
|
||||||
|
callback.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
callback.fail(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package com.ckkj.griddle.shop.mvp;
|
|||||||
import com.ckkj.griddle.base.BasePresenter;
|
import com.ckkj.griddle.base.BasePresenter;
|
||||||
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
import com.ckkj.griddle.shop.entity.ShopBannerEntity;
|
||||||
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
import com.ckkj.griddle.shop.entity.ShopCategoryEntity;
|
||||||
|
import com.ckkj.griddle.shop.entity.ShopGoodsPageEntity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商城页面业务协调层。
|
* 商城页面业务协调层。
|
||||||
@@ -12,6 +15,10 @@ import java.util.List;
|
|||||||
public class ShopPresenter extends BasePresenter<ShopContract.ShopView> {
|
public class ShopPresenter extends BasePresenter<ShopContract.ShopView> {
|
||||||
|
|
||||||
private final ShopImpl mImpl;
|
private final ShopImpl mImpl;
|
||||||
|
/** 每类请求仅接收最新一轮的回调,防止切换分类或刷新后旧数据覆盖页面。 */
|
||||||
|
private int bannerRequestVersion;
|
||||||
|
private int categoryRequestVersion;
|
||||||
|
private int goodsRequestVersion;
|
||||||
|
|
||||||
public ShopPresenter(ShopImpl mImpl) {
|
public ShopPresenter(ShopImpl mImpl) {
|
||||||
this.mImpl = mImpl;
|
this.mImpl = mImpl;
|
||||||
@@ -21,18 +28,21 @@ public class ShopPresenter extends BasePresenter<ShopContract.ShopView> {
|
|||||||
* 获取商城顶部轮播数据,并将结果转发给页面。
|
* 获取商城顶部轮播数据,并将结果转发给页面。
|
||||||
*/
|
*/
|
||||||
public void getShopBanners() {
|
public void getShopBanners() {
|
||||||
|
final int requestVersion = ++bannerRequestVersion;
|
||||||
mImpl.getShopBanners(new ShopContract.CallBack<List<ShopBannerEntity>>() {
|
mImpl.getShopBanners(new ShopContract.CallBack<List<ShopBannerEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(List<ShopBannerEntity> data) {
|
public void success(List<ShopBannerEntity> data) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == bannerRequestVersion) {
|
||||||
getView().getShopBannersSuccess(data);
|
getView().getShopBannersSuccess(data);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.BANNERS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fail(String message) {
|
public void fail(String message) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == bannerRequestVersion) {
|
||||||
getView().showError(message);
|
getView().showError(message);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.BANNERS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -42,38 +52,67 @@ public class ShopPresenter extends BasePresenter<ShopContract.ShopView> {
|
|||||||
* 获取商城商品分类列表,并将结果转发给页面。
|
* 获取商城商品分类列表,并将结果转发给页面。
|
||||||
*/
|
*/
|
||||||
public void getShopCategories() {
|
public void getShopCategories() {
|
||||||
|
final int requestVersion = ++categoryRequestVersion;
|
||||||
mImpl.getShopCategories(new ShopContract.CallBack<List<ShopCategoryEntity>>() {
|
mImpl.getShopCategories(new ShopContract.CallBack<List<ShopCategoryEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(List<ShopCategoryEntity> data) {
|
public void success(List<ShopCategoryEntity> data) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == categoryRequestVersion) {
|
||||||
getView().getShopCategoriesSuccess(data);
|
getView().getShopCategoriesSuccess(data);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.CATEGORIES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fail(String message) {
|
public void fail(String message) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == categoryRequestVersion) {
|
||||||
getView().showError(message);
|
getView().showError(message);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.CATEGORIES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadContent() {
|
/** 将真实分类 ID 和分页参数交给数据层,忽略此前分类的过期响应。 */
|
||||||
mImpl.loadContent(new ShopContract.CallBack<ShopContract.ShopContent>() {
|
public void getShopGoods(long categoryId, int page, int size) {
|
||||||
|
final int requestVersion = ++goodsRequestVersion;
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("categoryId", categoryId);
|
||||||
|
map.put("page", page);
|
||||||
|
map.put("size", size);
|
||||||
|
mImpl.getShopGoods(map, new ShopContract.CallBack<ShopGoodsPageEntity>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(ShopContract.ShopContent data) {
|
public void success(ShopGoodsPageEntity data) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == goodsRequestVersion) {
|
||||||
getView().showShopContent(data);
|
getView().getShopGoodsSuccess(data);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.GOODS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fail(String message) {
|
public void fail(String message) {
|
||||||
if (getView() != null) {
|
if (getView() != null && requestVersion == goodsRequestVersion) {
|
||||||
getView().showError(message);
|
getView().showError(message);
|
||||||
|
getView().onShopRequestFinished(ShopContract.RequestType.GOODS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 分类为空或重新加载分类时,让此前商品请求的回调失效。 */
|
||||||
|
public void cancelGoodsRequest() {
|
||||||
|
goodsRequestVersion++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 视图销毁时停止向旧页面派发回调。 */
|
||||||
|
public void cancelRequests() {
|
||||||
|
bannerRequestVersion++;
|
||||||
|
categoryRequestVersion++;
|
||||||
|
cancelGoodsRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
cancelRequests();
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
app/src/main/res/color/carbon_filter_text.xml
Normal file
5
app/src/main/res/color/carbon_filter_text.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_selected="true" android:color="@android:color/white" />
|
||||||
|
<item android:color="@color/carbon_label" />
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/color/device_home_icon_tint.xml
Normal file
5
app/src/main/res/color/device_home_icon_tint.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_activated="true" android:color="#C8C8C8" />
|
||||||
|
<item android:color="#2CC58B" />
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/color/device_timer_repeat_text.xml
Normal file
5
app/src/main/res/color/device_timer_repeat_text.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_selected="true" android:color="@color/device_data_orange" />
|
||||||
|
<item android:color="#3D444D" />
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/color/device_timer_switch_track.xml
Normal file
5
app/src/main/res/color/device_timer_switch_track.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_checked="true" android:color="@color/device_data_orange" />
|
||||||
|
<item android:color="#E1E5EA" />
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/color/device_timer_time_text.xml
Normal file
5
app/src/main/res/color/device_timer_time_text.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_activated="true" android:color="@color/device_data_green" />
|
||||||
|
<item android:color="@color/device_data_legend" />
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/color/mine_history_filter_text.xml
Normal file
5
app/src/main/res/color/mine_history_filter_text.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_selected="true" android:color="@android:color/white" />
|
||||||
|
<item android:color="#6B7280" />
|
||||||
|
</selector>
|
||||||
BIN
app/src/main/res/drawable-xhdpi/device_home_location.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/device_home_location.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 618 B |
BIN
app/src/main/res/drawable-xhdpi/device_home_weather_sunny.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/device_home_weather_sunny.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 651 B |
5
app/src/main/res/drawable/carbon_icon_bg.xml
Normal file
5
app/src/main/res/drawable/carbon_icon_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="@color/carbon_accent_background" />
|
||||||
|
<corners android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
4
app/src/main/res/drawable/carbon_legend_dot.xml
Normal file
4
app/src/main/res/drawable/carbon_legend_dot.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<solid android:color="@color/carbon_chart_light" />
|
||||||
|
</shape>
|
||||||
5
app/src/main/res/drawable/carbon_metric_accent_bg.xml
Normal file
5
app/src/main/res/drawable/carbon_metric_accent_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="@color/carbon_accent_background" />
|
||||||
|
<corners android:radius="12dp" />
|
||||||
|
</shape>
|
||||||
5
app/src/main/res/drawable/carbon_metric_bg.xml
Normal file
5
app/src/main/res/drawable/carbon_metric_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="@color/carbon_tile_background" />
|
||||||
|
<corners android:radius="12dp" />
|
||||||
|
</shape>
|
||||||
11
app/src/main/res/drawable/carbon_metric_filter_bg.xml
Normal file
11
app/src/main/res/drawable/carbon_metric_filter_bg.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_selected="true"><shape>
|
||||||
|
<solid android:color="@color/device_data_orange" /><corners android:radius="999dp" />
|
||||||
|
<stroke android:width="1dp" android:color="@color/device_data_orange" />
|
||||||
|
</shape></item>
|
||||||
|
<item><shape>
|
||||||
|
<solid android:color="@android:color/white" /><corners android:radius="999dp" />
|
||||||
|
<stroke android:width="1dp" android:color="@color/carbon_divider" />
|
||||||
|
</shape></item>
|
||||||
|
</selector>
|
||||||
7
app/src/main/res/drawable/carbon_period_bg.xml
Normal file
7
app/src/main/res/drawable/carbon_period_bg.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_selected="true"><shape>
|
||||||
|
<solid android:color="@color/device_data_orange" /><corners android:radius="8dp" />
|
||||||
|
</shape></item>
|
||||||
|
<item><shape><solid android:color="@android:color/transparent" /><corners android:radius="8dp" /></shape></item>
|
||||||
|
</selector>
|
||||||
4
app/src/main/res/drawable/carbon_points_earned_bg.xml
Normal file
4
app/src/main/res/drawable/carbon_points_earned_bg.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<solid android:color="@color/carbon_accent_background" />
|
||||||
|
</shape>
|
||||||
4
app/src/main/res/drawable/carbon_points_spent_bg.xml
Normal file
4
app/src/main/res/drawable/carbon_points_spent_bg.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<solid android:color="@color/carbon_points_spent_background" />
|
||||||
|
</shape>
|
||||||
10
app/src/main/res/drawable/device_data_power_bg.xml
Normal file
10
app/src/main/res/drawable/device_data_power_bg.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<gradient
|
||||||
|
android:angle="315"
|
||||||
|
android:startColor="#F0F9F5"
|
||||||
|
android:endColor="#E7F5EF" />
|
||||||
|
<corners
|
||||||
|
android:radius="14dp" />
|
||||||
|
</shape>
|
||||||
21
app/src/main/res/drawable/device_data_status_bg.xml
Normal file
21
app/src/main/res/drawable/device_data_status_bg.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:state_activated="true">
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="#EBF7F1" />
|
||||||
|
<corners
|
||||||
|
android:radius="999dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="#ECEEF1" />
|
||||||
|
<corners
|
||||||
|
android:radius="999dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</selector>
|
||||||
7
app/src/main/res/drawable/device_data_status_dot.xml
Normal file
7
app/src/main/res/drawable/device_data_status_dot.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid
|
||||||
|
android:color="@color/device_data_green" />
|
||||||
|
</shape>
|
||||||
13
app/src/main/res/drawable/device_data_switch_bg.xml
Normal file
13
app/src/main/res/drawable/device_data_switch_bg.xml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ripple
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="#33FFFFFF">
|
||||||
|
<item>
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="@color/device_data_orange" />
|
||||||
|
<corners
|
||||||
|
android:radius="20dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
10
app/src/main/res/drawable/device_data_temperature_bg.xml
Normal file
10
app/src/main/res/drawable/device_data_temperature_bg.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<gradient
|
||||||
|
android:angle="315"
|
||||||
|
android:startColor="#FFF6EE"
|
||||||
|
android:endColor="#FFEDDC" />
|
||||||
|
<corners
|
||||||
|
android:radius="14dp" />
|
||||||
|
</shape>
|
||||||
14
app/src/main/res/drawable/device_home_griddle_icon.xml
Normal file
14
app/src/main/res/drawable/device_home_griddle_icon.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="26dp"
|
||||||
|
android:height="26dp"
|
||||||
|
android:viewportWidth="32"
|
||||||
|
android:viewportHeight="32">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#2CC58B"
|
||||||
|
android:strokeWidth="1.7"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:pathData="M13,10 C11,7 14,3 18,3 C23,3 25,10 21,12 M8,9 L8,12 M6.5,10.5 L9.5,10.5 M3,15 L29,15 L29,19 L3,19 Z M6,19 L6,28 L26,28 L26,19 M12,23 L20,23" />
|
||||||
|
</vector>
|
||||||
5
app/src/main/res/drawable/device_preview_action_bg.xml
Normal file
5
app/src/main/res/drawable/device_preview_action_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#F7F8FA" />
|
||||||
|
<corners android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
|
<solid android:color="#FFF1E8" />
|
||||||
|
<corners android:radius="7dp" />
|
||||||
|
</shape>
|
||||||
7
app/src/main/res/drawable/device_timer_cancel_bg.xml
Normal file
7
app/src/main/res/drawable/device_timer_cancel_bg.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid
|
||||||
|
android:color="#F6F7F9" />
|
||||||
|
</shape>
|
||||||
7
app/src/main/res/drawable/device_timer_confirm_bg.xml
Normal file
7
app/src/main/res/drawable/device_timer_confirm_bg.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="oval">
|
||||||
|
<solid
|
||||||
|
android:color="@color/device_data_orange" />
|
||||||
|
</shape>
|
||||||
5
app/src/main/res/drawable/device_timer_picker_bg.xml
Normal file
5
app/src/main/res/drawable/device_timer_picker_bg.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/device_preview_background" />
|
||||||
|
<corners android:topLeftRadius="24dp" android:topRightRadius="24dp" />
|
||||||
|
</shape>
|
||||||
27
app/src/main/res/drawable/device_timer_repeat_bg.xml
Normal file
27
app/src/main/res/drawable/device_timer_repeat_bg.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:state_selected="true">
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="#FFF4EA" />
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="#FFD9BA" />
|
||||||
|
<corners
|
||||||
|
android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="@android:color/white" />
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="#E3E7EB" />
|
||||||
|
<corners
|
||||||
|
android:radius="10dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</selector>
|
||||||
5
app/src/main/res/drawable/device_timer_switch_thumb.xml
Normal file
5
app/src/main/res/drawable/device_timer_switch_thumb.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
|
||||||
|
<solid android:color="@android:color/white" />
|
||||||
|
<stroke android:width="0.5dp" android:color="#10000000" />
|
||||||
|
</shape>
|
||||||
21
app/src/main/res/drawable/device_timer_time_bg.xml
Normal file
21
app/src/main/res/drawable/device_timer_time_bg.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:state_activated="true">
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="#EBF7F1" />
|
||||||
|
<corners
|
||||||
|
android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<shape>
|
||||||
|
<solid
|
||||||
|
android:color="#F6F7F9" />
|
||||||
|
<corners
|
||||||
|
android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</selector>
|
||||||
8
app/src/main/res/drawable/ic_carbon_chevron.xml
Normal file
8
app/src/main/res/drawable/ic_carbon_chevron.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#C4C9D0"
|
||||||
|
android:strokeWidth="2" android:strokeLineCap="round" android:strokeLineJoin="round"
|
||||||
|
android:pathData="M9,6 L15,12 L9,18" />
|
||||||
|
</vector>
|
||||||
8
app/src/main/res/drawable/ic_carbon_details.xml
Normal file
8
app/src/main/res/drawable/ic_carbon_details.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#FF6900"
|
||||||
|
android:strokeWidth="2" android:strokeLineCap="round" android:strokeLineJoin="round"
|
||||||
|
android:pathData="M7,3 L17,3 Q20,3 20,6 L20,18 Q20,21 17,21 L7,21 Q4,21 4,18 L4,6 Q4,3 7,3 M8,8 L16,8 M8,12 L16,12 M8,16 L12,16" />
|
||||||
|
</vector>
|
||||||
7
app/src/main/res/drawable/ic_carbon_points_bag.xml
Normal file
7
app/src/main/res/drawable/ic_carbon_points_bag.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M7,8L7,6C7,3.2 9.2,1 12,1C14.8,1 17,3.2 17,6L17,8 M5,8L19,8C20.1,8 21,8.9 21,10L21,21C21,22.1 20.1,23 19,23L5,23C3.9,23 3,22.1 3,21L3,10C3,8.9 3.9,8 5,8Z" android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="@color/device_data_orange" android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round" android:strokeLineJoin="round" />
|
||||||
|
</vector>
|
||||||
7
app/src/main/res/drawable/ic_carbon_points_device.xml
Normal file
7
app/src/main/res/drawable/ic_carbon_points_device.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M3,4L21,4C22,4 23,5 23,6L23,18C23,19 22,20 21,20L3,20C2,20 1,19 1,18L1,6C1,5 2,4 3,4Z M1,10L23,10 M5,15L9,15" android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="@color/device_data_orange" android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round" android:strokeLineJoin="round" />
|
||||||
|
</vector>
|
||||||
7
app/src/main/res/drawable/ic_carbon_points_flame.xml
Normal file
7
app/src/main/res/drawable/ic_carbon_points_flame.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M12,2C13,7 19,8 19,14C19,19 16,22 12,22C8,22 5,19 5,15C5,12 7,10 8,8C7,13 10,14 12,12C14,10 12,7 12,2Z M12,22C8,19 11,16 12,15C12,17 15,18 14,20" android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="@color/device_data_orange" android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round" android:strokeLineJoin="round" />
|
||||||
|
</vector>
|
||||||
7
app/src/main/res/drawable/ic_carbon_points_gift.xml
Normal file
7
app/src/main/res/drawable/ic_carbon_points_gift.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M2,9L22,9L22,13L2,13Z M3,13L3,22L21,22L21,13 M12,9L12,22 M12,9C7,9 5,7 6,4C7,1 11,3 12,9C13,3 17,1 18,4C19,7 17,9 12,9Z" android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="@color/device_data_orange" android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round" android:strokeLineJoin="round" />
|
||||||
|
</vector>
|
||||||
7
app/src/main/res/drawable/ic_carbon_points_invite.xml
Normal file
7
app/src/main/res/drawable/ic_carbon_points_invite.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:pathData="M13,7A4,4 0,1 1,5,7A4,4 0,1 1,13,7 M2,21C2,16 5,14 9,14C13,14 16,16 16,21 M20,4L20,10 M17,7L23,7" android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="@color/device_data_orange" android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round" android:strokeLineJoin="round" />
|
||||||
|
</vector>
|
||||||
8
app/src/main/res/drawable/ic_carbon_trend.xml
Normal file
8
app/src/main/res/drawable/ic_carbon_trend.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
|
||||||
|
<path android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#FF6900"
|
||||||
|
android:strokeWidth="2" android:strokeLineCap="round" android:strokeLineJoin="round"
|
||||||
|
android:pathData="M3,17 L9,11 L14,16 L21,7 M14,7 L21,7 L21,14" />
|
||||||
|
</vector>
|
||||||
15
app/src/main/res/drawable/ic_device_data_diagnosis.xml
Normal file
15
app/src/main/res/drawable/ic_device_data_diagnosis.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#FF6900"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:strokeLineJoin="round"
|
||||||
|
android:pathData="M14,3 C17,1 20,2 22,4 L18,7 L18,10 L21,10 C21,14 18,16 14,14 L6,22 C4,24 1,21 3,19 L11,11 C9,8 10,5 12,4 L12,8 L15,8 L16,5 Z" />
|
||||||
|
</vector>
|
||||||
14
app/src/main/res/drawable/ic_device_data_info.xml
Normal file
14
app/src/main/res/drawable/ic_device_data_info.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/transparent"
|
||||||
|
android:strokeColor="#FF6900"
|
||||||
|
android:strokeWidth="1.8"
|
||||||
|
android:strokeLineCap="round"
|
||||||
|
android:pathData="M12,2 A10,10 0,1 1,12 22 A10,10 0,1 1,12 2 M12,11 L12,17 M12,7 L12,7.3" />
|
||||||
|
</vector>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user