Permalink
Browse files

Step 3: Replace switch statements with if statements

Buck always uses non-constant resource ids when compiling, so we can't
use switch statements with them.  I just used IntelliJ's intention to
convert all of these to if statements (and renamed the switch
variables), and it reformatted some of the code a bit.
  • Loading branch information...
dreiss committed Jul 8, 2014
1 parent 6c80927 commit 5f7ce4934e9e8ea9a391a09d2093c79b64b7d207
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.activity;
import android.app.Activity;
@@ -290,18 +291,18 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.new_folder_item:
} else if (itemId == R.id.new_folder_item) {
openNewFolderDialog();
return true;
case R.id.set_to_default_folder_item:
} else if (itemId == R.id.set_to_default_folder_item) {
selectedDir = null;
returnSelectedFolder();
return true;
default:
} else {
return false;
}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.activity;
import android.content.Intent;
@@ -298,12 +299,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToogle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.show_preferences:
startActivity(new Intent(this, PreferenceActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
int itemId = item.getItemId();
if (itemId == R.id.show_preferences) {
startActivity(new Intent(this, PreferenceActivity.class));
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.activity;
import android.app.AlertDialog;
@@ -277,74 +278,79 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(intent);
return true;
} else if (media != null) {
switch (item.getItemId()) {
case R.id.disable_sleeptimer_item:
if (controller.serviceAvailable()) {
AlertDialog.Builder stDialog = new AlertDialog.Builder(this);
stDialog.setTitle(R.string.sleep_timer_label);
stDialog.setMessage(getString(R.string.time_left_label)
+ Converter.getDurationStringLong((int) controller
.getSleepTimerTimeLeft()));
stDialog.setPositiveButton(
R.string.disable_sleeptimer_label,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
controller.disableSleepTimer();
}
int itemId = item.getItemId();
if (itemId == R.id.disable_sleeptimer_item) {
if (controller.serviceAvailable()) {
AlertDialog.Builder stDialog = new AlertDialog.Builder(this);
stDialog.setTitle(R.string.sleep_timer_label);
stDialog.setMessage(
getString(R.string.time_left_label)
+ Converter.getDurationStringLong(
(int) controller
.getSleepTimerTimeLeft()));
stDialog.setPositiveButton(
R.string.disable_sleeptimer_label,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
controller.disableSleepTimer();
}
);
stDialog.setNegativeButton(R.string.cancel_label,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
}
);
stDialog.setNegativeButton(
R.string.cancel_label,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
}
);
stDialog.create().show();
}
break;
case R.id.set_sleeptimer_item:
if (controller.serviceAvailable()) {
TimeDialog td = new TimeDialog(this,
R.string.set_sleeptimer_label,
R.string.set_sleeptimer_label) {
@Override
public void onTimeEntered(long millis) {
controller.setSleepTimer(millis);
}
};
td.show();
break;
);
stDialog.create().show();
}
}
case R.id.visit_website_item:
Uri uri = Uri.parse(media.getWebsiteLink());
startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
if (media instanceof FeedMedia) {
FeedItem feedItem = ((FeedMedia) media).getItem();
DBTasks.flattrItemIfLoggedIn(this, feedItem);
}
break;
case R.id.share_link_item:
ShareUtils.shareLink(this, media.getWebsiteLink());
break;
case R.id.skip_episode_item:
sendBroadcast(new Intent(
PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
break;
default:
return false;
} else if (itemId == R.id.set_sleeptimer_item) {
if (controller.serviceAvailable()) {
TimeDialog td = new TimeDialog(
this,
R.string.set_sleeptimer_label,
R.string.set_sleeptimer_label) {
@Override
public void onTimeEntered(long millis) {
controller.setSleepTimer(millis);
}
};
td.show();
}
} else if (itemId == R.id.visit_website_item) {
Uri uri = Uri.parse(media.getWebsiteLink());
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else if (itemId == R.id.support_item) {
if (media instanceof FeedMedia) {
FeedItem feedItem = ((FeedMedia) media).getItem();
DBTasks.flattrItemIfLoggedIn(this, feedItem);
}
} else if (itemId == R.id.share_link_item) {
ShareUtils.shareLink(this, media.getWebsiteLink());
} else if (itemId == R.id.skip_episode_item) {
sendBroadcast(
new Intent(
PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
} else {
return false;
}
return true;
} else {
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.activity;
import android.content.Intent;
@@ -113,15 +114,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.select_all_item:
selectAllItems(true);
return true;
case R.id.deselect_all_item:
selectAllItems(false);
return true;
default:
return false;
int itemId = item.getItemId();
if (itemId == R.id.select_all_item) {
selectAllItems(true);
return true;
} else if (itemId == R.id.deselect_all_item) {
selectAllItems(false);
return true;
} else {
return false;
}
}
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.fragment;
import android.annotation.SuppressLint;
@@ -270,34 +271,35 @@ public boolean onLongClick(View v) {
public boolean onContextItemSelected(MenuItem item) {
boolean handled = selectedURL != null;
if (selectedURL != null) {
switch (item.getItemId()) {
case R.id.open_in_browser_item:
Uri uri = Uri.parse(selectedURL);
getActivity()
.startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.share_url_item:
ShareUtils.shareLink(getActivity(), selectedURL);
break;
case R.id.copy_url_item:
if (android.os.Build.VERSION.SDK_INT >= 11) {
ClipData clipData = ClipData.newPlainText(selectedURL,
selectedURL);
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
} else {
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(selectedURL);
}
Toast t = Toast.makeText(getActivity(),
R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();
break;
default:
handled = false;
break;
int itemId = item.getItemId();
if (itemId == R.id.open_in_browser_item) {
Uri uri = Uri.parse(selectedURL);
getActivity()
.startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else if (itemId == R.id.share_url_item) {
ShareUtils.shareLink(getActivity(), selectedURL);
} else if (itemId == R.id.copy_url_item) {
if (Build.VERSION.SDK_INT >= 11) {
ClipData clipData = ClipData.newPlainText(
selectedURL,
selectedURL);
ClipboardManager cm = (ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
} else {
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(selectedURL);
}
Toast t = Toast.makeText(
getActivity(),
R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();
} else {
handled = false;
}
selectedURL = null;
@@ -1,3 +1,4 @@
// The files and modifications provided by Facebook are for testing and evaluation purposes only. Facebook reserves all rights not expressly granted.
package de.danoeh.antennapod.fragment;
import android.annotation.SuppressLint;
@@ -187,32 +188,34 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (!super.onOptionsItemSelected(item)) {
try {
if (!FeedMenuHandler.onOptionsItemClicked(getActivity(), item, feed)) {
switch (item.getItemId()) {
case R.id.remove_item:
final FeedRemover remover = new FeedRemover(
getActivity(), feed) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
((MainActivity) getActivity()).loadNavFragment(MainActivity.POS_NEW, null);
}
};
ConfirmationDialog conDialog = new ConfirmationDialog(getActivity(),
R.string.remove_feed_label,
R.string.feed_delete_confirmation_msg) {
@Override
public void onConfirmButtonPressed(
DialogInterface dialog) {
dialog.dismiss();
remover.executeAsync();
}
};
conDialog.createNewDialog().show();
return true;
default:
return false;
int itemId = item.getItemId();
if (itemId == R.id.remove_item) {
final FeedRemover remover = new FeedRemover(
getActivity(), feed) {
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
((MainActivity) getActivity()).loadNavFragment(
MainActivity.POS_NEW,
null);
}
};
ConfirmationDialog conDialog = new ConfirmationDialog(
getActivity(),
R.string.remove_feed_label,
R.string.feed_delete_confirmation_msg) {
@Override
public void onConfirmButtonPressed(
DialogInterface dialog) {
dialog.dismiss();
remover.executeAsync();
}
};
conDialog.createNewDialog().show();
return true;
} else {
return false;
}
} else {
return true;
Oops, something went wrong.

0 comments on commit 5f7ce49

Please sign in to comment.