Simplify some bits of code

* Don't call getIntent() multiple times
* Drop else after return
* Don't do "if (!cond) foo else bar"
This commit is contained in:
Daniel Martí 2015-10-06 14:49:23 +02:00
parent fd8355e872
commit 7cfc2ea004
2 changed files with 14 additions and 14 deletions

View File

@ -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 * never happen as AppDetails is only to be called by the FDroid activity
* and not externally. * and not externally.
*/ */
private String getAppIdFromIntent() { private String getAppIdFromIntent(Intent intent) {
Intent i = getIntent(); if (!intent.hasExtra(EXTRA_APPID)) {
if (!i.hasExtra(EXTRA_APPID)) {
Log.e(TAG, "No application ID found in the intent!"); Log.e(TAG, "No application ID found in the intent!");
return null; return null;
} }
return i.getStringExtra(EXTRA_APPID); return intent.getStringExtra(EXTRA_APPID);
} }
@Override @Override
@ -384,8 +383,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
// compat implementation is assigned in the ActionBarActivity base class. // compat implementation is assigned in the ActionBarActivity base class.
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
if (getIntent().hasExtra(EXTRA_FROM)) { Intent intent = getIntent();
setTitle(getIntent().getStringExtra(EXTRA_FROM)); if (intent.hasExtra(EXTRA_FROM)) {
setTitle(intent.getStringExtra(EXTRA_FROM));
} }
mPm = getPackageManager(); mPm = getPackageManager();
@ -403,7 +403,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
app = previousData.app; app = previousData.app;
setApp(app); setApp(app);
} else { } else {
if (!reset(getAppIdFromIntent())) { if (!reset(getAppIdFromIntent(intent))) {
finish(); finish();
return; return;
} }

View File

@ -288,10 +288,10 @@ public class FDroidApp extends Application {
private BluetoothAdapter getBluetoothAdapter() { private BluetoothAdapter getBluetoothAdapter() {
// to use the new, recommended way of getting the adapter // to use the new, recommended way of getting the adapter
// http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html // http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html
if (Build.VERSION.SDK_INT < 18) if (Build.VERSION.SDK_INT < 18) {
return BluetoothAdapter.getDefaultAdapter(); 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) { public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
@ -327,13 +327,13 @@ public class FDroidApp extends Application {
found = false; found = false;
} }
if (sendBt != null) { 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.makeText(this, R.string.bluetooth_activity_not_found,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send))); activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
} else {
sendBt.setClassName(bluetoothPackageName, className);
activity.startActivity(sendBt);
} }
} }
} }