Fix filters
This commit is contained in:
parent
2625101883
commit
ee68f4fc7d
|
@ -60,17 +60,6 @@ public class TimelineHelper {
|
||||||
return retrofit.create(MastodonAccountsService.class);
|
return retrofit.create(MastodonAccountsService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows to filter statuses, should be called in API calls (background)
|
|
||||||
*
|
|
||||||
* @param context - Context
|
|
||||||
* @param statuses - List of {@link Status}
|
|
||||||
* @param filterTimeLineType - {@link Timeline.TimeLineEnum}
|
|
||||||
* @return filtered List<Status>
|
|
||||||
*/
|
|
||||||
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
|
|
||||||
return filterStatus(context, statuses, filterTimeLineType, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to filter statuses, should be called in API calls (background)
|
* Allows to filter statuses, should be called in API calls (background)
|
||||||
|
@ -80,7 +69,7 @@ public class TimelineHelper {
|
||||||
* @param filterTimeLineType - {@link Timeline.TimeLineEnum}
|
* @param filterTimeLineType - {@link Timeline.TimeLineEnum}
|
||||||
* @return filtered List<Status>
|
* @return filtered List<Status>
|
||||||
*/
|
*/
|
||||||
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType, boolean cached) {
|
public static List<Status> filterStatus(Context context, List<Status> statuses, Timeline.TimeLineEnum filterTimeLineType) {
|
||||||
//A security to make sure filters have been fetched before displaying messages
|
//A security to make sure filters have been fetched before displaying messages
|
||||||
List<Status> statusesToRemove = new ArrayList<>();
|
List<Status> statusesToRemove = new ArrayList<>();
|
||||||
if (!BaseMainActivity.filterFetched) {
|
if (!BaseMainActivity.filterFetched) {
|
||||||
|
@ -102,9 +91,6 @@ public class TimelineHelper {
|
||||||
}
|
}
|
||||||
//If there are filters:
|
//If there are filters:
|
||||||
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) {
|
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) {
|
for (Filter filter : BaseMainActivity.mainFilters) {
|
||||||
if (filter.irreversible) { //Dealt by the server
|
if (filter.irreversible) { //Dealt by the server
|
||||||
continue;
|
continue;
|
||||||
|
@ -200,7 +186,7 @@ public class TimelineHelper {
|
||||||
for (String filterContext : filter.context) {
|
for (String filterContext : filter.context) {
|
||||||
if (Timeline.TimeLineEnum.NOTIFICATION.getValue().equalsIgnoreCase(filterContext)) {
|
if (Timeline.TimeLineEnum.NOTIFICATION.getValue().equalsIgnoreCase(filterContext)) {
|
||||||
if (filter.whole_word) {
|
if (filter.whole_word) {
|
||||||
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)");
|
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)", Pattern.CASE_INSENSITIVE);
|
||||||
for (Notification notification : notifications) {
|
for (Notification notification : notifications) {
|
||||||
notification.cached = cached;
|
notification.cached = cached;
|
||||||
if (notification.status != null) {
|
if (notification.status != null) {
|
||||||
|
|
|
@ -413,9 +413,12 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
List<Status> statusList = timelineResponse.body();
|
List<Status> statusList = timelineResponse.body();
|
||||||
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
||||||
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
||||||
|
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
||||||
|
//Fetch More is added on filtered statuses
|
||||||
|
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
||||||
|
//All statuses (even filtered will be added to cache)
|
||||||
if (statusList != null && statusList.size() > 0) {
|
if (statusList != null && statusList.size() > 0) {
|
||||||
addFetchMore(statusList, timelineStatuses, timelineParams);
|
for (Status status : statusList) {
|
||||||
for (Status status : statuses.statuses) {
|
|
||||||
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
||||||
StatusCache statusCache = new StatusCache();
|
StatusCache statusCache = new StatusCache();
|
||||||
statusCache.instance = timelineParams.instance;
|
statusCache.instance = timelineParams.instance;
|
||||||
|
@ -433,6 +436,7 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -465,7 +469,7 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
//Only not already present statuses are added
|
//Only not already present statuses are added
|
||||||
statusesDb.statuses = notPresentStatuses;
|
statusesDb.statuses = notPresentStatuses;
|
||||||
}
|
}
|
||||||
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type, true);
|
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusesDb.statuses, timelineParams.type);
|
||||||
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
||||||
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
||||||
statuses.pagination = new Pagination();
|
statuses.pagination = new Pagination();
|
||||||
|
|
Loading…
Reference in New Issue