diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-10-16 02:39:02 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-10-16 02:39:02 +0200 |
commit | 88d88ffb7b704e2ae5a2eaf1af6e8a21fb0fb574 (patch) | |
tree | 0434c3b0eb6ba27ba7f9ff5d3fa27dc025f5b676 | |
parent | f5019ba96647bd1c33153e6e9099d21dcf47bfa7 (diff) |
added file observer to get notified when files are deleted: fixes #396
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/persistance/FileBackend.java | 9 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 26 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 72c620a7..74918670 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -72,9 +72,7 @@ public class FileBackend { public DownloadableFile getFile(Message message, boolean decrypted) { StringBuilder filename = new StringBuilder(); - filename.append(Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_PICTURES).getAbsolutePath()); - filename.append("/Conversations/"); + filename.append(getConversationsDirectory()); filename.append(message.getUuid()); if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) { filename.append(".webp"); @@ -87,6 +85,11 @@ public class FileBackend { } return new DownloadableFile(filename.toString()); } + + public static String getConversationsDirectory() { + return Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_PICTURES).getAbsolutePath()+"/Conversations/"; + } public Bitmap resize(Bitmap originalBitmap, int size) { int w = originalBitmap.getWidth(); diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 04d5711a..9a540df0 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -76,6 +76,7 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.Binder; import android.os.Bundle; +import android.os.FileObserver; import android.os.IBinder; import android.os.PowerManager; import android.os.PowerManager.WakeLock; @@ -143,6 +144,16 @@ public class XmppConnectionService extends Service { startService(intent); } }; + + private FileObserver fileObserver = new FileObserver(FileBackend.getConversationsDirectory()) { + + @Override + public void onEvent(int event, String path) { + if (event == FileObserver.DELETE) { + markFileDeleted(path.split("\\.")[0]); + } + } + }; private final IBinder mBinder = new XmppConnectionBinder(); private OnStatusChanged statusListener = new OnStatusChanged() { @@ -424,6 +435,7 @@ public class XmppConnectionService extends Service { getContentResolver().registerContentObserver( ContactsContract.Contacts.CONTENT_URI, true, contactObserver); + this.fileObserver.startWatching(); this.pgpServiceConnection = new OpenPgpServiceConnection( getApplicationContext(), "org.sufficientlysecure.keychain"); this.pgpServiceConnection.bindToService(); @@ -813,6 +825,20 @@ public class XmppConnectionService extends Service { } } } + + private void markFileDeleted(String uuid) { + for(Conversation conversation : getConversations()) { + for(Message message : conversation.getMessages()) { + if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getUuid().equals(uuid)) { + if (!getFileBackend().isFileAvailable(message)) { + message.setDownloadable(new DeletedDownloadable()); + updateConversationUi(); + } + return; + } + } + } + } public void populateWithOrderedConversations(List<Conversation> list) { populateWithOrderedConversations(list, true); |