Loader for email list
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
package i2p.bote;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import i2p.bote.email.Email;
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
|
||||
public class FolderFragment extends ListFragment {
|
||||
public class FolderFragment extends ListFragment implements
|
||||
LoaderManager.LoaderCallbacks<List<Email>> {
|
||||
public static final String FOLDER_NAME = "folder_name";
|
||||
|
||||
private static final int EMAIL_LIST_LOADER = 1;
|
||||
|
||||
private EmailListAdapter mAdapter;
|
||||
private EmailFolder mFolder;
|
||||
|
||||
public static FolderFragment newInstance(String folderName) {
|
||||
FolderFragment f = new FolderFragment();
|
||||
Bundle args = new Bundle();
|
||||
@@ -16,10 +27,37 @@ public class FolderFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mAdapter = new EmailListAdapter(getActivity());
|
||||
String folderName = getArguments().getString(FOLDER_NAME);
|
||||
EmailFolder folder = BoteHelper.getMailFolder(folderName);
|
||||
mFolder = BoteHelper.getMailFolder(folderName);
|
||||
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
setListShown(false);
|
||||
if (mFolder != null)
|
||||
getLoaderManager().initLoader(EMAIL_LIST_LOADER, null, this);
|
||||
}
|
||||
|
||||
// LoaderManager.LoaderCallbacks<List<Email>>
|
||||
|
||||
public Loader<List<Email>> onCreateLoader(int id, Bundle args) {
|
||||
return new EmailListLoader(getActivity(), mFolder);
|
||||
}
|
||||
|
||||
public void onLoadFinished(Loader<List<Email>> loader,
|
||||
List<Email> data) {
|
||||
mAdapter.setData(data);
|
||||
|
||||
if (isResumed()) {
|
||||
setListShown(true);
|
||||
} else {
|
||||
setListShownNoAnimation(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onLoaderReset(Loader<List<Email>> loader) {
|
||||
mAdapter.setData(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user