diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java index e926c6eec..21ffd7633 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/Status.java @@ -48,7 +48,7 @@ public class Status extends TwitterResponseObject implements Comparable, String id; @JsonField(name = "raw_id") - long rawId; + long rawId = -1; @JsonField(name = "text") String text; @@ -325,7 +325,14 @@ public class Status extends TwitterResponseObject implements Comparable, public int compareTo(@NonNull final Status that) { final int delta = createdAt.compareTo(that.createdAt); if (delta == 0) { - // TODO compare with raw id + if (rawId != -1) { + return (int) (rawId - that.rawId); + } + try { + return (int) (Long.parseLong(id) - Long.parseLong(that.id)); + } catch (NumberFormatException e) { + // Ignore + } } return delta; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java index 646b63134..310af47ed 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/TwitterAPIStatusesLoader.java @@ -146,18 +146,14 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader } final String[] statusIds = new String[statuses.size()]; - String minId = null; int minIdx = -1; int rowsDeleted = 0; for (int i = 0, j = statuses.size(); i < j; i++) { final Status status = statuses.get(i); - final String id = status.getId(); - if (minId == null || id < minId) { - minId = id; + if (minIdx == -1 || status.compareTo(statuses.get(minIdx)) < 0) { minIdx = i; } - statusIds[i] = id; - + statusIds[i] = status.getId(); if (deleteStatus(data, status.getId())) { rowsDeleted++; } @@ -166,7 +162,7 @@ public abstract class TwitterAPIStatusesLoader extends ParcelableStatusesLoader // Insert a gap. final boolean deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, mMaxId); final boolean noRowsDeleted = rowsDeleted == 0; - final boolean insertGap = minId != null && (noRowsDeleted || deletedOldGap) && !noItemsBefore + final boolean insertGap = minIdx != -1 && (noRowsDeleted || deletedOldGap) && !noItemsBefore && statuses.size() >= loadItemLimit; for (int i = 0, j = statuses.size(); i < j; i++) { final Status status = statuses.get(i); diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java index 8c8d331fa..8a049d1f5 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetStatusesTask.java @@ -90,21 +90,19 @@ public abstract class GetStatusesTask extends AbstractTask 0 && ArrayUtils.contains(statusIds, maxId); final boolean noRowsDeleted = rowsDeleted == 0; - final boolean insertGap = minId != null && (noRowsDeleted || deletedOldGap) && !noItemsBefore + final boolean insertGap = minIdx != -1 && (noRowsDeleted || deletedOldGap) && !noItemsBefore && !hasIntersection; - if (insertGap && minIdx != -1) { + if (insertGap) { values[minIdx].put(Statuses.IS_GAP, true); } // Insert previously fetched items.