Pull to check email

This commit is contained in:
str4d
2014-06-14 07:11:35 +00:00
parent 0d6e1bd1db
commit 9b7ebf7ef6
6 changed files with 110 additions and 5 deletions

2
TODO
View File

@@ -13,8 +13,6 @@ Tasks:
-- Optimize use of Android lifecycles
Features:
- Show check mail status in inbox list header
- Pull-to-check
- Import/export identities
-- Export Destination / make it copyable
- Show contact pictures in recipients dropdown

View File

@@ -24,4 +24,5 @@ clean.dependsOn preclean
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}

View File

@@ -7,6 +7,10 @@ import java.util.List;
import javax.mail.Flags.Flag;
import javax.mail.MessagingException;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarcompat.PullToRefreshLayout;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.Options;
import uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener;
import net.i2p.I2PAppContext;
import net.i2p.util.Log;
import i2p.bote.I2PBote;
@@ -37,6 +41,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
@@ -46,13 +51,15 @@ import android.widget.TextView;
public class EmailListFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<List<Email>>,
MoveToDialogFragment.MoveToDialogListener,
EmailListAdapter.EmailSelector {
EmailListAdapter.EmailSelector, OnRefreshListener {
public static final String FOLDER_NAME = "folder_name";
private static final int EMAIL_LIST_LOADER = 1;
OnEmailSelectedListener mCallback;
private PullToRefreshLayout mPullToRefreshLayout;
private EmailListAdapter mAdapter;
private EmailFolder mFolder;
private ActionMode mMode;
@@ -94,10 +101,42 @@ public class EmailListFragment extends ListFragment implements
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view,savedInstanceState);
String folderName = getArguments().getString(FOLDER_NAME);
mFolder = BoteHelper.getMailFolder(folderName);
if (BoteHelper.isInbox(mFolder)) {
// This is the View which is created by ListFragment
ViewGroup viewGroup = (ViewGroup) view;
// We need to create a PullToRefreshLayout manually
mPullToRefreshLayout = new PullToRefreshLayout(viewGroup.getContext());
// We can now setup the PullToRefreshLayout
ActionBarPullToRefresh.from(getActivity())
// We need to insert the PullToRefreshLayout into the Fragment's ViewGroup
.insertLayoutInto(viewGroup)
// We need to mark the ListView and it's Empty View as pullable
// This is because they are not dirent children of the ViewGroup
.theseChildrenArePullable(getListView(), getListView().getEmptyView())
// We can now complete the setup as desired
.listener(this)
.options(Options.create()
.refreshOnUp(true)
.build())
.setup(mPullToRefreshLayout);
mPullToRefreshLayout.setRefreshing(I2PBote.getInstance().isCheckingForMail());
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new EmailListAdapter(getActivity(), this,
BoteHelper.isOutbox(mFolder));
@@ -461,4 +500,46 @@ public class EmailListFragment extends ListFragment implements
public void select(int position) {
onListItemSelect(position);
}
// OnRefreshListener
public void onRefreshStarted(View view) {
I2PBote bote = I2PBote.getInstance();
if (bote.isConnected()) {
try {
if (!bote.isCheckingForMail())
bote.checkForMail();
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
while (I2PBote.getInstance().isCheckingForMail()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Notify PullToRefreshLayout that the refresh has finished
mPullToRefreshLayout.setRefreshComplete();
}
}.execute();
} catch (PasswordException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
mPullToRefreshLayout.setRefreshComplete();
}
}

View File

@@ -202,6 +202,14 @@ public class BoteHelper extends GeneralHelper {
}
}
public static boolean isInbox(EmailFolder folder) {
return isInbox(folder.getName());
}
public static boolean isInbox(String folderName) {
return "Inbox".equalsIgnoreCase(folderName);
}
public static boolean isOutbox(EmailFolder folder) {
return isOutbox(folder.getName());
}

View File

@@ -9,6 +9,9 @@
<string name="action_settings">Settings</string>
<string name="start_i2p_android">It appears that I2P Android is not running. Would you like to start it?</string>
<string name="pull_text">Pull to check email</string>
<string name="refreshing_text">Checking email...</string>
<string name="release_text">Let go to check email</string>
<string name="items_selected">%s selected</string>
<string name="action_delete">Delete</string>

View File

@@ -15,6 +15,20 @@
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="ptrHeaderStyle">@style/Widget.Custom.PtrHeader</item>
</style>
<!--
ptrHeaderStyle above refers to this style which contains all of the
DefaultHeaderTransformer customization values. The name and parent
can be anything, but only the attributes defined in
library/res/attrs.xml are actually read in.
-->
<style name="Widget.Custom.PtrHeader" parent="android:Widget">
<!-- The strings to be displayed at the various states -->
<item name="ptrPullText">@string/pull_text</item>
<item name="ptrRefreshingText">@string/refreshing_text</item>
<item name="ptrReleaseText">@string/release_text</item>
</style>
</resources>