diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-06 21:49:09 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-06 21:49:09 +0200 |
commit | b33eaff4f4fc74aef4acc1a4e1d7d5745c1174c2 (patch) | |
tree | 6bfa355ee1524128a70547cecbb6775a0cced7be /src/main | |
parent | a2ff79a4c39b91069fb0c6c0d1d5f011a891aded (diff) |
check for orphaned files
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 4cdefccc3..e87554818 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; 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) { displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)), darkBackground); } 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) { if (message.getFileParams().width > 0 && message.getFileParams().height > 0) { @@ -1141,6 +1146,28 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie 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) { activity.showInstallPgpDialog(); } |