port everything over to new Downloader.ACTION_PROGRESS
This replaces all of the previous progress events and listeners.
This commit is contained in:
parent
2e3d2c84ae
commit
5e59f812ce
@ -474,7 +474,7 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
localBroadcastManager.registerReceiver(startedReceiver,
|
localBroadcastManager.registerReceiver(startedReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
|
||||||
localBroadcastManager.registerReceiver(progressReceiver,
|
localBroadcastManager.registerReceiver(progressReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.LOCAL_ACTION_PROGRESS));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
|
||||||
localBroadcastManager.registerReceiver(completeReceiver,
|
localBroadcastManager.registerReceiver(completeReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
|
||||||
localBroadcastManager.registerReceiver(interruptedReceiver,
|
localBroadcastManager.registerReceiver(interruptedReceiver,
|
||||||
|
@ -48,6 +48,7 @@ import org.fdroid.fdroid.data.AppProvider;
|
|||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
import org.fdroid.fdroid.net.Downloader;
|
import org.fdroid.fdroid.net.Downloader;
|
||||||
|
import org.fdroid.fdroid.net.DownloaderService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -129,8 +130,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
||||||
localBroadcastManager.registerReceiver(downloadProgressReceiver,
|
|
||||||
new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS));
|
|
||||||
localBroadcastManager.registerReceiver(updateStatusReceiver,
|
localBroadcastManager.registerReceiver(updateStatusReceiver,
|
||||||
new IntentFilter(LOCAL_ACTION_STATUS));
|
new IntentFilter(LOCAL_ACTION_STATUS));
|
||||||
|
|
||||||
@ -192,16 +191,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
private final BroadcastReceiver downloadProgressReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver downloadProgressReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String repoAddress = intent.getDataString();
|
||||||
if (TextUtils.isEmpty(action)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!action.equals(Downloader.LOCAL_ACTION_PROGRESS)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String repoAddress = intent.getStringExtra(Downloader.EXTRA_ADDRESS);
|
|
||||||
int downloadedSize = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1);
|
int downloadedSize = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1);
|
||||||
String downloadedSizeFriendly = Utils.getFriendlySize(downloadedSize);
|
String downloadedSizeFriendly = Utils.getFriendlySize(downloadedSize);
|
||||||
int totalSize = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1);
|
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));
|
sendStatus(this, STATUS_INFO, getString(R.string.status_connecting_to_repo, repo.address));
|
||||||
RepoUpdater updater = new RepoUpdater(getBaseContext(), repo);
|
RepoUpdater updater = new RepoUpdater(getBaseContext(), repo);
|
||||||
|
localBroadcastManager.registerReceiver(downloadProgressReceiver,
|
||||||
|
DownloaderService.getIntentFilter(updater.indexUrl, Downloader.ACTION_PROGRESS));
|
||||||
updater.setProgressListener(this);
|
updater.setProgressListener(this);
|
||||||
try {
|
try {
|
||||||
updater.update();
|
updater.update();
|
||||||
@ -395,6 +387,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
repoErrors.add(e.getMessage());
|
repoErrors.add(e.getMessage());
|
||||||
Log.e(TAG, "Error updating repository " + repo.address, e);
|
Log.e(TAG, "Error updating repository " + repo.address, e);
|
||||||
}
|
}
|
||||||
|
localBroadcastManager.unregisterReceiver(downloadProgressReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changes) {
|
if (!changes) {
|
||||||
|
@ -15,12 +15,11 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
private static final String TAG = "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_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_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 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_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_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";
|
public static final String EXTRA_TOTAL_BYTES = "org.fdroid.fdroid.net.Downloader.extra.TOTAL_BYTES";
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
@ -57,17 +56,6 @@ public class DownloaderFactory {
|
|||||||
downloader = new HttpDownloader(url, destFile, repo.username, repo.password);
|
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;
|
return downloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ public class DownloaderService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
public void sendProgress(URL sourceUrl, int bytesRead, int totalBytes) {
|
||||||
//Log.i(TAG, "sendProgress " + sourceUrl + " " + bytesRead + " / " + 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.setData(uri);
|
||||||
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
||||||
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
|
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.
|
* Get a prepared {@link IntentFilter} for use for matching this service's action events.
|
||||||
*
|
*
|
||||||
* @param urlString The full file URL to match.
|
* @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},
|
* {@link Downloader#ACTION_INTERRUPTED}, or {@link Downloader#ACTION_COMPLETE},
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -290,7 +290,7 @@ public class SwapAppsView extends ListView implements
|
|||||||
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
|
||||||
localBroadcastManager.registerReceiver(downloadProgressReceiver,
|
localBroadcastManager.registerReceiver(downloadProgressReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.LOCAL_ACTION_PROGRESS));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
|
||||||
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
||||||
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
|
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
|
||||||
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user