From a535d74a85271b230b1da48ea8638c8a46d8aca7 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sat, 18 Sep 2010 10:53:39 +0200 Subject: [PATCH] ServerListActivity: Show "Add server" item if no server in database yet --- res/layout/addserveritem.xml | 45 +++ res/values/strings.xml | 322 ++++++++++--------- src/org/yaaic/activity/ServersActivity.java | 11 + src/org/yaaic/adapter/ServerListAdapter.java | 23 +- 4 files changed, 240 insertions(+), 161 deletions(-) create mode 100644 res/layout/addserveritem.xml diff --git a/res/layout/addserveritem.xml b/res/layout/addserveritem.xml new file mode 100644 index 0000000..4667e66 --- /dev/null +++ b/res/layout/addserveritem.xml @@ -0,0 +1,45 @@ + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 6b83403..5b7f8b1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,176 +1,178 @@ - Add server - Settings - About - Exit + Add server + Add server - About - Settings - Join channel - Users - Channels - Add new server + Settings + About + Exit - Title - Host - Port - Password - Use SSL - Auto connect on startup - Channels - Add server - Select a charset - Nickname - Aliases - Ident - Real Name + About + Settings + Join channel + Users + Channels + Add new server - Server - Channel - Channels - Commands - User - Join - Join Channel - Close - Users - Connect - Disconnect - Edit - Delete - On connect - Preferences - Charset + Title + Host + Port + Password + Use SSL + Auto connect on startup + Channels + Add server + Select a charset + Nickname + Aliases + Ident + Real Name - Remove - Add - Ok - Cancel - No + Server + Channel + Channels + Commands + User + Join + Join Channel + Close + Users + Connect + Disconnect + Edit + Delete + On connect + Preferences + Charset - These aliases will be used if the main nickname is unavailable. - These channels will be automatically joined after connect. - These commands will be executed after connect. + Remove + Add + Ok + Cancel + No - Title cannot be blank - Host cannot be blank - Enter a numeric port - Charset is not supported by your device - There is already a server with this title - Nickname cannot be blank - Ident cannot be blank - Realname cannot be blank - Invalid nickname - Invalid ident + These aliases will be used if the main nickname is unavailable. + These channels will be automatically joined after connect. + These commands will be executed after connect. - Only usable from within a channel - Only usable from within a channel or a query - You can only chat from within a channel or a query - You disconnected from %1$s. Do you want to reconnect? - Disconnect from server before editing - Unknown command: %1$s - Syntax: %1$s - Invalid number of params - You can\'t close the server window - Currently only SEND is allowed - File does not exist: %1$s - Waiting for %1$s to accept the file transfer - Text is missing - Available commands: - or - You cannot open queries to channels - Query already exists - Line is missing + Title cannot be blank + Host cannot be blank + Enter a numeric port + Charset is not supported by your device + There is already a server with this title + Nickname cannot be blank + Ident cannot be blank + Realname cannot be blank + Invalid nickname + Invalid ident - Send a message to all channels - Sets you away - Closes the current window - Send a file to a user - Remove operator status from a user - Remove voice status from a user - Print text to window - Lists all available commands - Join a channel - Kicks a user - Perform an action - Change channel modes - Send a message to a channel or user - Lists all users in channel - Change own nickname - Send a notice to an other user - Give a user operator status - Leave the current channel - Open a private chat with a user - Disconnect from server - Send a raw line to the server - Show or change the current topic - Give a user voice status - Get information about a user + Only usable from within a channel + Only usable from within a channel or a query + You can only chat from within a channel or a query + You disconnected from %1$s. Do you want to reconnect? + Disconnect from server before editing + Unknown command: %1$s + Syntax: %1$s + Invalid number of params + You can\'t close the server window + Currently only SEND is allowed + File does not exist: %1$s + Waiting for %1$s to accept the file transfer + Text is missing + Available commands: + or + You cannot open queries to channels + Query already exists + Line is missing - Connected to %1$s - Disconnected from %1$s + Send a message to all channels + Sets you away + Closes the current window + Send a file to a user + Remove operator status from a user + Remove voice status from a user + Print text to window + Lists all available commands + Join a channel + Kicks a user + Perform an action + Change channel modes + Send a message to a channel or user + Lists all users in channel + Change own nickname + Send a notice to an other user + Give a user operator status + Leave the current channel + Open a private chat with a user + Disconnect from server + Send a raw line to the server + Show or change the current topic + Give a user voice status + Get information about a user - Connected to %1$s - %1$s deops %2$s - %1$s devoices %2$s - %1$s invites you into %2$s - %1$s invites %2$s into %3$s - %1$s joines - %1$s kicks %2$s - %1$s is now known as %2$s - %1$s ops %2$s - %1$s parts - %1$s quits (%2$s) - Topic: %1$s - %1$s sets topic: %2$s - %1$s voices %2$s - %1$s removes channel key - %1$s sets channel key: %2$s - %1$s sets channel secret - %1$s sets channel public - %1$s sets channel private - %1$s sets limit: %2$s - %1$s removes limit - %1$s sets ban: %2$s - %1$s removes ban: %2$s - %1$s sets topic protection - %1$s removes topic protection - %1$s disables external messages - %1$s enables external messages - %1$s sets invite only - %1$s removes invite only - %1$s sets moderated - %1$s removes moderated - Disconnected + Connected to %1$s + Disconnected from %1$s - Op - DeOp - Voice - DeVoice - Kick - Ban + Connected to %1$s + %1$s deops %2$s + %1$s devoices %2$s + %1$s invites you into %2$s + %1$s invites %2$s into %3$s + %1$s joines + %1$s kicks %2$s + %1$s is now known as %2$s + %1$s ops %2$s + %1$s parts + %1$s quits (%2$s) + Topic: %1$s + %1$s sets topic: %2$s + %1$s voices %2$s + %1$s removes channel key + %1$s sets channel key: %2$s + %1$s sets channel secret + %1$s sets channel public + %1$s sets channel private + %1$s sets limit: %2$s + %1$s removes limit + %1$s sets ban: %2$s + %1$s removes ban: %2$s + %1$s sets topic protection + %1$s removes topic protection + %1$s disables external messages + %1$s enables external messages + %1$s sets invite only + %1$s removes invite only + %1$s sets moderated + %1$s removes moderated + Disconnected - Connection - Reconnect - Automatically reconnect on disconnect - Chat + Op + DeOp + Voice + DeVoice + Kick + Ban + + Connection + Reconnect + Automatically reconnect on disconnect + Chat Show icons - Show icons to highlight special events - Show colors - Show colors to highlight special eventsColorize nicknamesShow nicknames in different colors - Show timestamp - Prefix all messages with a timestamp - 24 hour format - Use 24 hour format for timestamps - Misc - Quit message - Message to show when you disconnect - Quit message - Message to show when you disconnect: - Font size - Set the global font size - Font size - Voice recognition - Show button for voice recognition + Show icons to highlight special events + Show colors + Show colors to highlight special eventsColorize nicknamesShow nicknames in different colors + Show timestamp + Prefix all messages with a timestamp + 24 hour format + Use 24 hour format for timestamps + Misc + Quit message + Message to show when you disconnect + Quit message + Message to show when you disconnect: + Font size + Set the global font size + Font size + Voice recognition + Show button for voice recognition diff --git a/src/org/yaaic/activity/ServersActivity.java b/src/org/yaaic/activity/ServersActivity.java index cef4233..2bc217d 100644 --- a/src/org/yaaic/activity/ServersActivity.java +++ b/src/org/yaaic/activity/ServersActivity.java @@ -139,6 +139,12 @@ public class ServersActivity extends ListActivity implements ServiceConnection, protected void onListItemClick(ListView l, View v, int position, long id) { Server server = adapter.getItem(position); + if (server == null) { + // "Add server" was selected + startActivityForResult(new Intent(this, AddServerActivity.class), 0); + return; + } + Intent intent = new Intent(this, ConversationActivity.class); if (server.getStatus() == Status.DISCONNECTED) { @@ -157,6 +163,11 @@ public class ServersActivity extends ListActivity implements ServiceConnection, { final Server server = adapter.getItem(position); + if (server == null) { + // "Add server" view selected + return true; + } + final CharSequence[] items = { getString(R.string.connect), getString(R.string.disconnect), diff --git a/src/org/yaaic/adapter/ServerListAdapter.java b/src/org/yaaic/adapter/ServerListAdapter.java index a986436..f6a54b2 100644 --- a/src/org/yaaic/adapter/ServerListAdapter.java +++ b/src/org/yaaic/adapter/ServerListAdapter.java @@ -62,7 +62,14 @@ public class ServerListAdapter extends BaseAdapter */ public int getCount() { - return servers.size(); + int size = servers.size(); + + // Display "Add server" item + if (size == 0) { + return 1; + } + + return size; } /** @@ -72,6 +79,10 @@ public class ServerListAdapter extends BaseAdapter */ public Server getItem(int position) { + if (servers.size() == 0) { + return null; // No server object for the "add server" view + } + return servers.get(position); } @@ -82,6 +93,10 @@ public class ServerListAdapter extends BaseAdapter */ public long getItemId(int position) { + if (servers.size() == 0) { + return 0; + } + return getItem(position).getId(); } @@ -97,6 +112,12 @@ public class ServerListAdapter extends BaseAdapter Server server = getItem(position); LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + if (server == null) { + // Return "Add server" view + return inflater.inflate(R.layout.addserveritem, null); + } + View v = inflater.inflate(R.layout.serveritem, null); ((TextView) v.findViewById(R.id.title)).setText(server.getTitle());