Skip to content

Commit

Permalink
Chat window updates
Browse files Browse the repository at this point in the history
- Show a spinner during the loading of chats from the database
- When the user doesn't have any messages, show the software keyboard (if it already isn't showing)
  • Loading branch information
Nicole Borrelli authored and ge0rg committed Oct 30, 2014
1 parent 3dd417a commit 0996147
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 52 deletions.
103 changes: 62 additions & 41 deletions res/layout/mainchat.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:fastScrollEnabled="true"
android:stackFromBottom="true"
android:transcriptMode="normal" />

<LinearLayout android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:baselineAligned="false"
>

<EditText
android:id="@+id/Chat_UserInput"
android:layout_width="200dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="@string/chat_enterMsgHint"
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
>
<requestFocus />
</EditText>

<Button android:id="@+id/Chat_SendButton"
android:layout_width="wrap_content"
android:minWidth="60sp"
android:layout_height="wrap_content"
android:text="@android:string/ok"
/>

</LinearLayout>

</LinearLayout>
<FrameLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:fastScrollEnabled="true"
android:stackFromBottom="true"
android:transcriptMode="normal"/>

<LinearLayout
android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="bottom"
>

<EditText
android:id="@+id/Chat_UserInput"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/chat_enterMsgHint"
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
>
</EditText>

<Button
android:id="@+id/Chat_SendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="60sp"
android:text="@android:string/ok"
/>

</LinearLayout>

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ProgressBar
android:id="@+id/loading_progress"
style="@android:style/Widget.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
</FrameLayout>
48 changes: 37 additions & 11 deletions src/org/yaxim/androidclient/chat/ChatWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.*;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import android.widget.AdapterView.AdapterContextMenuInfo;

Expand Down Expand Up @@ -72,6 +68,7 @@ public class ChatWindow extends SherlockFragmentActivity implements OnKeyListene
private TextView mTitle;
private TextView mSubTitle;
private Button mSendButton = null;
private ProgressBar mLoadingProgress;
private EditText mChatInput = null;
private String mWithJabberID = null;
private String mUserScreenName = null;
Expand All @@ -83,6 +80,8 @@ public class ChatWindow extends SherlockFragmentActivity implements OnKeyListene
private ListView mListView;
private ChatWindowAdapter mChatAdapter;

private boolean mShowOrHide = true;

@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(YaximApplication.getConfig(this).getTheme());
Expand All @@ -91,12 +90,14 @@ public void onCreate(Bundle savedInstanceState) {
mChatFontSize = Integer.valueOf(YaximApplication.getConfig(this).chatFontSize);

requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);

setContentView(R.layout.mainchat);

getContentResolver().registerContentObserver(RosterProvider.CONTENT_URI,
true, mContactObserver);

ActionBar actionBar = getSupportActionBar();
actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);

Expand Down Expand Up @@ -124,6 +125,10 @@ public void onCreate(Bundle savedInstanceState) {

// Setup the loader
getSupportLoaderManager().initLoader(CHAT_MSG_LOADER, null, this);

// Loading progress
mLoadingProgress = (ProgressBar) findViewById(R.id.loading_progress);
mLoadingProgress.setVisibility(View.VISIBLE);
}

private void setCustomTitle(String title) {
Expand Down Expand Up @@ -154,7 +159,16 @@ public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
mLoadingProgress.setVisibility(View.GONE);
mChatAdapter.changeCursor(cursor);

// Only do this the first time (show or hide the keyboard)
if (mShowOrHide) {
if (cursor.getCount() == 0) {
showKeyboard();
}
mShowOrHide = false;
}
}

@Override
Expand Down Expand Up @@ -583,6 +597,22 @@ private void updateContactStatus() {
cursor.close();
}

public ListView getListView() {
return mListView;
}

private void showKeyboard() {
mChatInput.requestFocus();
new Handler(getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager keyboard = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(mChatInput, InputMethodManager.SHOW_IMPLICIT);
}
}, 200);
}

private class ContactObserver extends ContentObserver {
public ContactObserver() {
super(new Handler());
Expand All @@ -593,8 +623,4 @@ public void onChange(boolean selfChange) {
updateContactStatus();
}
}

public ListView getListView() {
return mListView;
}
}

0 comments on commit 0996147

Please sign in to comment.