Migrate theme colors when loading old backup file

pull/935/head
Alex Baker 6 years ago
parent 27f9d66e3c
commit acb8ed9ea5

@ -56,7 +56,7 @@ public class Upgrader {
private static final int V6_8_1 = 607; private static final int V6_8_1 = 607;
private static final int V6_9 = 608; private static final int V6_9 = 608;
private static final int V7_0 = 617; private static final int V7_0 = 617;
private static final int V8_2 = 675; public static final int V8_2 = 675;
private final Context context; private final Context context;
private final Preferences preferences; private final Preferences preferences;
private final Tracker tracker; private final Tracker tracker;
@ -144,6 +144,10 @@ public class Upgrader {
} }
private int getAndroidColor(int index) { private int getAndroidColor(int index) {
return getAndroidColor(context, index);
}
public static int getAndroidColor(Context context, int index) {
return index >= 0 && index < ThemeColor.COLORS.length return index >= 0 && index < ThemeColor.COLORS.length
? ContextCompat.getColor(context, ThemeColor.COLORS[index]) ? ContextCompat.getColor(context, ThemeColor.COLORS[index])
: 0; : 0;

@ -15,6 +15,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.Upgrader;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -124,6 +125,7 @@ public class TasksJsonImporter {
int version = input.get("version").getAsInt(); int version = input.get("version").getAsInt();
BackupContainer backupContainer = gson.fromJson(data, BackupContainer.class); BackupContainer backupContainer = gson.fromJson(data, BackupContainer.class);
for (TagData tagData : backupContainer.getTags()) { for (TagData tagData : backupContainer.getTags()) {
tagData.setColor(themeToColor(context, version, tagData.getColor()));
if (tagDataDao.getByUuid(tagData.getRemoteId()) == null) { if (tagDataDao.getByUuid(tagData.getRemoteId()) == null) {
tagDataDao.createNew(tagData); tagDataDao.createNew(tagData);
} }
@ -139,11 +141,13 @@ public class TasksJsonImporter {
} }
} }
for (GoogleTaskList googleTaskList : backupContainer.getGoogleTaskLists()) { for (GoogleTaskList googleTaskList : backupContainer.getGoogleTaskLists()) {
googleTaskList.setColor(themeToColor(context, version, googleTaskList.getColor()));
if (googleTaskListDao.getByRemoteId(googleTaskList.getRemoteId()) == null) { if (googleTaskListDao.getByRemoteId(googleTaskList.getRemoteId()) == null) {
googleTaskListDao.insert(googleTaskList); googleTaskListDao.insert(googleTaskList);
} }
} }
for (Filter filter : backupContainer.getFilters()) { for (Filter filter : backupContainer.getFilters()) {
filter.setColor(themeToColor(context, version, filter.getColor()));
if (filterDao.getByName(filter.getTitle()) == null) { if (filterDao.getByName(filter.getTitle()) == null) {
filterDao.insert(filter); filterDao.insert(filter);
} }
@ -154,6 +158,7 @@ public class TasksJsonImporter {
} }
} }
for (CaldavCalendar calendar : backupContainer.getCaldavCalendars()) { for (CaldavCalendar calendar : backupContainer.getCaldavCalendars()) {
calendar.setColor(themeToColor(context, version, calendar.getColor()));
if (caldavDao.getCalendarByUuid(calendar.getUuid()) == null) { if (caldavDao.getCalendarByUuid(calendar.getUuid()) == null) {
caldavDao.insert(calendar); caldavDao.insert(calendar);
} }
@ -245,6 +250,14 @@ public class TasksJsonImporter {
for (Entry<String, Boolean> entry : backupContainer.getBoolPrefs().entrySet()) { for (Entry<String, Boolean> entry : backupContainer.getBoolPrefs().entrySet()) {
preferences.setBoolean(entry.getKey(), entry.getValue()); preferences.setBoolean(entry.getKey(), entry.getValue());
} }
if (version < Upgrader.V8_2) {
int themeIndex = preferences.getInt(R.string.p_theme_color, 7);
preferences.setInt(
R.string.p_theme_color,
Upgrader.getAndroidColor(context, themeIndex));
}
reader.close(); reader.close();
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {
@ -255,6 +268,10 @@ public class TasksJsonImporter {
return result; return result;
} }
private int themeToColor(Context context, int version, int color) {
return version < Upgrader.V8_2 ? Upgrader.getAndroidColor(context, color) : color;
}
public static class ImportResult { public static class ImportResult {
public int taskCount; public int taskCount;
public int importCount; public int importCount;

Loading…
Cancel
Save