More robust email checking

This commit is contained in:
str4d
2014-12-16 06:07:55 +00:00
parent dd5fe0e827
commit 8d03317da1
3 changed files with 47 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
0.3.1 0.3.1
* Fixed crash when clicking "Create new contact" button * Fixed crash when clicking "Create new contact" button
* Fixed occasional crashes when Bote connects to / disconnects from the network * Fixed occasional crashes when Bote connects to / disconnects from the network
* Improved robustness and user feedback for email checking
* Added "Copy to clipboard" button to identities and contacts * Added "Copy to clipboard" button to identities and contacts
* Added labels to the address book actions menu * Added labels to the address book actions menu
* Updated translations * Updated translations

View File

@@ -58,6 +58,7 @@ public class EmailListFragment extends AuthenticatedListFragment implements
OnEmailSelectedListener mCallback; OnEmailSelectedListener mCallback;
private MultiSwipeRefreshLayout mSwipeRefreshLayout; private MultiSwipeRefreshLayout mSwipeRefreshLayout;
private AsyncTask<Void, Void, Void> mCheckingTask;
private TextView mEmptyText; private TextView mEmptyText;
private TextView mNumIncompleteEmails; private TextView mNumIncompleteEmails;
@@ -135,7 +136,6 @@ public class EmailListFragment extends AuthenticatedListFragment implements
R.color.primary, R.color.accent, R.color.primary, R.color.accent); R.color.primary, R.color.accent, R.color.primary, R.color.accent);
mSwipeRefreshLayout.setSwipeableChildren(android.R.id.list, android.R.id.empty); mSwipeRefreshLayout.setSwipeableChildren(android.R.id.list, android.R.id.empty);
mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setOnRefreshListener(this);
mSwipeRefreshLayout.setRefreshing(I2PBote.getInstance().isCheckingForMail());
} }
return v; return v;
@@ -177,6 +177,29 @@ public class EmailListFragment extends AuthenticatedListFragment implements
} }
} }
@Override
public void onStart() {
super.onStart();
if (mSwipeRefreshLayout != null) {
boolean isChecking = I2PBote.getInstance().isCheckingForMail();
mSwipeRefreshLayout.setRefreshing(isChecking);
if (isChecking)
onRefresh();
}
}
@Override
public void onStop() {
super.onStop();
if (mCheckingTask != null) {
mCheckingTask.cancel(true);
mCheckingTask = null;
mSwipeRefreshLayout.setRefreshing(false);
}
}
/** /**
* Start loading the list of emails from this folder. * Start loading the list of emails from this folder.
* Only called when we have a password cached, or no * Only called when we have a password cached, or no
@@ -237,8 +260,16 @@ public class EmailListFragment extends AuthenticatedListFragment implements
boolean passwordRequired = I2PBote.getInstance().isPasswordRequired(); boolean passwordRequired = I2PBote.getInstance().isPasswordRequired();
mNewEmail.setVisibility(passwordRequired ? View.GONE : View.VISIBLE); mNewEmail.setVisibility(passwordRequired ? View.GONE : View.VISIBLE);
mCheckEmail.setVisible(mSwipeRefreshLayout != null && !passwordRequired); mCheckEmail.setVisible(mSwipeRefreshLayout != null && !passwordRequired);
if (mSwipeRefreshLayout != null) if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setEnabled(!passwordRequired); mSwipeRefreshLayout.setEnabled(!passwordRequired);
if (mSwipeRefreshLayout.isRefreshing()) {
mCheckEmail.setTitle(R.string.checking_email);
mCheckEmail.setEnabled(false);
} else {
mCheckEmail.setTitle(R.string.check_email);
mCheckEmail.setEnabled(true);
}
}
} }
@Override @Override
@@ -248,6 +279,7 @@ public class EmailListFragment extends AuthenticatedListFragment implements
if (!mSwipeRefreshLayout.isRefreshing()) { if (!mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(true); mSwipeRefreshLayout.setRefreshing(true);
onRefresh(); onRefresh();
getActivity().supportInvalidateOptionsMenu();
} }
return true; return true;
@@ -496,13 +528,17 @@ public class EmailListFragment extends AuthenticatedListFragment implements
// SwipeRefreshLayout.OnRefreshListener // SwipeRefreshLayout.OnRefreshListener
public void onRefresh() { public void onRefresh() {
// If we are already checking, do nothing else
if (mCheckingTask != null)
return;
I2PBote bote = I2PBote.getInstance(); I2PBote bote = I2PBote.getInstance();
if (bote.isConnected()) { if (bote.isConnected()) {
try { try {
if (!bote.isCheckingForMail()) if (!bote.isCheckingForMail())
bote.checkForMail(); bote.checkForMail();
new AsyncTask<Void, Void, Void>() { mCheckingTask = new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
while (I2PBote.getInstance().isCheckingForMail()) { while (I2PBote.getInstance().isCheckingForMail()) {
@@ -510,6 +546,9 @@ public class EmailListFragment extends AuthenticatedListFragment implements
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
if (isCancelled()) {
break;
}
} }
return null; return null;
} }
@@ -534,8 +573,10 @@ public class EmailListFragment extends AuthenticatedListFragment implements
// Notify PullToRefreshLayout that the refresh has finished // Notify PullToRefreshLayout that the refresh has finished
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
getActivity().supportInvalidateOptionsMenu();
} }
}.execute(); };
mCheckingTask.execute();
} catch (PasswordException e) { } catch (PasswordException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View File

@@ -43,6 +43,7 @@
<string name="action_stop_bote">Disconnect from network</string> <string name="action_stop_bote">Disconnect from network</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="check_email">Check email</string> <string name="check_email">Check email</string>
<string name="checking_email">Checking email&#8230;</string>
<!-- Argument is a number --> <!-- Argument is a number -->
<plurals name="incomplete_emails"> <plurals name="incomplete_emails">
<item quantity="one">One incomplete email</item> <item quantity="one">One incomplete email</item>