progress for http images as well. fixed open button for sent files

This commit is contained in:
iNPUTmice 2014-11-14 01:29:56 +01:00
parent dac12be53e
commit c7acfe85c3
7 changed files with 40 additions and 8 deletions

View file

@ -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() {

View file

@ -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();

View file

@ -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;

View file

@ -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()));
}

View file

@ -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) {

View file

@ -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();
}

View file

@ -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>