]> Pileus Git - ~andy/spades/blobdiff - src/Main.java
Prevent app crash on Empty Send.
[~andy/spades] / src / Main.java
index 0b29dbad516662d39776170ef7b9409865c8786d..a88c5164572b70053a15d7fc5b31430edc866b04 100644 (file)
@@ -145,6 +145,12 @@ public class Main extends Activity
                this.send.setVisibility(running ? View.VISIBLE : View.GONE);
        }
 
+       private void scroll()
+       {
+               this.dscroll.smoothScrollTo(0, this.debug.getBottom());
+               this.lscroll.smoothScrollTo(0, this.log.getBottom());
+       }
+
        /* Private handler methods */
        private void onRegister(Task task)
        {
@@ -160,13 +166,13 @@ public class Main extends Activity
                        if (Message.class.isInstance(obj))
                                this.onMessage((Message)obj);
                }
+               this.scroll();
        }
 
        private void onMessage(Message msg)
        {
                // Debug
                this.debug.append("> " + msg.line + "\n");
-               this.dscroll.smoothScrollTo(0, this.debug.getBottom());
 
                // Chat
                switch (msg.type) {
@@ -194,7 +200,12 @@ public class Main extends Activity
                                this.notice("Authentication failed: " + msg.txt);
                                break;
                }
-               this.lscroll.smoothScrollTo(0, this.log.getBottom());
+
+               // Update title
+               if (this.cards.turn  != null && this.cards.turn  != "" &&
+                   this.cards.state != null && this.cards.state != "") {
+                       this.setTitle("Spades - " + this.cards.turn + "'s " + this.cards.state);
+               }
        }
 
        private void onNotify(String text)
@@ -252,6 +263,8 @@ public class Main extends Activity
                if (this.task == null)
                        return;
                String  txt = this.input.getText().toString();
+               if (txt.isEmpty())
+                       return;
                Message msg = this.task.send(txt);
                if (msg == null)
                        return;
@@ -420,6 +433,7 @@ public class Main extends Activity
                                        break;
                                case Task.MESSAGE:
                                        Main.this.onMessage((Message)msg.obj);
+                                       Main.this.scroll();
                                        break;
                                case Task.CONNECT:
                                        Main.this.update(true);