Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change switch by if #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions app/src/main/java/org/yaaic/activity/AddAliasActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,25 @@ public void onCreate(Bundle savedInstanceState)
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.add:
String alias = aliasInput.getText().toString().trim();
aliases.add(alias);
adapter.add(alias);
aliasInput.setText("");
okButton.setEnabled(true);
break;

case R.id.cancel:
setResult(RESULT_CANCELED);
finish();
break;

case R.id.ok:
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.ALIASES, aliases);
setResult(RESULT_OK, intent);
finish();
break;

int id = v.getId();
if(id == R.id.add) {
String alias = aliasInput.getText().toString().trim();
aliases.add(alias);
adapter.add(alias);
aliasInput.setText("");
okButton.setEnabled(true);
} else if(id == R.id.cancel) {
setResult(RESULT_CANCELED);
finish();
} else if(id == R.id.ok) {
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.ALIASES, aliases);
setResult(RESULT_OK, intent);
finish();
}

}

/**
Expand Down
39 changes: 17 additions & 22 deletions app/src/main/java/org/yaaic/activity/AddChannelActivity.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,23 @@ public void onCreate(Bundle savedInstanceState)
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.add:
String channel = channelInput.getText().toString().trim();
channels.add(channel);
adapter.add(channel);
channelInput.setText("#");
channelInput.setSelection(1);
okButton.setEnabled(true);
break;

case R.id.cancel:
setResult(RESULT_CANCELED);
finish();
break;

case R.id.ok:
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.CHANNELS, channels);
setResult(RESULT_OK, intent);
finish();
break;
int id = v.getId();
if(id == R.id.add) {
String channel = channelInput.getText().toString().trim();
channels.add(channel);
adapter.add(channel);
channelInput.setText("#");
channelInput.setSelection(1);
okButton.setEnabled(true);
} else if(id == R.id.cancel) {
setResult(RESULT_CANCELED);
finish();
} else if(id == R.id.ok) {
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.CHANNELS, channels);
setResult(RESULT_OK, intent);
finish();
}
}

Expand Down
43 changes: 19 additions & 24 deletions app/src/main/java/org/yaaic/activity/AddCommandsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,27 @@ public void onCreate(Bundle savedInstanceState)
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.add:
String command = commandInput.getText().toString().trim();
int id = v.getId();
if(id == R.id.add) {
String command = commandInput.getText().toString().trim();

if (!command.startsWith("/")) {
command = "/" + command;
}
if (!command.startsWith("/")) {
command = "/" + command;
}

commands.add(command);
adapter.add(command);
commandInput.setText("/");
okButton.setEnabled(true);
break;

case R.id.cancel:
setResult(RESULT_CANCELED);
finish();
break;

case R.id.ok:
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.COMMANDS, commands);
setResult(RESULT_OK, intent);
finish();
break;
commands.add(command);
adapter.add(command);
commandInput.setText("/");
okButton.setEnabled(true);
} else if(id == R.id.cancel) {
setResult(RESULT_CANCELED);
finish();
} else if(id == R.id.ok) {
// Get list and return as result
Intent intent = new Intent();
intent.putExtra(Extra.COMMANDS, commands);
setResult(RESULT_OK, intent);
finish();
}
}

Expand Down
45 changes: 19 additions & 26 deletions app/src/main/java/org/yaaic/activity/AddServerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,32 +198,25 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data)
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.aliases:
Intent aliasIntent = new Intent(this, AddAliasActivity.class);
aliasIntent.putExtra(Extra.ALIASES, aliases);
startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES);
break;

case R.id.authentication:
Intent authIntent = new Intent(this, AuthenticationActivity.class);
authIntent.putExtra(Extra.NICKSERV_PASSWORD, authentication.getNickservPassword());
authIntent.putExtra(Extra.SASL_USER, authentication.getSaslUsername());
authIntent.putExtra(Extra.SASL_PASSWORD, authentication.getSaslPassword());
startActivityForResult(authIntent, REQUEST_CODE_AUTHENTICATION);
break;

case R.id.channels:
Intent channelIntent = new Intent(this, AddChannelActivity.class);
channelIntent.putExtra(Extra.CHANNELS, channels);
startActivityForResult(channelIntent, REQUEST_CODE_CHANNELS);
break;

case R.id.commands:
Intent commandsIntent = new Intent(this, AddCommandsActivity.class);
commandsIntent.putExtra(Extra.COMMANDS, commands);
startActivityForResult(commandsIntent, REQUEST_CODE_COMMANDS);
break;
int id = v.getId();
if(id == R.id.aliases) {
Intent aliasIntent = new Intent(this, AddAliasActivity.class);
aliasIntent.putExtra(Extra.ALIASES, aliases);
startActivityForResult(aliasIntent, REQUEST_CODE_ALIASES);
} else if(id == R.id.authentication) {
Intent authIntent = new Intent(this, AuthenticationActivity.class);
authIntent.putExtra(Extra.NICKSERV_PASSWORD, authentication.getNickservPassword());
authIntent.putExtra(Extra.SASL_USER, authentication.getSaslUsername());
authIntent.putExtra(Extra.SASL_PASSWORD, authentication.getSaslPassword());
startActivityForResult(authIntent, REQUEST_CODE_AUTHENTICATION);
} else if(id == R.id.channels) {
Intent channelIntent = new Intent(this, AddChannelActivity.class);
channelIntent.putExtra(Extra.CHANNELS, channels);
startActivityForResult(channelIntent, REQUEST_CODE_CHANNELS);
} else if(id == R.id.commands) {
Intent commandsIntent = new Intent(this, AddCommandsActivity.class);
commandsIntent.putExtra(Extra.COMMANDS, commands);
startActivityForResult(commandsIntent, REQUEST_CODE_COMMANDS);
}
}

Expand Down
60 changes: 28 additions & 32 deletions app/src/main/java/org/yaaic/activity/AuthenticationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,27 @@ public void onCreate(Bundle savedInstanceState)
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
switch (buttonView.getId()) {
case R.id.nickserv_checkbox:
nickservPasswordLabel.setEnabled(isChecked);
nickservPasswordEditText.setEnabled(isChecked);

if (!isChecked) {
nickservPasswordEditText.setText("");
}
int id = buttonView.getId();
if(id == R.id.nickserv_checkbox) {
nickservPasswordLabel.setEnabled(isChecked);
nickservPasswordEditText.setEnabled(isChecked);

break;
if (!isChecked) {
nickservPasswordEditText.setText("");
}

case R.id.sasl_checkbox:
saslUsernameLabel.setEnabled(isChecked);
saslUsernameEditText.setEnabled(isChecked);
saslPasswordLabel.setEnabled(isChecked);
saslPasswordEditText.setEnabled(isChecked);
} else if(id == R.id.sasl_checkbox) {
saslUsernameLabel.setEnabled(isChecked);
saslUsernameEditText.setEnabled(isChecked);
saslPasswordLabel.setEnabled(isChecked);
saslPasswordEditText.setEnabled(isChecked);

if (!isChecked) {
saslUsernameEditText.setText("");
saslPasswordEditText.setText("");
}
if (!isChecked) {
saslUsernameEditText.setText("");
saslPasswordEditText.setText("");
}

break;
}
}

Expand All @@ -140,20 +138,18 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
@Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.ok:
Intent intent = new Intent();
intent.putExtra(Extra.NICKSERV_PASSWORD, nickservPasswordEditText.getText().toString());
intent.putExtra(Extra.SASL_USER, saslUsernameEditText.getText().toString());
intent.putExtra(Extra.SASL_PASSWORD, saslPasswordEditText.getText().toString());
setResult(RESULT_OK, intent);
finish();
break;

case R.id.cancel:
setResult(RESULT_CANCELED);
finish();
break;
int id = v.getId();
if(id == R.id.ok) {
Intent intent = new Intent();
intent.putExtra(Extra.NICKSERV_PASSWORD, nickservPasswordEditText.getText().toString());
intent.putExtra(Extra.SASL_USER, saslUsernameEditText.getText().toString());
intent.putExtra(Extra.SASL_PASSWORD, saslPasswordEditText.getText().toString());
setResult(RESULT_OK, intent);
finish();

} else if(id == R.id.cancel) {
setResult(RESULT_CANCELED);
finish();
}
}
}
80 changes: 34 additions & 46 deletions app/src/main/java/org/yaaic/fragment/ConversationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,52 +428,40 @@ public void onPrepareOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.disconnect:
server.setStatus(Status.DISCONNECTED);
server.setMayReconnect(false);
binder.getService().getConnection(serverId).quitServer();
server.clearConversations();
break;

case R.id.close:
Conversation conversationToClose = pagerAdapter.getItem(pager.getCurrentItem());
// Make sure we part a channel when closing the channel conversation
if (conversationToClose.getType() == Conversation.TYPE_CHANNEL) {
binder.getService().getConnection(serverId).partChannel(conversationToClose.getName());
}
else if (conversationToClose.getType() == Conversation.TYPE_QUERY) {
server.removeConversation(conversationToClose.getName());
onRemoveConversation(conversationToClose.getName());
} else {
Toast.makeText(getActivity(), getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show();
}
break;

case R.id.join:
startActivityForResult(new Intent(getActivity(), JoinActivity.class), REQUEST_CODE_JOIN);
break;

case R.id.users:
Conversation conversationForUserList = pagerAdapter.getItem(pager.getCurrentItem());
if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) {
Intent intent = new Intent(getActivity(), UsersActivity.class);
intent.putExtra(
Extra.USERS,
binder.getService().getConnection(server.getId()).getUsersAsStringArray(
conversationForUserList.getName()
)
);
startActivityForResult(intent, REQUEST_CODE_USERS);
} else {
Toast.makeText(getActivity(), getResources().getString(R.string.only_usable_from_channel), Toast.LENGTH_SHORT).show();
}
break;

case R.id.notify:
Conversation conversationForNotify = pagerAdapter.getItem(pager.getCurrentItem());
conversationForNotify.setAlwaysNotify(!item.isChecked());
break;
int id = item.getItemId();
if(id == R.id.disconnect) {
server.setStatus(Status.DISCONNECTED);
server.setMayReconnect(false);
binder.getService().getConnection(serverId).quitServer();
server.clearConversations();
} else if(id == R.id.close) {
Conversation conversationToClose = pagerAdapter.getItem(pager.getCurrentItem());
// Make sure we part a channel when closing the channel conversation
if (conversationToClose.getType() == Conversation.TYPE_CHANNEL) {
binder.getService().getConnection(serverId).partChannel(conversationToClose.getName());
}
else if (conversationToClose.getType() == Conversation.TYPE_QUERY) {
server.removeConversation(conversationToClose.getName());
onRemoveConversation(conversationToClose.getName());
} else {
Toast.makeText(getActivity(), getResources().getString(R.string.close_server_window), Toast.LENGTH_SHORT).show();
}
} else if(id == R.id.join) {
startActivityForResult(new Intent(getActivity(), JoinActivity.class), REQUEST_CODE_JOIN);
} else if(id == R.id.users) {
Conversation conversationForUserList = pagerAdapter.getItem(pager.getCurrentItem());
if (conversationForUserList.getType() == Conversation.TYPE_CHANNEL) {
Intent intent = new Intent(getActivity(), UsersActivity.class);
intent.putExtra(
Extra.USERS,
binder.getService().getConnection(server.getId()).getUsersAsStringArray(
conversationForUserList.getName()
)
);
startActivityForResult(intent, REQUEST_CODE_USERS);
} else {
Toast.makeText(getActivity(), getResources().getString(R.string.only_usable_from_channel), Toast.LENGTH_SHORT).show();
}
}

return true;
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/org/yaaic/menu/ServerPopupMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ public void updateServer(Server server) {
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();

switch (id) {
case R.id.edit:
listener.onEditServer(server);
break;
case R.id.delete:
listener.onDeleteServer(server);
break;
case R.id.connect:
listener.onConnectToServer(server);
break;
case R.id.disconnect:
listener.onDisconnectFromServer(server);
break;
if(id == R.id.edit) {
listener.onEditServer(server);
} else if(id == R.id.delete) {
listener.onDeleteServer(server);
} else if(id == R.id.connect) {
listener.onConnectToServer(server);
} else if(id == R.id.disconnect) {
listener.onDisconnectFromServer(server);
}

return true;
Expand Down