mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-11 21:58:35 -05:00
Add basic pull to refresh support to MessageList.
This commit is contained in:
parent
ea373934c8
commit
c574088f57
@ -4,7 +4,7 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
<ListView
|
<com.handmark.pulltorefresh.library.PullToRefreshListView
|
||||||
android:id="@+id/message_list"
|
android:id="@+id/message_list"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
|
@ -74,6 +74,8 @@ import com.fsck.k9.mail.store.LocalStore;
|
|||||||
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
|
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
|
||||||
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
||||||
import com.fsck.k9.mail.store.StorageManager;
|
import com.fsck.k9.mail.store.StorageManager;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
||||||
|
import com.handmark.pulltorefresh.library.PullToRefreshListView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,6 +254,7 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
|
private PullToRefreshListView mPullToRefreshView;
|
||||||
|
|
||||||
private int mPreviewLines = 0;
|
private int mPreviewLines = 0;
|
||||||
|
|
||||||
@ -552,10 +555,7 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
private void progress(final boolean progress) {
|
private void progress(final boolean progress) {
|
||||||
// Make sure we don't try this before the menu is initialized
|
// Make sure we don't try this before the menu is initialized
|
||||||
// this could happen while the activity is initialized.
|
// this could happen while the activity is initialized.
|
||||||
if (mRefreshMenuItem == null) {
|
if (mRefreshMenuItem != null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progress) {
|
if (progress) {
|
||||||
mRefreshMenuItem.setActionView(mActionBarProgressView);
|
mRefreshMenuItem.setActionView(mActionBarProgressView);
|
||||||
} else {
|
} else {
|
||||||
@ -563,6 +563,11 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mPullToRefreshView != null && !progress) {
|
||||||
|
mPullToRefreshView.onRefreshComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the message list that was used to open the {@link MessageView} for a message.
|
* Show the message list that was used to open the {@link MessageView} for a message.
|
||||||
*
|
*
|
||||||
@ -668,9 +673,9 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
final MessageInfoHolder message = (MessageInfoHolder) parent.getItemAtPosition(position);
|
||||||
if (mSelectedCount > 0) {
|
if (mSelectedCount > 0) {
|
||||||
toggleMessageSelect(position);
|
toggleMessageSelect(message);
|
||||||
} else {
|
} else {
|
||||||
onOpenMessage(message);
|
onOpenMessage(message);
|
||||||
}
|
}
|
||||||
@ -680,12 +685,15 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
context = this;
|
context = this;
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.message_list);
|
||||||
|
|
||||||
mActionBarProgressView = getLayoutInflater().inflate(R.layout.actionbar_indeterminate_progress_actionview, null);
|
mActionBarProgressView = getLayoutInflater().inflate(R.layout.actionbar_indeterminate_progress_actionview, null);
|
||||||
|
|
||||||
// need this for actionbar initialization
|
// need this for actionbar initialization
|
||||||
mQueryString = getIntent().getStringExtra(EXTRA_QUERY);
|
mQueryString = getIntent().getStringExtra(EXTRA_QUERY);
|
||||||
|
|
||||||
|
mPullToRefreshView = (PullToRefreshListView) findViewById(R.id.message_list);
|
||||||
|
|
||||||
mInflater = getLayoutInflater();
|
mInflater = getLayoutInflater();
|
||||||
mActionBar = getSupportActionBar();
|
mActionBar = getSupportActionBar();
|
||||||
initializeActionBar();
|
initializeActionBar();
|
||||||
@ -694,14 +702,15 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
mPreviewLines = K9.messageListPreviewLines();
|
mPreviewLines = K9.messageListPreviewLines();
|
||||||
|
|
||||||
initializeMessageList(getIntent(), true);
|
initializeMessageList(getIntent(), true);
|
||||||
getListView().setVerticalFadingEdgeEnabled(false);
|
mListView.setVerticalFadingEdgeEnabled(false);
|
||||||
|
|
||||||
// Enable context action bar behaviour
|
// Enable context action bar behaviour
|
||||||
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
|
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
toggleMessageSelect(position);
|
final MessageInfoHolder message = (MessageInfoHolder) parent.getItemAtPosition(position);
|
||||||
|
toggleMessageSelect(message);
|
||||||
return true;
|
return true;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@ -843,6 +852,18 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
mStars = K9.messageListStars();
|
mStars = K9.messageListStars();
|
||||||
mCheckboxes = K9.messageListCheckboxes();
|
mCheckboxes = K9.messageListCheckboxes();
|
||||||
|
|
||||||
|
// TODO Add support for pull to fresh on searches.
|
||||||
|
if(mQueryString == null) {
|
||||||
|
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
||||||
|
checkMail(mAccount, mFolderName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mPullToRefreshView.setMode(PullToRefreshBase.Mode.DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
mController.addListener(mAdapter.mListener);
|
mController.addListener(mAdapter.mListener);
|
||||||
|
|
||||||
Account[] accountsWithNotification;
|
Account[] accountsWithNotification;
|
||||||
@ -932,7 +953,7 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeLayout() {
|
private void initializeLayout() {
|
||||||
mListView = getListView();
|
mListView = mPullToRefreshView.getRefreshableView();
|
||||||
mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
mListView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
||||||
mListView.setLongClickable(true);
|
mListView.setLongClickable(true);
|
||||||
mListView.setFastScrollEnabled(true);
|
mListView.setFastScrollEnabled(true);
|
||||||
@ -2400,11 +2421,6 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleMessageSelect(int position){
|
|
||||||
MessageInfoHolder holder = (MessageInfoHolder) mAdapter.getItem(position);
|
|
||||||
toggleMessageSelect(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleMessageSelect(final MessageInfoHolder holder){
|
private void toggleMessageSelect(final MessageInfoHolder holder){
|
||||||
if (mActionMode != null) {
|
if (mActionMode != null) {
|
||||||
if (mSelectedCount == 1 && holder.selected) {
|
if (mSelectedCount == 1 && holder.selected) {
|
||||||
|
Loading…
Reference in New Issue
Block a user