Skip to content
This repository has been archived by the owner on Sep 15, 2019. It is now read-only.

Commit

Permalink
Display a progress bar while fetching new messages in conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff committed Sep 29, 2018
1 parent e174a64 commit 3fa38e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ android {
dependencies {
implementation 'com.github.stfalcon:chatkit:0.3.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pro.rudloff.hangupsdroid.R;
import pro.rudloff.hangupsdroid.User;
import pro.rudloff.hangupsdroid.runnables.AddMessageRunnable;
import pro.rudloff.hangupsdroid.runnables.HideViewRunnable;

/** Activity that lists messages in a specific conversation. */
public class ConversationActivity extends Activity implements OnLoadMoreListener, InputListener {
Expand Down Expand Up @@ -60,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
messageAdapter.setLoadMoreListener(this);
messageAdapter.addToEnd(conversation.getMessages(this), true);
app.pythonApp.callAttr("add_conversation_observer", this, conversation.getId());

findViewById(R.id.conversationLoader).animate().alpha(1);
app.pythonApp.callAttr(
"add_messages", this, conversation.getId(), conversation.getFirstMessage().getId());

Expand All @@ -76,7 +79,7 @@ public void onNewMessages(PyObject messageList) {
App app = (App) getApplicationContext();

runOnUiThread(new AddMessageRunnable(this, messageAdapter, messageList));
app.progressDialog.dismiss();
runOnUiThread(new HideViewRunnable(findViewById(R.id.conversationLoader)));
app.pythonApp.callAttr("set_read", conversation.getId());
}

Expand All @@ -89,6 +92,7 @@ public void onNewMessages(PyObject messageList) {
public void onLoadMore(int page, int totalItemsCount) {
App app = (App) getApplicationContext();

findViewById(R.id.conversationLoader).animate().alpha(1);
app.pythonApp.callAttr(
"add_messages", this, conversation.getId(), conversation.getFirstMessage().getId());
}
Expand All @@ -110,6 +114,7 @@ public void onChatMessageEvent(PyObject event) {
new User(
app.pythonApp.callAttr(
"get_user", event.get("user_id"))))));
runOnUiThread(new HideViewRunnable(findViewById(R.id.conversationLoader)));
if (hasWindowFocus()) {
app.pythonApp.callAttr("set_read", conversation.getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pro.rudloff.hangupsdroid.runnables;

import android.view.View;

/** Runnable used to hide a specific view. */
public class HideViewRunnable implements Runnable {

/** View to hide. */
private View view;

/**
* HideViewRunnable constructor.
*
* @param newView View to hide.
*/
public HideViewRunnable(View newView) {
view = newView;
}

/** Called to run the runnable. */
public void run() {
view.animate().alpha(0);
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/conversation.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<com.stfalcon.chatkit.messages.MessagesList android:id="@+id/messagesList" android:layout_width="match_parent" android:layout_height="match_parent" app:textAutoLink="all" android:layout_above="@+id/input"/>
<me.zhanghai.android.materialprogressbar.MaterialProgressBar android:id="@+id/conversationLoader" style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="3dp" android:indeterminate="true" app:mpb_progressStyle="horizontal" app:mpb_useIntrinsicPadding="false" android:layout_gravity="top" android:alpha="0"/>
<View android:layout_width="match_parent" android:layout_height="1dp" android:layout_above="@+id/input" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:background="@android:color/darker_gray"/>
<com.stfalcon.chatkit.messages.MessageInput android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/>
</RelativeLayout>

0 comments on commit 3fa38e1

Please sign in to comment.