From cf6670a7d29cd1668bea058647533d4e66d707ea Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 14 Sep 2018 06:28:23 +0000 Subject: [PATCH] Handle folder events Refs #71 --- .../java/eu/faircode/email/DaoFolder.java | 3 +++ .../eu/faircode/email/ServiceSynchronize.java | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index dd11220f..cda003f0 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -117,6 +117,9 @@ public interface DaoFolder { @Query("UPDATE folder SET synchronize = :synchronize, unified = :unified, after = :after WHERE id = :id") int setFolderProperties(long id, boolean synchronize, boolean unified, int after); + @Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old") + int renameFolder(long account, String old, String name); + @Query("DELETE FROM folder WHERE account= :account AND name = :name") void deleteFolder(Long account, String name); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index beb73e3a..f683d4fd 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -440,17 +440,32 @@ public class ServiceSynchronize extends LifecycleService { istore.addFolderListener(new FolderAdapter() { @Override public void folderCreated(FolderEvent e) { - // TODO: folder created + Log.i(Helper.TAG, "Folder created=" + e.getFolder().getFullName()); + synchronized (state) { + state.notifyAll(); + } } @Override public void folderRenamed(FolderEvent e) { - // TODO: folder renamed + Log.i(Helper.TAG, "Folder renamed=" + e.getFolder()); + + String old = e.getFolder().getFullName(); + String name = e.getNewFolder().getFullName(); + int count = db.folder().renameFolder(account.id, old, name); + Log.i(Helper.TAG, "Renamed to " + name + " count=" + count); + + synchronized (state) { + state.notifyAll(); + } } @Override public void folderDeleted(FolderEvent e) { - // TODO: folder deleted + Log.i(Helper.TAG, "Folder deleted=" + e.getFolder().getFullName()); + synchronized (state) { + state.notifyAll(); + } } });