优化方法名,去掉无用代码
This commit is contained in:
@@ -23,7 +23,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
@@ -32,19 +34,31 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
|
||||
public class AppManager {
|
||||
private static final String TAG = "AppManager";
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static AppManager INSTANCE;
|
||||
private Context mContext;
|
||||
private AppRepository mAppRepository;
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
private Set<ProgressCallback> mProgressCallbacks = new CopyOnWriteArraySet<>();
|
||||
|
||||
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
private static final int CORE_POOL_SIZE = Math.max(2, Math.min(CPU_COUNT - 1, 4));
|
||||
private static final ExecutorService ASYNC_EXECUTOR = Executors.newFixedThreadPool(CORE_POOL_SIZE);
|
||||
|
||||
public interface ProgressCallback {
|
||||
void onProgress(String step, int current, int total);
|
||||
|
||||
void onCompleted(boolean success, String message);
|
||||
}
|
||||
|
||||
public void addProgressCallback(ProgressCallback progressCallback) {
|
||||
mProgressCallbacks.add(progressCallback);
|
||||
}
|
||||
|
||||
public static final List<String> DEFAULT_APP_PACKAGES = new ArrayList<String>() {{
|
||||
this.add("com.android.settings");
|
||||
@@ -74,11 +88,6 @@ public class AppManager {
|
||||
executeAppListProcessing();
|
||||
}
|
||||
|
||||
public interface ProgressCallback {
|
||||
void onProgress(String step, int current, int total);
|
||||
|
||||
void onCompleted(boolean success, String message);
|
||||
}
|
||||
|
||||
// 异步执行方法
|
||||
public void executeAppListProcessing() {
|
||||
@@ -107,7 +116,7 @@ public class AppManager {
|
||||
// 第一步:获取所有桌面应用(增加空值安全处理)
|
||||
private List<DesktopSortApp> getAllDesktopSortApps() {
|
||||
try {
|
||||
List<DesktopSortApp> result = mAppRepository.getAllContacts();
|
||||
List<DesktopSortApp> result = mAppRepository.getAllApp();
|
||||
return result != null ? result : Collections.emptyList();
|
||||
} catch (Exception e) {
|
||||
Log.e("AppListProcessor", "获取桌面应用列表失败", e);
|
||||
@@ -117,7 +126,7 @@ public class AppManager {
|
||||
|
||||
private Optional<List<DesktopSortApp>> getAllDesktopSortAppsSafe() {
|
||||
try {
|
||||
return Optional.ofNullable(mAppRepository.getAllContacts())
|
||||
return Optional.ofNullable(mAppRepository.getAllApp())
|
||||
.filter(list -> !list.isEmpty());
|
||||
} catch (Exception e) {
|
||||
Log.e("AppListProcessor", "获取应用列表失败", e);
|
||||
@@ -286,7 +295,7 @@ public class AppManager {
|
||||
}
|
||||
|
||||
public void getAllApp() {
|
||||
List<DesktopSortApp> desktopSortApps = mAppRepository.getAllContacts();
|
||||
List<DesktopSortApp> desktopSortApps = mAppRepository.getAllApp();
|
||||
List<Integer> ids = desktopSortApps.stream().filter(new Predicate<DesktopSortApp>() {
|
||||
@Override
|
||||
public boolean test(DesktopSortApp desktopSortApp) {
|
||||
|
||||
Reference in New Issue
Block a user