use of org.orcid.jaxb.model.record_v2.Preferences in project k-9 by k9mail.
the class MigrationTest method getNewAccount.
private Account getNewAccount() {
Preferences preferences = Preferences.getPreferences(RuntimeEnvironment.application);
//FIXME: This is a hack to get Preferences into a state where it's safe to call newAccount()
preferences.loadAccounts();
return preferences.newAccount();
}
use of org.orcid.jaxb.model.record_v2.Preferences in project k-9 by k9mail.
the class MessagingController method getSearchAccountStatsSynchronous.
public AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount, final MessagingListener listener) {
Preferences preferences = Preferences.getPreferences(context);
LocalSearch search = searchAccount.getRelatedSearch();
// Collect accounts that belong to the search
String[] accountUuids = search.getAccountUuids();
List<Account> accounts;
if (search.searchAllAccounts()) {
accounts = preferences.getAccounts();
} else {
accounts = new ArrayList<>(accountUuids.length);
for (int i = 0, len = accountUuids.length; i < len; i++) {
String accountUuid = accountUuids[i];
accounts.set(i, preferences.getAccount(accountUuid));
}
}
ContentResolver cr = context.getContentResolver();
int unreadMessageCount = 0;
int flaggedMessageCount = 0;
String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
for (Account account : accounts) {
StringBuilder query = new StringBuilder();
List<String> queryArgs = new ArrayList<>();
ConditionsTreeNode conditions = search.getConditions();
SqlQueryBuilder.buildWhereClause(account, conditions, query, queryArgs);
String selection = query.toString();
String[] selectionArgs = queryArgs.toArray(new String[queryArgs.size()]);
Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/stats");
// Query content provider to get the account stats
Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
try {
if (cursor != null && cursor.moveToFirst()) {
unreadMessageCount += cursor.getInt(0);
flaggedMessageCount += cursor.getInt(1);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
// Create AccountStats instance...
AccountStats stats = new AccountStats();
stats.unreadMessageCount = unreadMessageCount;
stats.flaggedMessageCount = flaggedMessageCount;
// ...and notify the listener
if (listener != null) {
listener.accountStatusChanged(searchAccount, stats);
}
return stats;
}
use of org.orcid.jaxb.model.record_v2.Preferences in project k-9 by k9mail.
the class MessageCompose method processDraftMessage.
private void processDraftMessage(MessageViewInfo messageViewInfo) {
Message message = messageViewInfo.message;
draftId = MessagingController.getInstance(getApplication()).getId(message);
subjectView.setText(message.getSubject());
recipientPresenter.initFromDraftMessage(message);
// Read In-Reply-To header from draft
final String[] inReplyTo = message.getHeader("In-Reply-To");
if (inReplyTo.length >= 1) {
repliedToMessageId = inReplyTo[0];
}
// Read References header from draft
final String[] references = message.getHeader("References");
if (references.length >= 1) {
referencedMessageIds = references[0];
}
if (!relatedMessageProcessed) {
attachmentPresenter.loadNonInlineAttachments(messageViewInfo);
}
// Decode the identity header when loading a draft.
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
Map<IdentityField, String> k9identity = new HashMap<>();
String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
if (identityHeaders.length > 0 && identityHeaders[0] != null) {
k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
}
Identity newIdentity = new Identity();
if (k9identity.containsKey(IdentityField.SIGNATURE)) {
newIdentity.setSignatureUse(true);
newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
signatureChanged = true;
} else {
if (message instanceof LocalMessage) {
newIdentity.setSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
}
newIdentity.setSignature(identity.getSignature());
}
if (k9identity.containsKey(IdentityField.NAME)) {
newIdentity.setName(k9identity.get(IdentityField.NAME));
identityChanged = true;
} else {
newIdentity.setName(identity.getName());
}
if (k9identity.containsKey(IdentityField.EMAIL)) {
newIdentity.setEmail(k9identity.get(IdentityField.EMAIL));
identityChanged = true;
} else {
newIdentity.setEmail(identity.getEmail());
}
if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
relatedMessageReference = null;
String originalMessage = k9identity.get(IdentityField.ORIGINAL_MESSAGE);
MessageReference messageReference = MessageReference.parse(originalMessage);
if (messageReference != null) {
// Check if this is a valid account in our database
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = prefs.getAccount(messageReference.getAccountUuid());
if (account != null) {
relatedMessageReference = messageReference;
}
}
}
identity = newIdentity;
updateSignature();
updateFrom();
quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
use of org.orcid.jaxb.model.record_v2.Preferences in project k-9 by k9mail.
the class MessageProviderTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
mMockResolver = getMockContentResolver();
mContext = K9.app;
Preferences preferences = Preferences.getPreferences(getMockContext());
List<Account> accountList = preferences.getAccounts();
for (Account account : accountList) {
preferences.deleteAccount(account);
}
}
use of org.orcid.jaxb.model.record_v2.Preferences in project k-9 by k9mail.
the class MessageList method onToggleTheme.
private void onToggleTheme() {
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
K9.setK9MessageViewThemeSetting(K9.Theme.LIGHT);
} else {
K9.setK9MessageViewThemeSetting(K9.Theme.DARK);
}
new Thread(new Runnable() {
@Override
public void run() {
Context appContext = getApplicationContext();
Preferences prefs = Preferences.getPreferences(appContext);
StorageEditor editor = prefs.getStorage().edit();
K9.save(editor);
editor.commit();
}
}).start();
recreate();
}
Aggregations