fix display of swap cancel button and installing progress

closes #1612
This commit is contained in:
Hans-Christoph Steiner 2019-05-22 21:59:47 +02:00
parent fea778793c
commit e02bc4134a
2 changed files with 44 additions and 47 deletions

View File

@ -2,6 +2,7 @@ package org.fdroid.fdroid.views.swap;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -20,6 +21,7 @@ import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.CursorAdapter; import android.support.v4.widget.CursorAdapter;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -40,6 +42,7 @@ import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.Schema.AppMetadataTable; import org.fdroid.fdroid.data.Schema.AppMetadataTable;
import org.fdroid.fdroid.installer.InstallManagerService; import org.fdroid.fdroid.installer.InstallManagerService;
import org.fdroid.fdroid.installer.Installer;
import org.fdroid.fdroid.localrepo.SwapView; import org.fdroid.fdroid.localrepo.SwapView;
import org.fdroid.fdroid.net.Downloader; import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.net.DownloaderService; import org.fdroid.fdroid.net.DownloaderService;
@ -221,6 +224,46 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
if (apk != null) { if (apk != null) {
localBroadcastManager.registerReceiver(new DownloadReceiver(), localBroadcastManager.registerReceiver(new DownloadReceiver(),
DownloaderService.getIntentFilter(apk.getCanonicalUrl())); DownloaderService.getIntentFilter(apk.getCanonicalUrl()));
localBroadcastManager.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case Installer.ACTION_INSTALL_STARTED:
statusInstalled.setText(R.string.installing);
statusInstalled.setVisibility(View.VISIBLE);
btnInstall.setVisibility(View.GONE);
progressView.setIndeterminate(true);
progressView.setVisibility(View.VISIBLE);
break;
case Installer.ACTION_INSTALL_USER_INTERACTION:
PendingIntent installPendingIntent =
intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI);
try {
installPendingIntent.send();
} catch (PendingIntent.CanceledException e) {
Log.e(TAG, "PI canceled", e);
}
break;
case Installer.ACTION_INSTALL_COMPLETE:
localBroadcastManager.unregisterReceiver(this);
statusInstalled.setText(R.string.app_installed);
statusInstalled.setVisibility(View.VISIBLE);
btnInstall.setVisibility(View.GONE);
progressView.setVisibility(View.GONE);
break;
case Installer.ACTION_INSTALL_INTERRUPTED:
localBroadcastManager.unregisterReceiver(this);
statusInstalled.setVisibility(View.GONE);
btnInstall.setVisibility(View.VISIBLE);
progressView.setVisibility(View.GONE);
String errorMessage = intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
if (errorMessage != null) {
Toast.makeText(getContext(), errorMessage, Toast.LENGTH_LONG).show();
}
break;
}
}
}, Installer.getInstallIntentFilter(apk.getCanonicalUrl()));
} }
// NOTE: Instead of continually unregistering and re-registering the observer // NOTE: Instead of continually unregistering and re-registering the observer
@ -248,8 +291,8 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (apk != null && (app.hasUpdates() || app.compatible)) { if (apk != null && (app.hasUpdates() || app.compatible)) {
getActivity().install(app, apk);
showProgress(); showProgress();
InstallManagerService.queue(getContext(), app, apk);
} }
} }
}; };

View File

@ -2,7 +2,6 @@ package org.fdroid.fdroid.views.swap;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
@ -55,13 +54,9 @@ import org.fdroid.fdroid.QrGenAsyncTask;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.NewRepoConfig; import org.fdroid.fdroid.data.NewRepoConfig;
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.installer.InstallManagerService;
import org.fdroid.fdroid.installer.Installer;
import org.fdroid.fdroid.localrepo.BluetoothManager; import org.fdroid.fdroid.localrepo.BluetoothManager;
import org.fdroid.fdroid.localrepo.BonjourManager; import org.fdroid.fdroid.localrepo.BonjourManager;
import org.fdroid.fdroid.localrepo.LocalHTTPDManager; import org.fdroid.fdroid.localrepo.LocalHTTPDManager;
@ -838,47 +833,6 @@ public class SwapWorkflowActivity extends AppCompatActivity {
} }
} }
public void install(@NonNull final App app, @NonNull final Apk apk) {
localBroadcastManager.registerReceiver(new InstallReceiver(),
Installer.getInstallIntentFilter(apk.getCanonicalUrl()));
InstallManagerService.queue(this, app, apk);
}
private class InstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case Installer.ACTION_INSTALL_STARTED:
break;
case Installer.ACTION_INSTALL_COMPLETE:
localBroadcastManager.unregisterReceiver(this);
showRelevantView();
break;
case Installer.ACTION_INSTALL_INTERRUPTED:
localBroadcastManager.unregisterReceiver(this);
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 =
intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI);
try {
installPendingIntent.send();
} catch (PendingIntent.CanceledException e) {
Log.e(TAG, "PI canceled", e);
}
break;
default:
throw new RuntimeException("intent action not handled!");
}
}
}
private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() { private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {