create download and install receivers per-app, not globally
Each individual app needs its own receivers for these things, just like in AppListActivity and InstallManagerService.
This commit is contained in:
parent
d91fbe7b0e
commit
910f5da81a
@ -50,6 +50,12 @@ import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* This is a view that shows a listing of all apps in the swap repo that this
|
||||
* just connected to. The app listing and search should be replaced by
|
||||
* {@link org.fdroid.fdroid.views.apps.AppListActivity}'s plumbing.
|
||||
*/
|
||||
// TODO merge this with AppListActivity, perhaps there could be AppListView?
|
||||
public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String TAG = "SwapAppsView";
|
||||
|
||||
@ -72,20 +78,12 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
||||
|
||||
private Repo repo;
|
||||
private AppListAdapter adapter;
|
||||
private String currentFilterString;
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
repo = getActivity().getState().getPeerRepo();
|
||||
|
||||
/*
|
||||
if (repo == null) {
|
||||
TODO: Uh oh, something stuffed up for this to happen.
|
||||
TODO: What is the best course of action from here?
|
||||
}
|
||||
*/
|
||||
|
||||
adapter = new AppListAdapter(getContext(), getContext().getContentResolver().query(
|
||||
AppProvider.getRepoUri(repo), AppMetadataTable.Cols.ALL, null, null, null));
|
||||
ListView listView = findViewById(R.id.list);
|
||||
@ -173,7 +171,7 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
||||
TextView statusInstalled;
|
||||
TextView statusIncompatible;
|
||||
|
||||
private final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
|
||||
private class DownloadReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
@ -195,9 +193,11 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
||||
}
|
||||
break;
|
||||
case Downloader.ACTION_COMPLETE:
|
||||
localBroadcastManager.unregisterReceiver(this);
|
||||
resetView();
|
||||
break;
|
||||
case Downloader.ACTION_INTERRUPTED:
|
||||
localBroadcastManager.unregisterReceiver(this);
|
||||
if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) {
|
||||
String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE)
|
||||
+ " " + intent.getDataString();
|
||||
@ -212,7 +212,7 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
||||
throw new RuntimeException("intent action not handled!");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final ContentObserver appObserver = new ContentObserver(new Handler()) {
|
||||
@Override
|
||||
@ -244,9 +244,8 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
||||
}
|
||||
|
||||
if (apk != null) {
|
||||
// TODO unregister receivers? or will they just die with this instance
|
||||
IntentFilter downloadFilter = DownloaderService.getIntentFilter(apk.getCanonicalUrl());
|
||||
localBroadcastManager.registerReceiver(downloadReceiver, downloadFilter);
|
||||
localBroadcastManager.registerReceiver(new DownloadReceiver(),
|
||||
DownloaderService.getIntentFilter(apk.getCanonicalUrl()));
|
||||
}
|
||||
|
||||
// NOTE: Instead of continually unregistering and re-registering the observer
|
||||
|
@ -839,12 +839,12 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void install(@NonNull final App app, @NonNull final Apk apk) {
|
||||
localBroadcastManager.registerReceiver(installReceiver,
|
||||
localBroadcastManager.registerReceiver(new InstallReceiver(),
|
||||
Installer.getInstallIntentFilter(apk.getCanonicalUrl()));
|
||||
InstallManagerService.queue(this, app, apk);
|
||||
}
|
||||
|
||||
private final BroadcastReceiver installReceiver = new BroadcastReceiver() {
|
||||
private class InstallReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
@ -857,7 +857,10 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
break;
|
||||
case Installer.ACTION_INSTALL_INTERRUPTED:
|
||||
localBroadcastManager.unregisterReceiver(this);
|
||||
// TODO: handle errors!
|
||||
String errorMessage = intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
|
||||
if (errorMessage != null) {
|
||||
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
break;
|
||||
case Installer.ACTION_INSTALL_USER_INTERACTION:
|
||||
PendingIntent installPendingIntent =
|
||||
@ -874,7 +877,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
throw new RuntimeException("intent action not handled!");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() {
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user