use new PendingInstall mechanism to control AppDetails buttons
This should hopefully give more reliable display/hiding of the buttons. refs #1357
This commit is contained in:
parent
d1cbbe72d7
commit
1c50e28910
@ -373,6 +373,12 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void installApk() {
|
||||||
|
Apk apkToInstall = ApkProvider.Helper.findSuggestedApk(this, app);
|
||||||
|
installApk(apkToInstall);
|
||||||
|
}
|
||||||
|
|
||||||
// Install the version of this app denoted by 'app.curApk'.
|
// Install the version of this app denoted by 'app.curApk'.
|
||||||
@Override
|
@Override
|
||||||
public void installApk(final Apk apk) {
|
public void installApk(final Apk apk) {
|
||||||
@ -426,12 +432,6 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initiateInstall(Apk apk) {
|
private void initiateInstall(Apk apk) {
|
||||||
if (isAppDownloading()) {
|
|
||||||
Log.i(TAG, "Ignoring request to install " + apk.packageName + " version " + apk.versionName
|
|
||||||
+ ", as we are already downloading (either that or a different version).");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Installer installer = InstallerFactory.create(this, apk);
|
Installer installer = InstallerFactory.create(this, apk);
|
||||||
Intent intent = installer.getPermissionScreen();
|
Intent intent = installer.getPermissionScreen();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
@ -705,11 +705,6 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAppDownloading() {
|
|
||||||
return currentStatus != null && currentStatus.status == AppUpdateStatusManager.Status.Downloading;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableAndroidBeam() {
|
public void enableAndroidBeam() {
|
||||||
NfcHelper.setAndroidBeam(this, app.packageName);
|
NfcHelper.setAndroidBeam(this, app.packageName);
|
||||||
@ -734,7 +729,7 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installCancel() {
|
public void installCancel() {
|
||||||
if (isAppDownloading()) {
|
if (currentStatus != null) {
|
||||||
InstallManagerService.cancel(this, currentStatus.getUniqueKey());
|
InstallManagerService.cancel(this, currentStatus.getUniqueKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -750,18 +745,6 @@ public class AppDetails2 extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void installApk() {
|
|
||||||
Apk apkToInstall = ApkProvider.Helper.findSuggestedApk(this, app);
|
|
||||||
installApk(apkToInstall);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void upgradeApk() {
|
|
||||||
Apk apkToInstall = ApkProvider.Helper.findSuggestedApk(this, app);
|
|
||||||
installApk(apkToInstall);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uninstall the app from the current screen. Since there are many ways
|
* Uninstall the app from the current screen. Since there are many ways
|
||||||
* to uninstall an app, including from Google Play, {@code adb uninstall},
|
* to uninstall an app, including from Google Play, {@code adb uninstall},
|
||||||
|
@ -489,12 +489,25 @@ public class InstallManagerService extends Service {
|
|||||||
return pendingInstalls.contains(urlString);
|
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
|
* Mark a given APK as in the process of being installed, with
|
||||||
* the {@code urlString} of the download used as the unique ID,
|
* the {@code urlString} of the download used as the unique ID,
|
||||||
* and the file hash used to verify that things are the same.
|
* and the file hash used to verify that things are the same.
|
||||||
*
|
*
|
||||||
* @see #isPendingInstall(String)
|
* @see #isPendingInstall(String)
|
||||||
|
* @see #isPendingInstall(Context, String)
|
||||||
*/
|
*/
|
||||||
public static void putPendingInstall(Context context, String urlString, String packageName) {
|
public static void putPendingInstall(Context context, String urlString, String packageName) {
|
||||||
if (pendingInstalls == null) {
|
if (pendingInstalls == null) {
|
||||||
|
@ -43,6 +43,7 @@ import org.fdroid.fdroid.data.ApkProvider;
|
|||||||
import org.fdroid.fdroid.data.App;
|
import org.fdroid.fdroid.data.App;
|
||||||
import org.fdroid.fdroid.data.InstalledAppProvider;
|
import org.fdroid.fdroid.data.InstalledAppProvider;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
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.AppDiff;
|
||||||
import org.fdroid.fdroid.privileged.views.AppSecurityPermissions;
|
import org.fdroid.fdroid.privileged.views.AppSecurityPermissions;
|
||||||
import org.fdroid.fdroid.views.main.MainActivity;
|
import org.fdroid.fdroid.views.main.MainActivity;
|
||||||
@ -57,8 +58,6 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
|
|
||||||
public interface AppDetailsRecyclerViewAdapterCallbacks {
|
public interface AppDetailsRecyclerViewAdapterCallbacks {
|
||||||
|
|
||||||
boolean isAppDownloading();
|
|
||||||
|
|
||||||
void enableAndroidBeam();
|
void enableAndroidBeam();
|
||||||
|
|
||||||
void disableAndroidBeam();
|
void disableAndroidBeam();
|
||||||
@ -69,8 +68,6 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
|
|
||||||
void installApk(Apk apk);
|
void installApk(Apk apk);
|
||||||
|
|
||||||
void upgradeApk();
|
|
||||||
|
|
||||||
void uninstallApk();
|
void uninstallApk();
|
||||||
|
|
||||||
void installCancel();
|
void installCancel();
|
||||||
@ -490,9 +487,11 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
buttonSecondaryView.setOnClickListener(onUnInstallClickListener);
|
buttonSecondaryView.setOnClickListener(onUnInstallClickListener);
|
||||||
buttonPrimaryView.setText(R.string.menu_install);
|
buttonPrimaryView.setText(R.string.menu_install);
|
||||||
buttonPrimaryView.setVisibility(versions.size() > 0 ? View.VISIBLE : View.GONE);
|
buttonPrimaryView.setVisibility(versions.size() > 0 ? View.VISIBLE : View.GONE);
|
||||||
if (callbacks.isAppDownloading()) {
|
if (InstallManagerService.isPendingInstall(context, app.packageName)) {
|
||||||
buttonPrimaryView.setText(R.string.downloading);
|
buttonPrimaryView.setText(R.string.downloading);
|
||||||
buttonPrimaryView.setEnabled(false);
|
buttonPrimaryView.setEnabled(false);
|
||||||
|
buttonLayout.setVisibility(View.GONE);
|
||||||
|
progressLayout.setVisibility(View.VISIBLE);
|
||||||
} else if (!app.isInstalled(context) && suggestedApk != null) {
|
} else if (!app.isInstalled(context) && suggestedApk != null) {
|
||||||
// Check count > 0 due to incompatible apps resulting in an empty list.
|
// Check count > 0 due to incompatible apps resulting in an empty list.
|
||||||
callbacks.disableAndroidBeam();
|
callbacks.disableAndroidBeam();
|
||||||
@ -500,6 +499,8 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
buttonPrimaryView.setText(R.string.menu_install);
|
buttonPrimaryView.setText(R.string.menu_install);
|
||||||
buttonPrimaryView.setOnClickListener(onInstallClickListener);
|
buttonPrimaryView.setOnClickListener(onInstallClickListener);
|
||||||
buttonPrimaryView.setEnabled(true);
|
buttonPrimaryView.setEnabled(true);
|
||||||
|
buttonLayout.setVisibility(View.VISIBLE);
|
||||||
|
progressLayout.setVisibility(View.GONE);
|
||||||
} else if (app.isInstalled(context)) {
|
} else if (app.isInstalled(context)) {
|
||||||
callbacks.enableAndroidBeam();
|
callbacks.enableAndroidBeam();
|
||||||
if (app.canAndWantToUpdate(context) && suggestedApk != null) {
|
if (app.canAndWantToUpdate(context) && suggestedApk != null) {
|
||||||
@ -514,10 +515,8 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buttonPrimaryView.setEnabled(true);
|
buttonPrimaryView.setEnabled(true);
|
||||||
}
|
buttonLayout.setVisibility(View.VISIBLE);
|
||||||
if (callbacks.isAppDownloading()) {
|
progressLayout.setVisibility(View.GONE);
|
||||||
buttonLayout.setVisibility(View.GONE);
|
|
||||||
progressLayout.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
} else {
|
||||||
buttonLayout.setVisibility(View.VISIBLE);
|
buttonLayout.setVisibility(View.VISIBLE);
|
||||||
progressLayout.setVisibility(View.GONE);
|
progressLayout.setVisibility(View.GONE);
|
||||||
@ -1103,7 +1102,7 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
private final View.OnClickListener onUpgradeClickListener = new View.OnClickListener() {
|
private final View.OnClickListener onUpgradeClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
callbacks.upgradeApk();
|
callbacks.installApk();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,10 +101,6 @@ public class AppDetailsAdapterTest extends FDroidProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks dummyCallbacks = new AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks() { // NOCHECKSTYLE LineLength
|
private final AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks dummyCallbacks = new AppDetailsRecyclerViewAdapter.AppDetailsRecyclerViewAdapterCallbacks() { // NOCHECKSTYLE LineLength
|
||||||
@Override
|
|
||||||
public boolean isAppDownloading() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableAndroidBeam() {
|
public void enableAndroidBeam() {
|
||||||
@ -131,11 +127,6 @@ public class AppDetailsAdapterTest extends FDroidProviderTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void upgradeApk() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninstallApk() {
|
public void uninstallApk() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user