From e28cebf5315c3d795829a146a1341d7edf6b2328 Mon Sep 17 00:00:00 2001 From: HenriDellal Date: Thu, 4 Oct 2018 16:16:13 +0300 Subject: [PATCH] Close #86 --- .../java/ru/henridellal/emerald/AppData.java | 4 ++-- .../java/ru/henridellal/emerald/Apps.java | 4 +++- .../henridellal/emerald/CategoryManager.java | 15 +++--------- .../emerald/DatabaseConverter.java | 23 ++++++++++++++----- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/ru/henridellal/emerald/AppData.java b/app/src/main/java/ru/henridellal/emerald/AppData.java index 8d281a5..e178f7b 100644 --- a/app/src/main/java/ru/henridellal/emerald/AppData.java +++ b/app/src/main/java/ru/henridellal/emerald/AppData.java @@ -53,9 +53,9 @@ public void addCategory(String category) { private String getCategoriesString() { StringBuilder result = new StringBuilder(); for (String s: categories) { - result.append("-"); + result.append("@"); result.append(s); - result.append("-"); + result.append("@"); } return result.toString(); } diff --git a/app/src/main/java/ru/henridellal/emerald/Apps.java b/app/src/main/java/ru/henridellal/emerald/Apps.java index db27282..a0127d7 100644 --- a/app/src/main/java/ru/henridellal/emerald/Apps.java +++ b/app/src/main/java/ru/henridellal/emerald/Apps.java @@ -330,6 +330,7 @@ public static void writeIconToFile(File iconFile, Drawable d, String component) private void openCategoriesList() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true); + categories.loadCategoriesList(); // TODO Remove after migration to 0.6.0 final ArrayList cats = new ArrayList(categories.getCategories()); cats.remove(CategoryManager.HIDDEN); ArrayList toRemove = new ArrayList(); @@ -897,9 +898,10 @@ protected void onCreate(Bundle savedInstanceState) { } categories = LauncherApp.getCategoryManager(); if (new File(MyCache.genFilename(this, "apps")).exists()) { + categories.setCurCategory(CategoryManager.ALL); new MoveCustomIconsTask(this).execute(); - categories.convert(); DatabaseConverter.convert(this); + categories.convert(); launcherUpdate = true; } super.onCreate(savedInstanceState); diff --git a/app/src/main/java/ru/henridellal/emerald/CategoryManager.java b/app/src/main/java/ru/henridellal/emerald/CategoryManager.java index 2d45e0d..7393575 100644 --- a/app/src/main/java/ru/henridellal/emerald/CategoryManager.java +++ b/app/src/main/java/ru/henridellal/emerald/CategoryManager.java @@ -101,7 +101,6 @@ public ArrayList getCategoryData(String category) { return DatabaseHelper.getEntries(contextRef.get(), category); } public void convert() { - setCurCategory(ALL); BufferedReader reader = null; File file = new File(contextRef.get().getFilesDir() + "/categories.props"); ArrayList hiddenCategories = new ArrayList(); @@ -137,19 +136,11 @@ public void convert() { file.delete(); } catch (IOException e) { } - for (File f : contextRef.get().getFilesDir().listFiles()) { - //get files names and look for .cat ones - String n = f.getName(); - if (n.endsWith(".cat")) { - String name = n.substring(0, n.length()-4); - name = URLDecoder.decode(name); - DatabaseHelper.addCategory(contextRef.get(), name); - } - } + if (hiddenCategories.contains("History")) { - options.edit().putBoolean(Keys.HIDE_HISTORY, true); + options.edit().putBoolean(Keys.HIDE_HISTORY, true).commit(); } else if (hiddenCategories.contains("Unclassified")) { - options.edit().putBoolean(Keys.HIDE_UNCLASSIFIED, true); + options.edit().putBoolean(Keys.HIDE_UNCLASSIFIED, true).commit(); } } diff --git a/app/src/main/java/ru/henridellal/emerald/DatabaseConverter.java b/app/src/main/java/ru/henridellal/emerald/DatabaseConverter.java index 92f0509..0fe38cf 100644 --- a/app/src/main/java/ru/henridellal/emerald/DatabaseConverter.java +++ b/app/src/main/java/ru/henridellal/emerald/DatabaseConverter.java @@ -4,6 +4,7 @@ import android.database.sqlite.SQLiteDatabase; import java.io.File; +import java.net.URLDecoder; import java.util.ArrayList; public class DatabaseConverter { @@ -13,18 +14,28 @@ public static void convert(Context context) { MyCache.read(context, "apps", appsData); CategoryManager cm = LauncherApp.getCategoryManager(); ArrayList components = new ArrayList(); - for (String category: cm.getEditableCategories()) { - components = cm.getEntriesComponents(cm.catPath(category)); - for (BaseData data: appsData) { - if (components.contains(data.getComponent())) { - ((AppData)data).addCategory(category); + + for (File f : context.getFilesDir().listFiles()) { + String filename = f.getName(); + if (filename.endsWith(".cat")) { + String categoryName = filename.substring(0, filename.length()-4); + categoryName = URLDecoder.decode(categoryName); + DatabaseHelper.addCategory(context, categoryName); + + components = cm.getEntriesComponents(f); + for (BaseData data: appsData) { + if (components.contains(data.getComponent())) { + ((AppData)data).addCategory(categoryName); + } } + f.delete(); } - cm.catPath(category).delete(); } + for (BaseData data: appsData) { db.insert("apps", null, ((AppData)data).getContentValues()); } + try { new File(MyCache.genFilename(context, "apps")).delete(); } catch (Exception e) {}