Display correct new email count for per-identity views
This commit is contained in:
@@ -38,6 +38,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
|
||||||
import i2p.bote.I2PBote;
|
import i2p.bote.I2PBote;
|
||||||
import i2p.bote.android.addressbook.AddressBookActivity;
|
import i2p.bote.android.addressbook.AddressBookActivity;
|
||||||
import i2p.bote.android.config.SettingsActivity;
|
import i2p.bote.android.config.SettingsActivity;
|
||||||
@@ -330,6 +332,8 @@ public class EmailListActivity extends BoteActivityBase implements
|
|||||||
.putString(Constants.PREF_SELECTED_IDENTITY,
|
.putString(Constants.PREF_SELECTED_IDENTITY,
|
||||||
identity == null ? null : identity.getKey())
|
identity == null ? null : identity.getKey())
|
||||||
.apply();
|
.apply();
|
||||||
|
// Trigger the drawer folder loader to update the drawer badges
|
||||||
|
getSupportLoaderManager().restartLoader(LOADER_DRAWER_FOLDERS, null, new DrawerFolderLoaderCallbacks());
|
||||||
EmailListFragment f = (EmailListFragment) getSupportFragmentManager()
|
EmailListFragment f = (EmailListFragment) getSupportFragmentManager()
|
||||||
.findFragmentById(R.id.list_fragment);
|
.findFragmentById(R.id.list_fragment);
|
||||||
f.onIdentitySelected();
|
f.onIdentitySelected();
|
||||||
@@ -441,10 +445,10 @@ public class EmailListActivity extends BoteActivityBase implements
|
|||||||
// Fetch the identities first, so we trigger any exceptions
|
// Fetch the identities first, so we trigger any exceptions
|
||||||
Collection<EmailIdentity> identities = I2PBote.getInstance().getIdentities().getAll();
|
Collection<EmailIdentity> identities = I2PBote.getInstance().getIdentities().getAll();
|
||||||
profiles.add(new ProfileDrawerItem()
|
profiles.add(new ProfileDrawerItem()
|
||||||
.withIdentifier(ID_ALL_MAIL)
|
.withIdentifier(ID_ALL_MAIL)
|
||||||
.withTag(null)
|
.withTag(null)
|
||||||
.withEmail(getContext().getString(R.string.all_mail))
|
.withEmail(getContext().getString(R.string.all_mail))
|
||||||
.withIcon(getContext().getResources().getDrawable(R.drawable.ic_contact_picture))
|
.withIcon(getContext().getResources().getDrawable(R.drawable.ic_contact_picture))
|
||||||
);
|
);
|
||||||
for (EmailIdentity identity : identities) {
|
for (EmailIdentity identity : identities) {
|
||||||
profiles.add(getIdentityDrawerItem(identity));
|
profiles.add(getIdentityDrawerItem(identity));
|
||||||
@@ -539,12 +543,13 @@ public class EmailListActivity extends BoteActivityBase implements
|
|||||||
.withName(BoteHelper.getFolderDisplayName(getContext(), folder));
|
.withName(BoteHelper.getFolderDisplayName(getContext(), folder));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO change this when per-identity new emails can be determined
|
int numNew = BoteHelper.getNumNewEmails(getContext(), folder);
|
||||||
int numNew = folder.getNumNewEmails();
|
|
||||||
if (numNew > 0)
|
if (numNew > 0)
|
||||||
item.withBadge("" + numNew);
|
item.withBadge("" + numNew);
|
||||||
} catch (PasswordException e) {
|
} catch (PasswordException e) {
|
||||||
// Password fetching is handled in EmailListFragment
|
// Password fetching is handled in EmailListFragment
|
||||||
|
} catch (MessagingException | GeneralSecurityException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@@ -498,6 +498,8 @@ public class EmailListFragment extends AuthenticatedFragment implements
|
|||||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(EmailListFragment.class);
|
Log log = I2PAppContext.getGlobalContext().logManager().getLog(EmailListFragment.class);
|
||||||
if (log.shouldLog(Log.WARN))
|
if (log.shouldLog(Log.WARN))
|
||||||
log.warn("Email list loader finished, but password is no longer cached", e);
|
log.warn("Email list loader finished, but password is no longer cached", e);
|
||||||
|
} catch (MessagingException | GeneralSecurityException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,33 @@ import i2p.bote.util.GeneralHelper;
|
|||||||
import im.delight.android.identicons.Identicon;
|
import im.delight.android.identicons.Identicon;
|
||||||
|
|
||||||
public class BoteHelper extends GeneralHelper {
|
public class BoteHelper extends GeneralHelper {
|
||||||
|
public static int getNumNewEmails(Context ctx, EmailFolder folder) throws PasswordException, GeneralSecurityException, IOException, MessagingException {
|
||||||
|
String selectedIdentityKey = ctx.getSharedPreferences(Constants.SHARED_PREFS, 0)
|
||||||
|
.getString(Constants.PREF_SELECTED_IDENTITY, null);
|
||||||
|
if (selectedIdentityKey == null)
|
||||||
|
return folder.getNumNewEmails();
|
||||||
|
|
||||||
|
int numNew = 0;
|
||||||
|
for (Email email : BoteHelper.getEmails(folder, null, true)) {
|
||||||
|
if (email.getMetadata().isUnread()) {
|
||||||
|
if (BoteHelper.isSentEmail(email)) {
|
||||||
|
String senderDest = BoteHelper.extractEmailDestination(email.getOneFromAddress());
|
||||||
|
if (selectedIdentityKey.equals(senderDest))
|
||||||
|
numNew++;
|
||||||
|
} else {
|
||||||
|
for (Address recipient : email.getAllRecipients()) {
|
||||||
|
String recipientDest = BoteHelper.extractEmailDestination(recipient.toString());
|
||||||
|
if (selectedIdentityKey.equals(recipientDest)) {
|
||||||
|
numNew++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return numNew;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the translated name of the folder.
|
* Get the translated name of the folder.
|
||||||
* Built-in folders are special-cased; other folders are created by the
|
* Built-in folders are special-cased; other folders are created by the
|
||||||
@@ -83,10 +110,10 @@ public class BoteHelper extends GeneralHelper {
|
|||||||
* @return The name of the folder.
|
* @return The name of the folder.
|
||||||
* @throws PasswordException
|
* @throws PasswordException
|
||||||
*/
|
*/
|
||||||
public static String getFolderDisplayNameWithNew(Context ctx, EmailFolder folder) throws PasswordException {
|
public static String getFolderDisplayNameWithNew(Context ctx, EmailFolder folder) throws PasswordException, GeneralSecurityException, IOException, MessagingException {
|
||||||
String displayName = getFolderDisplayName(ctx, folder);
|
String displayName = getFolderDisplayName(ctx, folder);
|
||||||
|
|
||||||
int numNew = folder.getNumNewEmails();
|
int numNew = getNumNewEmails(ctx, folder);
|
||||||
if (numNew > 0)
|
if (numNew > 0)
|
||||||
displayName = displayName + " (" + numNew + ")";
|
displayName = displayName + " (" + numNew + ")";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user