feat: add icon pack management with iconloader 1.0.5
This commit is contained in:
1 parent
064af2f80f
commit
46d49c467a
24 files changed
+489
-112
No files matched your search
+1
-1
@@ -384,7 +384,7 @@ dependencies {
|
||||
implementation 'com.zackratos.ultimatebarx:ultimatebarx:0.8.1'
|
||||
//以后替换为ShapeableImageView
|
||||
implementation 'com.shehuan:niceimageview:1.0.5'
|
||||
implementation 'com.ttstd:iconloader:1.0.3'
|
||||
implementation 'com.ttstd:iconloader:1.0.5'
|
||||
implementation 'com.iqiyi.xcrash:xcrash-android-lib:3.1.0'
|
||||
|
||||
// TinyPinyin核心包,约80KB
|
||||
|
||||
@@ -5,6 +5,18 @@
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<queries>
|
||||
<intent><action android:name="org.adw.launcher.THEMES" /></intent>
|
||||
<intent><action android:name="com.gau.go.launcherex.theme" /></intent>
|
||||
<intent><action android:name="com.novalauncher.THEME" /></intent>
|
||||
<intent><action android:name="com.anddoes.launcher.THEME" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="org.adw.launcher.THEMES" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="com.gau.go.launcherex.theme" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="com.novalauncher.THEME" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="com.anddoes.launcher.THEME" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="com.teslacoilsw.launcher.THEME" /></intent>
|
||||
<intent><action android:name="android.intent.action.MAIN" /><category android:name="com.fede.launcher.THEME_ICONPACK" /></intent>
|
||||
<intent><action android:name="com.teslacoilsw.launcher.THEME" /></intent>
|
||||
<intent><action android:name="com.fede.launcher.THEME_ICONPACK" /></intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent>
|
||||
@@ -85,6 +97,10 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".activity.settings.iconpack.IconPackActivity"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.main.MainActivity"
|
||||
android:excludeFromRecents="true"
|
||||
|
||||
@@ -51,6 +51,10 @@ public class SettingsActivity extends BaseMvvmActivity<SettingsViewModel, Activi
|
||||
|
||||
public class BtnClick {
|
||||
public void openFamilyAlbum(View view) { startActivity(new Intent(SettingsActivity.this, com.ttstd.dialer.activity.album.FamilyAlbumActivity.class)); }
|
||||
public void openIconPacks(View view) {
|
||||
startActivity(new Intent(SettingsActivity.this, com.ttstd.dialer.activity.settings.iconpack.IconPackActivity.class));
|
||||
}
|
||||
|
||||
public void exit(View view) {
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.ttstd.dialer.activity.settings.iconpack;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.ttstd.dialer.R;
|
||||
import com.ttstd.dialer.base.mvvm.BaseMvvmActivity;
|
||||
import com.ttstd.dialer.databinding.ActivityIconPackBinding;
|
||||
import com.ttstd.dialer.databinding.ItemIconPackBinding;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IconPackActivity extends BaseMvvmActivity<IconPackViewModel, ActivityIconPackBinding> {
|
||||
private final PackAdapter adapter = new PackAdapter();
|
||||
@Override public boolean setfitWindow() { return true; }
|
||||
@Override public boolean setNightMode() { return true; }
|
||||
@Override protected int getLayoutId() { return R.layout.activity_icon_pack; }
|
||||
@Override protected void initDataBinding() { }
|
||||
@Override protected void initView() {
|
||||
mViewDataBinding.close.setOnClickListener(v -> finish());
|
||||
mViewDataBinding.refresh.setOnClickListener(v -> mViewModel.refresh());
|
||||
mViewDataBinding.packs.setLayoutManager(new LinearLayoutManager(this));
|
||||
mViewDataBinding.packs.setAdapter(adapter);
|
||||
}
|
||||
@Override protected void observeViewModel() {
|
||||
mViewModel.getState().observe(this, state -> {
|
||||
adapter.entries = state.entries;
|
||||
adapter.selected = state.selected;
|
||||
adapter.notifyDataSetChanged();
|
||||
String label = state.selected;
|
||||
for (IconPackRepository.Entry entry : state.entries) {
|
||||
if (entry.packageName.equals(state.selected)) label = entry.label;
|
||||
}
|
||||
mViewDataBinding.current.setText(getString(R.string.icon_pack_current, label));
|
||||
mViewDataBinding.empty.setVisibility(state.entries.size() == 1 ? View.VISIBLE : View.GONE);
|
||||
});
|
||||
mViewModel.getLoadingLiveData().observe(this, loading -> {
|
||||
mViewDataBinding.progress.setVisibility(Boolean.TRUE.equals(loading) ? View.VISIBLE : View.GONE);
|
||||
});
|
||||
}
|
||||
@Override protected void onResume() { super.onResume(); mViewModel.refresh(); }
|
||||
|
||||
private class PackAdapter extends RecyclerView.Adapter<PackHolder> {
|
||||
List<IconPackRepository.Entry> entries = new ArrayList<>();
|
||||
String selected = "";
|
||||
@NonNull @Override public PackHolder onCreateViewHolder(@NonNull ViewGroup parent, int type) {
|
||||
return new PackHolder(ItemIconPackBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
|
||||
}
|
||||
@Override public void onBindViewHolder(@NonNull PackHolder holder, int position) {
|
||||
IconPackRepository.Entry entry = entries.get(position);
|
||||
holder.binding.label.setText(entry.label);
|
||||
holder.binding.packageName.setText(entry.packageName.isEmpty() ? getString(R.string.icon_pack_original_detail) : entry.packageName);
|
||||
holder.binding.icon.setImageDrawable(entry.icon);
|
||||
holder.binding.selected.setChecked(entry.packageName.equals(selected));
|
||||
holder.binding.getRoot().setEnabled(entry.available);
|
||||
holder.binding.getRoot().setAlpha(entry.available ? 1f : 0.5f);
|
||||
holder.binding.getRoot().setOnClickListener(v -> mViewModel.select(entry.packageName));
|
||||
holder.binding.getRoot().setContentDescription(entry.label + (entry.packageName.equals(selected) ? getString(R.string.icon_pack_selected) : ""));
|
||||
}
|
||||
@Override public int getItemCount() { return entries.size(); }
|
||||
}
|
||||
private static class PackHolder extends RecyclerView.ViewHolder {
|
||||
final ItemIconPackBinding binding;
|
||||
PackHolder(ItemIconPackBinding binding) { super(binding.getRoot()); this.binding = binding; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.ttstd.dialer.activity.settings.iconpack;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.ttstd.dialer.R;
|
||||
import com.ttstd.iconloader.IconCacheManager;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class IconPackRepository {
|
||||
static final class Entry {
|
||||
final String packageName, label;
|
||||
final Drawable icon;
|
||||
final boolean available;
|
||||
Entry(String packageName, String label, Drawable icon, boolean available) {
|
||||
this.packageName = packageName; this.label = label; this.icon = icon; this.available = available;
|
||||
}
|
||||
}
|
||||
static final class State {
|
||||
final List<Entry> entries;
|
||||
final String selected;
|
||||
State(List<Entry> entries, String selected) { this.entries = entries; this.selected = selected; }
|
||||
}
|
||||
private final Context context;
|
||||
IconPackRepository(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
IconCacheManager.init(this.context);
|
||||
}
|
||||
Single<State> load() { return Single.fromCallable(this::read); }
|
||||
Single<State> select(String packageName) {
|
||||
return Single.fromCallable(() -> {
|
||||
if (!packageName.isEmpty()) context.getPackageManager().getApplicationInfo(packageName, 0);
|
||||
IconCacheManager.getInstance().setDefaultIconPack(packageName);
|
||||
return read();
|
||||
});
|
||||
}
|
||||
private State read() {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Map<String, Entry> found = new LinkedHashMap<>();
|
||||
List<Intent> queries = new ArrayList<>();
|
||||
for (String marker : new String[]{"org.adw.launcher.THEMES", "com.gau.go.launcherex.theme",
|
||||
"com.novalauncher.THEME", "com.anddoes.launcher.THEME",
|
||||
"com.teslacoilsw.launcher.THEME", "com.fede.launcher.THEME_ICONPACK"}) {
|
||||
queries.add(new Intent(marker));
|
||||
queries.add(new Intent(Intent.ACTION_MAIN).addCategory(marker));
|
||||
}
|
||||
for (Intent query : queries) {
|
||||
for (ResolveInfo info : pm.queryIntentActivities(query, 0)) {
|
||||
if (!info.activityInfo.enabled || !info.activityInfo.applicationInfo.enabled) continue;
|
||||
String name = info.activityInfo.packageName;
|
||||
if (found.containsKey(name) || !hasAppFilter(pm, name)) continue;
|
||||
found.put(name, new Entry(name, info.loadLabel(pm).toString(), info.loadIcon(pm), true));
|
||||
}
|
||||
}
|
||||
List<Entry> entries = new ArrayList<>(found.values());
|
||||
java.text.Collator collator = java.text.Collator.getInstance();
|
||||
entries.sort((a, b) -> collator.compare(a.label, b.label));
|
||||
entries.add(0, new Entry("", context.getString(R.string.icon_pack_original), pm.getDefaultActivityIcon(), true));
|
||||
String selected = IconCacheManager.getInstance().getDefaultIconPack();
|
||||
if (!selected.isEmpty() && !found.containsKey(selected)) {
|
||||
try {
|
||||
android.content.pm.ApplicationInfo app = pm.getApplicationInfo(selected, 0);
|
||||
entries.add(new Entry(selected, app.loadLabel(pm).toString(), app.loadIcon(pm), true));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
entries.add(new Entry(selected, context.getString(R.string.icon_pack_missing), pm.getDefaultActivityIcon(), false));
|
||||
}
|
||||
}
|
||||
return new State(entries, selected);
|
||||
}
|
||||
private boolean hasAppFilter(PackageManager pm, String packageName) {
|
||||
try {
|
||||
android.content.res.Resources resources = pm.getResourcesForApplication(packageName);
|
||||
if (resources.getIdentifier("appfilter", "xml", packageName) != 0) return true;
|
||||
try (java.io.InputStream ignored = resources.getAssets().open("appfilter.xml")) { return true; }
|
||||
} catch (Exception ignored) { return false; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.ttstd.dialer.activity.settings.iconpack;
|
||||
|
||||
import android.app.Application;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import com.ttstd.dialer.base.mvvm.BaseAndroidViewModel;
|
||||
import com.ttstd.dialer.repository.AppIconRepository;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class IconPackViewModel extends BaseAndroidViewModel {
|
||||
private final IconPackRepository repository;
|
||||
private final MutableLiveData<IconPackRepository.State> state = new MutableLiveData<>();
|
||||
private long requestId;
|
||||
public IconPackViewModel(Application application) {
|
||||
super(application);
|
||||
repository = new IconPackRepository(application);
|
||||
addDisposable(new AppIconRepository().changes().observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(pack -> refresh(), error -> setError(error.getMessage())));
|
||||
}
|
||||
LiveData<IconPackRepository.State> getState() { return state; }
|
||||
void refresh() { submit(repository.load()); }
|
||||
void select(String packageName) { submit(repository.select(packageName)); }
|
||||
private void submit(io.reactivex.rxjava3.core.Single<IconPackRepository.State> operation) {
|
||||
long id = ++requestId;
|
||||
setLoading(true);
|
||||
addDisposable(operation.subscribeOn(Schedulers.single()).observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(value -> {
|
||||
if (id != requestId) return;
|
||||
state.setValue(value); setLoading(false);
|
||||
}, error -> {
|
||||
if (id != requestId) return;
|
||||
setLoading(false); setError(error.getMessage());
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.ttstd.dialer.adapter;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -15,7 +12,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.kongzue.dialogx.dialogs.PopTip;
|
||||
@@ -28,24 +24,21 @@ import com.ttstd.dialer.fragment.dialog.move.MoveAppDialogFagment;
|
||||
import com.ttstd.dialer.utils.ApkUtils;
|
||||
import com.ttstd.dialer.utils.Logger;
|
||||
import com.ttstd.dialer.utils.TouchTrace;
|
||||
import com.ttstd.iconloader.IconCacheManager;
|
||||
import com.ttstd.iconloader.IconLoader;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> implements LoaderManager.LoaderCallbacks<Drawable> {
|
||||
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> {
|
||||
private static final String TAG = "AppAdapter";
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private LoaderManager mLoaderManager;
|
||||
private IconCacheManager mIconCacheManager = IconCacheManager.getInstance();
|
||||
private final AppIconBinder mIcons = new AppIconBinder();
|
||||
|
||||
public AppAdapter(LoaderManager loaderManager) {
|
||||
mLoaderManager = loaderManager;
|
||||
// Retain the public constructor for existing callers.
|
||||
}
|
||||
|
||||
private List<AppInfo> mAppInfos;
|
||||
@@ -76,14 +69,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> imple
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull @NotNull AppHolder holder, int position) {
|
||||
AppInfo appInfo = mAppInfos.get(position);
|
||||
Drawable drawable = mIconCacheManager.getIcon(appInfo.getComponentName().flattenToShortString());
|
||||
if (drawable != null) {
|
||||
holder.iv_icon.setImageDrawable(drawable);
|
||||
} else {
|
||||
if (mLoaderManager.getLoader(position) == null) {
|
||||
mLoaderManager.restartLoader(position, null, this).forceLoad();
|
||||
}
|
||||
}
|
||||
mIcons.bind(holder.iv_icon, appInfo.getComponentName());
|
||||
holder.tv_app_name.setText(appInfo.getLabel());
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -141,24 +127,22 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> imple
|
||||
return mAppInfos == null ? 0 : mAppInfos.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Override
|
||||
public Loader<Drawable> onCreateLoader(int id, @Nullable @org.jetbrains.annotations.Nullable Bundle args) {
|
||||
AppInfo appInfo = mAppInfos.get(id);
|
||||
ComponentName componentName = appInfo.getComponentName(); // 从数据项中获取 ComponentName
|
||||
return new IconLoader(mContext, componentName, mIconCacheManager);
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
mIcons.attach(this, recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(@NonNull @NotNull Loader<Drawable> loader, Drawable data) {
|
||||
int position = loader.getId();
|
||||
notifyItemChanged(position);
|
||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
mIcons.detach();
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(@NonNull @NotNull Loader<Drawable> loader) {
|
||||
Logger.e(TAG, "onLoaderReset: ");
|
||||
public void onViewRecycled(@NonNull AppHolder holder) {
|
||||
mIcons.recycle(holder.iv_icon);
|
||||
super.onViewRecycled(holder);
|
||||
}
|
||||
|
||||
public class AppHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.ttstd.dialer.adapter;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.DragEvent;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -19,7 +16,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
@@ -30,21 +26,18 @@ import com.ttstd.dialer.db.app.AppInfo;
|
||||
import com.ttstd.dialer.fragment.dialog.shortcut.ShortcutDialogFagment;
|
||||
import com.ttstd.dialer.utils.ApkUtils;
|
||||
import com.ttstd.dialer.utils.Logger;
|
||||
import com.ttstd.iconloader.IconCacheManager;
|
||||
import com.ttstd.iconloader.IconLoader;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AppGridAdapter extends RecyclerView.Adapter<AppGridAdapter.ViewHolder> implements LoaderManager.LoaderCallbacks<Drawable> {
|
||||
public class AppGridAdapter extends RecyclerView.Adapter<AppGridAdapter.ViewHolder> {
|
||||
private static final String TAG = "AppGridAdapter";
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private LoaderManager mLoaderManager;
|
||||
private IconCacheManager mIconCacheManager = IconCacheManager.getInstance();
|
||||
private final AppIconBinder mIcons = new AppIconBinder();
|
||||
private List<AppInfo> mAppInfos;
|
||||
private boolean mLongClickEnabled = true;
|
||||
|
||||
@@ -65,12 +58,12 @@ public class AppGridAdapter extends RecyclerView.Adapter<AppGridAdapter.ViewHold
|
||||
|
||||
public AppGridAdapter(FragmentActivity context, LoaderManager loaderManager) {
|
||||
mContext = context;
|
||||
mLoaderManager = loaderManager;
|
||||
// Retain the public constructor for existing callers.
|
||||
}
|
||||
|
||||
public AppGridAdapter(FragmentActivity context, LoaderManager loaderManager, boolean longClickEnabled) {
|
||||
mContext = context;
|
||||
mLoaderManager = loaderManager;
|
||||
// Retain the public constructor for existing callers.
|
||||
mLongClickEnabled = longClickEnabled;
|
||||
}
|
||||
|
||||
@@ -90,14 +83,7 @@ public class AppGridAdapter extends RecyclerView.Adapter<AppGridAdapter.ViewHold
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
|
||||
AppInfo appInfo = mAppInfos.get(position);
|
||||
Drawable drawable = mIconCacheManager.getIcon(appInfo.getComponentName().flattenToShortString());
|
||||
if (drawable != null) {
|
||||
holder.iv_icon.setImageDrawable(drawable);
|
||||
} else {
|
||||
if (mLoaderManager.getLoader(position) == null) {
|
||||
mLoaderManager.restartLoader(position, null, this).forceLoad();
|
||||
}
|
||||
}
|
||||
mIcons.bind(holder.iv_icon, appInfo.getComponentName());
|
||||
holder.tv_app_name.setText(appInfo.getLabel());
|
||||
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -223,24 +209,20 @@ public class AppGridAdapter extends RecyclerView.Adapter<AppGridAdapter.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Override
|
||||
public Loader<Drawable> onCreateLoader(int id, @Nullable @org.jetbrains.annotations.Nullable Bundle args) {
|
||||
AppInfo appInfo = mAppInfos.get(id);
|
||||
ComponentName componentName = appInfo.getComponentName();
|
||||
return new IconLoader(mContext, componentName, mIconCacheManager);
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
mIcons.attach(this, recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(@NonNull @NotNull Loader<Drawable> loader, Drawable data) {
|
||||
int position = loader.getId();
|
||||
notifyItemChanged(position);
|
||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
mIcons.detach();
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(@NonNull @NotNull Loader<Drawable> loader) {
|
||||
Logger.e(TAG, "onLoaderReset: ");
|
||||
public void onViewRecycled(@NonNull ViewHolder holder) {
|
||||
mIcons.recycle(holder.iv_icon);
|
||||
super.onViewRecycled(holder);
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.ttstd.dialer.adapter;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.widget.ImageView;
|
||||
import android.view.View;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.ttstd.dialer.repository.AppIconRepository;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** View binding with cancellable per-view requests; no position-based loader IDs. */
|
||||
final class AppIconBinder {
|
||||
private final AppIconRepository repository = new AppIconRepository();
|
||||
private final Map<ImageView, Disposable> requests = new IdentityHashMap<>();
|
||||
private Disposable changes;
|
||||
private long generation;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private View.OnAttachStateChangeListener attachment;
|
||||
|
||||
void attach(RecyclerView.Adapter<?> adapter, RecyclerView view) {
|
||||
detach();
|
||||
recyclerView = view;
|
||||
attachment = new View.OnAttachStateChangeListener() {
|
||||
@Override public void onViewAttachedToWindow(View v) { observe(adapter, view); }
|
||||
@Override public void onViewDetachedFromWindow(View v) { stop(); }
|
||||
};
|
||||
view.addOnAttachStateChangeListener(attachment);
|
||||
if (view.isAttachedToWindow()) observe(adapter, view);
|
||||
}
|
||||
|
||||
private void observe(RecyclerView.Adapter<?> adapter, RecyclerView view) {
|
||||
stop();
|
||||
changes = repository.changes().observeOn(AndroidSchedulers.mainThread()).subscribe(pack -> {
|
||||
cancelRequests();
|
||||
view.post(() -> {
|
||||
if (view.isAttachedToWindow() && view.getAdapter() == adapter) adapter.notifyDataSetChanged();
|
||||
});
|
||||
});
|
||||
view.post(() -> {
|
||||
if (view.isAttachedToWindow() && view.getAdapter() == adapter) adapter.notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
void bind(ImageView view, ComponentName component) {
|
||||
recycle(view);
|
||||
view.setImageDrawable(null);
|
||||
long requestGeneration = generation;
|
||||
Disposable request = repository.load(component).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(icon -> {
|
||||
if (requestGeneration == generation) view.setImageDrawable(icon);
|
||||
}, error -> view.setImageDrawable(null));
|
||||
requests.put(view, request);
|
||||
}
|
||||
|
||||
void recycle(ImageView view) {
|
||||
Disposable request = requests.remove(view);
|
||||
if (request != null) request.dispose();
|
||||
}
|
||||
|
||||
private void cancelRequests() {
|
||||
generation++;
|
||||
for (Disposable request : requests.values()) request.dispose();
|
||||
requests.clear();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
if (changes != null) changes.dispose();
|
||||
changes = null;
|
||||
cancelRequests();
|
||||
}
|
||||
void detach() {
|
||||
stop();
|
||||
if (recyclerView != null && attachment != null) recyclerView.removeOnAttachStateChangeListener(attachment);
|
||||
recyclerView = null;
|
||||
attachment = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.ttstd.dialer.adapter;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.DragEvent;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -19,7 +16,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
@@ -31,21 +27,18 @@ import com.ttstd.dialer.fragment.dialog.dock.DockAppDialogFagment;
|
||||
import com.ttstd.dialer.fragment.dialog.shortcut.ShortcutDialogFagment;
|
||||
import com.ttstd.dialer.utils.ApkUtils;
|
||||
import com.ttstd.dialer.utils.Logger;
|
||||
import com.ttstd.iconloader.IconCacheManager;
|
||||
import com.ttstd.iconloader.IconLoader;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MoreAppAdapter extends RecyclerView.Adapter<MoreAppAdapter.AppHolder> implements LoaderManager.LoaderCallbacks<Drawable> {
|
||||
public class MoreAppAdapter extends RecyclerView.Adapter<MoreAppAdapter.AppHolder> {
|
||||
private static final String TAG = "MoreAppAdapter";
|
||||
|
||||
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
|
||||
|
||||
private FragmentActivity mContext;
|
||||
private LoaderManager mLoaderManager;
|
||||
private IconCacheManager mIconCacheManager = IconCacheManager.getInstance();
|
||||
private final AppIconBinder mIcons = new AppIconBinder();
|
||||
private boolean mLongClickEnabled = true;
|
||||
|
||||
public interface ShortcutCallback {
|
||||
@@ -65,11 +58,11 @@ public class MoreAppAdapter extends RecyclerView.Adapter<MoreAppAdapter.AppHolde
|
||||
}
|
||||
|
||||
public MoreAppAdapter(LoaderManager loaderManager) {
|
||||
mLoaderManager = loaderManager;
|
||||
// Retain the public constructor for existing callers.
|
||||
}
|
||||
|
||||
public MoreAppAdapter(LoaderManager loaderManager, boolean longClickEnabled) {
|
||||
mLoaderManager = loaderManager;
|
||||
// Retain the public constructor for existing callers.
|
||||
mLongClickEnabled = longClickEnabled;
|
||||
}
|
||||
|
||||
@@ -97,14 +90,7 @@ public class MoreAppAdapter extends RecyclerView.Adapter<MoreAppAdapter.AppHolde
|
||||
public void onBindViewHolder(@NonNull @NotNull AppHolder holder, int position) {
|
||||
AppInfo appInfo = mAppInfos.get(position);
|
||||
holder.root.setAlpha(1.0f);
|
||||
Drawable drawable = mIconCacheManager.getIcon(appInfo.getComponentName().flattenToShortString());
|
||||
if (drawable != null) {
|
||||
holder.iv_icon.setImageDrawable(drawable);
|
||||
} else {
|
||||
if (mLoaderManager.getLoader(position) == null) {
|
||||
mLoaderManager.restartLoader(position, null, this).forceLoad();
|
||||
}
|
||||
}
|
||||
mIcons.bind(holder.iv_icon, appInfo.getComponentName());
|
||||
holder.tv_app_name.setText(appInfo.getLabel());
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -239,24 +225,20 @@ public class MoreAppAdapter extends RecyclerView.Adapter<MoreAppAdapter.AppHolde
|
||||
return mAppInfos == null ? 0 : mAppInfos.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@NotNull
|
||||
@Override
|
||||
public Loader<Drawable> onCreateLoader(int id, @Nullable @org.jetbrains.annotations.Nullable Bundle args) {
|
||||
AppInfo appInfo = mAppInfos.get(id);
|
||||
ComponentName componentName = appInfo.getComponentName(); // 从数据项中获取 ComponentName
|
||||
return new IconLoader(mContext, componentName, mIconCacheManager);
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
mIcons.attach(this, recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(@NonNull @NotNull Loader<Drawable> loader, Drawable data) {
|
||||
int position = loader.getId();
|
||||
notifyItemChanged(position);
|
||||
public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
mIcons.detach();
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(@NonNull @NotNull Loader<Drawable> loader) {
|
||||
Logger.e(TAG, "onLoaderReset: ");
|
||||
public void onViewRecycled(@NonNull AppHolder holder) {
|
||||
mIcons.recycle(holder.iv_icon);
|
||||
super.onViewRecycled(holder);
|
||||
}
|
||||
|
||||
public class AppHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
@@ -114,11 +113,11 @@ public class DockAppDialogFagment extends BaseMvvmDialogFragment<DockAppViewMode
|
||||
}
|
||||
|
||||
if (mAppInfo != null) {
|
||||
mViewModel.loadIcon(mAppInfo.getComponentName());
|
||||
try {
|
||||
ActivityInfo info = mPackageManager.getActivityInfo(mAppInfo.getComponentName(), 0);
|
||||
mViewDataBinding.tvAppName.setText(info.loadLabel(mPackageManager));
|
||||
Drawable rawIcon = info.loadIcon(mPackageManager);
|
||||
mViewDataBinding.ivIcon.setImageDrawable(rawIcon);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -127,7 +126,7 @@ public class DockAppDialogFagment extends BaseMvvmDialogFragment<DockAppViewMode
|
||||
|
||||
@Override
|
||||
protected void observeViewModel() {
|
||||
|
||||
mViewModel.getIcon().observe(getViewLifecycleOwner(), icon -> mViewDataBinding.ivIcon.setImageDrawable(icon));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ttstd.dialer.fragment.dialog.dock;
|
||||
|
||||
import com.ttstd.dialer.base.mvvm.BaseViewModel;
|
||||
import com.ttstd.dialer.viewmodel.AppIconViewModel;
|
||||
|
||||
public class DockAppViewModel extends BaseViewModel {
|
||||
public class DockAppViewModel extends AppIconViewModel {
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
@@ -109,11 +108,11 @@ public class MoveAppDialogFagment extends BaseMvvmDialogFragment<MoveAppViewMode
|
||||
}
|
||||
|
||||
if (mAppInfo != null) {
|
||||
mViewModel.loadIcon(mAppInfo.getComponentName());
|
||||
try {
|
||||
ActivityInfo info = mPackageManager.getActivityInfo(mAppInfo.getComponentName(), 0);
|
||||
mViewDataBinding.tvAppName.setText(info.loadLabel(mPackageManager));
|
||||
Drawable rawIcon = info.loadIcon(mPackageManager);
|
||||
mViewDataBinding.ivAppIcon.setImageDrawable(rawIcon);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -122,7 +121,7 @@ public class MoveAppDialogFagment extends BaseMvvmDialogFragment<MoveAppViewMode
|
||||
|
||||
@Override
|
||||
protected void observeViewModel() {
|
||||
|
||||
mViewModel.getIcon().observe(getViewLifecycleOwner(), icon -> mViewDataBinding.ivAppIcon.setImageDrawable(icon));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ttstd.dialer.fragment.dialog.move;
|
||||
|
||||
import com.ttstd.dialer.base.mvvm.BaseViewModel;
|
||||
import com.ttstd.dialer.viewmodel.AppIconViewModel;
|
||||
|
||||
public class MoveAppViewModel extends BaseViewModel {
|
||||
public class MoveAppViewModel extends AppIconViewModel {
|
||||
|
||||
}
|
||||
+3
-4
@@ -5,7 +5,6 @@ import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
@@ -114,11 +113,11 @@ public class ShortcutDialogFagment extends BaseMvvmDialogFragment<ShortcutViewMo
|
||||
}
|
||||
|
||||
if (mAppInfo != null) {
|
||||
mViewModel.loadIcon(mAppInfo.getComponentName());
|
||||
try {
|
||||
ActivityInfo info = mPackageManager.getActivityInfo(mAppInfo.getComponentName(), 0);
|
||||
mViewDataBinding.tvAppName.setText(info.loadLabel(mPackageManager));
|
||||
Drawable rawIcon = info.loadIcon(mPackageManager);
|
||||
mViewDataBinding.ivIcon.setImageDrawable(rawIcon);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -127,7 +126,7 @@ public class ShortcutDialogFagment extends BaseMvvmDialogFragment<ShortcutViewMo
|
||||
|
||||
@Override
|
||||
protected void observeViewModel() {
|
||||
|
||||
mViewModel.getIcon().observe(getViewLifecycleOwner(), icon -> mViewDataBinding.ivIcon.setImageDrawable(icon));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ttstd.dialer.fragment.dialog.shortcut;
|
||||
|
||||
import com.ttstd.dialer.base.mvvm.BaseViewModel;
|
||||
import com.ttstd.dialer.viewmodel.AppIconViewModel;
|
||||
|
||||
public class ShortcutViewModel extends BaseViewModel {
|
||||
public class ShortcutViewModel extends AppIconViewModel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ttstd.dialer.repository;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.ttstd.iconloader.IconCacheManager;
|
||||
import io.reactivex.rxjava3.core.Observable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
|
||||
/** Shared icon source for desktop lists and dialogs. */
|
||||
public class AppIconRepository {
|
||||
public Single<Drawable> load(ComponentName component) {
|
||||
return Single.fromCallable(() -> IconCacheManager.getInstance().loadIcon(component));
|
||||
}
|
||||
|
||||
public Observable<String> changes() {
|
||||
return Observable.create(emitter -> {
|
||||
IconCacheManager cache = IconCacheManager.getInstance();
|
||||
IconCacheManager.OnIconPackChangedListener listener = pack -> {
|
||||
if (!emitter.isDisposed()) emitter.onNext(pack);
|
||||
};
|
||||
cache.addOnIconPackChangedListener(listener);
|
||||
emitter.setCancellable(() -> cache.removeOnIconPackChangedListener(listener));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.ttstd.dialer.viewmodel;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import com.ttstd.dialer.base.mvvm.BaseViewModel;
|
||||
import com.ttstd.dialer.repository.AppIconRepository;
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
|
||||
public class AppIconViewModel extends BaseViewModel {
|
||||
private final AppIconRepository repository = new AppIconRepository();
|
||||
private final MutableLiveData<Drawable> icon = new MutableLiveData<>();
|
||||
private ComponentName component;
|
||||
private long requestId;
|
||||
|
||||
public AppIconViewModel() {
|
||||
addDisposable(repository.changes().observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(pack -> { if (component != null) loadIcon(component); }, error -> setError(error.getMessage())));
|
||||
}
|
||||
|
||||
public LiveData<Drawable> getIcon() { return icon; }
|
||||
|
||||
public void loadIcon(ComponentName component) {
|
||||
this.component = component;
|
||||
long id = ++requestId;
|
||||
icon.setValue(null);
|
||||
addDisposable(repository.load(component).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(value -> { if (id == requestId) icon.setValue(value); }, error -> setError(error.getMessage())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<data />
|
||||
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp">
|
||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical">
|
||||
<Button android:id="@+id/close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="48dp" android:text="@string/icon_pack_back" />
|
||||
<TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="@string/icon_pack_title" android:textSize="24sp" android:textColor="@color/theme_text_primary" />
|
||||
</LinearLayout>
|
||||
<TextView android:id="@+id/current" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="16dp" android:textSize="20sp" android:textColor="@color/theme_text_primary" />
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="8dp" android:paddingBottom="8dp" android:text="@string/icon_pack_tip" android:textSize="16sp" android:textColor="@color/theme_text_primary" />
|
||||
<Button android:id="@+id/refresh" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="48dp" android:text="@string/icon_pack_refresh" android:textSize="20sp" />
|
||||
<ProgressBar android:id="@+id/progress" android:layout_width="32dp" android:layout_height="32dp" android:layout_gravity="center" android:visibility="gone" />
|
||||
<TextView android:id="@+id/empty" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="12dp" android:text="@string/icon_pack_empty" android:textSize="18sp" android:textColor="@color/theme_text_primary" android:visibility="gone" />
|
||||
<androidx.recyclerview.widget.RecyclerView android:id="@+id/packs" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
@@ -70,6 +70,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
@@ -78,6 +79,13 @@
|
||||
android:background="@drawable/settings_card_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:onClick="@{click::openIconPacks}"
|
||||
android:text="@string/icon_pack_title"
|
||||
android:textSize="22sp" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<data />
|
||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="88dp" android:padding="12dp" android:gravity="center_vertical" android:background="?attr/selectableItemBackground" android:clickable="true" android:focusable="true" android:orientation="horizontal">
|
||||
<ImageView android:id="@+id/icon" android:layout_width="48dp" android:layout_height="48dp" android:importantForAccessibility="no" />
|
||||
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginStart="12dp" android:orientation="vertical">
|
||||
<TextView android:id="@+id/label" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22sp" android:textColor="@color/theme_text_primary" />
|
||||
<TextView android:id="@+id/package_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="14sp" android:textColor="@color/theme_text_primary" />
|
||||
</LinearLayout>
|
||||
<RadioButton android:id="@+id/selected" android:layout_width="48dp" android:layout_height="48dp" android:clickable="false" android:focusable="false" android:importantForAccessibility="no" />
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
@@ -0,0 +1,12 @@
|
||||
<resources>
|
||||
<string name="icon_pack_title">图标包管理</string>
|
||||
<string name="icon_pack_back">返回</string>
|
||||
<string name="icon_pack_original">原始图标</string>
|
||||
<string name="icon_pack_original_detail">使用应用自带的图标</string>
|
||||
<string name="icon_pack_current">当前图标包:%1$s</string>
|
||||
<string name="icon_pack_selected">,已选中</string>
|
||||
<string name="icon_pack_tip">点击图标包即可应用。未适配的应用保留原始图标。</string>
|
||||
<string name="icon_pack_refresh">刷新图标包列表</string>
|
||||
<string name="icon_pack_empty">尚未发现图标包。安装兼容 Nova / ADW 格式的图标包后,点击刷新。</string>
|
||||
<string name="icon_pack_missing">所选图标包未安装,暂用原始图标</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,19 @@
|
||||
# 图标包管理
|
||||
|
||||
入口:桌面设置 → 图标包管理。选择即应用,选择“原始图标”恢复;默认选择由 iconloader 持久保存。
|
||||
|
||||
支持以 action 或 MAIN + category 声明的常见 Nova/ADW/Apex/GO 图标包。页面列出已安装包;所选包卸载后显示缺失状态并回退原图。安装、卸载、更新会刷新打开的列表;从安装界面返回时也会刷新。没有匹配映射的应用使用原始图标。
|
||||
|
||||
应用列表和快捷方式、Dock、移动应用弹窗均通过 AppIconRepository 加载。列表按视图取消异步请求,回收或离开窗口时取消订阅,主题变化后重新绑定。应用原始图标上传逻辑保持独立。
|
||||
|
||||
## 共享库构建
|
||||
|
||||
默认依赖已发布的 `com.ttstd:iconloader:1.0.5`,本地及 CI 构建均通过 Maven 仓库解析。需要共享源码联调时,可显式传入 `-PiconloaderSourceDir=路径` 指向 IconLoader_ttstd 仓库,settings.gradle 将通过组合构建替换该依赖;不再自动使用本机相邻目录。
|
||||
|
||||
远程获取和设置默认图标包继续由共享库预留接口承接,本次不新增后端接口或推送协议。动态日历、时钟和遮罩合成仍以共享库的支持范围为准。
|
||||
|
||||
## 验证
|
||||
|
||||
本项目 app/libs/framework.jar 含 Java 21 字节码,命令行构建需使用 JDK 21(例如 Android Studio 自带的 jbr)。验证命令:`gradlew.bat :app:compileDebugJavaWithJavac --offline --max-workers=2`。
|
||||
|
||||
真机复测:安装兼容图标包 → 在管理页选择 → 检查首页、更多应用及三个应用弹窗 → 恢复原始图标 → 重启检查选择持久化 → 卸载所选包检查回退 → 重新安装检查恢复。快速切换图标包、滚动应用列表和重排应用时应始终显示当前组件的图标。
|
||||
@@ -1,2 +1,17 @@
|
||||
rootProject.name = '拨号助手'
|
||||
include ':app'
|
||||
|
||||
// Optional source debugging: -PiconloaderSourceDir=/path/to/IconLoader_ttstd.
|
||||
// Normal and CI builds use the published Maven artifact.
|
||||
def iconloaderSourcePath = providers.gradleProperty('iconloaderSourceDir').orNull
|
||||
if (iconloaderSourcePath != null) {
|
||||
def iconloaderSource = file(iconloaderSourcePath)
|
||||
if (!new File(iconloaderSource, 'settings.gradle').isFile()) {
|
||||
throw new GradleException("iconloaderSourceDir must point to the IconLoader_ttstd checkout")
|
||||
}
|
||||
includeBuild(iconloaderSource) {
|
||||
dependencySubstitution {
|
||||
substitute module('com.ttstd:iconloader') using project(':iconloader')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user