diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java index bfe2ab8c3..7a1251258 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails2.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails2.java @@ -698,6 +698,13 @@ public class AppDetails2 extends AppCompatActivity }); } + @Override + public boolean isAppDownloading() { + return currentStatus != null && + (currentStatus.status == AppUpdateStatusManager.Status.PendingInstall + || currentStatus.status == AppUpdateStatusManager.Status.Downloading); + } + @Override public void enableAndroidBeam() { NfcHelper.setAndroidBeam(this, app.packageName); diff --git a/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java b/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java index 726b1496f..8e0f5e926 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/InstallManagerService.java @@ -51,6 +51,8 @@ import java.io.IOException; * {@code {@link #stopSelf(int)}}, so {@code Intent}s are sometimes redelivered even * though they are no longer valid. {@link #onStartCommand(Intent, int, int)} checks * first that the incoming {@code Intent} is not an invalid, redelivered {@code Intent}. + * {@link #isPendingInstall(String)} and other checks are used to check whether to + * process the redelivered {@code Intent} or not. * <p> * The canonical URL for the APK file to download is also used as the unique ID to * represent the download itself throughout F-Droid. This follows the model @@ -471,25 +473,12 @@ public class InstallManagerService extends Service { return pendingInstalls.contains(urlString); } - /** - * Look up by {@code packageName} whether it is a Pending Install. - * - * @see #isPendingInstall(String) - */ - public static boolean isPendingInstall(Context context, String packageName) { - if (pendingInstalls == null) { - pendingInstalls = getPendingInstalls(context); - } - return pendingInstalls.getAll().values().contains(packageName); - } - /** * Mark a given APK as in the process of being installed, with * the {@code urlString} of the download used as the unique ID, * and the file hash used to verify that things are the same. * * @see #isPendingInstall(String) - * @see #isPendingInstall(Context, String) */ public static void putPendingInstall(Context context, String urlString, String packageName) { if (pendingInstalls == null) { diff --git a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java index 150aabbc5..b59403ac8 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/AppDetailsRecyclerViewAdapter.java @@ -43,7 +43,6 @@ import org.fdroid.fdroid.data.ApkProvider; import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.InstalledAppProvider; import org.fdroid.fdroid.data.RepoProvider; -import org.fdroid.fdroid.installer.InstallManagerService; import org.fdroid.fdroid.privileged.views.AppDiff; import org.fdroid.fdroid.privileged.views.AppSecurityPermissions; import org.fdroid.fdroid.views.main.MainActivity; @@ -58,6 +57,8 @@ public class AppDetailsRecyclerViewAdapter public interface AppDetailsRecyclerViewAdapterCallbacks { + boolean isAppDownloading(); + void enableAndroidBeam(); void disableAndroidBeam(); @@ -487,7 +488,7 @@ public class AppDetailsRecyclerViewAdapter buttonSecondaryView.setOnClickListener(onUnInstallClickListener); buttonPrimaryView.setText(R.string.menu_install); buttonPrimaryView.setVisibility(versions.size() > 0 ? View.VISIBLE : View.GONE); - if (InstallManagerService.isPendingInstall(context, app.packageName)) { + if (callbacks.isAppDownloading()) { buttonPrimaryView.setText(R.string.downloading); buttonPrimaryView.setEnabled(false); buttonLayout.setVisibility(View.GONE); diff --git a/app/src/test/java/org/fdroid/fdroid/views/AppDetailsAdapterTest.java b/app/src/test/java/org/fdroid/fdroid/views/AppDetailsAdapterTest.java index 1a829fddf..c072af430 100644 --- a/app/src/test/java/org/fdroid/fdroid/views/AppDetailsAdapterTest.java +++ b/app/src/test/java/org/fdroid/fdroid/views/AppDetailsAdapterTest.java @@ -101,6 +101,10 @@ public class AppDetailsAdapterTest extends FDroidProviderTest { } private final AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks dummyCallbacks = new AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks() { // NOCHECKSTYLE LineLength + @Override + public boolean isAppDownloading() { + return false; + } @Override public void enableAndroidBeam() {