migrating to string ids
This commit is contained in:
parent
2456f710e5
commit
d6061bf3ec
|
@ -48,7 +48,7 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
|
|||
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<Status>,
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -90,21 +90,19 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
|
|||
final boolean noItemsBefore = DataStoreUtils.getStatusCount(context, uri, accountKey) <= 0;
|
||||
final ContentValues[] values = new ContentValues[statuses.size()];
|
||||
final String[] statusIds = new String[statuses.size()];
|
||||
String minId = null;
|
||||
int minIdx = -1;
|
||||
boolean hasIntersection = false;
|
||||
for (int i = 0, j = statuses.size(); i < j; i++) {
|
||||
final Status status = statuses.get(i);
|
||||
values[i] = ContentValuesCreator.createStatus(status, accountKey);
|
||||
values[i].put(Statuses.INSERTED_DATE, System.currentTimeMillis());
|
||||
if (minIdx == -1 || status.compareTo(statuses.get(minIdx)) < 0) {
|
||||
minIdx = i;
|
||||
}
|
||||
final String id = status.getId();
|
||||
if (sinceId != null && id <= sinceId) {
|
||||
hasIntersection = true;
|
||||
}
|
||||
if (minId == null || id < minId) {
|
||||
minId = id;
|
||||
minIdx = i;
|
||||
}
|
||||
statusIds[i] = id;
|
||||
}
|
||||
// Delete all rows conflicting before new data inserted.
|
||||
|
@ -134,9 +132,9 @@ public abstract class GetStatusesTask extends AbstractTask<RefreshTaskParam,
|
|||
// Insert a gap.
|
||||
final boolean deletedOldGap = rowsDeleted > 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.
|
||||
|
|
Loading…
Reference in New Issue