Added other upload queue for small files
This commit is contained in:
parent
b8ecf4e083
commit
8eea00b7b4
@ -80,7 +80,7 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 19
|
||||
versionCode 319
|
||||
versionCode 320
|
||||
versionName "1.8.0"
|
||||
}
|
||||
}
|
||||
|
@ -583,9 +583,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||
queue = documentDownloadQueue;
|
||||
}
|
||||
queue.addAll(objects);
|
||||
for (DownloadObject downloadObject : queue) {
|
||||
String path = FileLoader.getAttachFileName(downloadObject.object);
|
||||
downloadQueueKeys.put(path, downloadObject);
|
||||
for (int a = 0; a < queue.size(); a++) {
|
||||
DownloadObject downloadObject = queue.get(a);
|
||||
|
||||
boolean added = true;
|
||||
if (downloadObject.object instanceof TLRPC.Audio) {
|
||||
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
|
||||
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
|
||||
@ -594,6 +595,15 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
|
||||
} else if (downloadObject.object instanceof TLRPC.Document) {
|
||||
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) {
|
||||
DownloadObject downloadObject = downloadQueueKeys.get(fileName);
|
||||
if (downloadObject != null) {
|
||||
FileLog.e("tmessages", "check download finished " + fileName + " canceled = " + canceled);
|
||||
downloadQueueKeys.remove(fileName);
|
||||
if (!canceled) {
|
||||
MessagesStorage.getInstance().removeFromDownloadQueue(downloadObject.id, downloadObject.type);
|
||||
|
@ -909,7 +909,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
|
||||
if (bigPhoto != null) {
|
||||
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";
|
||||
putToDelayedMessages(location, message);
|
||||
if (message.sendRequest != null) {
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, true);
|
||||
} else {
|
||||
FileLoader.getInstance().uploadFile(location, true);
|
||||
FileLoader.getInstance().uploadFile(location, true, true);
|
||||
}
|
||||
} else if (message.type == 1) {
|
||||
if (message.sendRequest != null) {
|
||||
@ -781,14 +781,14 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
if (media.thumb == null) {
|
||||
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
||||
putToDelayedMessages(location, message);
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, true);
|
||||
} else {
|
||||
String location = message.videoLocation.path;
|
||||
if (location == null) {
|
||||
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
||||
}
|
||||
putToDelayedMessages(location, message);
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, false);
|
||||
}
|
||||
} else {
|
||||
String location = message.videoLocation.path;
|
||||
@ -796,7 +796,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
|
||||
}
|
||||
putToDelayedMessages(location, message);
|
||||
FileLoader.getInstance().uploadFile(location, true);
|
||||
FileLoader.getInstance().uploadFile(location, true, false);
|
||||
}
|
||||
} else if (message.type == 2) {
|
||||
TLRPC.InputMedia media = null;
|
||||
@ -808,23 +808,23 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||
if (message.sendRequest != null && media.thumb == null && message.location != null) {
|
||||
String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
|
||||
putToDelayedMessages(location, message);
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, true);
|
||||
} else {
|
||||
String location = message.documentLocation.path;
|
||||
putToDelayedMessages(location, message);
|
||||
if (message.sendRequest != null) {
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, false);
|
||||
} else {
|
||||
FileLoader.getInstance().uploadFile(location, true);
|
||||
FileLoader.getInstance().uploadFile(location, true, false);
|
||||
}
|
||||
}
|
||||
} else if (message.type == 3) {
|
||||
String location = message.audioLocation.path;
|
||||
putToDelayedMessages(location, message);
|
||||
if (message.sendRequest != null) {
|
||||
FileLoader.getInstance().uploadFile(location, false);
|
||||
FileLoader.getInstance().uploadFile(location, false, true);
|
||||
} 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 LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>();
|
||||
private LinkedList<FileUploadOperation> uploadSmallOperationQueue = new LinkedList<FileUploadOperation>();
|
||||
private LinkedList<FileLoadOperation> loadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||
private LinkedList<FileLoadOperation> audioLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||
private LinkedList<FileLoadOperation> photoLoadOperationQueue = new LinkedList<FileLoadOperation>();
|
||||
@ -43,6 +44,7 @@ public class FileLoader {
|
||||
private int currentAudioLoadOperationsCount = 0;
|
||||
private int currentPhotoLoadOperationsCount = 0;
|
||||
private int currentUploadOperationsCount = 0;
|
||||
private int currentUploadSmallOperationsCount = 0;
|
||||
|
||||
private static volatile FileLoader Instance = null;
|
||||
public static FileLoader getInstance() {
|
||||
@ -62,18 +64,16 @@ public class FileLoader {
|
||||
fileLoaderQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileUploadOperation operation = null;
|
||||
if (!enc) {
|
||||
FileUploadOperation operation = uploadOperationPaths.get(location);
|
||||
if (operation != null) {
|
||||
uploadOperationQueue.remove(operation);
|
||||
operation.cancel();
|
||||
}
|
||||
operation = uploadOperationPaths.get(location);
|
||||
} else {
|
||||
FileUploadOperation operation = uploadOperationPathsEnc.get(location);
|
||||
if (operation != null) {
|
||||
uploadOperationQueue.remove(operation);
|
||||
operation.cancel();
|
||||
}
|
||||
operation = uploadOperationPathsEnc.get(location);
|
||||
}
|
||||
if (operation != null) {
|
||||
uploadOperationQueue.remove(operation);
|
||||
uploadSmallOperationQueue.remove(operation);
|
||||
operation.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -83,7 +83,7 @@ public class FileLoader {
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -113,12 +113,23 @@ public class FileLoader {
|
||||
} else {
|
||||
uploadOperationPaths.remove(location);
|
||||
}
|
||||
currentUploadOperationsCount--;
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
if (small) {
|
||||
currentUploadSmallOperationsCount--;
|
||||
if (currentUploadSmallOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadSmallOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadSmallOperationsCount++;
|
||||
operation.start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentUploadOperationsCount--;
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (delegate != null) {
|
||||
@ -153,12 +164,23 @@ public class FileLoader {
|
||||
fileProgresses.remove(location);
|
||||
}
|
||||
});
|
||||
currentUploadOperationsCount--;
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
if (small) {
|
||||
currentUploadSmallOperationsCount--;
|
||||
if (currentUploadSmallOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadSmallOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadSmallOperationsCount++;
|
||||
operation.start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentUploadOperationsCount--;
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
FileUploadOperation operation = uploadOperationQueue.poll();
|
||||
if (operation != null) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,11 +197,20 @@ public class FileLoader {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
if (small) {
|
||||
if (currentUploadSmallOperationsCount < 2) {
|
||||
currentUploadSmallOperationsCount++;
|
||||
operation.start();
|
||||
} else {
|
||||
uploadSmallOperationQueue.add(operation);
|
||||
}
|
||||
} else {
|
||||
uploadOperationQueue.add(operation);
|
||||
if (currentUploadOperationsCount < 2) {
|
||||
currentUploadOperationsCount++;
|
||||
operation.start();
|
||||
} else {
|
||||
uploadOperationQueue.add(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -296,10 +327,30 @@ public class FileLoader {
|
||||
if (fileName == null || fileName.contains("" + Integer.MIN_VALUE)) {
|
||||
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;
|
||||
}
|
||||
FileLoadOperation operation = null;
|
||||
|
||||
if (video != null) {
|
||||
operation = new FileLoadOperation(video);
|
||||
} 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";
|
||||
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
|
||||
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
|
||||
FileLoader.getInstance().uploadFile(uploadingAvatar, false);
|
||||
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user