New method in IndexesForest: remove(Account account). Use this method for cancelling downloads

This commit is contained in:
masensio 2015-02-20 10:23:46 +01:00
parent 83ad608faa
commit 0f7ea542c9
2 changed files with 7 additions and 21 deletions

View file

@ -671,22 +671,6 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
*/
private void cancelDownloadsForAccount(Account account) {
// Cancel pending downloads
ConcurrentMap downloadsAccount = mPendingDownloads.get(account);
Iterator<String> it = downloadsAccount.keySet().iterator();
Log_OC.d(TAG, "Number of pending downloads= " + downloadsAccount.size());
DownloadFileOperation download;
while (it.hasNext()) {
String key = it.next();
Log_OC.d(TAG, "download CANCELLED " + key);
if (key.startsWith(account.name)) {
synchronized (mPendingDownloads) {
download = mPendingDownloads.get(key);
if (download != null) {
String remotePath = download.getRemotePath();
mPendingDownloads.remove(account, remotePath);
}
}
}
}
mPendingDownloads.remove(account);
}
}

View file

@ -213,17 +213,19 @@ public class IndexedForest<V> {
}
public ConcurrentMap<String, Node<V>> get(Account account){
ConcurrentMap<String, Node<V>> accountMap = new ConcurrentHashMap<String, Node<V>>();
/**
* Remove the elements that contains account as a part of its key
* @param account
*/
public void remove(Account account){
Iterator<String> it = mMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
Log_OC.d("IndexedForest", "Number of pending downloads= " + mMap.size());
if (key.startsWith(account.name)) {
accountMap.putIfAbsent(key, mMap.get(key));
mMap.remove(key);
}
}
return accountMap;
}
/**