Use new BriarRecyclerView in ConversationView

This now handles progress bar and empty view itself.
With this commit, it also scrolls down on layout changes like when
keyboard is opened.
This commit is contained in:
Torsten Grote
2015-12-31 12:16:54 -02:00
parent b1f2f7d120
commit a4437a729a
3 changed files with 52 additions and 90 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.android.util;
import android.content.Context;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -51,6 +52,26 @@ public class BriarRecyclerView extends FrameLayout {
showProgressBar();
// scroll down when opening keyboard
if (Build.VERSION.SDK_INT >= 11) {
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v,
int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) {
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
scrollToPosition(
recyclerView.getAdapter().getItemCount() - 1);
}
}, 100);
}
}
});
}
emptyObserver = new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
@@ -112,6 +133,10 @@ public class BriarRecyclerView extends FrameLayout {
}
}
public void scrollToPosition(int position) {
recyclerView.scrollToPosition(position);
}
public RecyclerView getRecyclerView() {
return recyclerView;
}