From f5019ba96647bd1c33153e6e9099d21dcf47bfa7 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 15 Oct 2014 22:08:13 +0200 Subject: detect deleted files on start up. got rid of lagecy image provider for performance reasons. NOTE: this will prevent you to access images older than version 0.6 --- .../siacs/conversations/http/HttpConnection.java | 23 +++++++++------------- .../conversations/http/HttpConnectionManager.java | 8 +------- 2 files changed, 10 insertions(+), 21 deletions(-) (limited to 'src/eu/siacs/conversations/http') diff --git a/src/eu/siacs/conversations/http/HttpConnection.java b/src/eu/siacs/conversations/http/HttpConnection.java index c53b9fd5..34036412 100644 --- a/src/eu/siacs/conversations/http/HttpConnection.java +++ b/src/eu/siacs/conversations/http/HttpConnection.java @@ -9,7 +9,9 @@ import java.net.URL; import javax.net.ssl.HttpsURLConnection; +import android.content.Intent; import android.graphics.BitmapFactory; +import android.net.Uri; import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.DownloadableFile; @@ -24,8 +26,8 @@ public class HttpConnection implements Downloadable { private URL mUrl; private Message message; private DownloadableFile file; - private long mPreviousFileSize = 0; private int mStatus = Downloadable.STATUS_UNKNOWN; + private boolean mAutostart = true; public HttpConnection(HttpConnectionManager manager) { this.mHttpConnectionManager = manager; @@ -44,23 +46,14 @@ public class HttpConnection implements Downloadable { try { mUrl = new URL(message.getBody()); this.file = mXmppConnectionService.getFileBackend() - .getConversationsFile(message, false); + .getFile(message, false); + this.mAutostart = true; checkFileSize(); } catch (MalformedURLException e) { this.cancel(); } } - public void init(Message message, URL url) { - this.message = message; - this.message.setDownloadable(this); - this.mUrl = url; - this.file = mXmppConnectionService.getFileBackend() - .getConversationsFile(message, false); - this.mPreviousFileSize = message.getImageParams().size; - checkFileSize(); - } - private void checkFileSize() { changeStatus(STATUS_CHECKING); new Thread(new FileSizeChecker()).start(); @@ -74,6 +67,9 @@ public class HttpConnection implements Downloadable { } private void finish() { + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(file)); + mXmppConnectionService.sendBroadcast(intent); message.setDownloadable(null); mHttpConnectionManager.finishConnection(this); } @@ -96,8 +92,7 @@ public class HttpConnection implements Downloadable { } file.setExpectedSize(size); message.setType(Message.TYPE_IMAGE); - if (size <= mHttpConnectionManager.getAutoAcceptFileSize() - || size == mPreviousFileSize) { + if (size <= mHttpConnectionManager.getAutoAcceptFileSize() && mAutostart) { start(); } else { changeStatus(STATUS_OFFER); diff --git a/src/eu/siacs/conversations/http/HttpConnectionManager.java b/src/eu/siacs/conversations/http/HttpConnectionManager.java index 011ecc3f..ff71d45c 100644 --- a/src/eu/siacs/conversations/http/HttpConnectionManager.java +++ b/src/eu/siacs/conversations/http/HttpConnectionManager.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Message.ImageParams; import eu.siacs.conversations.services.AbstractConnectionManager; import eu.siacs.conversations.services.XmppConnectionService; @@ -23,13 +24,6 @@ public class HttpConnectionManager extends AbstractConnectionManager { return connection; } - public HttpConnection createNewConnection(Message message, URL url) { - HttpConnection connection = new HttpConnection(this); - connection.init(message, url); - this.connections.add(connection); - return connection; - } - public void finishConnection(HttpConnection connection) { this.connections.remove(connection); } -- cgit v1.2.3