Skip to content

Commit

Permalink
v1.2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Banes committed Mar 4, 2012
1 parent 29179ca commit 6193d18
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 35 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ I will gladly accept pull requests for fixes and feature enhancements but please
* Fix not being able to Pull when the Empty View is show (#40)
* Add Japanese Translations (thanks to nagoya0)

#### 1.2.3.1

* Properly fix not being able to Pull when the Empty View is show (#40)

## Acknowledgments

* [Stefano Dacchille](https://github.com/stefanodacchille)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public final void onScroll(final AbsListView view, final int firstVisibleItem, f
}

if (null != mOnScrollListener) {
mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
}

public final void onScrollStateChanged(final AbsListView view, final int scrollState) {
if (null != mOnScrollListener) {
if (null != mOnScrollListener) {
mOnScrollListener.onScrollStateChanged(view, scrollState);
}
}
Expand All @@ -80,26 +80,27 @@ public final void onScrollStateChanged(final AbsListView view, final int scrollS
public final void setEmptyView(View newEmptyView) {
// If we already have an Empty View, remove it
if (null != mEmptyView) {
mRefreshableViewHolder.removeView(mEmptyView);
mRefreshableViewHolder.removeView(mEmptyView);
}

if (null != newEmptyView) {
// New view needs to be clickable so that Android recognizes it as a target for Touch Events
// New view needs to be clickable so that Android recognizes it as a
// target for Touch Events
newEmptyView.setClickable(true);

ViewParent newEmptyViewParent = newEmptyView.getParent();
if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
((ViewGroup) newEmptyViewParent).removeView(newEmptyView);
}

mRefreshableViewHolder.addView(newEmptyView, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
if (mRefreshableView instanceof EmptyViewMethodAccessor) {
((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
} else {
mRefreshableView.setEmptyView(newEmptyView);
}
}

mRefreshableViewHolder.addView(newEmptyView, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);

if (mRefreshableView instanceof EmptyViewMethodAccessor) {
((EmptyViewMethodAccessor) mRefreshableView).setEmptyViewInternal(newEmptyView);
} else {
mRefreshableView.setEmptyView(newEmptyView);
}
}
}

Expand All @@ -112,9 +113,9 @@ public final void setOnScrollListener(OnScrollListener listener) {
}

protected void addRefreshableView(Context context, T refreshableView) {
mRefreshableViewHolder = new FrameLayout(context);
mRefreshableViewHolder.addView(refreshableView, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
mRefreshableViewHolder = new FrameLayout(context);
mRefreshableViewHolder.addView(refreshableView, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
addView(mRefreshableViewHolder, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, 1.0f));
};

Expand All @@ -127,27 +128,27 @@ protected boolean isReadyForPullUp() {
}

private boolean isFirstItemVisible() {
if (this.mRefreshableView.getCount() == 0) {
if (mRefreshableView.getCount() == getNumberInternalViews()) {
return true;
} else if (mRefreshableView.getFirstVisiblePosition() == 0) {

final View firstVisibleChild = mRefreshableView.getChildAt(0);

if (firstVisibleChild != null) {
return firstVisibleChild.getTop() >= mRefreshableView.getTop();
}
}

return false;
}

private boolean isLastItemVisible() {
final int count = this.mRefreshableView.getCount();
final int count = mRefreshableView.getCount();
final int lastVisiblePosition = mRefreshableView.getLastVisiblePosition();

if (count == 0) {
if (count == getNumberInternalViews()) {
return true;
} else if (lastVisiblePosition == count - 1) {
} else if (lastVisiblePosition == (count - 1 - getNumberInternalFooterViews())) {

final int childIndex = lastVisiblePosition - mRefreshableView.getFirstVisiblePosition();
final View lastVisibleChild = mRefreshableView.getChildAt(childIndex);
Expand All @@ -156,7 +157,31 @@ private boolean isLastItemVisible() {
return lastVisibleChild.getBottom() <= mRefreshableView.getBottom();
}
}

return false;
}

protected int getNumberInternalViews() {
return getNumberInternalHeaderViews() + getNumberInternalFooterViews();
}

/**
* Returns the number of Adapter View Header Views. This will always return
* 0 for non-ListView views.
*
* @return 0 for non-ListView views, possibly 1 for ListView
*/
protected int getNumberInternalHeaderViews() {
return 0;
}

/**
* Returns the number of Adapter View Footer Views. This will always return
* 0 for non-ListView views.
*
* @return 0 for non-ListView views, possibly 1 for ListView
*/
protected int getNumberInternalFooterViews() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PullToRefreshListView extends PullToRefreshAdapterViewBase<ListView

private LoadingLayout mHeaderLoadingView;
private LoadingLayout mFooterLoadingView;

private FrameLayout mLvFooterLoadingFrame;
private boolean mAddedLvFooter = false;

Expand All @@ -23,15 +23,15 @@ class InternalListView extends ListView implements EmptyViewMethodAccessor {
public InternalListView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public void setAdapter(ListAdapter adapter) {
// Add the Footer View at the last possible moment
if (!mAddedLvFooter && null != mLvFooterLoadingFrame) {
addFooterView(mLvFooterLoadingFrame, null, false);
mAddedLvFooter = true;
}

super.setAdapter(adapter);
}

Expand All @@ -54,7 +54,7 @@ public PullToRefreshListView(Context context) {
super(context);
setDisableScrollingWhileRefreshing(false);
}

public PullToRefreshListView(Context context, int mode) {
super(context, mode);
setDisableScrollingWhileRefreshing(false);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void setPullLabel(String pullLabel) {
}

public void setRefreshingLabel(String refreshingLabel) {
super.setRefreshingLabel(refreshingLabel);
super.setRefreshingLabel(refreshingLabel);

if (null != mHeaderLoadingView) {
mHeaderLoadingView.setRefreshingLabel(refreshingLabel);
Expand All @@ -118,18 +118,18 @@ protected final ListView createRefreshableView(Context context, AttributeSet att
if (mode == MODE_PULL_DOWN_TO_REFRESH || mode == MODE_BOTH) {
FrameLayout frame = new FrameLayout(context);
mHeaderLoadingView = new LoadingLayout(context, MODE_PULL_DOWN_TO_REFRESH, releaseLabel, pullLabel,
refreshingLabel);
refreshingLabel);
frame.addView(mHeaderLoadingView, FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout.LayoutParams.WRAP_CONTENT);
mHeaderLoadingView.setVisibility(View.GONE);
lv.addHeaderView(frame, null, false);
}
if (mode == MODE_PULL_UP_TO_REFRESH || mode == MODE_BOTH) {
mLvFooterLoadingFrame = new FrameLayout(context);
mFooterLoadingView = new LoadingLayout(context, MODE_PULL_UP_TO_REFRESH, releaseLabel, pullLabel,
refreshingLabel);
refreshingLabel);
mLvFooterLoadingFrame.addView(mFooterLoadingView, FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
FrameLayout.LayoutParams.WRAP_CONTENT);
mFooterLoadingView.setVisibility(View.GONE);
}

Expand All @@ -140,6 +140,15 @@ protected final ListView createRefreshableView(Context context, AttributeSet att

@Override
protected void setRefreshingInternal(boolean doScroll) {

// If we're empty, then the header/footer views won't show so we use the
// normal method
ListAdapter adapter = mRefreshableView.getAdapter();
if (null == adapter || adapter.isEmpty()) {
super.setRefreshingInternal(doScroll);
return;
}

super.setRefreshingInternal(false);

final LoadingLayout originalLoadingLayout, listViewLoadingLayout;
Expand Down Expand Up @@ -187,6 +196,14 @@ protected void setRefreshingInternal(boolean doScroll) {
@Override
protected void resetHeader() {

// If we're empty, then the header/footer views won't show so we use the
// normal method
ListAdapter adapter = mRefreshableView.getAdapter();
if (null == adapter || adapter.isEmpty()) {
super.resetHeader();
return;
}

LoadingLayout originalLoadingLayout;
LoadingLayout listViewLoadingLayout;

Expand Down Expand Up @@ -223,4 +240,12 @@ protected void resetHeader() {
super.resetHeader();
}

protected int getNumberInternalHeaderViews() {
return null != mHeaderLoadingView ? 1 : 0;
}

protected int getNumberInternalFooterViews() {
return null != mFooterLoadingView ? 1 : 0;
}

}

0 comments on commit 6193d18

Please sign in to comment.