mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
progress for http images as well. fixed open button for sent files
This commit is contained in:
parent
dac12be53e
commit
c7acfe85c3
@ -19,6 +19,7 @@ public final class Config {
|
|||||||
public static final int MESSAGE_MERGE_WINDOW = 20;
|
public static final int MESSAGE_MERGE_WINDOW = 20;
|
||||||
|
|
||||||
public static final boolean PARSE_EMOTICONS = false;
|
public static final boolean PARSE_EMOTICONS = false;
|
||||||
|
public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
|
||||||
|
|
||||||
private Config() {
|
private Config() {
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ public interface Downloadable {
|
|||||||
public static final int STATUS_DOWNLOADING = 0x204;
|
public static final int STATUS_DOWNLOADING = 0x204;
|
||||||
public static final int STATUS_DELETED = 0x205;
|
public static final int STATUS_DELETED = 0x205;
|
||||||
public static final int STATUS_OFFER_CHECK_FILESIZE = 0x206;
|
public static final int STATUS_OFFER_CHECK_FILESIZE = 0x206;
|
||||||
|
public static final int STATUS_UPLOADING = 0x207;
|
||||||
|
|
||||||
public boolean start();
|
public boolean start();
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package eu.siacs.conversations.http;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import org.apache.http.conn.ssl.StrictHostnameVerifier;
|
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.SSLHandshakeException;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.entities.Downloadable;
|
import eu.siacs.conversations.entities.Downloadable;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
@ -38,6 +40,7 @@ public class HttpConnection implements Downloadable {
|
|||||||
private int mStatus = Downloadable.STATUS_UNKNOWN;
|
private int mStatus = Downloadable.STATUS_UNKNOWN;
|
||||||
private boolean acceptedAutomatically = false;
|
private boolean acceptedAutomatically = false;
|
||||||
private int mProgress = 0;
|
private int mProgress = 0;
|
||||||
|
private long mLastGuiRefresh = 0;
|
||||||
|
|
||||||
public HttpConnection(HttpConnectionManager manager) {
|
public HttpConnection(HttpConnectionManager manager) {
|
||||||
this.mHttpConnectionManager = manager;
|
this.mHttpConnectionManager = manager;
|
||||||
@ -243,7 +246,7 @@ public class HttpConnection implements Downloadable {
|
|||||||
while ((count = is.read(buffer)) != -1) {
|
while ((count = is.read(buffer)) != -1) {
|
||||||
transmitted += count;
|
transmitted += count;
|
||||||
os.write(buffer, 0, count);
|
os.write(buffer, 0, count);
|
||||||
mProgress = (int) (expected * 100 / transmitted);
|
updateProgress((int) ((((double) transmitted) / expected) * 100));
|
||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
os.close();
|
os.close();
|
||||||
@ -252,12 +255,20 @@ public class HttpConnection implements Downloadable {
|
|||||||
|
|
||||||
private void updateImageBounds() {
|
private void updateImageBounds() {
|
||||||
message.setType(Message.TYPE_IMAGE);
|
message.setType(Message.TYPE_IMAGE);
|
||||||
mXmppConnectionService.getFileBackend().updateFileParams(message);
|
mXmppConnectionService.getFileBackend().updateFileParams(message,mUrl);
|
||||||
mXmppConnectionService.updateMessage(message);
|
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
|
@Override
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return this.mStatus;
|
return this.mStatus;
|
||||||
|
@ -8,6 +8,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.security.DigestOutputStream;
|
import java.security.DigestOutputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -462,6 +463,10 @@ public class FileBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateFileParams(Message message) {
|
public void updateFileParams(Message message) {
|
||||||
|
updateFileParams(message,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateFileParams(Message message, URL url) {
|
||||||
DownloadableFile file = getFile(message);
|
DownloadableFile file = getFile(message);
|
||||||
if (message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/")) {
|
if (message.getType() == Message.TYPE_IMAGE || file.getMimeType().startsWith("image/")) {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
@ -469,7 +474,11 @@ public class FileBackend {
|
|||||||
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||||
int imageHeight = options.outHeight;
|
int imageHeight = options.outHeight;
|
||||||
int imageWidth = options.outWidth;
|
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 {
|
} else {
|
||||||
message.setBody(Long.toString(file.getSize()));
|
message.setBody(Long.toString(file.getSize()));
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||||||
info = getContext().getString(R.string.waiting);
|
info = getContext().getString(R.string.waiting);
|
||||||
break;
|
break;
|
||||||
case Message.STATUS_UNSEND:
|
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;
|
break;
|
||||||
case Message.STATUS_OFFERED:
|
case Message.STATUS_OFFERED:
|
||||||
info = getContext().getString(R.string.offering);
|
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();
|
Downloadable d = item.getDownloadable();
|
||||||
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
|
||||||
if (item.getType() == Message.TYPE_FILE) {
|
if (item.getType() == Message.TYPE_FILE) {
|
||||||
|
@ -44,7 +44,7 @@ public class JingleConnection implements Downloadable {
|
|||||||
private int ibbBlockSize = 4096;
|
private int ibbBlockSize = 4096;
|
||||||
|
|
||||||
private int mJingleStatus = -1;
|
private int mJingleStatus = -1;
|
||||||
private int mStatus = -1;
|
private int mStatus = Downloadable.STATUS_UNKNOWN;
|
||||||
private Message message;
|
private Message message;
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
private Account account;
|
private Account account;
|
||||||
@ -95,6 +95,8 @@ public class JingleConnection implements Downloadable {
|
|||||||
mXmppConnectionService.databaseBackend.createMessage(message);
|
mXmppConnectionService.databaseBackend.createMessage(message);
|
||||||
mXmppConnectionService.markMessage(message,
|
mXmppConnectionService.markMessage(message,
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
|
} else {
|
||||||
|
message.setDownloadable(null);
|
||||||
}
|
}
|
||||||
Log.d(Config.LOGTAG,
|
Log.d(Config.LOGTAG,
|
||||||
"sucessfully transmitted file:" + file.getAbsolutePath());
|
"sucessfully transmitted file:" + file.getAbsolutePath());
|
||||||
@ -198,6 +200,8 @@ public class JingleConnection implements Downloadable {
|
|||||||
this.contentCreator = "initiator";
|
this.contentCreator = "initiator";
|
||||||
this.contentName = this.mJingleConnectionManager.nextRandomId();
|
this.contentName = this.mJingleConnectionManager.nextRandomId();
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.message.setDownloadable(this);
|
||||||
|
this.mStatus = Downloadable.STATUS_UPLOADING;
|
||||||
this.account = message.getConversation().getAccount();
|
this.account = message.getConversation().getAccount();
|
||||||
this.initiator = this.account.getJid();
|
this.initiator = this.account.getJid();
|
||||||
this.responder = this.message.getCounterpart();
|
this.responder = this.message.getCounterpart();
|
||||||
@ -858,7 +862,7 @@ public class JingleConnection implements Downloadable {
|
|||||||
|
|
||||||
public void updateProgress(int i) {
|
public void updateProgress(int i) {
|
||||||
this.mProgress = i;
|
this.mProgress = i;
|
||||||
if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > 1000) {
|
if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > Config.PROGRESS_UI_UPDATE_INTERVAL) {
|
||||||
this.mLastGuiRefresh = SystemClock.elapsedRealtime();
|
this.mLastGuiRefresh = SystemClock.elapsedRealtime();
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,8 @@
|
|||||||
<string name="show_qr_code">Show QR code</string>
|
<string name="show_qr_code">Show QR code</string>
|
||||||
<string name="account_details">Account details</string>
|
<string name="account_details">Account details</string>
|
||||||
<string name="choose_file">Choose file</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="download_file">Download %s file</string>
|
||||||
<string name="open_file">Open %s file</string>
|
<string name="open_file">Open %s file</string>
|
||||||
|
<string name="sending_file">sending (%1$d%% completed)</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user