Decode folder hierarchy

pull/153/head
M66B 6 years ago
parent 60a87826c9
commit 0927dd7d8f

File diff suppressed because it is too large Load Diff

@ -742,6 +742,8 @@ class Core {
Folder[] ifolders = defaultFolder.list("*");
Log.i("Remote folder count=" + ifolders.length + " separator=" + separator);
Map<String, EntityFolder> nameFolder = new HashMap<>();
Map<String, List<EntityFolder>> parentFolders = new HashMap<>();
for (Folder ifolder : ifolders) {
String fullName = ifolder.getFullName();
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
@ -803,6 +805,18 @@ class Core {
db.folder().setFolderType(folder.id, type);
}
}
nameFolder.put(folder.name, folder);
String parentName = folder.getParentName(separator);
if (!parentFolders.containsKey(parentName))
parentFolders.put(parentName, new ArrayList<EntityFolder>());
parentFolders.get(parentName).add(folder);
}
for (String parentName : parentFolders.keySet()) {
EntityFolder parent = nameFolder.get(parentName);
for (EntityFolder child : parentFolders.get(parentName))
db.folder().setFolderParent(child.id, parent == null ? null : parent.id);
}
}

@ -50,7 +50,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 59,
version = 60,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -655,6 +655,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("CREATE INDEX `index_contact_avatar` ON `contact` (`avatar`)");
}
})
.addMigrations(new Migration(59, 60) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `parent` INTEGER");
}
})
.build();
}

@ -155,6 +155,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET level = :level WHERE id = :id")
int setFolderLevel(long id, int level);
@Query("UPDATE folder SET parent = :parent WHERE id = :id")
int setFolderParent(long id, Long parent);
@Query("UPDATE folder" +
" SET type = '" + EntityFolder.USER + "'" +
" WHERE account = :account" +

@ -63,6 +63,7 @@ public class EntityFolder implements Serializable {
@PrimaryKey(autoGenerate = true)
public Long id;
public Long account; // Outbox = null
public Long parent;
@NonNull
public String name;
@NonNull
@ -239,6 +240,19 @@ public class EntityFolder implements Serializable {
return level;
}
String getParentName(Character separator) {
if (separator == null)
return null;
else {
int p = name.lastIndexOf(separator);
if (p < 0)
return null;
else
return name.substring(0, p);
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityFolder) {

Loading…
Cancel
Save