From e02bc4134a5bb34b3f0fdd21a1bcee3b726a24eb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 22 May 2019 21:59:47 +0200 Subject: [PATCH] fix display of swap cancel button and installing progress closes #1612 --- .../fdroid/views/swap/SwapSuccessView.java | 45 +++++++++++++++++- .../views/swap/SwapWorkflowActivity.java | 46 ------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapSuccessView.java b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapSuccessView.java index bcc445421..e642a32a4 100644 --- a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapSuccessView.java +++ b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapSuccessView.java @@ -2,6 +2,7 @@ package org.fdroid.fdroid.views.swap; import android.annotation.TargetApi; import android.app.Activity; +import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -20,6 +21,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.CursorAdapter; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; 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.Schema.AppMetadataTable; import org.fdroid.fdroid.installer.InstallManagerService; +import org.fdroid.fdroid.installer.Installer; import org.fdroid.fdroid.localrepo.SwapView; import org.fdroid.fdroid.net.Downloader; import org.fdroid.fdroid.net.DownloaderService; @@ -221,6 +224,46 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal if (apk != null) { localBroadcastManager.registerReceiver(new DownloadReceiver(), 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 @@ -248,8 +291,8 @@ public class SwapSuccessView extends SwapView implements LoaderManager.LoaderCal @Override public void onClick(View v) { if (apk != null && (app.hasUpdates() || app.compatible)) { - getActivity().install(app, apk); showProgress(); + InstallManagerService.queue(getContext(), app, apk); } } }; diff --git a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 4685d71cb..4939df3f4 100644 --- a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -2,7 +2,6 @@ package org.fdroid.fdroid.views.swap; import android.annotation.TargetApi; import android.app.Activity; -import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -55,13 +54,9 @@ import org.fdroid.fdroid.QrGenAsyncTask; import org.fdroid.fdroid.R; import org.fdroid.fdroid.UpdateService; 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.Repo; 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.BonjourManager; 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() { @Override public void onReceive(Context context, Intent intent) {