port everything over to new Downloader.ACTION_PROGRESS

This replaces all of the previous progress events and listeners.
This commit is contained in:
Hans-Christoph Steiner 2016-03-31 22:01:07 +02:00
parent 2e3d2c84ae
commit 5e59f812ce
6 changed files with 10 additions and 30 deletions

View File

@ -474,7 +474,7 @@ public class AppDetails extends AppCompatActivity {
localBroadcastManager.registerReceiver(startedReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(progressReceiver,
DownloaderService.getIntentFilter(url, Downloader.LOCAL_ACTION_PROGRESS));
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(completeReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(interruptedReceiver,

View File

@ -48,6 +48,7 @@ import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.net.DownloaderService;
import java.util.ArrayList;
import java.util.List;
@ -129,8 +130,6 @@ public class UpdateService extends IntentService implements ProgressListener {
super.onCreate();
localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.registerReceiver(downloadProgressReceiver,
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
localBroadcastManager.registerReceiver(updateStatusReceiver,
new IntentFilter(LOCAL_ACTION_STATUS));
@ -192,16 +191,7 @@ public class UpdateService extends IntentService implements ProgressListener {
private final BroadcastReceiver downloadProgressReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (TextUtils.isEmpty(action)) {
return;
}
if (!action.equals(Downloader.LOCAL_ACTION_PROGRESS)) {
return;
}
String repoAddress = intent.getStringExtra(Downloader.EXTRA_ADDRESS);
String repoAddress = intent.getDataString();
int downloadedSize = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1);
String downloadedSizeFriendly = Utils.getFriendlySize(downloadedSize);
int totalSize = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1);
@ -381,6 +371,8 @@ public class UpdateService extends IntentService implements ProgressListener {
sendStatus(this, STATUS_INFO, getString(R.string.status_connecting_to_repo, repo.address));
RepoUpdater updater = new RepoUpdater(getBaseContext(), repo);
localBroadcastManager.registerReceiver(downloadProgressReceiver,
DownloaderService.getIntentFilter(updater.indexUrl, Downloader.ACTION_PROGRESS));
updater.setProgressListener(this);
try {
updater.update();
@ -395,6 +387,7 @@ public class UpdateService extends IntentService implements ProgressListener {
repoErrors.add(e.getMessage());
Log.e(TAG, "Error updating repository " + repo.address, e);
}
localBroadcastManager.unregisterReceiver(downloadProgressReceiver);
}
if (!changes) {

View File

@ -15,12 +15,11 @@ public abstract class Downloader {
private static final String TAG = "Downloader";
public static final String LOCAL_ACTION_PROGRESS = "Downloader.PROGRESS";
public static final String ACTION_STARTED = "org.fdroid.fdroid.net.Downloader.action.STARTED";
public static final String ACTION_PROGRESS = "org.fdroid.fdroid.net.Downloader.action.PROGRESS";
public static final String ACTION_INTERRUPTED = "org.fdroid.fdroid.net.Downloader.action.INTERRUPTED";
public static final String ACTION_COMPLETE = "org.fdroid.fdroid.net.Downloader.action.COMPLETE";
public static final String EXTRA_ADDRESS = "extraAddress";
public static final String EXTRA_DOWNLOAD_PATH = "org.fdroid.fdroid.net.Downloader.extra.DOWNLOAD_PATH";
public static final String EXTRA_BYTES_READ = "org.fdroid.fdroid.net.Downloader.extra.BYTES_READ";
public static final String EXTRA_TOTAL_BYTES = "org.fdroid.fdroid.net.Downloader.extra.TOTAL_BYTES";

View File

@ -1,7 +1,6 @@
package org.fdroid.fdroid.net;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;
@ -57,17 +56,6 @@ public class DownloaderFactory {
downloader = new HttpDownloader(url, destFile, repo.username, repo.password);
}
}
downloader.setListener(new Downloader.DownloaderProgressListener() {
@Override
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
Intent intent = new Intent(Downloader.LOCAL_ACTION_PROGRESS);
intent.putExtra(Downloader.EXTRA_ADDRESS, sourceUrl.toString());
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
localBroadcastManager.sendBroadcast(intent);
}
});
return downloader;
}

View File

@ -186,7 +186,7 @@ public class DownloaderService extends Service {
@Override
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
//Log.i(TAG, "sendProgress " + sourceUrl + " " + bytesRead + " / " + totalBytes);
Intent intent = new Intent(Downloader.LOCAL_ACTION_PROGRESS);
Intent intent = new Intent(Downloader.ACTION_PROGRESS);
intent.setData(uri);
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
@ -261,7 +261,7 @@ public class DownloaderService extends Service {
* Get a prepared {@link IntentFilter} for use for matching this service's action events.
*
* @param urlString The full file URL to match.
* @param action {@link Downloader#ACTION_STARTED}, {@link Downloader#LOCAL_ACTION_PROGRESS},
* @param action {@link Downloader#ACTION_STARTED}, {@link Downloader#ACTION_PROGRESS},
* {@link Downloader#ACTION_INTERRUPTED}, or {@link Downloader#ACTION_COMPLETE},
* @return
*/

View File

@ -290,7 +290,7 @@ public class SwapAppsView extends ListView implements
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(downloadProgressReceiver,
DownloaderService.getIntentFilter(url, Downloader.LOCAL_ACTION_PROGRESS));
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(appListViewResetReceiver,