mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-01-09 20:58:02 -05:00
ServerListActivity: Show "Add server" item if no server in database yet
This commit is contained in:
parent
8775d93020
commit
a535d74a85
45
res/layout/addserveritem.xml
Normal file
45
res/layout/addserveritem.xml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Yaaic - Yet Another Android IRC Client
|
||||||
|
|
||||||
|
Copyright 2009-2010 Sebastian Kaspari
|
||||||
|
|
||||||
|
This file is part of Yaaic.
|
||||||
|
|
||||||
|
Yaaic is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Yaaic is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="5px">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@android:drawable/ic_menu_add"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:paddingRight="5px" />
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/add_server_list"
|
||||||
|
android:textSize="14px" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="add_server_menu">Add server</string>
|
<string name="add_server_menu">Add server</string>
|
||||||
|
<string name="add_server_list">Add server</string>
|
||||||
|
|
||||||
<string name="settings_menu">Settings</string>
|
<string name="settings_menu">Settings</string>
|
||||||
<string name="about_menu">About</string>
|
<string name="about_menu">About</string>
|
||||||
<string name="exit_menu">Exit</string>
|
<string name="exit_menu">Exit</string>
|
||||||
|
@ -139,6 +139,12 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
|||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
Server server = adapter.getItem(position);
|
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);
|
Intent intent = new Intent(this, ConversationActivity.class);
|
||||||
|
|
||||||
if (server.getStatus() == Status.DISCONNECTED) {
|
if (server.getStatus() == Status.DISCONNECTED) {
|
||||||
@ -157,6 +163,11 @@ public class ServersActivity extends ListActivity implements ServiceConnection,
|
|||||||
{
|
{
|
||||||
final Server server = adapter.getItem(position);
|
final Server server = adapter.getItem(position);
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
// "Add server" view selected
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
final CharSequence[] items = {
|
final CharSequence[] items = {
|
||||||
getString(R.string.connect),
|
getString(R.string.connect),
|
||||||
getString(R.string.disconnect),
|
getString(R.string.disconnect),
|
||||||
|
@ -62,7 +62,14 @@ public class ServerListAdapter extends BaseAdapter
|
|||||||
*/
|
*/
|
||||||
public int getCount()
|
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)
|
public Server getItem(int position)
|
||||||
{
|
{
|
||||||
|
if (servers.size() == 0) {
|
||||||
|
return null; // No server object for the "add server" view
|
||||||
|
}
|
||||||
|
|
||||||
return servers.get(position);
|
return servers.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +93,10 @@ public class ServerListAdapter extends BaseAdapter
|
|||||||
*/
|
*/
|
||||||
public long getItemId(int position)
|
public long getItemId(int position)
|
||||||
{
|
{
|
||||||
|
if (servers.size() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return getItem(position).getId();
|
return getItem(position).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +112,12 @@ public class ServerListAdapter extends BaseAdapter
|
|||||||
Server server = getItem(position);
|
Server server = getItem(position);
|
||||||
|
|
||||||
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
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);
|
View v = inflater.inflate(R.layout.serveritem, null);
|
||||||
|
|
||||||
((TextView) v.findViewById(R.id.title)).setText(server.getTitle());
|
((TextView) v.findViewById(R.id.title)).setText(server.getTitle());
|
||||||
|
Loading…
Reference in New Issue
Block a user