Replace if/else with switch
This is common throughout the F-Droid code base.
This commit is contained in:
parent
49f20f64b3
commit
875b0d091f
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user