1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-28 18:59:01 +00:00

Day headers can change

This commit is contained in:
M66B 2019-01-20 13:27:35 +00:00
parent e38a5346b2
commit ff15246ce2
2 changed files with 31 additions and 21 deletions

View file

@ -403,27 +403,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvSubject.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
boolean day;
TupleMessageEx prev = (position == 0 ? null : differ.getItem(position - 1));
if (prev == null)
day = true;
else {
Calendar cal0 = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal0.setTimeInMillis(prev.received);
cal1.setTimeInMillis(message.received);
int day0 = cal0.get(Calendar.DAY_OF_YEAR);
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
day = (day0 != day1);
}
if (day)
TupleMessageEx prev = null;
if (position > 0)
prev = differ.getItem(position - 1);
message.day = getDay(prev, message);
if (message.day)
tvDay.setText(
DateUtils.getRelativeTimeSpanString(
message.received,
new Date().getTime(),
DAY_IN_MILLIS, 0));
grpDay.setVisibility(day ? View.VISIBLE : View.GONE);
grpDay.setVisibility(message.day ? View.VISIBLE : View.GONE);
itemView.setAlpha(message.uid == null && !EntityFolder.OUTBOX.equals(message.folderType)
? Helper.LOW_LIGHT : 1.0f);
@ -2083,9 +2073,29 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
void submitList(PagedList<TupleMessageEx> pagedList) {
TupleMessageEx prev = null;
for (TupleMessageEx message : pagedList) {
if (message != null)
message.day = getDay(prev, message);
prev = message;
}
differ.submitList(pagedList);
}
boolean getDay(TupleMessageEx prev, TupleMessageEx cur) {
if (prev == null)
return true;
Calendar cal0 = Calendar.getInstance();
Calendar cal1 = Calendar.getInstance();
cal0.setTimeInMillis(prev.received);
cal1.setTimeInMillis(cur.received);
int day0 = cal0.get(Calendar.DAY_OF_YEAR);
int day1 = cal1.get(Calendar.DAY_OF_YEAR);
return (day0 != day1);
}
PagedList<TupleMessageEx> getCurrentList() {
return differ.getCurrentList();
}

View file

@ -23,7 +23,6 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@ -33,8 +32,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import javax.mail.Address;
@ -42,6 +39,7 @@ import javax.mail.Address;
import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;
@ -143,7 +141,8 @@ public class EntityMessage implements Serializable {
public String error; // volatile
public Long last_attempt; // send
private static final Map<String, Uri> emailLookupUri = new HashMap<>();
@Ignore
public boolean day = false;
static String generateMessageId() {
StringBuilder sb = new StringBuilder();
@ -260,7 +259,8 @@ public class EntityMessage implements Serializable {
this.ui_browsed.equals(other.ui_browsed) &&
(this.ui_snoozed == null ? other.ui_snoozed == null : this.ui_snoozed.equals(other.ui_snoozed)) &&
(this.warning == null ? other.warning == null : this.warning.equals(other.warning)) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
(this.error == null ? other.error == null : this.error.equals(other.error)) &&
this.day == other.day);
}
return false;
}