From 6258118ed64bc8ea28df401713c68320c91deeca Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 30 Mar 2011 05:08:49 +0200 Subject: [PATCH] Write identity elements in correct order (export) --- .../fsck/k9/preferences/StorageExporter.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/fsck/k9/preferences/StorageExporter.java b/src/com/fsck/k9/preferences/StorageExporter.java index 08f1d6e6c..e424ddcab 100644 --- a/src/com/fsck/k9/preferences/StorageExporter.java +++ b/src/com/fsck/k9/preferences/StorageExporter.java @@ -4,7 +4,10 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import org.xmlpull.v1.XmlSerializer; @@ -140,7 +143,7 @@ public class StorageExporter { private static void writeAccount(XmlSerializer serializer, String accountUuid, Map prefs) throws IOException { - Set identities = new HashSet(); + Set identities = new HashSet(); Set folders = new HashSet(); serializer.startTag(null, ACCOUNT_ELEMENT); @@ -162,7 +165,9 @@ public class StorageExporter { if (Account.IDENTITY_KEYS.contains(secondPart)) { // This is an identity key. Save identity index for later... - identities.add(thirdPart); + try { + identities.add(Integer.parseInt(thirdPart)); + } catch (NumberFormatException e) { /* ignore */ } // ... but don't write it now. continue; } @@ -191,8 +196,13 @@ public class StorageExporter { if (identities.size() > 0) { serializer.startTag(null, IDENTITIES_ELEMENT); - for (String identityIndex : identities) { - writeIdentity(serializer, accountUuid, identityIndex, prefs); + + // Sort identity indices (that's why we store them as Integers) + List sortedIdentities = new ArrayList(identities); + Collections.sort(sortedIdentities); + + for (Integer identityIndex : sortedIdentities) { + writeIdentity(serializer, accountUuid, identityIndex.toString(), prefs); } serializer.endTag(null, IDENTITIES_ELEMENT); }