mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Don't allow 'this' to escape the constructor.
This commit is contained in:
@@ -21,27 +21,18 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
|
|
||||||
public BriarRecyclerView(Context context) {
|
public BriarRecyclerView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
initViews();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BriarRecyclerView(Context context, AttributeSet attrs) {
|
public BriarRecyclerView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
initViews();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BriarRecyclerView(Context context, AttributeSet attrs,
|
public BriarRecyclerView(Context context, AttributeSet attrs,
|
||||||
int defStyle) {
|
int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
|
||||||
initViews();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initViews() {
|
private void initViews() {
|
||||||
if (isInEditMode()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
View v = LayoutInflater.from(getContext()).inflate(
|
View v = LayoutInflater.from(getContext()).inflate(
|
||||||
R.layout.briar_recycler_view, this, true);
|
R.layout.briar_recycler_view, this, true);
|
||||||
@@ -54,22 +45,24 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
|
|
||||||
// scroll down when opening keyboard
|
// scroll down when opening keyboard
|
||||||
if (Build.VERSION.SDK_INT >= 11) {
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
recyclerView.addOnLayoutChangeListener(
|
||||||
@Override
|
new View.OnLayoutChangeListener() {
|
||||||
public void onLayoutChange(View v,
|
@Override
|
||||||
int left, int top, int right, int bottom,
|
public void onLayoutChange(View v, int left, int top,
|
||||||
int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
int right, int bottom, int oldLeft, int oldTop,
|
||||||
if (bottom < oldBottom) {
|
int oldRight, int oldBottom) {
|
||||||
recyclerView.postDelayed(new Runnable() {
|
if (bottom < oldBottom) {
|
||||||
@Override
|
recyclerView.postDelayed(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
scrollToPosition(
|
public void run() {
|
||||||
recyclerView.getAdapter().getItemCount() - 1);
|
scrollToPosition(
|
||||||
|
recyclerView.getAdapter()
|
||||||
|
.getItemCount() - 1);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}, 100);
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyObserver = new RecyclerView.AdapterDataObserver() {
|
emptyObserver = new RecyclerView.AdapterDataObserver() {
|
||||||
@@ -82,10 +75,13 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLayoutManager(RecyclerView.LayoutManager layout) {
|
public void setLayoutManager(RecyclerView.LayoutManager layout) {
|
||||||
|
if (recyclerView == null) initViews();
|
||||||
recyclerView.setLayoutManager(layout);
|
recyclerView.setLayoutManager(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdapter(RecyclerView.Adapter adapter) {
|
public void setAdapter(RecyclerView.Adapter adapter) {
|
||||||
|
if (recyclerView == null) initViews();
|
||||||
|
|
||||||
RecyclerView.Adapter oldAdapter = recyclerView.getAdapter();
|
RecyclerView.Adapter oldAdapter = recyclerView.getAdapter();
|
||||||
if (oldAdapter != null) {
|
if (oldAdapter != null) {
|
||||||
oldAdapter.unregisterAdapterDataObserver(emptyObserver);
|
oldAdapter.unregisterAdapterDataObserver(emptyObserver);
|
||||||
@@ -105,35 +101,34 @@ public class BriarRecyclerView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEmptyText(String text) {
|
public void setEmptyText(String text) {
|
||||||
|
if (recyclerView == null) initViews();
|
||||||
emptyView.setText(text);
|
emptyView.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressBar() {
|
public void showProgressBar() {
|
||||||
recyclerView.setVisibility(View.INVISIBLE);
|
if (recyclerView == null) initViews();
|
||||||
emptyView.setVisibility(View.INVISIBLE);
|
recyclerView.setVisibility(INVISIBLE);
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
emptyView.setVisibility(INVISIBLE);
|
||||||
|
progressBar.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showData() {
|
public void showData() {
|
||||||
RecyclerView.Adapter<?> adapter = recyclerView.getAdapter();
|
if (recyclerView == null) initViews();
|
||||||
|
RecyclerView.Adapter adapter = recyclerView.getAdapter();
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
if (adapter.getItemCount() == 0) {
|
if (adapter.getItemCount() == 0) {
|
||||||
emptyView.setVisibility(View.VISIBLE);
|
emptyView.setVisibility(VISIBLE);
|
||||||
recyclerView.setVisibility(View.INVISIBLE);
|
recyclerView.setVisibility(INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
emptyView.setVisibility(View.INVISIBLE);
|
emptyView.setVisibility(INVISIBLE);
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(VISIBLE);
|
||||||
}
|
}
|
||||||
progressBar.setVisibility(View.INVISIBLE);
|
progressBar.setVisibility(INVISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scrollToPosition(int position) {
|
public void scrollToPosition(int position) {
|
||||||
|
if (recyclerView == null) initViews();
|
||||||
recyclerView.scrollToPosition(position);
|
recyclerView.scrollToPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecyclerView getRecyclerView() {
|
|
||||||
return recyclerView;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user