Some fixes with cache and notifications
This commit is contained in:
parent
ea1df98d15
commit
bb4851e424
|
@ -35,6 +35,9 @@ public class Notification {
|
|||
public Account account;
|
||||
@SerializedName("status")
|
||||
public Status status;
|
||||
@SerializedName("cached")
|
||||
public boolean cached;
|
||||
|
||||
public PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM;
|
||||
|
||||
public enum PositionFetchMore {
|
||||
|
|
|
@ -358,7 +358,7 @@ public class StatusCache {
|
|||
throw new DBException("db is null. Wrong initialization.");
|
||||
}
|
||||
String order = " DESC";
|
||||
String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_SLUG + "= '" + Timeline.TimeLineEnum.NOTIFICATION.getValue() + "' ";
|
||||
String selection = Sqlite.COL_INSTANCE + "='" + instance + "' AND " + Sqlite.COL_USER_ID + "= '" + user_id + "' AND " + Sqlite.COL_TYPE + "= '" + Timeline.TimeLineEnum.NOTIFICATION.getValue() + "' ";
|
||||
String limit = String.valueOf(MastodonHelper.statusesPerCall(context));
|
||||
if (min_id != null) {
|
||||
selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + min_id + "' ";
|
||||
|
@ -369,6 +369,7 @@ public class StatusCache {
|
|||
selection += "AND " + Sqlite.COL_STATUS_ID + " > '" + since_id + "' ";
|
||||
limit = null;
|
||||
}
|
||||
|
||||
if (exclude_type != null && exclude_type.size() > 0) {
|
||||
StringBuilder exclude = new StringBuilder();
|
||||
for (String excluded : exclude_type) {
|
||||
|
|
|
@ -101,6 +101,9 @@ public class TimelineHelper {
|
|||
|
||||
//If there are filters:
|
||||
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) {
|
||||
for (Status status : statuses) {
|
||||
status.cached = cached;
|
||||
}
|
||||
for (Filter filter : BaseMainActivity.mainFilters) {
|
||||
if (filter.irreversible) { //Dealt by the server
|
||||
continue;
|
||||
|
@ -111,7 +114,6 @@ public class TimelineHelper {
|
|||
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)");
|
||||
for (Status status : statuses) {
|
||||
String content;
|
||||
status.cached = cached;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
|
@ -136,7 +138,6 @@ public class TimelineHelper {
|
|||
} else {
|
||||
for (Status status : statuses) {
|
||||
String content;
|
||||
status.cached = cached;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
|
@ -175,7 +176,7 @@ public class TimelineHelper {
|
|||
* @param notifications - List of {@link Notification}
|
||||
* @return filtered List<Status>
|
||||
*/
|
||||
public static List<Notification> filterNotification(Context context, List<Notification> notifications) {
|
||||
public static List<Notification> filterNotification(Context context, List<Notification> notifications, boolean cached) {
|
||||
//A security to make sure filters have been fetched before displaying messages
|
||||
List<Notification> notificationToRemove = new ArrayList<>();
|
||||
if (!BaseMainActivity.filterFetched) {
|
||||
|
@ -200,6 +201,7 @@ public class TimelineHelper {
|
|||
if (filter.whole_word) {
|
||||
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)");
|
||||
for (Notification notification : notifications) {
|
||||
notification.cached = cached;
|
||||
if (notification.status != null) {
|
||||
String content;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
|
@ -215,6 +217,7 @@ public class TimelineHelper {
|
|||
} else {
|
||||
for (Notification notification : notifications) {
|
||||
String content;
|
||||
notification.cached = cached;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(notification.status.content, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
|
@ -224,6 +227,10 @@ public class TimelineHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Notification notification : notifications) {
|
||||
notification.cached = cached;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,6 +186,11 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
} else {
|
||||
holderFollow.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
|
||||
}
|
||||
if (notification.cached) {
|
||||
holderFollow.binding.cacheIndicator.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holderFollow.binding.cacheIndicator.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
StatusAdapter.StatusViewHolder holderStatus = (StatusAdapter.StatusViewHolder) viewHolder;
|
||||
holderStatus.bindingNotification.status.typeOfNotification.setVisibility(View.VISIBLE);
|
||||
|
@ -205,6 +210,9 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
}
|
||||
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
|
||||
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
|
||||
if (notification.status != null) {
|
||||
notification.status.cached = notification.cached;
|
||||
}
|
||||
statusManagement(context, statusesVM, searchVM, holderStatus, this, null, notification.status, Timeline.TimeLineEnum.NOTIFICATION, false, true, null);
|
||||
holderStatus.bindingNotification.status.dateShort.setText(Helper.dateDiff(context, notification.created_at));
|
||||
holderStatus.bindingNotification.containerTransparent.setAlpha(.3f);
|
||||
|
|
|
@ -109,8 +109,8 @@ public class NotificationsVM extends AndroidViewModel {
|
|||
try {
|
||||
Response<List<Notification>> notificationsResponse = notificationsCall.execute();
|
||||
if (notificationsResponse.isSuccessful()) {
|
||||
notifications.notifications = notificationsResponse.body();
|
||||
TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications);
|
||||
List<Notification> notFiltered = notificationsResponse.body();
|
||||
notifications.notifications = TimelineHelper.filterNotification(getApplication().getApplicationContext(), notFiltered, false);
|
||||
addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams);
|
||||
notifications.pagination = MastodonHelper.getPagination(notificationsResponse.headers());
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class NotificationsVM extends AndroidViewModel {
|
|||
notifications = statusCacheDAO.getNotifications(timelineParams.excludeType, timelineParams.instance, timelineParams.userId, timelineParams.maxId, timelineParams.minId, timelineParams.sinceId);
|
||||
if (notifications != null) {
|
||||
if (notifications.notifications != null && notifications.notifications.size() > 0) {
|
||||
TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications);
|
||||
TimelineHelper.filterNotification(getApplication().getApplicationContext(), notifications.notifications, true);
|
||||
addFetchMoreNotifications(notifications.notifications, notificationList, timelineParams);
|
||||
notifications.pagination = new Pagination();
|
||||
notifications.pagination.min_id = notifications.notifications.get(0).id;
|
||||
|
|
|
@ -34,6 +34,17 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/cache_indicator"
|
||||
android:layout_width="16sp"
|
||||
android:layout_height="16sp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:src="@drawable/ic_baseline_cached_24"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
|
|
Loading…
Reference in New Issue