From a55d839a73dd7490cb092098d34f243fc0d198f4 Mon Sep 17 00:00:00 2001 From: HenriDellal Date: Wed, 2 Jan 2019 22:11:12 +0300 Subject: [PATCH] (0.6.1) Fix fast scroll, other minor changes --- app/src/main/AndroidManifest.xml | 2 +- .../ru/henridellal/emerald/CustomAdapter.java | 107 ++++++++++-------- .../ru/henridellal/emerald/MainLayout.java | 1 - app/src/main/res/values/strings.xml | 2 +- 4 files changed, 63 insertions(+), 49 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dfd443b..6aeb80a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ diff --git a/app/src/main/java/ru/henridellal/emerald/CustomAdapter.java b/app/src/main/java/ru/henridellal/emerald/CustomAdapter.java index da59fb3..69f6357 100644 --- a/app/src/main/java/ru/henridellal/emerald/CustomAdapter.java +++ b/app/src/main/java/ru/henridellal/emerald/CustomAdapter.java @@ -1,8 +1,6 @@ package ru.henridellal.emerald; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Typeface; @@ -29,25 +27,24 @@ public class CustomAdapter extends BaseAdapter implements SectionIndexer private View.OnClickListener onClickListener; private View.OnLongClickListener onLongClickListener; + private ViewGroup.LayoutParams imageViewLayoutParams; private SoftReference contextRef; private SharedPreferences options; private ArrayList categoryData, toDisplay; - private ArrayList sectionsList; private HashMap indexData; private String[] sections; - private int curMode, iconSize, textSize, textColor, appShortcut, inflatedLayoutId, fontStyle; + private int iconSize, textSize, textColor, appShortcut, inflatedLayoutId, fontStyle; boolean lock, fastScrollEnabled; - private ImageView img; - private TextView tv; private String searchInput; - private Set sectionsSet; private Comparator comparator; - public void setIconSize(int size) {iconSize = size;} + public void setIconSize(int size) { + iconSize = size; + imageViewLayoutParams = null; + } public void setTextSize(int size) {textSize = size;} public void filter(CharSequence searchInput) { - indexData.clear(); this.searchInput = searchInput.toString(); toDisplay = new ArrayList(); for (BaseData a: categoryData) { @@ -55,28 +52,33 @@ public void filter(CharSequence searchInput) { toDisplay.add(a); } } - setSections(); Collections.sort(toDisplay, comparator); + setSections(); notifyDataSetChanged(); } public void setSections() { indexData.clear(); if (fastScrollEnabled) { - if (this.searchInput.equals("")) { + if (!searchInput.equals("") || CategoryManager.HISTORY.equals(LauncherApp.getCategoryManager().getCurCategory())) { + sections = new String[0]; + return; + } else { String ch; - int appIndex = 0; - for (BaseData a: categoryData) { + int sectionIndex = 0; + for (int i = 0; i < toDisplay.size(); i++) { + BaseData a = toDisplay.get(i); ch = (a.name.length() > 1) ? a.name.substring(0,1).toUpperCase() : a.name; - indexData.put(ch, appIndex); - appIndex++; + if (!indexData.containsKey(ch)) { + indexData.put(ch, sectionIndex); + sectionIndex++; + } } + Set sectionsSet = indexData.keySet(); + ArrayList sectionsList = new ArrayList(sectionsSet); + Collections.sort(sectionsList); + sections = new String[sectionsList.size()]; + sectionsList.toArray(sections); } - - sectionsSet = indexData.keySet(); - sectionsList = new ArrayList(sectionsSet); - Collections.sort(sectionsList); - sections = new String[sectionsList.size()]; - sectionsList.toArray(sections); } } @@ -88,48 +90,61 @@ public boolean isEnabled(int position) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view; - BaseData a; - - a = toDisplay.get(position); + ImageView img; + TextView tv; + BaseData a = toDisplay.get(position); boolean isEmptyView = (convertView == null); if (isEmptyView) { LayoutInflater inflater = (LayoutInflater)contextRef.get().getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(inflatedLayoutId, parent, false); + img = (ImageView) view.findViewById(R.id.icon); + tv = (TextView) view.findViewById(R.id.text); + switch (appShortcut) { + case TEXT: + img.setVisibility(View.GONE); + setTextViewParams(tv); + break; + case ICON: + setImageViewLayoutParams(img); + tv.setVisibility(View.GONE); + break; + default: + setImageViewLayoutParams(img); + setTextViewParams(tv); + } + view.setOnClickListener(onClickListener); + view.setOnLongClickListener(onLongClickListener); } else { view = convertView; + img = (ImageView) view.findViewById(R.id.icon); + tv = (TextView) view.findViewById(R.id.text); } // app shortcut view.setTag(a); - img = (ImageView) view.findViewById(R.id.icon); - tv = (TextView) view.findViewById(R.id.text); - if (appShortcut != ICON) { tv.setText(a.name); - if (isEmptyView) { - if (appShortcut == TEXT) { - img.setVisibility(View.GONE); - } - tv.setTextSize(textSize); - tv.setTextColor(textColor); - tv.setTypeface(Typeface.DEFAULT, fontStyle); - } - } else { - tv.setVisibility(View.GONE); + tv.setTextSize(textSize); } if (appShortcut >= ICON) { IconPackManager.setIcon(contextRef.get(), img, a); - if (isEmptyView) { - img.setVisibility(View.VISIBLE); - ViewGroup.LayoutParams p = img.getLayoutParams(); - p.width = iconSize; - p.height = iconSize; - img.setLayoutParams(p); - } } - view.setOnClickListener(onClickListener); - view.setOnLongClickListener(onLongClickListener); return view; } + + public void setTextViewParams(TextView tv) { + tv.setTextColor(textColor); + tv.setTypeface(Typeface.DEFAULT, fontStyle); + } + + public void setImageViewLayoutParams(ImageView img) { + if (null == imageViewLayoutParams) { + imageViewLayoutParams = img.getLayoutParams(); + imageViewLayoutParams.width = iconSize; + imageViewLayoutParams.height = iconSize; + } + img.setLayoutParams(imageViewLayoutParams); + } + public String getAppName(int position) { return toDisplay.get(position).name; } diff --git a/app/src/main/java/ru/henridellal/emerald/MainLayout.java b/app/src/main/java/ru/henridellal/emerald/MainLayout.java index b817cf1..36e8101 100644 --- a/app/src/main/java/ru/henridellal/emerald/MainLayout.java +++ b/app/src/main/java/ru/henridellal/emerald/MainLayout.java @@ -1,6 +1,5 @@ package ru.henridellal.emerald; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5819006..d749e67 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ Emerald Launcher - 0.6.0.3 + 0.6.1 Appearance preferences Portrait mode preferences Landscape mode preferences