Bugfixes to tag case migration

pull/14/head
Sam Bosley 13 years ago
parent e3ef6cde30
commit e065947528

@ -2,12 +2,17 @@ package com.todoroo.astrid.tags;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
@ -32,15 +37,17 @@ public class TagCaseMigrator {
private final HashMap<String, Long> nameToRemoteId = new HashMap<String, Long>();
private final HashMap<String, Integer> nameCountMap = new HashMap<String, Integer>();
public void performTagCaseMigration() {
public void performTagCaseMigration(Context context) {
if (!Preferences.getBoolean(PREF_CASE_MIGRATION_PERFORMED, false)) {
TagService.Tag[] allTagData = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all);
boolean shouldShowDialog = false;
for (int i = 0; i < allTagData.length - 1; i++) {
TagService.Tag first = allTagData[i];
TagService.Tag second = allTagData[i+1];
if (first.tag.equalsIgnoreCase(second.tag)) {
shouldShowDialog = true;
markForRenaming(first.tag, first.remoteId);
markForRenaming(second.tag, second.remoteId);
}
@ -52,6 +59,9 @@ public class TagCaseMigrator {
}
Preferences.setBoolean(PREF_CASE_MIGRATION_PERFORMED, true);
if (context instanceof Activity && shouldShowDialog) {
DialogUtilities.okDialog((Activity)context, context.getString(R.string.tag_case_migration_notice), null);
}
}
}
@ -97,12 +107,12 @@ public class TagCaseMigrator {
private void addTasksToTargetTag(String tag, String target) {
TodorooCursor<Task> tasks = taskService.query(Query.select(Task.ID).join(Join.inner(Metadata.TABLE,
Task.ID.eq(Metadata.TASK))).where(TagService.tagEq(tag, null)));
Task.ID.eq(Metadata.TASK))).where(TagService.tagEq(tag, Criterion.all)));
try {
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
Task curr = new Task(tasks);
TodorooCursor<Metadata> tagMetadata = metadataService.query(Query.select(TagService.TAG)
.where(Criterion.and(TagService.TAG.eq(target), Metadata.KEY.eq(TagService.KEY))));
.where(Criterion.and(TagService.TAG.eq(target), Metadata.KEY.eq(TagService.KEY), Metadata.TASK.eq(curr.getId()))));
try {
if (tagMetadata.getCount() == 0) {
Metadata newTag = new Metadata();

@ -80,5 +80,10 @@
<!-- Toast notification that a tag has been renamed -->
<string name="TEA_tags_renamed">Renamed %1$s with %2$s for %3$d tasks</string>
<!-- Tag case migration -->
<string name="tag_case_migration_notice">Greetings!\n\nWe\'ve noticed that you have some lists that have the same name with different capitalizations. We think you may have intended them to
be the same list, so we\'ve combined the duplicates. Don\'t worry though: the original lists are simply renamed with numbers (e.g. Shopping_1, Shopping_2).\n\nIf you don\'t want this, you
can simply delete the new combined list.\n\nHave a nice day!\nAstrid</string>
</resources>

@ -105,6 +105,10 @@ public final class UpgradeService {
dialog = null;
Preferences.setInt(AstridPreferences.P_UPGRADE_FROM, from);
if (from <= V3_8_3_1) // This needs to happen synchronously
abChooser.setChoiceForOption(ABOptions.AB_OPTION_FIRST_ACTIVITY, 0);
new Thread(new Runnable() {
@Override
public void run() {
@ -115,10 +119,8 @@ public final class UpgradeService {
if(from < V3_1_0)
new Astrid2To3UpgradeHelper().upgrade3To3_1(context, from);
if (from <= V3_8_3_1) {
new TagCaseMigrator().performTagCaseMigration();
abChooser.setChoiceForOption(ABOptions.AB_OPTION_FIRST_ACTIVITY, 0);
}
if (from <= V3_8_3_1)
new TagCaseMigrator().performTagCaseMigration(context);
} finally {
DialogUtilities.dismissDialog((Activity)context, dialog);
}

Loading…
Cancel
Save