aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-14 01:29:56 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-15 15:34:12 +0100
commitc7acfe85c379b99c05cef98dbbab6f815b99ed83 (patch)
treebebb789d4f6edd18aae07495ec3fca477066b1d8 /src
parentdac12be53e18962c80fd471421adac29b5c92f06 (diff)
progress for http images as well. fixed open button for sent files
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java1
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Downloadable.java1
-rw-r--r--src/main/java/eu/siacs/conversations/http/HttpConnection.java15
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java11
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java9
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java8
-rw-r--r--src/main/res/values/strings.xml3
7 files changed, 40 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 7dd5a7995..b1d915d24 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -19,6 +19,7 @@ public final class Config {
public static final int MESSAGE_MERGE_WINDOW = 20;
public static final boolean PARSE_EMOTICONS = false;
+ public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
private Config() {
diff --git a/src/main/java/eu/siacs/conversations/entities/Downloadable.java b/src/main/java/eu/siacs/conversations/entities/Downloadable.java
index cc0dc157f..d3e863ef5 100644
--- a/src/main/java/eu/siacs/conversations/entities/Downloadable.java
+++ b/src/main/java/eu/siacs/conversations/entities/Downloadable.java
@@ -12,6 +12,7 @@ public interface Downloadable {
public static final int STATUS_DOWNLOADING = 0x204;
public static final int STATUS_DELETED = 0x205;
public static final int STATUS_OFFER_CHECK_FILESIZE = 0x206;
+ public static final int STATUS_UPLOADING = 0x207;
public boolean start();
diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnection.java b/src/main/java/eu/siacs/conversations/http/HttpConnection.java
index 7ef813833..68c26c474 100644
--- a/src/main/java/eu/siacs/conversations/http/HttpConnection.java
+++ b/src/main/java/eu/siacs/conversations/http/HttpConnection.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.http;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.SystemClock;
import org.apache.http.conn.ssl.StrictHostnameVerifier;
@@ -21,6 +22,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.X509TrustManager;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
@@ -38,6 +40,7 @@ public class HttpConnection implements Downloadable {
private int mStatus = Downloadable.STATUS_UNKNOWN;
private boolean acceptedAutomatically = false;
private int mProgress = 0;
+ private long mLastGuiRefresh = 0;
public HttpConnection(HttpConnectionManager manager) {
this.mHttpConnectionManager = manager;
@@ -243,7 +246,7 @@ public class HttpConnection implements Downloadable {
while ((count = is.read(buffer)) != -1) {
transmitted += count;
os.write(buffer, 0, count);
- mProgress = (int) (expected * 100 / transmitted);
+ updateProgress((int) ((((double) transmitted) / expected) * 100));
}
os.flush();
os.close();
@@ -252,12 +255,20 @@ public class HttpConnection implements Downloadable {
private void updateImageBounds() {
message.setType(Message.TYPE_IMAGE);
- mXmppConnectionService.getFileBackend().updateFileParams(message);
+ mXmppConnectionService.getFileBackend().updateFileParams(message,mUrl);
mXmppConnectionService.updateMessage(message);
}
}
+ public void updateProgress(int i) {
+ this.mProgress = i;
+ if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > Config.PROGRESS_UI_UPDATE_INTERVAL) {
+ this.mLastGuiRefresh = SystemClock.elapsedRealtime();
+ mXmppConnectionService.updateConversationUi();
+ }
+ }
+
@Override
public int getStatus() {
return this.mStatus;
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 908cbefc1..7b0ae1807 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
import java.net.URLConnection;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
@@ -462,6 +463,10 @@ public class FileBackend {
}
public void updateFileParams(Message message) {
+ updateFileParams(message,null);
+ }
+
+ public void updateFileParams(Message message, URL url) {
DownloadableFile file = getFile(message);
if (message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/")) {
BitmapFactory.Options options = new BitmapFactory.Options();
@@ -469,7 +474,11 @@ public class FileBackend {
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
- message.setBody(Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
+ if (url == null) {
+ message.setBody(Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
+ } else {
+ message.setBody(url.toString()+"|"+Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight);
+ }
} else {
message.setBody(Long.toString(file.getSize()));
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 4d46f90e5..81eccacce 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -119,7 +119,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
info = getContext().getString(R.string.waiting);
break;
case Message.STATUS_UNSEND:
- info = getContext().getString(R.string.sending);
+ Downloadable d = message.getDownloadable();
+ if (d!=null) {
+ info = getContext().getString(R.string.sending_file,d.getProgress());
+ } else {
+ info = getContext().getString(R.string.sending);
+ }
break;
case Message.STATUS_OFFERED:
info = getContext().getString(R.string.offering);
@@ -478,7 +483,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
});
}
- if (item.getDownloadable() != null) {
+ if (item.getDownloadable() != null && item.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
Downloadable d = item.getDownloadable();
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
if (item.getType() == Message.TYPE_FILE) {
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index ade19c0ed..f42e89a99 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -44,7 +44,7 @@ public class JingleConnection implements Downloadable {
private int ibbBlockSize = 4096;
private int mJingleStatus = -1;
- private int mStatus = -1;
+ private int mStatus = Downloadable.STATUS_UNKNOWN;
private Message message;
private String sessionId;
private Account account;
@@ -95,6 +95,8 @@ public class JingleConnection implements Downloadable {
mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.markMessage(message,
Message.STATUS_RECEIVED);
+ } else {
+ message.setDownloadable(null);
}
Log.d(Config.LOGTAG,
"sucessfully transmitted file:" + file.getAbsolutePath());
@@ -198,6 +200,8 @@ public class JingleConnection implements Downloadable {
this.contentCreator = "initiator";
this.contentName = this.mJingleConnectionManager.nextRandomId();
this.message = message;
+ this.message.setDownloadable(this);
+ this.mStatus = Downloadable.STATUS_UPLOADING;
this.account = message.getConversation().getAccount();
this.initiator = this.account.getJid();
this.responder = this.message.getCounterpart();
@@ -858,7 +862,7 @@ public class JingleConnection implements Downloadable {
public void updateProgress(int i) {
this.mProgress = i;
- if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > 1000) {
+ if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > Config.PROGRESS_UI_UPDATE_INTERVAL) {
this.mLastGuiRefresh = SystemClock.elapsedRealtime();
mXmppConnectionService.updateConversationUi();
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index e51fbd186..43552aef3 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -312,7 +312,8 @@
<string name="show_qr_code">Show QR code</string>
<string name="account_details">Account details</string>
<string name="choose_file">Choose file</string>
- <string name="receiving_file">Receiving %1$s file (%2$d%%)</string>
+ <string name="receiving_file">Receiving %1$s file (%2$d%% completed)</string>
<string name="download_file">Download %s file</string>
<string name="open_file">Open %s file</string>
+ <string name="sending_file">sending (%1$d%% completed)</string>
</resources>