2010-08-17 22:49:13 -04:00
|
|
|
package com.fsck.k9.activity;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
import com.fsck.k9.mail.Folder;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
|
2010-08-17 22:49:13 -04:00
|
|
|
public String name;
|
|
|
|
public String displayName;
|
|
|
|
public long lastChecked;
|
|
|
|
public int unreadMessageCount;
|
|
|
|
public int flaggedMessageCount;
|
|
|
|
public boolean loading;
|
|
|
|
public String status;
|
|
|
|
public boolean lastCheckFailed;
|
|
|
|
public Folder folder;
|
|
|
|
public boolean pushActive;
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean equals(Object o) {
|
2010-08-17 22:49:13 -04:00
|
|
|
return this.name.equals(((FolderInfoHolder)o).name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public int hashCode() {
|
2010-08-17 22:49:13 -04:00
|
|
|
return name.hashCode();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public int compareTo(FolderInfoHolder o) {
|
2010-08-17 22:49:13 -04:00
|
|
|
String s1 = this.name;
|
|
|
|
String s2 = o.name;
|
|
|
|
|
|
|
|
int ret = s1.compareToIgnoreCase(s2);
|
2011-02-06 17:09:48 -05:00
|
|
|
if (ret != 0) {
|
2010-08-17 22:49:13 -04:00
|
|
|
return ret;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2010-08-17 22:49:13 -04:00
|
|
|
return s1.compareTo(s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private String truncateStatus(String mess) {
|
|
|
|
if (mess != null && mess.length() > 27) {
|
2010-08-17 22:49:13 -04:00
|
|
|
mess = mess.substring(0, 27);
|
|
|
|
}
|
|
|
|
return mess;
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor for an empty object for comparisons
|
2011-02-06 17:09:48 -05:00
|
|
|
public FolderInfoHolder() {
|
2010-08-17 22:49:13 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public FolderInfoHolder(Context context, Folder folder, Account account) {
|
|
|
|
if (context == null) {
|
2010-11-13 16:40:56 -05:00
|
|
|
throw new IllegalArgumentException("null context given");
|
|
|
|
}
|
2010-08-17 22:49:13 -04:00
|
|
|
populate(context, folder, account);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public FolderInfoHolder(Context context, Folder folder, Account account, int unreadCount) {
|
2010-11-12 22:09:23 -05:00
|
|
|
populate(context, folder, account, unreadCount);
|
2010-08-17 22:49:13 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void populate(Context context, Folder folder, Account account, int unreadCount) {
|
2010-08-17 22:49:13 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2010-08-17 22:49:13 -04:00
|
|
|
folder.open(Folder.OpenMode.READ_WRITE);
|
|
|
|
// unreadCount = folder.getUnreadMessageCount();
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException me) {
|
2010-08-17 22:49:13 -04:00
|
|
|
Log.e(K9.LOG_TAG, "Folder.getUnreadMessageCount() failed", me);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
populate(context, folder, account);
|
2010-08-17 22:49:13 -04:00
|
|
|
|
|
|
|
this.unreadMessageCount = unreadCount;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.flaggedMessageCount = folder.getFlaggedMessageCount();
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (Exception e) {
|
2010-08-17 22:49:13 -04:00
|
|
|
Log.e(K9.LOG_TAG, "Unable to get flaggedMessageCount", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
folder.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void populate(Context context, Folder folder, Account account) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.folder = folder;
|
|
|
|
this.name = folder.getName();
|
2010-11-12 22:09:23 -05:00
|
|
|
this.lastChecked = folder.getLastUpdate();
|
|
|
|
|
2010-11-30 22:00:36 -05:00
|
|
|
this.status = truncateStatus(folder.getStatus());
|
2010-08-17 22:49:13 -04:00
|
|
|
|
2011-04-05 05:11:21 -04:00
|
|
|
if (this.name.equalsIgnoreCase(account.getInboxFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = context.getString(R.string.special_mailbox_name_inbox);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2010-11-12 22:09:23 -05:00
|
|
|
this.displayName = folder.getName();
|
2010-08-17 22:49:13 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getOutboxFolderName())) {
|
2011-02-19 22:47:28 -05:00
|
|
|
this.displayName = context.getString(R.string.special_mailbox_name_outbox);
|
2010-08-17 22:49:13 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getDraftsFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = String.format(context.getString(R.string.special_mailbox_name_drafts_fmt), this.name);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getTrashFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = String.format(context.getString(R.string.special_mailbox_name_trash_fmt), this.name);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getSentFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = String.format(context.getString(R.string.special_mailbox_name_sent_fmt), this.name);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getArchiveFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = String.format(context.getString(R.string.special_mailbox_name_archive_fmt), this.name);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (this.name.equals(account.getSpamFolderName())) {
|
2010-08-17 22:49:13 -04:00
|
|
|
this.displayName = String.format(context.getString(R.string.special_mailbox_name_spam_fmt), this.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|