mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
New group notifications management ui.
This commit is contained in:
committed by
Greyson Parrelli
parent
a2de8a2a05
commit
c3832cf8b1
@@ -42,6 +42,10 @@ public class DateUtils extends android.text.format.DateUtils {
|
||||
return System.currentTimeMillis() - millis <= unit.toMillis(span);
|
||||
}
|
||||
|
||||
private static boolean isWithinAbs(final long millis, final long span, final TimeUnit unit) {
|
||||
return Math.abs(System.currentTimeMillis() - millis) <= unit.toMillis(span);
|
||||
}
|
||||
|
||||
private static boolean isYesterday(final long when) {
|
||||
return DateUtils.isToday(when + TimeUnit.DAYS.toMillis(1));
|
||||
}
|
||||
@@ -92,6 +96,20 @@ public class DateUtils extends android.text.format.DateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTimeString(final Context c, final Locale locale, final long timestamp) {
|
||||
StringBuilder format = new StringBuilder();
|
||||
|
||||
if (isSameDay(System.currentTimeMillis(), timestamp)) format.append("");
|
||||
else if (isWithinAbs(timestamp, 6, TimeUnit.DAYS)) format.append("EEE ");
|
||||
else if (isWithinAbs(timestamp, 364, TimeUnit.DAYS)) format.append("MMM d, ");
|
||||
else format.append("MMM d, yyyy, ");
|
||||
|
||||
if (DateFormat.is24HourFormat(c)) format.append("HH:mm");
|
||||
else format.append("hh:mm a");
|
||||
|
||||
return getFormattedDateTime(timestamp, format.toString(), locale);
|
||||
}
|
||||
|
||||
public static String getDayPrecisionTimeSpanString(Context context, Locale locale, long timestamp) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.thoughtcrime.securesms.util.livedata;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MediatorLiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.annimon.stream.function.Predicate;
|
||||
|
||||
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
|
||||
import org.whispersystems.libsignal.util.guava.Function;
|
||||
@@ -14,6 +17,26 @@ public final class LiveDataUtil {
|
||||
private LiveDataUtil() {
|
||||
}
|
||||
|
||||
public static @NonNull <A> LiveData<A> filterNotNull(@NonNull LiveData<A> source) {
|
||||
//noinspection Convert2MethodRef
|
||||
return filter(source, a -> a != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters output of a given live data based off a predicate.
|
||||
*/
|
||||
public static @NonNull <A> LiveData<A> filter(@NonNull LiveData<A> source, @NonNull Predicate<A> predicate) {
|
||||
MediatorLiveData<A> mediator = new MediatorLiveData<>();
|
||||
|
||||
mediator.addSource(source, newValue -> {
|
||||
if (predicate.test(newValue)) {
|
||||
mediator.setValue(newValue);
|
||||
}
|
||||
});
|
||||
|
||||
return mediator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the {@param backgroundFunction} on {@link SignalExecutors#BOUNDED}.
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user