aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout-land/item_host.xml35
-rw-r--r--res/layout-port/item_host.xml18
-rw-r--r--res/values/arrays.xml1
-rw-r--r--res/values/strings.xml4
-rw-r--r--src/org/connectbot/HostList.java67
-rw-r--r--src/org/connectbot/R.java57
-rw-r--r--src/org/connectbot/service/TerminalBridge.java1
-rw-r--r--src/org/connectbot/service/TerminalManager.java15
-rw-r--r--src/org/connectbot/util/HostAdapter.java8
-rw-r--r--src/org/connectbot/util/HostBinder.java105
-rw-r--r--src/org/connectbot/util/HostDatabase.java31
11 files changed, 249 insertions, 93 deletions
diff --git a/res/layout-land/item_host.xml b/res/layout-land/item_host.xml
index 34abd59..426b18c 100644
--- a/res/layout-land/item_host.xml
+++ b/res/layout-land/item_host.xml
@@ -1,56 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:padding="10dip"
+ android:padding="10dip"
>
<ImageView
- android:id="@+id/host_connected"
- android:src="@android:drawable/presence_online"
+ android:id="@android:id/icon"
+ android:src="@drawable/connected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dip"
/>
- <!--
-
- <TextView android:id="@+id/host_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceLarge"
- />
-
- <TextView android:id="@+id/host_caption"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_below="@id/host_title"
- />
-
- -->
-
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
- <TextView android:id="@+id/host_title"
+ <TextView
+ android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
- android:textColor="@color/blue"
/>
- <TextView android:id="@+id/host_caption"
+ <TextView
+ android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="@color/blue"
/>
diff --git a/res/layout-port/item_host.xml b/res/layout-port/item_host.xml
index 7fa381e..e5db460 100644
--- a/res/layout-port/item_host.xml
+++ b/res/layout-port/item_host.xml
@@ -1,33 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
>
<ImageView
- android:id="@+id/host_connected"
- android:src="@android:drawable/presence_online"
+ android:id="@android:id/icon"
+ android:src="@drawable/connected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dip"
/>
- <TextView android:id="@+id/host_title"
+ <TextView
+ android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
- android:textColor="@color/blue"
/>
- <TextView android:id="@+id/host_caption"
+ <TextView
+ android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="@color/blue"
- android:layout_below="@id/host_title"
+ android:layout_below="@android:id/text1"
/>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index f4ef7c3..020a1ab 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -12,6 +12,7 @@
<item>red</item>
<item>green</item>
<item>blue</item>
+ <item>gray</item>
</string-array>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d4056aa..eb8cdff 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -32,6 +32,8 @@
<string name="msg_copyright">Copyright &#169; 2007-2008 Kenny Root http://the-b.org/, Jeffrey Sharkey http://jsharkey.org/</string>
<string name="msg_version">v1.0</string>
-
+ <string name="bind_minutes">%s minutes ago</string>
+ <string name="bind_hours">%s hours ago</string>
+ <string name="bind_days">%s days ago</string>
</resources>
diff --git a/src/org/connectbot/HostList.java b/src/org/connectbot/HostList.java
index 446346a..90d8d32 100644
--- a/src/org/connectbot/HostList.java
+++ b/src/org/connectbot/HostList.java
@@ -9,6 +9,7 @@ import java.util.regex.Pattern;
import org.connectbot.service.TerminalBridge;
import org.connectbot.service.TerminalManager;
import org.connectbot.util.HostAdapter;
+import org.connectbot.util.HostBinder;
import org.connectbot.util.HostDatabase;
import org.theb.ssh.InteractiveHostKeyVerifier;
@@ -37,6 +38,7 @@ import android.view.View.OnKeyListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
+import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
@@ -48,12 +50,13 @@ public class HostList extends Activity {
public void onServiceConnected(ComponentName className, IBinder service) {
bound = ((TerminalManager.TerminalBinder) service).getService();
- // TODO: update our green bulb icons by checking for existing bridges
-
+ // update our listview binder to find the service
+ HostList.this.updateCursor();
}
public void onServiceDisconnected(ComponentName className) {
bound = null;
+ HostList.this.updateCursor();
}
};
@@ -84,7 +87,7 @@ public class HostList extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- setContentView(R.layout.act_frontpage);
+ setContentView(R.layout.act_hostlist);
// connect with hosts database and populate list
this.hostdb = new HostDatabase(this);
@@ -126,14 +129,33 @@ public class HostList extends Activity {
text.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
+
+ if(keyCode == KeyEvent.KEYCODE_ENTER) {
+
+ // make sure we follow pattern
+ if (text.getText().length() < 3)
+ return false;
+
+ // show error if poorly formed
+ if (!hostmask.matcher(text.getText().toString()).find()) {
+ text.setError("Use the format 'username@hostname:port'");
+ return false;
+ }
+
+ // create new host for entered string and then launch
+ Uri uri = Uri.parse(String.format("ssh://%s", text.getText().toString()));
+ String username = uri.getUserInfo();
+ String hostname = uri.getHost();
+ int port = uri.getPort();
+ if(port == -1) port = 22;
+
+ String nickname = String.format("%s@%s", username, hostname);
+ hostdb.createHost(null, nickname, username, hostname, port, hostdb.COLOR_GRAY);
+
+ Intent intent = new Intent(HostList.this, Console.class);
+ intent.setData(Uri.parse(String.format("ssh://%s@%s:%s/#%s", username, hostname, port, nickname)));
+ HostList.this.startActivity(intent);
- // make sure we follow pattern
- if (text.getText().length() < 1)
- return false;
-
- // TODO: only show error when trying to hit enter
- if (!hostmask.matcher(text.getText().toString()).find()) {
- text.setError("Use the format 'username@hostname:port'");
}
// set list filter based on text
@@ -158,7 +180,13 @@ public class HostList extends Activity {
if(this.hosts != null)
this.hosts.close();
this.hosts = this.hostdb.allHosts(sortedByColor);
- this.adapter = new HostAdapter(this, this.hosts);
+
+ SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_host, this.hosts,
+ new String[] { hostdb.FIELD_HOST_NICKNAME, hostdb.FIELD_HOST_LASTCONNECT, hostdb.FIELD_HOST_LASTCONNECT, hostdb.FIELD_HOST_COLOR },
+ new int[] { android.R.id.text1, android.R.id.text2, android.R.id.icon, android.R.id.content });
+ adapter.setViewBinder(new HostBinder(bound, this.getResources()));
+
+ //this.adapter = new HostAdapter(this, this.hosts);
this.list.setAdapter(adapter);
}
@@ -180,13 +208,13 @@ public class HostList extends Activity {
// add host, ssh keys, about
- MenuItem add = menu.add(0, 0, Menu.NONE, "New host");
- add.setIcon(android.R.drawable.ic_menu_add);
- add.setOnMenuItemClickListener(new OnMenuItemClickListener() {
- public boolean onMenuItemClick(MenuItem item) {
- return true;
- }
- });
+// MenuItem add = menu.add(0, 0, Menu.NONE, "New host");
+// add.setIcon(android.R.drawable.ic_menu_add);
+// add.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+// public boolean onMenuItemClick(MenuItem item) {
+// return true;
+// }
+// });
sortcolor = menu.add(0, 0, Menu.NONE, "Sort by color");
sortcolor.setIcon(android.R.drawable.ic_menu_share);
@@ -198,7 +226,7 @@ public class HostList extends Activity {
}
});
- sortlast = menu.add(0, 0, Menu.NONE, "Sort by last");
+ sortlast = menu.add(0, 0, Menu.NONE, "Sort by name");
sortlast.setIcon(android.R.drawable.ic_menu_share);
sortlast.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
@@ -210,6 +238,7 @@ public class HostList extends Activity {
MenuItem keys = menu.add(0, 0, Menu.NONE, "Manage keys");
keys.setIcon(android.R.drawable.ic_lock_lock);
+ keys.setEnabled(false);
MenuItem settings = menu.add(0, 0, Menu.NONE, "Settings");
settings.setIcon(android.R.drawable.ic_menu_preferences);
diff --git a/src/org/connectbot/R.java b/src/org/connectbot/R.java
index 027ba6c..d326023 100644
--- a/src/org/connectbot/R.java
+++ b/src/org/connectbot/R.java
@@ -28,43 +28,41 @@ public final class R {
public static final int red=0x7f080002;
}
public static final class drawable {
- public static final int blue=0x7f020002;
- public static final int even_stripe=0x7f020003;
- public static final int highlight_disabled_pressed=0x7f020000;
- public static final int icon=0x7f020001;
- public static final int odd_stripe=0x7f020004;
+ public static final int blue=0x7f020003;
+ public static final int connected=0x7f020000;
+ public static final int even_stripe=0x7f020004;
+ public static final int highlight_disabled_pressed=0x7f020001;
+ public static final int icon=0x7f020002;
+ public static final int odd_stripe=0x7f020005;
}
public static final class id {
public static final int add=0x7f090011;
public static final int cancel=0x7f090012;
public static final int console_flip=0x7f090002;
public static final int copyright=0x7f090001;
- public static final int dismiss=0x7f090019;
- public static final int edit_emulation=0x7f090009;
- public static final int edit_hostname=0x7f090007;
- public static final int edit_nickname=0x7f090005;
- public static final int edit_port=0x7f090008;
- public static final int edit_scrollback=0x7f09000a;
- public static final int edit_username=0x7f090006;
- public static final int front_hostlist=0x7f090003;
- public static final int front_quickconnect=0x7f090004;
- public static final int generate=0x7f09001d;
- public static final int host_caption=0x7f090015;
- public static final int host_connected=0x7f090013;
- public static final int host_title=0x7f090014;
+ public static final int dismiss=0x7f090016;
+ public static final int edit_emulation=0x7f090007;
+ public static final int edit_hostname=0x7f090005;
+ public static final int edit_nickname=0x7f090003;
+ public static final int edit_port=0x7f090006;
+ public static final int edit_scrollback=0x7f090008;
+ public static final int edit_username=0x7f090004;
+ public static final int front_hostlist=0x7f090009;
+ public static final int front_quickconnect=0x7f09000a;
+ public static final int generate=0x7f09001a;
public static final int hostname=0x7f09000e;
public static final int hostnameLabel=0x7f09000d;
public static final int icon=0x7f090000;
- public static final int keyName=0x7f09001e;
- public static final int message=0x7f090018;
- public static final int ok=0x7f09001c;
- public static final int password=0x7f09001b;
- public static final int passwordLabel=0x7f09001a;
+ public static final int keyName=0x7f09001b;
+ public static final int message=0x7f090015;
+ public static final int ok=0x7f090019;
+ public static final int password=0x7f090018;
+ public static final int passwordLabel=0x7f090017;
public static final int port=0x7f090010;
public static final int portLabel=0x7f09000f;
- public static final int shell=0x7f090017;
- public static final int terminal=0x7f09001f;
- public static final int terminal_overlay=0x7f090016;
+ public static final int shell=0x7f090014;
+ public static final int terminal=0x7f09001c;
+ public static final int terminal_overlay=0x7f090013;
public static final int username=0x7f09000c;
public static final int usernameLabel=0x7f09000b;
}
@@ -72,8 +70,8 @@ public final class R {
public static final int about_dialog=0x7f030000;
public static final int act_about=0x7f030001;
public static final int act_console=0x7f030002;
- public static final int act_frontpage=0x7f030003;
- public static final int act_hosteditor=0x7f030004;
+ public static final int act_hosteditor=0x7f030003;
+ public static final int act_hostlist=0x7f030004;
public static final int host_editor=0x7f030005;
public static final int item_host=0x7f030006;
public static final int item_terminal=0x7f030007;
@@ -86,6 +84,9 @@ public final class R {
public static final class string {
public static final int alert_disconnect_msg=0x7f070014;
public static final int app_name=0x7f070000;
+ public static final int bind_days=0x7f070019;
+ public static final int bind_hours=0x7f070018;
+ public static final int bind_minutes=0x7f070017;
public static final int button_add=0x7f070010;
public static final int button_cancel=0x7f070011;
public static final int button_change=0x7f070012;
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index cadaf58..79510b1 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -180,6 +180,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener {
// try authenticating with given password
Log.d(this.getClass().toString(), String.format("tryPassword(password=%s) and username=%s", password, username));
if(this.connection.authenticateWithPassword(this.username, password)) {
+ this.buffer.deleteArea(0, 0, this.buffer.getColumns(), this.buffer.getRows());
finishConnection();
return;
}
diff --git a/src/org/connectbot/service/TerminalManager.java b/src/org/connectbot/service/TerminalManager.java
index 0f4da75..02a9d5f 100644
--- a/src/org/connectbot/service/TerminalManager.java
+++ b/src/org/connectbot/service/TerminalManager.java
@@ -3,6 +3,7 @@ package org.connectbot.service;
import java.util.LinkedList;
import java.util.List;
+import org.connectbot.util.HostDatabase;
import org.theb.ssh.InteractiveHostKeyVerifier;
import com.trilead.ssh2.Connection;
@@ -58,6 +59,10 @@ public class TerminalManager extends Service {
public void openConnection(String nickname, String hostname, String username, int port) throws Exception {
TerminalBridge bridge = new TerminalBridge(nickname, username, hostname, port);
this.bridges.add(bridge);
+
+ // also update database with new time
+ this.touchHost(nickname);
+
}
public void openConnection(Uri uri) throws Exception {
@@ -68,6 +73,16 @@ public class TerminalManager extends Service {
TerminalBridge bridge = new TerminalBridge(nickname, username, hostname, port);
this.bridges.add(bridge);
+
+ // also update database with new time
+ this.touchHost(nickname);
+ }
+
+ protected void touchHost(String nickname) {
+ // also update database with new time
+ HostDatabase hostdb = new HostDatabase(this);
+ hostdb.touchHost(nickname);
+ hostdb.close();
}
public TerminalBridge findBridge(String nickname) {
diff --git a/src/org/connectbot/util/HostAdapter.java b/src/org/connectbot/util/HostAdapter.java
index 3dec83c..b596ace 100644
--- a/src/org/connectbot/util/HostAdapter.java
+++ b/src/org/connectbot/util/HostAdapter.java
@@ -105,20 +105,22 @@ public class HostAdapter extends BaseAdapter {
boolean connected = true;
- TextView title = (TextView)convertView.findViewById(R.id.host_title);
+ TextView title = (TextView)convertView.findViewById(android.R.id.text1);
title.setText(source.getString(COL_NICKNAME));
- TextView caption = (TextView)convertView.findViewById(R.id.host_caption);
+ TextView caption = (TextView)convertView.findViewById(android.R.id.text2);
caption.setText(String.format("%s%s", nice, connected ? ", connected" : ""));
// correctly update text color as needed
+ title.setTextAppearance(context, android.R.attr.textAppearanceLarge);
+ caption.setTextAppearance(context, android.R.attr.textAppearanceSmall);
ColorStateList resolved = this.resolve(source.getString(COL_COLOR));
if(resolved != null) {
title.setTextColor(resolved);
caption.setTextColor(resolved);
}
- ((ImageView)convertView.findViewById(R.id.host_connected)).setImageResource(connected ? android.R.drawable.presence_online : android.R.drawable.presence_offline);
+ ((ImageView)convertView.findViewById(android.R.id.icon)).setImageResource(connected ? android.R.drawable.presence_online : android.R.drawable.presence_offline);
// update icon correctly if service is connected
diff --git a/src/org/connectbot/util/HostBinder.java b/src/org/connectbot/util/HostBinder.java
new file mode 100644
index 0000000..a995931
--- /dev/null
+++ b/src/org/connectbot/util/HostBinder.java
@@ -0,0 +1,105 @@
+package org.connectbot.util;
+
+import org.connectbot.R;
+import org.connectbot.service.TerminalBridge;
+import org.connectbot.service.TerminalManager;
+
+import android.content.res.ColorStateList;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Paint;
+import android.util.Log;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.SimpleCursorAdapter.ViewBinder;
+
+public class HostBinder implements ViewBinder {
+
+ protected final TerminalManager manager;
+ protected final ColorStateList red, green, blue;
+ protected int COL_NICKNAME = -1;
+
+ public HostBinder(TerminalManager manager, Resources res) {
+ this.manager = manager;
+ this.red = res.getColorStateList(R.color.red);
+ this.green = res.getColorStateList(R.color.green);
+ this.blue = res.getColorStateList(R.color.blue);
+ }
+
+ public boolean isConnected(Cursor cursor) {
+ // always disconnected if we dont have backend service
+ if(this.manager == null) return false;
+
+ // otherwise pull out nickname and check if active
+ if(COL_NICKNAME == -1)
+ COL_NICKNAME = cursor.getColumnIndexOrThrow(HostDatabase.FIELD_HOST_NICKNAME);
+
+ String nickname = cursor.getString(COL_NICKNAME);
+ return (this.manager.findBridge(nickname) != null);
+
+ }
+
+ public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
+
+ switch(view.getId()) {
+ case android.R.id.icon:
+ // set icon state based on status from backend service
+ ImageView icon = (ImageView)view;
+ if(this.isConnected(cursor)) {
+ icon.setImageState(new int[] { android.R.attr.state_checked }, true);
+ } else {
+ icon.setImageState(new int[] { }, true);
+ }
+ return true;
+
+ case android.R.id.content:
+ // set background color correctly
+ String color = cursor.getString(columnIndex);
+ TextView text1 = (TextView)view.findViewById(android.R.id.text1),
+ text2 = (TextView)view.findViewById(android.R.id.text2);
+
+ ColorStateList chosen = null;
+ if(HostDatabase.COLOR_RED.equals(color)) chosen = this.red;
+ if(HostDatabase.COLOR_GREEN.equals(color)) chosen = this.green;
+ if(HostDatabase.COLOR_BLUE.equals(color)) chosen = this.blue;
+
+ if(chosen != null) {
+ text1.setTextColor(chosen);
+ text2.setTextColor(chosen);
+ } else {
+ text1.setTextAppearance(view.getContext(), android.R.attr.textAppearanceLarge);
+ text2.setTextAppearance(view.getContext(), android.R.attr.textAppearanceSmall);
+ }
+ return true;
+
+ case android.R.id.text2:
+ // correctly set last-connected time and status
+ long created = cursor.getLong(columnIndex);
+ long now = System.currentTimeMillis() / 1000;
+
+ String nice = "never";
+ if(created > 0) {
+ int minutes = (int)((now - created) / 60);
+ nice = view.getContext().getString(R.string.bind_minutes, minutes);
+ if(minutes >= 60) {
+ int hours = (minutes / 60);
+ nice = view.getContext().getString(R.string.bind_hours, hours);
+ if(hours >= 24) {
+ int days = (hours / 24);
+ nice = view.getContext().getString(R.string.bind_days, days);
+ }
+ }
+ }
+
+ ((TextView)view).setText(nice);
+ return true;
+ }
+
+ // otherwise fall through to other binding methods
+ return false;
+
+ }
+
+
+}
diff --git a/src/org/connectbot/util/HostDatabase.java b/src/org/connectbot/util/HostDatabase.java
index 586246b..391959f 100644
--- a/src/org/connectbot/util/HostDatabase.java
+++ b/src/org/connectbot/util/HostDatabase.java
@@ -8,12 +8,13 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
public class HostDatabase extends SQLiteOpenHelper {
public final static String DB_NAME = "hosts";
- public final static int DB_VERSION = 5;
+ public final static int DB_VERSION = 8;
public final static String TABLE_HOSTS = "hosts";
public final static String FIELD_HOST_NICKNAME = "nickname";
@@ -32,6 +33,7 @@ public class HostDatabase extends SQLiteOpenHelper {
public final static String COLOR_RED = "red";
public final static String COLOR_GREEN = "green";
public final static String COLOR_BLUE = "blue";
+ public final static String COLOR_GRAY = "gray";
public HostDatabase(Context context) {
super(context, DB_NAME, null, DB_VERSION);
@@ -55,10 +57,10 @@ public class HostDatabase extends SQLiteOpenHelper {
+ FIELD_KEY_NAME + " TEXT, "
+ FIELD_KEY_PRIVATE + " TEXT)");
- this.createHost(db, "connectbot@bravo", "connectbot", "192.168.254.230", 22, COLOR_RED);
- this.createHost(db, "root@google.com", "root", "google.com", 22, COLOR_GREEN);
+ this.createHost(db, "connectbot@bravo", "connectbot", "192.168.254.230", 22, null);
+ this.createHost(db, "root@google.com", "root", "google.com", 22, null);
this.createHost(db, "cron@server.example.com", "cron", "server.example.com", 22, COLOR_BLUE);
- this.createHost(db, "backup@example.net", "backup", "example.net", 22, COLOR_RED);
+ this.createHost(db, "backup@example.net", "backup", "example.net", 22, COLOR_BLUE);
}
@@ -69,6 +71,21 @@ public class HostDatabase extends SQLiteOpenHelper {
onCreate(db);
}
+ public void touchHost(String nickname) {
+
+ Log.w(this.getClass().toString(), String.format("touchHost(nickname=%s)", nickname));
+
+ SQLiteDatabase db = this.getWritableDatabase();
+ long now = System.currentTimeMillis() / 1000;
+
+ ContentValues values = new ContentValues();
+ values.put(FIELD_HOST_LASTCONNECT, now);
+
+ db.update(TABLE_HOSTS, values, FIELD_HOST_NICKNAME + " = ?", new String[] { nickname });
+ db.close();
+
+ }
+
public long createHost(SQLiteDatabase db, String nickname, String username, String hostname, int port, String color) {
// create and insert new host
@@ -79,7 +96,7 @@ public class HostDatabase extends SQLiteOpenHelper {
values.put(FIELD_HOST_USERNAME, username);
values.put(FIELD_HOST_HOSTNAME, hostname);
values.put(FIELD_HOST_PORT, port);
- values.put(FIELD_HOST_LASTCONNECT, Integer.MAX_VALUE);
+ values.put(FIELD_HOST_LASTCONNECT, 0);
values.put(FIELD_HOST_USEKEYS, Boolean.toString(true));
if(color != null)
values.put(FIELD_HOST_COLOR, color);
@@ -90,13 +107,13 @@ public class HostDatabase extends SQLiteOpenHelper {
public Cursor allHosts(boolean sortColors) {
- String sortField = sortColors ? FIELD_HOST_COLOR : FIELD_HOST_LASTCONNECT;
+ String sortField = sortColors ? FIELD_HOST_COLOR : FIELD_HOST_NICKNAME;
SQLiteDatabase db = this.getReadableDatabase();
return db.query(TABLE_HOSTS, new String[] { "_id", FIELD_HOST_NICKNAME,
FIELD_HOST_USERNAME, FIELD_HOST_HOSTNAME, FIELD_HOST_PORT,
FIELD_HOST_HOSTKEY, FIELD_HOST_LASTCONNECT, FIELD_HOST_COLOR },
- null, null, null, null, sortField + " DESC");
+ null, null, null, null, sortField + " ASC");
}