From 7cfc2ea004c91d33d6a3da2c825345b1bc8050b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 6 Oct 2015 14:49:23 +0200 Subject: [PATCH] Simplify some bits of code * Don't call getIntent() multiple times * Drop else after return * Don't do "if (!cond) foo else bar" --- F-Droid/src/org/fdroid/fdroid/AppDetails.java | 14 +++++++------- F-Droid/src/org/fdroid/fdroid/FDroidApp.java | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index e11762c55..3cf25c4fa 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -362,14 +362,13 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A * never happen as AppDetails is only to be called by the FDroid activity * and not externally. */ - private String getAppIdFromIntent() { - Intent i = getIntent(); - if (!i.hasExtra(EXTRA_APPID)) { + private String getAppIdFromIntent(Intent intent) { + if (!intent.hasExtra(EXTRA_APPID)) { Log.e(TAG, "No application ID found in the intent!"); return null; } - return i.getStringExtra(EXTRA_APPID); + return intent.getStringExtra(EXTRA_APPID); } @Override @@ -384,8 +383,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A // compat implementation is assigned in the ActionBarActivity base class. supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - if (getIntent().hasExtra(EXTRA_FROM)) { - setTitle(getIntent().getStringExtra(EXTRA_FROM)); + Intent intent = getIntent(); + if (intent.hasExtra(EXTRA_FROM)) { + setTitle(intent.getStringExtra(EXTRA_FROM)); } mPm = getPackageManager(); @@ -403,7 +403,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A app = previousData.app; setApp(app); } else { - if (!reset(getAppIdFromIntent())) { + if (!reset(getAppIdFromIntent(intent))) { finish(); return; } diff --git a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java index e854b1263..d9f03fdd1 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java @@ -288,10 +288,10 @@ public class FDroidApp extends Application { private BluetoothAdapter getBluetoothAdapter() { // to use the new, recommended way of getting the adapter // http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html - if (Build.VERSION.SDK_INT < 18) + if (Build.VERSION.SDK_INT < 18) { return BluetoothAdapter.getDefaultAdapter(); - else - return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter(); + } + return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter(); } public void sendViaBluetooth(Activity activity, int resultCode, String packageName) { @@ -327,13 +327,13 @@ public class FDroidApp extends Application { found = false; } if (sendBt != null) { - if (!found) { + if (found) { + sendBt.setClassName(bluetoothPackageName, className); + activity.startActivity(sendBt); + } else { Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show(); activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send))); - } else { - sendBt.setClassName(bluetoothPackageName, className); - activity.startActivity(sendBt); } } }