diff options
author | Matthew Wong <wongma@protonmail.ch> | 2015-08-14 13:31:23 -0400 |
---|---|---|
committer | Matthew Wong <wongma@protonmail.ch> | 2015-08-14 17:38:17 -0400 |
commit | 8388d8530a63d1484607aa83faa27a99adb40f8e (patch) | |
tree | c45b0dd6d027a5ba45cbd8542a280698c9a997be | |
parent | b260a19be7172ad34487669a02c3002bc234b3b2 (diff) |
Load icons & labels async beforehand as well
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java | 12 | ||||
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java | 15 |
2 files changed, 22 insertions, 5 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java index 1170d7b7..16867bcd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java @@ -4,6 +4,7 @@ import android.app.DialogFragment; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.NavUtils; @@ -13,12 +14,14 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; +import android.util.Pair; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.zeapo.pwdstore.R; +import java.util.HashMap; import java.util.List; public class AutofillPreferenceActivity extends AppCompatActivity { @@ -60,7 +63,14 @@ public class AutofillPreferenceActivity extends AppCompatActivity { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> allApps = pm.queryIntentActivities(intent, 0); - recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this); + + HashMap<String, Pair<Drawable, String>> iconMap = new HashMap<>(allApps.size()); + for (ResolveInfo app : allApps) { + iconMap.put(app.activityInfo.packageName + , Pair.create(app.loadIcon(pm), app.loadLabel(pm).toString())); + } + + recyclerAdapter = new AutofillRecyclerAdapter(allApps, iconMap, pm, AutofillPreferenceActivity.this); return null; } diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java index 2162b53d..01916650 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java @@ -4,9 +4,11 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; import android.support.v7.util.SortedList; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.util.SortedListAdapterCallback; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,11 +18,13 @@ import android.widget.TextView; import com.zeapo.pwdstore.R; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapter.ViewHolder> { private SortedList<ResolveInfo> apps; private ArrayList<ResolveInfo> allApps; + private HashMap<String, Pair<Drawable, String>> iconMap; private PackageManager pm; private AutofillPreferenceActivity activity; @@ -47,11 +51,12 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl } - public AutofillRecyclerAdapter(List<ResolveInfo> allApps, final PackageManager pm, AutofillPreferenceActivity activity) { + public AutofillRecyclerAdapter(List<ResolveInfo> allApps, HashMap<String, Pair<Drawable, String>> iconMap + , final PackageManager pm, AutofillPreferenceActivity activity) { SortedList.Callback<ResolveInfo> callback = new SortedListAdapterCallback<ResolveInfo>(this) { @Override public int compare(ResolveInfo o1, ResolveInfo o2) { - return o1.loadLabel(pm).toString().compareTo(o2.loadLabel(pm).toString()); + return o1.loadLabel(pm).toString().toLowerCase().compareTo(o2.loadLabel(pm).toString().toLowerCase()); } @Override @@ -67,6 +72,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl this.apps = new SortedList<>(ResolveInfo.class, callback); this.apps.addAll(allApps); this.allApps = new ArrayList<>(allApps); + this.iconMap = new HashMap<>(iconMap); this.pm = pm; this.activity = activity; } @@ -81,10 +87,11 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl @Override public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) { ResolveInfo app = apps.get(position); - holder.name.setText(app.loadLabel(pm)); // 'No package identifier when getting value for resource number 0x00000000' 5+ - holder.icon.setImageDrawable(app.loadIcon(pm)); holder.packageName = app.activityInfo.packageName; + holder.icon.setImageDrawable(iconMap.get(holder.packageName).first); + holder.name.setText(iconMap.get(holder.packageName).second); + holder.secondary.setVisibility(View.VISIBLE); holder.view.setBackgroundResource(R.color.grey_white_1000); |