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.Timer;
|
||||||
import java.util.TimerTask;
|
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> {
|
public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
private static final String TAG = "SwapAppsView";
|
private static final String TAG = "SwapAppsView";
|
||||||
|
|
||||||
@ -72,20 +78,12 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
|||||||
|
|
||||||
private Repo repo;
|
private Repo repo;
|
||||||
private AppListAdapter adapter;
|
private AppListAdapter adapter;
|
||||||
private String currentFilterString;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
repo = getActivity().getState().getPeerRepo();
|
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(
|
adapter = new AppListAdapter(getContext(), getContext().getContentResolver().query(
|
||||||
AppProvider.getRepoUri(repo), AppMetadataTable.Cols.ALL, null, null, null));
|
AppProvider.getRepoUri(repo), AppMetadataTable.Cols.ALL, null, null, null));
|
||||||
ListView listView = findViewById(R.id.list);
|
ListView listView = findViewById(R.id.list);
|
||||||
@ -173,7 +171,7 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
|||||||
TextView statusInstalled;
|
TextView statusInstalled;
|
||||||
TextView statusIncompatible;
|
TextView statusIncompatible;
|
||||||
|
|
||||||
private final BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
|
private class DownloadReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
@ -195,9 +193,11 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Downloader.ACTION_COMPLETE:
|
case Downloader.ACTION_COMPLETE:
|
||||||
|
localBroadcastManager.unregisterReceiver(this);
|
||||||
resetView();
|
resetView();
|
||||||
break;
|
break;
|
||||||
case Downloader.ACTION_INTERRUPTED:
|
case Downloader.ACTION_INTERRUPTED:
|
||||||
|
localBroadcastManager.unregisterReceiver(this);
|
||||||
if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) {
|
if (intent.hasExtra(Downloader.EXTRA_ERROR_MESSAGE)) {
|
||||||
String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE)
|
String msg = intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE)
|
||||||
+ " " + intent.getDataString();
|
+ " " + intent.getDataString();
|
||||||
@ -212,7 +212,7 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
|||||||
throw new RuntimeException("intent action not handled!");
|
throw new RuntimeException("intent action not handled!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
private final ContentObserver appObserver = new ContentObserver(new Handler()) {
|
private final ContentObserver appObserver = new ContentObserver(new Handler()) {
|
||||||
@Override
|
@Override
|
||||||
@ -244,9 +244,8 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (apk != null) {
|
if (apk != null) {
|
||||||
// TODO unregister receivers? or will they just die with this instance
|
localBroadcastManager.registerReceiver(new DownloadReceiver(),
|
||||||
IntentFilter downloadFilter = DownloaderService.getIntentFilter(apk.getCanonicalUrl());
|
DownloaderService.getIntentFilter(apk.getCanonicalUrl()));
|
||||||
localBroadcastManager.registerReceiver(downloadReceiver, downloadFilter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Instead of continually unregistering and re-registering the observer
|
// 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) {
|
public void install(@NonNull final App app, @NonNull final Apk apk) {
|
||||||
localBroadcastManager.registerReceiver(installReceiver,
|
localBroadcastManager.registerReceiver(new InstallReceiver(),
|
||||||
Installer.getInstallIntentFilter(apk.getCanonicalUrl()));
|
Installer.getInstallIntentFilter(apk.getCanonicalUrl()));
|
||||||
InstallManagerService.queue(this, app, apk);
|
InstallManagerService.queue(this, app, apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver installReceiver = new BroadcastReceiver() {
|
private class InstallReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
@ -857,7 +857,10 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
break;
|
break;
|
||||||
case Installer.ACTION_INSTALL_INTERRUPTED:
|
case Installer.ACTION_INSTALL_INTERRUPTED:
|
||||||
localBroadcastManager.unregisterReceiver(this);
|
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;
|
break;
|
||||||
case Installer.ACTION_INSTALL_USER_INTERACTION:
|
case Installer.ACTION_INSTALL_USER_INTERACTION:
|
||||||
PendingIntent installPendingIntent =
|
PendingIntent installPendingIntent =
|
||||||
@ -874,7 +877,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
throw new RuntimeException("intent action not handled!");
|
throw new RuntimeException("intent action not handled!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() {
|
private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user