Skip to content

Commit

Permalink
Close #86
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriDellal committed Oct 4, 2018
1 parent fa31a96 commit e28cebf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/ru/henridellal/emerald/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/ru/henridellal/emerald/Apps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> cats = new ArrayList<String>(categories.getCategories());
cats.remove(CategoryManager.HIDDEN);
ArrayList<String> toRemove = new ArrayList<String>();
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/ru/henridellal/emerald/CategoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public ArrayList<BaseData> 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<String> hiddenCategories = new ArrayList<String>();
Expand Down Expand Up @@ -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();
}
}

Expand Down
23 changes: 17 additions & 6 deletions app/src/main/java/ru/henridellal/emerald/DatabaseConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.database.sqlite.SQLiteDatabase;

import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;

public class DatabaseConverter {
Expand All @@ -13,18 +14,28 @@ public static void convert(Context context) {
MyCache.read(context, "apps", appsData);
CategoryManager cm = LauncherApp.getCategoryManager();
ArrayList<String> components = new ArrayList<String>();
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) {}
Expand Down

0 comments on commit e28cebf

Please sign in to comment.