diff --git a/app/src/main/java/org/yaaic/activity/AddAliasActivity.java b/app/src/main/java/org/yaaic/activity/AddAliasActivity.java index 53bc5f74..ff44b088 100644 --- a/app/src/main/java/org/yaaic/activity/AddAliasActivity.java +++ b/app/src/main/java/org/yaaic/activity/AddAliasActivity.java @@ -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(); } + } /** diff --git a/app/src/main/java/org/yaaic/activity/AddChannelActivity.java b/app/src/main/java/org/yaaic/activity/AddChannelActivity.java old mode 100644 new mode 100755 index 47685fb7..f10de409 --- a/app/src/main/java/org/yaaic/activity/AddChannelActivity.java +++ b/app/src/main/java/org/yaaic/activity/AddChannelActivity.java @@ -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(); } } diff --git a/app/src/main/java/org/yaaic/activity/AddCommandsActivity.java b/app/src/main/java/org/yaaic/activity/AddCommandsActivity.java index 079453fe..bf964698 100644 --- a/app/src/main/java/org/yaaic/activity/AddCommandsActivity.java +++ b/app/src/main/java/org/yaaic/activity/AddCommandsActivity.java @@ -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(); } } diff --git a/app/src/main/java/org/yaaic/activity/AddServerActivity.java b/app/src/main/java/org/yaaic/activity/AddServerActivity.java index c4cb1896..40a52643 100644 --- a/app/src/main/java/org/yaaic/activity/AddServerActivity.java +++ b/app/src/main/java/org/yaaic/activity/AddServerActivity.java @@ -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); } } diff --git a/app/src/main/java/org/yaaic/activity/AuthenticationActivity.java b/app/src/main/java/org/yaaic/activity/AuthenticationActivity.java index 962562f1..4327c5f2 100644 --- a/app/src/main/java/org/yaaic/activity/AuthenticationActivity.java +++ b/app/src/main/java/org/yaaic/activity/AuthenticationActivity.java @@ -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; } } @@ -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(); } } } diff --git a/app/src/main/java/org/yaaic/fragment/ConversationFragment.java b/app/src/main/java/org/yaaic/fragment/ConversationFragment.java index 2388fa9f..72e73971 100644 --- a/app/src/main/java/org/yaaic/fragment/ConversationFragment.java +++ b/app/src/main/java/org/yaaic/fragment/ConversationFragment.java @@ -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; diff --git a/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java b/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java index 4f72819e..63d13ff9 100644 --- a/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java +++ b/app/src/main/java/org/yaaic/menu/ServerPopupMenu.java @@ -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;