更新应用电量报告显示风格,精简冗余代码。

This commit is contained in:
ZhanGSKen
2025-10-22 18:35:29 +08:00
parent ca4e4c7feb
commit 10b8da2e21
2 changed files with 10 additions and 54 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Wed Oct 22 10:25:50 GMT 2025
#Wed Oct 22 10:33:32 GMT 2025
stageCount=16
libraryProject=
baseVersion=15.4
publishVersion=15.4.15
buildCount=1
buildCount=2
baseBetaVersion=15.4.16

View File

@@ -36,8 +36,6 @@ import cc.winboll.studio.libappbase.LogUtils;
public class BatteryReportActivity extends Activity {
public static final String TAG = "BatteryReportActivity";
// 目标应用包名常量(统一维护,数据计算核心标识)
private static final String TARGET_APP_PACKAGE = "cc.winboll.studio.mymessagemanager";
private RecyclerView rvBatteryReport;
private BatteryReportAdapter adapter;
@@ -78,8 +76,6 @@ public class BatteryReportActivity extends Activity {
loadAllAppPackage();
// 2. 预缓存所有包名对应的应用名称(为搜索名称做准备)
preCacheAllAppNames();
// 3. 强制添加目标应用(包名兜底)
//forceAddTargetPackage();
// 4. 首次获取运行时长key包名
appRunTimeCache = getAppRunTime();
// 5. 更新时长到数据模型(用包名匹配)
@@ -194,31 +190,6 @@ public class BatteryReportActivity extends Activity {
}
}
/**
* 强制添加目标包名(兜底逻辑,仅操作包名)
*/
private void forceAddTargetPackage() {
// 1. 先检查列表中是否已存在目标包名
boolean isTargetExists = false;
for (AppBatteryModel model : dataList) {
if (TARGET_APP_PACKAGE.equals(model.getPackageName())) {
isTargetExists = true;
break;
}
}
if (isTargetExists) {
LogUtils.d(TAG, "目标包名已在列表中,无需重复添加");
return;
}
// 2. 仅用包名创建模型,强制添加(不依赖名称查询)
dataList.add(0, new AppBatteryModel(TARGET_APP_PACKAGE, "0.0", 0));
// 同步更新名称缓存
packageToAppNameCache.put(TARGET_APP_PACKAGE, getAppNameByPackage(TARGET_APP_PACKAGE));
LogUtils.d(TAG, "强制添加目标包名成功:" + TARGET_APP_PACKAGE);
}
/**
* 更新运行时长到模型(用包名匹配,不涉及名称)
*/
@@ -251,7 +222,6 @@ public class BatteryReportActivity extends Activity {
filteredList.addAll(dataList);
} else {
String lowerKeyword = keyword.toLowerCase(); // 统一转为小写,实现不区分大小写搜索
boolean isTargetMatched = false;
for (AppBatteryModel model : dataList) {
String packageName = model.getPackageName();
@@ -266,21 +236,7 @@ public class BatteryReportActivity extends Activity {
if (isMatched) {
filteredList.add(model);
// 检查是否是目标包名
if (TARGET_APP_PACKAGE.equals(packageName)) {
isTargetMatched = true;
}
}
}
// 兜底:目标包名未匹配时强制添加
if (!isTargetMatched) {
for (AppBatteryModel model : dataList) {
if (TARGET_APP_PACKAGE.equals(model.getPackageName())) {
filteredList.add(0, model);
LogUtils.d(TAG, "搜索兜底:强制添加目标包名到结果列表");
break;
}
}
}
}
@@ -512,13 +468,13 @@ public class BatteryReportActivity extends Activity {
holder.tvConsumption.setText(consumptionText);
// 优化显示:目标应用文字标蓝(通过包名匹配)
if (BatteryReportActivity.TARGET_APP_PACKAGE.equals(packageName)) {
holder.tvAppName.setTextColor(mContext.getResources().getColor(android.R.color.holo_blue_dark));
holder.tvConsumption.setTextColor(mContext.getResources().getColor(android.R.color.holo_blue_dark));
} else {
holder.tvAppName.setTextColor(mContext.getResources().getColor(android.R.color.black));
holder.tvConsumption.setTextColor(mContext.getResources().getColor(android.R.color.darker_gray));
}
//holder.tvAppName.setTextColor(mContext.getResources().getColor(android.R.color.black));
//holder.tvConsumption.setTextColor(mContext.getResources().getColor(android.R.color.darker_gray));
// 调整文字大小(提升可读性)
holder.tvAppName.setTextSize(16);