mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 22:45:18 +01:00
Added other upload queue for small files
This commit is contained in:
parent
b8ecf4e083
commit
8eea00b7b4
6 changed files with 107 additions and 45 deletions
|
@ -80,7 +80,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 319
|
versionCode 320
|
||||||
versionName "1.8.0"
|
versionName "1.8.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -583,9 +583,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
queue = documentDownloadQueue;
|
queue = documentDownloadQueue;
|
||||||
}
|
}
|
||||||
queue.addAll(objects);
|
queue.addAll(objects);
|
||||||
for (DownloadObject downloadObject : queue) {
|
for (int a = 0; a < queue.size(); a++) {
|
||||||
String path = FileLoader.getAttachFileName(downloadObject.object);
|
DownloadObject downloadObject = queue.get(a);
|
||||||
downloadQueueKeys.put(path, downloadObject);
|
|
||||||
|
boolean added = true;
|
||||||
if (downloadObject.object instanceof TLRPC.Audio) {
|
if (downloadObject.object instanceof TLRPC.Audio) {
|
||||||
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
|
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
|
||||||
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
|
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
|
||||||
|
@ -594,6 +595,15 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
|
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
|
||||||
} else if (downloadObject.object instanceof TLRPC.Document) {
|
} else if (downloadObject.object instanceof TLRPC.Document) {
|
||||||
FileLoader.getInstance().loadFile((TLRPC.Document)downloadObject.object);
|
FileLoader.getInstance().loadFile((TLRPC.Document)downloadObject.object);
|
||||||
|
} else {
|
||||||
|
added = false;
|
||||||
|
queue.remove(a);
|
||||||
|
a--;
|
||||||
|
}
|
||||||
|
if (added) {
|
||||||
|
String path = FileLoader.getAttachFileName(downloadObject.object);
|
||||||
|
downloadQueueKeys.put(path, downloadObject);
|
||||||
|
FileLog.e("tmessages", "download file " + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,6 +627,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
private void checkDownloadFinished(String fileName, boolean canceled) {
|
private void checkDownloadFinished(String fileName, boolean canceled) {
|
||||||
DownloadObject downloadObject = downloadQueueKeys.get(fileName);
|
DownloadObject downloadObject = downloadQueueKeys.get(fileName);
|
||||||
if (downloadObject != null) {
|
if (downloadObject != null) {
|
||||||
|
FileLog.e("tmessages", "check download finished " + fileName + " canceled = " + canceled);
|
||||||
downloadQueueKeys.remove(fileName);
|
downloadQueueKeys.remove(fileName);
|
||||||
if (!canceled) {
|
if (!canceled) {
|
||||||
MessagesStorage.getInstance().removeFromDownloadQueue(downloadObject.id, downloadObject.type);
|
MessagesStorage.getInstance().removeFromDownloadQueue(downloadObject.id, downloadObject.type);
|
||||||
|
|
|
@ -909,7 +909,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||||
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
|
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
|
||||||
if (bigPhoto != null) {
|
if (bigPhoto != null) {
|
||||||
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
|
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
|
||||||
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
|
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -766,9 +766,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||||
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
if (message.sendRequest != null) {
|
if (message.sendRequest != null) {
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, true);
|
||||||
} else {
|
} else {
|
||||||
FileLoader.getInstance().uploadFile(location, true);
|
FileLoader.getInstance().uploadFile(location, true, true);
|
||||||
}
|
}
|
||||||
} else if (message.type == 1) {
|
} else if (message.type == 1) {
|
||||||
if (message.sendRequest != null) {
|
if (message.sendRequest != null) {
|
||||||
|
@ -781,14 +781,14 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||||
if (media.thumb == null) {
|
if (media.thumb == null) {
|
||||||
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, true);
|
||||||
} else {
|
} else {
|
||||||
String location = message.videoLocation.path;
|
String location = message.videoLocation.path;
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
||||||
}
|
}
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String location = message.videoLocation.path;
|
String location = message.videoLocation.path;
|
||||||
|
@ -796,7 +796,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||||
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
||||||
}
|
}
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
FileLoader.getInstance().uploadFile(location, true);
|
FileLoader.getInstance().uploadFile(location, true, false);
|
||||||
}
|
}
|
||||||
} else if (message.type == 2) {
|
} else if (message.type == 2) {
|
||||||
TLRPC.InputMedia media = null;
|
TLRPC.InputMedia media = null;
|
||||||
|
@ -808,23 +808,23 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||||
if (message.sendRequest != null && media.thumb == null && message.location != null) {
|
if (message.sendRequest != null && media.thumb == null && message.location != null) {
|
||||||
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, true);
|
||||||
} else {
|
} else {
|
||||||
String location = message.documentLocation.path;
|
String location = message.documentLocation.path;
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
if (message.sendRequest != null) {
|
if (message.sendRequest != null) {
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, false);
|
||||||
} else {
|
} else {
|
||||||
FileLoader.getInstance().uploadFile(location, true);
|
FileLoader.getInstance().uploadFile(location, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.type == 3) {
|
} else if (message.type == 3) {
|
||||||
String location = message.audioLocation.path;
|
String location = message.audioLocation.path;
|
||||||
putToDelayedMessages(location, message);
|
putToDelayedMessages(location, message);
|
||||||
if (message.sendRequest != null) {
|
if (message.sendRequest != null) {
|
||||||
FileLoader.getInstance().uploadFile(location, false);
|
FileLoader.getInstance().uploadFile(location, false, true);
|
||||||
} else {
|
} else {
|
||||||
FileLoader.getInstance().uploadFile(location, true);
|
FileLoader.getInstance().uploadFile(location, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class FileLoader {
|
||||||
private volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue");
|
private volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue");
|
||||||
|
|
||||||
private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>();
|
private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>();
|
||||||
|
private LinkedList<FileUploadOperation> uploadSmallOperationQueue = new LinkedList<FileUploadOperation>();
|
||||||
private LinkedList<FileLoadOperation> loadOperationQueue = new LinkedList<FileLoadOperation>();
|
private LinkedList<FileLoadOperation> loadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||||
private LinkedList<FileLoadOperation> audioLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
private LinkedList<FileLoadOperation> audioLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||||
private LinkedList<FileLoadOperation> photoLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
private LinkedList<FileLoadOperation> photoLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||||
|
@ -43,6 +44,7 @@ public class FileLoader {
|
||||||
private int currentAudioLoadOperationsCount = 0;
|
private int currentAudioLoadOperationsCount = 0;
|
||||||
private int currentPhotoLoadOperationsCount = 0;
|
private int currentPhotoLoadOperationsCount = 0;
|
||||||
private int currentUploadOperationsCount = 0;
|
private int currentUploadOperationsCount = 0;
|
||||||
|
private int currentUploadSmallOperationsCount = 0;
|
||||||
|
|
||||||
private static volatile FileLoader Instance = null;
|
private static volatile FileLoader Instance = null;
|
||||||
public static FileLoader getInstance() {
|
public static FileLoader getInstance() {
|
||||||
|
@ -62,20 +64,18 @@ public class FileLoader {
|
||||||
fileLoaderQueue.postRunnable(new Runnable() {
|
fileLoaderQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
FileUploadOperation operation = null;
|
||||||
if (!enc) {
|
if (!enc) {
|
||||||
FileUploadOperation operation = uploadOperationPaths.get(location);
|
operation = uploadOperationPaths.get(location);
|
||||||
if (operation != null) {
|
|
||||||
uploadOperationQueue.remove(operation);
|
|
||||||
operation.cancel();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
FileUploadOperation operation = uploadOperationPathsEnc.get(location);
|
operation = uploadOperationPathsEnc.get(location);
|
||||||
|
}
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
uploadOperationQueue.remove(operation);
|
uploadOperationQueue.remove(operation);
|
||||||
|
uploadSmallOperationQueue.remove(operation);
|
||||||
operation.cancel();
|
operation.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class FileLoader {
|
||||||
return fileProgresses.get(location);
|
return fileProgresses.get(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadFile(final String location, final boolean encrypted) {
|
public void uploadFile(final String location, final boolean encrypted, final boolean small) {
|
||||||
fileLoaderQueue.postRunnable(new Runnable() {
|
fileLoaderQueue.postRunnable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -113,6 +113,16 @@ public class FileLoader {
|
||||||
} else {
|
} else {
|
||||||
uploadOperationPaths.remove(location);
|
uploadOperationPaths.remove(location);
|
||||||
}
|
}
|
||||||
|
if (small) {
|
||||||
|
currentUploadSmallOperationsCount--;
|
||||||
|
if (currentUploadSmallOperationsCount < 2) {
|
||||||
|
FileUploadOperation operation = uploadSmallOperationQueue.poll();
|
||||||
|
if (operation != null) {
|
||||||
|
currentUploadSmallOperationsCount++;
|
||||||
|
operation.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
currentUploadOperationsCount--;
|
currentUploadOperationsCount--;
|
||||||
if (currentUploadOperationsCount < 2) {
|
if (currentUploadOperationsCount < 2) {
|
||||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||||
|
@ -121,6 +131,7 @@ public class FileLoader {
|
||||||
operation.start();
|
operation.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (delegate != null) {
|
if (delegate != null) {
|
||||||
delegate.fileDidUploaded(location, inputFile, inputEncryptedFile);
|
delegate.fileDidUploaded(location, inputFile, inputEncryptedFile);
|
||||||
}
|
}
|
||||||
|
@ -153,6 +164,16 @@ public class FileLoader {
|
||||||
fileProgresses.remove(location);
|
fileProgresses.remove(location);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (small) {
|
||||||
|
currentUploadSmallOperationsCount--;
|
||||||
|
if (currentUploadSmallOperationsCount < 2) {
|
||||||
|
FileUploadOperation operation = uploadSmallOperationQueue.poll();
|
||||||
|
if (operation != null) {
|
||||||
|
currentUploadSmallOperationsCount++;
|
||||||
|
operation.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
currentUploadOperationsCount--;
|
currentUploadOperationsCount--;
|
||||||
if (currentUploadOperationsCount < 2) {
|
if (currentUploadOperationsCount < 2) {
|
||||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||||
|
@ -162,6 +183,7 @@ public class FileLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +197,14 @@ public class FileLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (small) {
|
||||||
|
if (currentUploadSmallOperationsCount < 2) {
|
||||||
|
currentUploadSmallOperationsCount++;
|
||||||
|
operation.start();
|
||||||
|
} else {
|
||||||
|
uploadSmallOperationQueue.add(operation);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (currentUploadOperationsCount < 2) {
|
if (currentUploadOperationsCount < 2) {
|
||||||
currentUploadOperationsCount++;
|
currentUploadOperationsCount++;
|
||||||
operation.start();
|
operation.start();
|
||||||
|
@ -182,6 +212,7 @@ public class FileLoader {
|
||||||
uploadOperationQueue.add(operation);
|
uploadOperationQueue.add(operation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,10 +327,30 @@ public class FileLoader {
|
||||||
if (fileName == null || fileName.contains("" + Integer.MIN_VALUE)) {
|
if (fileName == null || fileName.contains("" + Integer.MIN_VALUE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (loadOperationPaths.containsKey(fileName)) {
|
|
||||||
|
FileLoadOperation operation = null;
|
||||||
|
operation = loadOperationPaths.get(fileName);
|
||||||
|
if (operation != null) {
|
||||||
|
if (force) {
|
||||||
|
LinkedList<FileLoadOperation> downloadQueue = null;
|
||||||
|
if (audio != null) {
|
||||||
|
downloadQueue = audioLoadOperationQueue;
|
||||||
|
} else if (location != null) {
|
||||||
|
downloadQueue = photoLoadOperationQueue;
|
||||||
|
} else {
|
||||||
|
downloadQueue = loadOperationQueue;
|
||||||
|
}
|
||||||
|
if (downloadQueue != null) {
|
||||||
|
int index = downloadQueue.indexOf(operation);
|
||||||
|
if (index != -1) {
|
||||||
|
downloadQueue.remove(index);
|
||||||
|
downloadQueue.add(0, operation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileLoadOperation operation = null;
|
|
||||||
if (video != null) {
|
if (video != null) {
|
||||||
operation = new FileLoadOperation(video);
|
operation = new FileLoadOperation(video);
|
||||||
} else if (location != null) {
|
} else if (location != null) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
|
||||||
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
|
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
|
||||||
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
|
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
|
||||||
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
|
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
|
||||||
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
|
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue