feat: 联系人增加头像选择
This commit is contained in:
@@ -15,9 +15,11 @@ import android.util.Log;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.ttstd.dialer.bean.ApkInstalledInfo;
|
||||
import com.ttstd.dialer.config.CommonConfig;
|
||||
import com.ttstd.dialer.config.LiveDataAction;
|
||||
import com.ttstd.dialer.db.app.AppInfo;
|
||||
import com.ttstd.dialer.db.app.AppRepository;
|
||||
import com.ttstd.dialer.gson.GsonUtils;
|
||||
import com.ttstd.dialer.livedata.LiveDataBus;
|
||||
import com.ttstd.dialer.utils.ApkUtils;
|
||||
import com.ttstd.dialer.utils.HashUtils;
|
||||
import com.ttstd.dialer.utils.Logger;
|
||||
@@ -398,23 +400,73 @@ public class AppManager {
|
||||
}
|
||||
|
||||
public void updateApp(String packageName) {
|
||||
List<ResolveInfo> resolveInfos = ApkUtils.getResolveInfoByPackageName(mContext, packageName);
|
||||
if (resolveInfos.isEmpty()) return;
|
||||
boolean isInstalled = ApkUtils.isInstalled(mContext, packageName);
|
||||
|
||||
resolveInfos.stream()
|
||||
.map(this::resolveInfoToDesktopApp)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(app -> !isAppExists(app))
|
||||
.forEach(app -> {
|
||||
app.setPosition(mAppRepository.getTotalCount());
|
||||
try {
|
||||
mAppRepository.insert(app);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "更新应用插入失败: " + app.getPackageName(), e);
|
||||
if (isInstalled) {
|
||||
Logger.i(TAG, "应用已安装: " + packageName + ", 开始更新数据库");
|
||||
|
||||
List<ResolveInfo> resolveInfos = ApkUtils.getResolveInfoByPackageName(mContext, packageName);
|
||||
|
||||
if (!resolveInfos.isEmpty()) {
|
||||
resolveInfos.stream()
|
||||
.map(this::resolveInfoToDesktopApp)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(app -> {
|
||||
try {
|
||||
int existingId = mAppRepository.getIdByPackageAndClass(app.getPackageName(), app.getClassName());
|
||||
|
||||
if (existingId > 0) {
|
||||
// app.setId(existingId);
|
||||
// mAppRepository.update(app);
|
||||
// Logger.i(TAG, "更新应用信息: " + app.getPackageName());
|
||||
} else {
|
||||
app.setOutside(1);
|
||||
app.setPosition(mAppRepository.getTotalCount());
|
||||
mAppRepository.insert(app);
|
||||
Logger.i(TAG, "新增应用信息: " + app.getPackageName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "处理应用失败: " + app.getPackageName(), e);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Logger.w(TAG, "应用已安装但无可启动的 Launcher Activity");
|
||||
}
|
||||
} else {
|
||||
Logger.i(TAG, "应用未安装或被禁用: " + packageName + ", 开始删除数据库数据");
|
||||
|
||||
try {
|
||||
List<AppInfo> allApps = mAppRepository.getAllApp();
|
||||
if (allApps != null) {
|
||||
List<Integer> idsToDelete = allApps.stream()
|
||||
.filter(app -> packageName.equals(app.getPackageName()))
|
||||
.map(AppInfo::getId)
|
||||
.filter(id -> id > 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!idsToDelete.isEmpty()) {
|
||||
idsToDelete.forEach(id -> {
|
||||
try {
|
||||
mAppRepository.deleteById(id);
|
||||
Logger.i(TAG, "删除应用数据库记录, ID: " + id);
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "删除应用记录失败, ID: " + id, e);
|
||||
}
|
||||
});
|
||||
Logger.i(TAG, "成功删除 " + idsToDelete.size() + " 条记录");
|
||||
} else {
|
||||
Logger.i(TAG, "数据库中未找到该应用的记录");
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, "删除应用记录时发生异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
LiveDataBus.get().send(LiveDataAction.ACTION_UPDATE_APPS, TAG);
|
||||
}
|
||||
|
||||
|
||||
// 重构getAllApp方法,复用现有处理逻辑
|
||||
public void refreshAllApps() {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
|
||||
Reference in New Issue
Block a user