mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-11 21:58:35 -05:00
Fix pull-to-refresh
- disable pull-to-refresh while showing the "Loading..." view - move initialization code from onResume() to initializePullToRefresh() and call it from onCreateView()
This commit is contained in:
parent
44348e08a4
commit
bc2f099c3c
@ -714,9 +714,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
|
|
||||||
mActionBarProgressView = inflater.inflate(R.layout.actionbar_indeterminate_progress_actionview, null);
|
mActionBarProgressView = inflater.inflate(R.layout.actionbar_indeterminate_progress_actionview, null);
|
||||||
|
|
||||||
mPullToRefreshView = (PullToRefreshListView) view.findViewById(R.id.message_list);
|
initializePullToRefresh(inflater, view);
|
||||||
View loadingView = inflater.inflate(R.layout.message_list_loading, null);
|
|
||||||
mPullToRefreshView.setEmptyView(loadingView);
|
|
||||||
|
|
||||||
initializeLayout();
|
initializeLayout();
|
||||||
mListView.setVerticalFadingEdgeEnabled(false);
|
mListView.setVerticalFadingEdgeEnabled(false);
|
||||||
@ -941,29 +939,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSingleFolderMode) {
|
|
||||||
if (mSearch.isManualSearch() && mAccount.allowRemoteSearch()) {
|
|
||||||
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
|
||||||
@Override
|
|
||||||
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
||||||
mPullToRefreshView.onRefreshComplete();
|
|
||||||
onRemoteSearchRequested();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mPullToRefreshView.setPullLabel(getString(R.string.pull_to_refresh_remote_search_from_local_search_pull));
|
|
||||||
mPullToRefreshView.setReleaseLabel(getString(R.string.pull_to_refresh_remote_search_from_local_search_release));
|
|
||||||
} else {
|
|
||||||
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
|
||||||
@Override
|
|
||||||
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
|
||||||
checkMail();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mPullToRefreshView.setMode(PullToRefreshBase.Mode.DISABLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
mController.addListener(mListener);
|
mController.addListener(mListener);
|
||||||
|
|
||||||
//Cancel pending new mail notifications when we open an account
|
//Cancel pending new mail notifications when we open an account
|
||||||
@ -987,6 +962,62 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
refreshTitle();
|
refreshTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializePullToRefresh(LayoutInflater inflater, View layout) {
|
||||||
|
mPullToRefreshView = (PullToRefreshListView) layout.findViewById(R.id.message_list);
|
||||||
|
|
||||||
|
// Set empty view
|
||||||
|
View loadingView = inflater.inflate(R.layout.message_list_loading, null);
|
||||||
|
mPullToRefreshView.setEmptyView(loadingView);
|
||||||
|
|
||||||
|
if (isPullToRefreshAllowed()) {
|
||||||
|
if (mSearch.isManualSearch() && mAccount.allowRemoteSearch()) {
|
||||||
|
// "Pull to search server"
|
||||||
|
mPullToRefreshView.setOnRefreshListener(
|
||||||
|
new PullToRefreshBase.OnRefreshListener<ListView>() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
||||||
|
mPullToRefreshView.onRefreshComplete();
|
||||||
|
onRemoteSearchRequested();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mPullToRefreshView.setPullLabel(getString(
|
||||||
|
R.string.pull_to_refresh_remote_search_from_local_search_pull));
|
||||||
|
mPullToRefreshView.setReleaseLabel(getString(
|
||||||
|
R.string.pull_to_refresh_remote_search_from_local_search_release));
|
||||||
|
} else {
|
||||||
|
// "Pull to refresh"
|
||||||
|
mPullToRefreshView.setOnRefreshListener(
|
||||||
|
new PullToRefreshBase.OnRefreshListener<ListView>() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
||||||
|
checkMail();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable pull-to-refresh until the message list has been loaded
|
||||||
|
setPullToRefreshEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not pull-to-refresh is allowed in this message list.
|
||||||
|
*/
|
||||||
|
private boolean isPullToRefreshAllowed() {
|
||||||
|
return mSingleFolderMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable pull-to-refresh.
|
||||||
|
*
|
||||||
|
* @param enable
|
||||||
|
* {@code true} to enable. {@code false} to disable.
|
||||||
|
*/
|
||||||
|
private void setPullToRefreshEnabled(boolean enable) {
|
||||||
|
mPullToRefreshView.setMode((enable) ?
|
||||||
|
PullToRefreshBase.Mode.PULL_DOWN_TO_REFRESH : PullToRefreshBase.Mode.DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeLayout() {
|
private void initializeLayout() {
|
||||||
mListView = mPullToRefreshView.getRefreshableView();
|
mListView = mPullToRefreshView.getRefreshableView();
|
||||||
mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
||||||
@ -2929,8 +2960,14 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||||
|
// Remove the "Loading..." view
|
||||||
mPullToRefreshView.setEmptyView(null);
|
mPullToRefreshView.setEmptyView(null);
|
||||||
|
|
||||||
|
// Enable pull-to-refresh if allowed
|
||||||
|
if (isPullToRefreshAllowed()) {
|
||||||
|
setPullToRefreshEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
if (mCursors.length > 1) {
|
if (mCursors.length > 1) {
|
||||||
mCursors[loader.getId()] = data;
|
mCursors[loader.getId()] = data;
|
||||||
|
Loading…
Reference in New Issue
Block a user