added file observer to get notified when files are deleted: fixes #396
This commit is contained in:
parent
f5019ba966
commit
88d88ffb7b
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue