Permalink
Browse files

Moved the initial poll out of the dialog phase of loading the room, p…

…resenting the user with room ready to speak to right away as messages get loaded, using the normal polling threads.
  • Loading branch information...
1 parent bbc9f65 commit 2b0f42de413f77ad5c8448b40fa2700224ebf231 @konklone konklone committed Jan 5, 2010
Showing with 44 additions and 27 deletions.
  1. +30 −0 res/layout/room.xml
  2. +14 −27 src/com/github/klondike/android/campfire/RoomView.java
View
@@ -10,6 +10,36 @@
android:layout_height="fill_parent"
android:layout_weight="1"
/>
+
+ <LinearLayout android:id="@id/android:empty"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+
+ android:orientation="horizontal"
+ android:gravity="center"
+ >
+
+ <ProgressBar android:id="@+id/empty_spinner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="?android:attr/progressBarStyleSmallTitle"
+
+ android:visibility="invisible"
+
+ android:layout_marginRight="10dp"
+ />
+
+ <TextView android:id="@+id/empty_message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:visibility="invisible"
+
+ android:text="Loading messages..."
+ />
+
+ </LinearLayout>
<LinearLayout android:id="@+id/room_bottom"
android:orientation="horizontal"
@@ -112,6 +112,9 @@ private void onJoined() {
setWindowTitle(room.name);
setListAdapter(new RoomAdapter(this, messages));
scrollToBottom();
+
+ ((ProgressBar) findViewById(R.id.empty_spinner)).setVisibility(View.VISIBLE);
+ ((TextView) findViewById(R.id.empty_message)).setVisibility(View.VISIBLE);
autoPoll();
}
@@ -142,21 +145,19 @@ private void onPoll(CampfireException exception) {
private void onSpeak(Message message) {
body.setText("");
- speak.setEnabled(true);
((RoomAdapter) getListAdapter()).add(message);
scrollToBottom();
}
private void onSpeak(CampfireException exception) {
- speak.setEnabled(true);
Utils.alert(this, exception);
}
private void setupControls() {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.room_title);
setWindowTitle(R.string.app_name);
-
+
titleSpinner = (ProgressBar) findViewById(R.id.title_spinner);
body = (EditText) findViewById(R.id.room_message_body);
@@ -207,6 +208,7 @@ public void run() {
final Runnable pollSuccess = new Runnable() {
public void run() {
pollFailures = 0;
+
hideSpinner();
onPoll();
}
@@ -244,12 +246,6 @@ private void autoPoll() {
new Thread() {
public void run() {
while(true) {
- try {
- sleep(AUTOPOLL_INTERVAL * 1000);
- } catch(InterruptedException ex) {
- // well, I never
- }
-
handler.post(pollStart);
try {
messages = poll(room, users);
@@ -261,6 +257,13 @@ public void run() {
} catch(CampfireException e) {
handler.post(pollFailure);
}
+
+ try {
+ sleep(AUTOPOLL_INTERVAL * 1000);
+ } catch(InterruptedException ex) {
+ // well, I never
+ }
+
}
}
}.start();
@@ -433,7 +436,6 @@ public SpeakTask(RoomView context) {
@Override
protected void onPreExecute() {
- context.speak.setEnabled(false);
loadingDialog();
}
@@ -478,9 +480,7 @@ protected void onPostExecute(Message message) {
private class JoinTask extends AsyncTask<Void,String,CampfireException> {
public RoomView context;
- public String dialogMessage;
- public ArrayList<Message> messages = null;
public Room room = null;
public HashMap<String,User> users;
private ProgressDialog dialog = null;
@@ -509,7 +509,7 @@ protected void onPreExecute() {
protected void loadingDialog() {
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- dialog.setMessage(dialogMessage);
+ dialog.setMessage("Joining room...");
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
@@ -527,10 +527,7 @@ protected CampfireException doInBackground(Void... nothing) {
try {
// join first, so that the logged in user shows up in the list of initial users
// and can be cached earlier
- publishProgress("Joining room...");
Room.joinRoom(campfire, roomId);
-
- publishProgress("Loading room details...");
room = Room.find(campfire, roomId);
// cache the initial users now while we can
@@ -541,31 +538,21 @@ protected CampfireException doInBackground(Void... nothing) {
users.put(user.id, user);
}
}
-
- publishProgress("Getting latest messages...");
- messages = poll(room, users);
} catch (CampfireException e) {
return e;
}
return null;
}
@Override
- protected void onProgressUpdate(String... message) {
- dialogMessage = message[0];
- dialog.setMessage(message[0]);
- }
-
- @Override
protected void onPostExecute(CampfireException exception) {
if (dialog != null && dialog.isShowing())
dialog.dismiss();
context.joinTask = null;
context.room = room;
- context.messages = messages;
context.users = users;
-
+
if (exception == null)
context.onJoined();
else

0 comments on commit 2b0f42d

Please sign in to comment.