Skip to content

Commit

Permalink
Add ability to set whether the Refreshing View is automatically shown…
Browse files Browse the repository at this point in the history
… after a Refresh
  • Loading branch information
Chris Banes committed Mar 26, 2012
1 parent 4dbcc11 commit 8531116
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void stop() {
static final String STATE_MODE = "ptr_mode";
static final String STATE_CURRENT_MODE = "ptr_current_mode";
static final String STATE_DISABLE_SCROLLING_REFRESHING = "ptr_disable_scrolling";
static final String STATE_SHOW_REFRESHING_VIEW = "ptr_show_refreshing_view";
static final String STATE_SUPER = "ptr_super";

// ===========================================================
Expand All @@ -116,10 +117,10 @@ public void stop() {
private int mMode = MODE_PULL_DOWN_TO_REFRESH;
private int mCurrentMode;

private boolean mDisableScrollingWhileRefreshing = true;

T mRefreshableView;
private boolean mIsPullToRefreshEnabled = true;
private boolean mPullToRefreshEnabled = true;
private boolean mShowViewWhileRefreshing = true;
private boolean mDisableScrollingWhileRefreshing = true;

private LoadingLayout mHeaderLayout;
private LoadingLayout mFooterLayout;
Expand Down Expand Up @@ -176,13 +177,23 @@ public final T getRefreshableView() {
return mRefreshableView;
}

/**
* Get whether the 'Refreshing' View should be automatically shown when
* refreshing. Returns true by default.
*
* @return - true if the Refreshing View will be show
*/
public final boolean getShowViewWhileRefreshing() {
return mShowViewWhileRefreshing;
}

/**
* Whether Pull-to-Refresh is enabled
*
* @return enabled
*/
public final boolean isPullToRefreshEnabled() {
return mIsPullToRefreshEnabled;
return mPullToRefreshEnabled;
}

/**
Expand Down Expand Up @@ -275,7 +286,17 @@ public final void setOnRefreshListener(OnRefreshListener2 listener) {
* Whether Pull-To-Refresh should be used
*/
public final void setPullToRefreshEnabled(boolean enable) {
mIsPullToRefreshEnabled = enable;
mPullToRefreshEnabled = enable;
}

/**
* A mutator to enable/disable whether the 'Refreshing' View should be
* automatically shown when refreshing.
*
* @param showView
*/
public final void setShowViewWhileRefreshing(boolean showView) {
mShowViewWhileRefreshing = showView;
}

/**
Expand Down Expand Up @@ -352,7 +373,7 @@ public final boolean hasPullFromTop() {

@Override
public final boolean onTouchEvent(MotionEvent event) {
if (!mIsPullToRefreshEnabled) {
if (!mPullToRefreshEnabled) {
return false;
}

Expand Down Expand Up @@ -421,7 +442,7 @@ public final boolean onTouchEvent(MotionEvent event) {
@Override
public final boolean onInterceptTouchEvent(MotionEvent event) {

if (!mIsPullToRefreshEnabled) {
if (!mPullToRefreshEnabled) {
return false;
}

Expand Down Expand Up @@ -545,6 +566,7 @@ protected Parcelable onSaveInstanceState() {
bundle.putInt(STATE_MODE, mMode);
bundle.putInt(STATE_CURRENT_MODE, mCurrentMode);
bundle.putBoolean(STATE_DISABLE_SCROLLING_REFRESHING, mDisableScrollingWhileRefreshing);
bundle.putBoolean(STATE_SHOW_REFRESHING_VIEW, mShowViewWhileRefreshing);
bundle.putParcelable(STATE_SUPER, super.onSaveInstanceState());
return bundle;
}
Expand All @@ -554,10 +576,11 @@ protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;

final int viewState = bundle.getInt(STATE_STATE);
mMode = bundle.getInt(STATE_MODE);
mCurrentMode = bundle.getInt(STATE_CURRENT_MODE);
mDisableScrollingWhileRefreshing = bundle.getBoolean(STATE_DISABLE_SCROLLING_REFRESHING);
final int viewState = bundle.getInt(STATE_STATE, PULL_TO_REFRESH);
mMode = bundle.getInt(STATE_MODE, MODE_PULL_DOWN_TO_REFRESH);
mCurrentMode = bundle.getInt(STATE_CURRENT_MODE, MODE_PULL_DOWN_TO_REFRESH);
mDisableScrollingWhileRefreshing = bundle.getBoolean(STATE_DISABLE_SCROLLING_REFRESHING, true);
mShowViewWhileRefreshing = bundle.getBoolean(STATE_SHOW_REFRESHING_VIEW, true);

// Let super Restore Itself
super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER));
Expand Down Expand Up @@ -601,7 +624,11 @@ protected void setRefreshingInternal(boolean doScroll) {
}

if (doScroll) {
smoothScrollTo(mCurrentMode == MODE_PULL_DOWN_TO_REFRESH ? -mHeaderHeight : mHeaderHeight);
if (mShowViewWhileRefreshing) {
smoothScrollTo(mCurrentMode == MODE_PULL_DOWN_TO_REFRESH ? -mHeaderHeight : mHeaderHeight);
} else {
smoothScrollTo(0);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ 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
// If we're not showing the Refreshing view, or the list is empty, then
// the header/footer views won't show so we use the
// normal method
ListAdapter adapter = mRefreshableView.getAdapter();
if (null == adapter || adapter.isEmpty()) {
if (!getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) {
super.setRefreshingInternal(doScroll);
return;
}
Expand Down Expand Up @@ -203,10 +204,11 @@ 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
// If we're not showing the Refreshing view, or the list is empty, then
// the header/footer views won't show so we use the
// normal method
ListAdapter adapter = mRefreshableView.getAdapter();
if (null == adapter || adapter.isEmpty()) {
if (!getShowViewWhileRefreshing() || null == adapter || adapter.isEmpty()) {
super.resetHeader();
return;
}
Expand Down

0 comments on commit 8531116

Please sign in to comment.