check for orphaned files

This commit is contained in:
Christian Schneppe 2019-09-06 21:49:09 +02:00
parent a2ff79a4c3
commit b33eaff4f4

View file

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -1051,7 +1052,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} else if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) { } else if (transferable != null && transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)), darkBackground); displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)), darkBackground);
} else { } else {
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground); if (checkFileExistence(message, view, viewHolder)) {
markFileExisting(message);
} else {
displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first, darkBackground);
}
} }
} else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (message.isFileOrImage() && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
if (message.getFileParams().width > 0 && message.getFileParams().height > 0) { if (message.getFileParams().width > 0 && message.getFileParams().height > 0) {
@ -1141,6 +1146,28 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
return view; return view;
} }
private void markFileExisting(Message message) {
new Thread(() -> {
message.setFileDeleted(false);
activity.xmppConnectionService.updateMessage(message, false);
notifyDataSetChanged();
}).start();
}
private boolean checkFileExistence(Message message, View view, ViewHolder viewHolder) {
Rect scrollBounds = new Rect();
view.getHitRect(scrollBounds);
if (viewHolder.messageBody.getText().equals(activity.getResources().getString(R.string.file_deleted)) && viewHolder.messageBody.getLocalVisibleRect(scrollBounds)) {
if (activity.xmppConnectionService.getFileBackend().getFile(message).exists()) {
return true;
} else {
return false;
}
} else {
return false;
}
}
private void promptOpenKeychainInstall(View view) { private void promptOpenKeychainInstall(View view) {
activity.showInstallPgpDialog(); activity.showInstallPgpDialog();
} }