Commit bb4851e4 authored by Thomas's avatar Thomas
Browse files

Some fixes with cache and notifications

parent ea1df98d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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 {
+2 −1
Original line number Diff line number Diff line
@@ -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) {
+10 −3
Original line number Diff line number Diff line
@@ -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;
                        }
                    }
                }
            }
+8 −0
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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;
Loading