diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails.java b/app/src/main/java/org/fdroid/fdroid/AppDetails.java index 5b3dc86a4..99d8c6e01 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails.java @@ -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, diff --git a/app/src/main/java/org/fdroid/fdroid/UpdateService.java b/app/src/main/java/org/fdroid/fdroid/UpdateService.java index 8f045744b..cfdd18012 100644 --- a/app/src/main/java/org/fdroid/fdroid/UpdateService.java +++ b/app/src/main/java/org/fdroid/fdroid/UpdateService.java @@ -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) { diff --git a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java index 76b7849a6..5dfc80f6e 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/Downloader.java +++ b/app/src/main/java/org/fdroid/fdroid/net/Downloader.java @@ -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"; diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java index e72eb0ed2..2c2b8cb65 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderFactory.java @@ -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; } diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index 0c3986610..7f308433a 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -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 */ diff --git a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java index 3a4df7e85..190cd747e 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java +++ b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java @@ -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,