fixed wrong cursor indices

This commit is contained in:
Mariotaku Lee 2017-03-31 16:26:56 +08:00
parent 4ca81cac7d
commit e56176fda7
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
3 changed files with 13 additions and 13 deletions

View File

@ -31,6 +31,7 @@ import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.library.objectcursor.ObjectCursor;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.annotation.CustomTabType;
@ -38,7 +39,6 @@ import org.mariotaku.twidere.annotation.ReadPositionTag;
import org.mariotaku.twidere.fragment.InvalidTabFragment;
import org.mariotaku.twidere.model.SupportTabSpec;
import org.mariotaku.twidere.model.Tab;
import org.mariotaku.twidere.model.TabCursorIndices;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.model.tab.DrawableHolder;
import org.mariotaku.twidere.model.tab.TabConfiguration;
@ -56,7 +56,6 @@ public class CustomTabUtils implements Constants {
private CustomTabUtils() {
}
public static List<Tab> getTabs(@NonNull final Context context) {
final ContentResolver resolver = context.getContentResolver();
final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER);
@ -64,7 +63,7 @@ public class CustomTabUtils implements Constants {
try {
final ArrayList<Tab> tabs = new ArrayList<>();
cur.moveToFirst();
TabCursorIndices indices = new TabCursorIndices(cur);
ObjectCursor.CursorIndices<Tab> indices = ObjectCursor.indicesFrom(cur, Tab.class);
while (!cur.isAfterLast()) {
tabs.add(indices.newObject(cur));
cur.moveToNext();

View File

@ -46,6 +46,7 @@ import org.mariotaku.twidere.fragment.CursorActivitiesFragment
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.model.util.ParcelableActivityUtils
import org.mariotaku.twidere.model.util.getActivityStatus
import org.mariotaku.twidere.provider.TwidereDataStore.Activities
import org.mariotaku.twidere.util.IntentUtils
import org.mariotaku.twidere.util.OnLinkClickHandler
import org.mariotaku.twidere.util.TwidereLinkify
@ -115,8 +116,8 @@ class ParcelableActivitiesAdapter(
if (data is ObjectCursor) {
val cursor = (data as ObjectCursor).cursor
if (!cursor.moveToPosition(dataPosition)) return false
val indices = (data as ObjectCursor).indices as ParcelableActivityCursorIndices
return cursor.getShort(indices.is_gap).toInt() == 1
val indices = (data as ObjectCursor).indices
return cursor.getInt(indices[Activities.IS_GAP]) == 1
}
return data!![dataPosition].is_gap
}
@ -126,11 +127,11 @@ class ParcelableActivitiesAdapter(
if (data is ObjectCursor) {
val cursor = (data as ObjectCursor).cursor
if (!cursor.moveToPosition(dataPosition)) return -1
val indices = (data as ObjectCursor).indices as ParcelableActivityCursorIndices
val accountKey = UserKey.valueOf(cursor.getString(indices.account_key))
val timestamp = cursor.getLong(indices.timestamp)
val maxPosition = cursor.getLong(indices.max_position)
val minPosition = cursor.getLong(indices.min_position)
val indices = (data as ObjectCursor).indices
val accountKey = UserKey.valueOf(cursor.getString(indices[Activities.ACCOUNT_KEY]))
val timestamp = cursor.getLong(indices[Activities.TIMESTAMP])
val maxPosition = cursor.getLong(indices[Activities.MAX_SORT_POSITION])
val minPosition = cursor.getLong(indices[Activities.MIN_SORT_POSITION])
return ParcelableActivity.calculateHashCode(accountKey, timestamp, maxPosition,
minPosition).toLong()
}
@ -143,8 +144,8 @@ class ParcelableActivitiesAdapter(
if (data is ObjectCursor) {
val cursor = (data as ObjectCursor).cursor
if (!cursor.safeMoveToPosition(dataPosition)) return -1
val indices = (data as ObjectCursor).indices as ParcelableActivityCursorIndices
return cursor.getLong(indices.timestamp)
val indices = (data as ObjectCursor).indices
return cursor.getLong(indices[Activities.TIMESTAMP])
}
return getActivity(adapterPosition, raw).timestamp
}

View File

@ -161,7 +161,7 @@ abstract class ParcelableStatusesAdapter(
val cursor = (data as ObjectCursor).cursor
if (!cursor.moveToPosition(dataPosition)) return false
val indices = (data as ObjectCursor).indices
return cursor.getShort(indices[Statuses.STATUS_ID]).toInt() == 1
return cursor.getInt(indices[Statuses.IS_GAP]) == 1
}
return getStatus(position).is_gap
}