From 875b0d091fc6b7bdcbf790a882ee2abe29aeb41a Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Fri, 24 Feb 2017 12:11:49 +1100 Subject: [PATCH] Replace if/else with switch This is common throughout the F-Droid code base. --- .../fdroid/fdroid/AppUpdateStatusManager.java | 34 ++++++++++--------- .../org/fdroid/fdroid/NotificationHelper.java | 16 +++++---- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusManager.java b/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusManager.java index dac5b099d..bdac704cd 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusManager.java +++ b/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusManager.java @@ -285,23 +285,25 @@ public class AppUpdateStatusManager { } private PendingIntent getContentIntent(AppUpdateStatus entry) { - if (entry.status == Status.UpdateAvailable) { - // Make sure we have an intent to install the app. If not set, we create an intent - // to open up the app details page for the app. From there, the user can hit "install" - return getAppDetailsIntent(entry.apk); - } else if (entry.status == Status.ReadyToInstall) { - return getAppDetailsIntent(entry.apk); - } else if (entry.status == Status.InstallError) { - return getAppErrorIntent(entry); - } else if (entry.status == Status.Installed) { - PackageManager pm = context.getPackageManager(); - Intent intentObject = pm.getLaunchIntentForPackage(entry.app.packageName); - if (intentObject != null) { - return PendingIntent.getActivity(context, 0, intentObject, 0); - } else { - // Could not get launch intent, maybe not launchable, e.g. a keyboard + switch (entry.status) { + case UpdateAvailable: + case ReadyToInstall: + // Make sure we have an intent to install the app. If not set, we create an intent + // to open up the app details page for the app. From there, the user can hit "install" return getAppDetailsIntent(entry.apk); - } + + case InstallError: + return getAppErrorIntent(entry); + + case Installed: + PackageManager pm = context.getPackageManager(); + Intent intentObject = pm.getLaunchIntentForPackage(entry.app.packageName); + if (intentObject != null) { + return PendingIntent.getActivity(context, 0, intentObject, 0); + } else { + // Could not get launch intent, maybe not launchable, e.g. a keyboard + return getAppDetailsIntent(entry.apk); + } } return null; } diff --git a/app/src/main/java/org/fdroid/fdroid/NotificationHelper.java b/app/src/main/java/org/fdroid/fdroid/NotificationHelper.java index 8bb088003..cf51be63d 100644 --- a/app/src/main/java/org/fdroid/fdroid/NotificationHelper.java +++ b/app/src/main/java/org/fdroid/fdroid/NotificationHelper.java @@ -249,12 +249,16 @@ class NotificationHelper { private NotificationCompat.Action getAction(AppUpdateStatusManager.AppUpdateStatus entry) { if (entry.intent != null) { - if (entry.status == AppUpdateStatusManager.Status.UpdateAvailable) { - return new NotificationCompat.Action(R.drawable.ic_notify_update_24dp, context.getString(R.string.notification_action_update), entry.intent); - } else if (entry.status == AppUpdateStatusManager.Status.Downloading || entry.status == AppUpdateStatusManager.Status.Installing) { - return new NotificationCompat.Action(R.drawable.ic_notify_cancel_24dp, context.getString(R.string.notification_action_cancel), entry.intent); - } else if (entry.status == AppUpdateStatusManager.Status.ReadyToInstall) { - return new NotificationCompat.Action(R.drawable.ic_notify_install_24dp, context.getString(R.string.notification_action_install), entry.intent); + switch (entry.status) { + case UpdateAvailable: + return new NotificationCompat.Action(R.drawable.ic_notify_update_24dp, context.getString(R.string.notification_action_update), entry.intent); + + case Downloading: + case Installing: + return new NotificationCompat.Action(R.drawable.ic_notify_cancel_24dp, context.getString(R.string.notification_action_cancel), entry.intent); + + case ReadyToInstall: + return new NotificationCompat.Action(R.drawable.ic_notify_install_24dp, context.getString(R.string.notification_action_install), entry.intent); } } return null;