Refactoring

pull/146/head
M66B 6 years ago
parent b4b173b8cf
commit 623ccaa522

@ -26,7 +26,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -291,9 +290,6 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
final boolean show_expanded = properties.isExpanded(message.id);
boolean show_addresses = properties.showAddresses(message.id);
boolean show_headers = properties.showHeaders(message.id);
boolean outgoing = EntityFolder.DRAFTS.equals(message.folderType) ||
EntityFolder.OUTBOX.equals(message.folderType) ||
EntityFolder.SENT.equals(message.folderType);
pbLoading.setVisibility(View.GONE);
@ -312,7 +308,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
}
}
if (!photo && identicons) {
Address[] addresses = (outgoing ? message.to : message.from);
Address[] addresses = (EntityFolder.isOutgoing(message.folderType) ? message.to : message.from);
if (addresses != null && addresses.length > 0) {
ivAvatar.setImageBitmap(Identicon.generate(addresses[0].toString(), dp24, 5, "light".equals(theme)));
photo = true;
@ -332,7 +328,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
else
ivFlagged.setVisibility(message.count - message.unflagged > 0 ? View.VISIBLE : View.GONE);
if (outgoing) {
if (EntityFolder.isOutgoing(message.folderType)) {
tvFrom.setText(MessageHelper.getFormattedAddresses(message.to, !compact));
tvTime.setText(DateUtils.getRelativeTimeSpanString(context, message.sent == null ? message.received : message.sent));
} else {
@ -423,9 +419,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
if (show_expanded) {
ivExpanderAddress.setImageResource(show_addresses ? R.drawable.baseline_expand_less_24 : R.drawable.baseline_expand_more_24);
if (EntityFolder.DRAFTS.equals(message.folderType) ||
EntityFolder.OUTBOX.equals(message.folderType) ||
EntityFolder.SENT.equals(message.folderType))
if (EntityFolder.isOutgoing(message.folderType))
tvTimeEx.setText(df.format(new Date(message.sent == null ? message.received : message.sent)));
else
tvTimeEx.setText(df.format(new Date(message.received)));

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.os.Handler;
import android.util.Log;

@ -126,6 +126,14 @@ public class EntityFolder implements Serializable {
public EntityFolder() {
}
boolean isOutgoing() {
return isOutgoing(this.type);
}
static boolean isOutgoing(String type) {
return DRAFTS.equals(type) || OUTBOX.equals(type) || SENT.equals(type);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityFolder) {

@ -1258,8 +1258,7 @@ public class FragmentMessages extends FragmentEx {
TupleMessageEx see = null;
for (TupleMessageEx message : messages)
if (!EntityFolder.ARCHIVE.equals(message.folderType) &&
!EntityFolder.SENT.equals(message.folderType) &&
!EntityFolder.OUTBOX.equals(message.folderType)) {
!EntityFolder.isOutgoing(message.folderType)) {
autoCount++;
single = message;
if (!message.ui_seen) {
@ -1291,10 +1290,8 @@ public class FragmentMessages extends FragmentEx {
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
if (!EntityFolder.ARCHIVE.equals(message.folderType) &&
!EntityFolder.SENT.equals(message.folderType) &&
!EntityFolder.OUTBOX.equals(message.folderType)) {
!EntityFolder.isOutgoing(message.folderType))
count++;
}
}
// Auto close when:

@ -1924,10 +1924,7 @@ public class ServiceSynchronize extends LifecycleService {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) {
try {
boolean outgoing = EntityFolder.DRAFTS.equals(folder.type) ||
EntityFolder.OUTBOX.equals(folder.type) ||
EntityFolder.SENT.equals(folder.type);
Address[] addresses = (outgoing ? message.to : message.from);
Address[] addresses = (folder.isOutgoing() ? message.to : message.from);
if (addresses != null)
for (int i = 0; i < addresses.length; i++) {

Loading…
Cancel
Save