don't ask for resource when server uses http upload v0.1

This commit is contained in:
Daniel Gultsch 2016-04-02 18:07:38 +02:00
parent 2549ce89b0
commit 701742f550
3 changed files with 8 additions and 6 deletions

View File

@ -114,7 +114,7 @@ public class FileBackend {
} }
} }
public static long getFileSize(Context context, Uri uri) { private static long getFileSize(Context context, Uri uri) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
@ -124,6 +124,9 @@ public class FileBackend {
} }
public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) { public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) {
if (max <= 0) {
return true; //exception to be compatible with HTTP Upload < v0.2
}
for(Uri uri : uris) { for(Uri uri : uris) {
if (FileBackend.getFileSize(context, uri) > max) { if (FileBackend.getFileSize(context, uri) > max) {
return false; return false;

View File

@ -1317,8 +1317,7 @@ public class ConversationActivity extends XmppActivity
} }
} }
}; };
if (max <= 0 if (c.getMode() == Conversation.MODE_MULTI
|| c.getMode() == Conversation.MODE_MULTI
|| FileBackend.allFilesUnderSize(this, uris, max) || FileBackend.allFilesUnderSize(this, uris, max)
|| c.getNextEncryption() == Message.ENCRYPTION_OTR) { || c.getNextEncryption() == Message.ENCRYPTION_OTR) {
callback.onPresenceSelected(); callback.onPresenceSelected();

View File

@ -296,10 +296,10 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
} }
}; };
if (account.httpUploadAvailable() if (account.httpUploadAvailable()
&& ( && ((share.image && !neverCompressPictures())
(share.image && !neverCompressPictures())
|| conversation.getMode() == Conversation.MODE_MULTI || conversation.getMode() == Conversation.MODE_MULTI
|| FileBackend.allFilesUnderSize(this, share.uris, max))) { || FileBackend.allFilesUnderSize(this, share.uris, max))
&& conversation.getNextEncryption() != Message.ENCRYPTION_OTR) {
callback.onPresenceSelected(); callback.onPresenceSelected();
} else { } else {
selectPresence(conversation, callback); selectPresence(conversation, callback);