improved save position
This commit is contained in:
parent
59566d966b
commit
e1df9771a6
|
@ -344,9 +344,14 @@ class ParcelableActivitiesAdapter(
|
|||
return start
|
||||
}
|
||||
|
||||
|
||||
fun findPositionBySortTimestamp(timestamp: Long): Int {
|
||||
return rangeOfSize(activityStartIndex, activityCount - 1).indexOfFirst { timestamp > 0 && getTimestamp(it) <= timestamp }
|
||||
if (timestamp <= 0) return RecyclerView.NO_POSITION
|
||||
val range = rangeOfSize(activityStartIndex, activityCount - 1)
|
||||
if (range.isEmpty()) return RecyclerView.NO_POSITION
|
||||
if (timestamp < getTimestamp(range.last)) {
|
||||
return range.last
|
||||
}
|
||||
return range.indexOfFirst { timestamp >= getTimestamp(it) }
|
||||
}
|
||||
|
||||
interface ActivityAdapterListener {
|
||||
|
@ -370,12 +375,10 @@ class ParcelableActivitiesAdapter(
|
|||
|
||||
internal class StubViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
val text1: TextView
|
||||
val text2: TextView
|
||||
internal val text1 = itemView.findViewById(android.R.id.text1) as TextView
|
||||
internal val text2 = itemView.findViewById(android.R.id.text2) as TextView
|
||||
|
||||
init {
|
||||
text1 = itemView.findViewById(android.R.id.text1) as TextView
|
||||
text2 = itemView.findViewById(android.R.id.text2) as TextView
|
||||
|
||||
text2.setSingleLine(false)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.mariotaku.twidere.util.MediaLoadingHandler
|
|||
import org.mariotaku.twidere.util.StatusAdapterLinkClickHandler
|
||||
import org.mariotaku.twidere.util.TwidereLinkify
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
import org.mariotaku.twidere.view.CardMediaContainer
|
||||
import org.mariotaku.twidere.view.holder.EmptyViewHolder
|
||||
import org.mariotaku.twidere.view.holder.GapViewHolder
|
||||
import org.mariotaku.twidere.view.holder.LoadIndicatorViewHolder
|
||||
|
@ -390,13 +389,25 @@ abstract class ParcelableStatusesAdapter(
|
|||
fun findPositionByPositionKey(positionKey: Long): Int {
|
||||
// Assume statuses are descend sorted by id, so break at first status with id
|
||||
// lesser equals than read position
|
||||
return rangeOfSize(statusStartIndex, statusCount - 1).indexOfFirst { positionKey > 0 && getStatusPositionKey(it) <= positionKey }
|
||||
if (positionKey <= 0) return RecyclerView.NO_POSITION
|
||||
val range = rangeOfSize(statusStartIndex, statusCount - 1)
|
||||
if (range.isEmpty()) return RecyclerView.NO_POSITION
|
||||
if (positionKey < getStatusPositionKey(range.last)) {
|
||||
return range.last
|
||||
}
|
||||
return range.indexOfFirst { positionKey >= getStatusPositionKey(it) }
|
||||
}
|
||||
|
||||
fun findPositionBySortId(sortId: Long): Int {
|
||||
// Assume statuses are descend sorted by id, so break at first status with id
|
||||
// lesser equals than read position
|
||||
return rangeOfSize(statusStartIndex, statusCount - 1).indexOfFirst { sortId > 0 && getStatusSortId(it) <= sortId }
|
||||
if (sortId <= 0) return RecyclerView.NO_POSITION
|
||||
val range = rangeOfSize(statusStartIndex, statusCount - 1)
|
||||
if (range.isEmpty()) return RecyclerView.NO_POSITION
|
||||
if (sortId < getStatusSortId(range.last)) {
|
||||
return range.last
|
||||
}
|
||||
return range.indexOfFirst { sortId >= getStatusSortId(it) }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mariotaku.twidere.model.util
|
||||
|
||||
import android.text.TextUtils
|
||||
import org.mariotaku.ktextension.isNotNullOrEmpty
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
|
@ -44,7 +45,7 @@ object ParcelableUserUtils {
|
|||
obj.profile_background_url = user.profileBackgroundImageUrl
|
||||
}
|
||||
obj.url = user.url
|
||||
if (obj.url != null && urlEntities != null && urlEntities.size > 0) {
|
||||
if (obj.url != null && urlEntities.isNotNullOrEmpty()) {
|
||||
obj.url_expanded = urlEntities[0].expandedUrl
|
||||
}
|
||||
obj.is_follow_request_sent = user.isFollowRequestSent
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.mariotaku.microblog.library.twitter.model.Paging
|
|||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
import org.mariotaku.twidere.extension.model.setFrom
|
||||
import org.mariotaku.twidere.extension.model.timestamp
|
||||
|
@ -50,9 +51,9 @@ class GetMessagesTask(context: Context) : BaseAbstractTask<RefreshTaskParam, Uni
|
|||
}
|
||||
AccountType.TWITTER -> {
|
||||
// Use official DM api
|
||||
// if (details.isOfficial(context)) {
|
||||
// return getTwitterOfficialMessages(microBlog)
|
||||
// }
|
||||
if (details.isOfficial(context)) {
|
||||
return getTwitterOfficialMessages(microBlog, details)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Use default method
|
||||
|
@ -63,8 +64,8 @@ class GetMessagesTask(context: Context) : BaseAbstractTask<RefreshTaskParam, Uni
|
|||
return GetMessagesData(emptyList(), emptyList(), emptyList())
|
||||
}
|
||||
|
||||
private fun getTwitterOfficialMessages(microBlog: MicroBlog): GetMessagesData {
|
||||
return GetMessagesData(emptyList(), emptyList(), emptyList())
|
||||
private fun getTwitterOfficialMessages(microBlog: MicroBlog, details: AccountDetails): GetMessagesData {
|
||||
return getDefaultMessages(microBlog, details)
|
||||
}
|
||||
|
||||
private fun getDefaultMessages(microBlog: MicroBlog, details: AccountDetails): GetMessagesData {
|
||||
|
|
|
@ -148,8 +148,7 @@ abstract class GetActivitiesTask(
|
|||
}
|
||||
|
||||
activity.inserted_date = System.currentTimeMillis()
|
||||
val values = ContentValuesCreator.createActivity(activity,
|
||||
details, userColorNameManager)
|
||||
val values = ContentValuesCreator.createActivity(activity, details)
|
||||
valuesList.add(values)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,10 @@ import org.mariotaku.twidere.model.util.ParcelableStatusUtils
|
|||
import org.mariotaku.twidere.model.util.ParcelableUserUtils
|
||||
import org.mariotaku.twidere.model.util.getActivityStatus
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.*
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
object ContentValuesCreator {
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun createCachedUser(user: User): ContentValues {
|
||||
val values = ContentValues()
|
||||
ParcelableUserValuesCreator.writeTo(ParcelableUserUtils.fromUser(user, null), values)
|
||||
|
@ -96,16 +94,12 @@ object ContentValuesCreator {
|
|||
return savedSearches.map { createSavedSearch(it, accountKey) }.toTypedArray()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun createStatus(orig: Status, accountKey: UserKey): ContentValues {
|
||||
return ParcelableStatusValuesCreator.create(ParcelableStatusUtils.fromStatus(orig,
|
||||
accountKey, false))
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun createActivity(activity: ParcelableActivity,
|
||||
details: AccountDetails,
|
||||
manager: UserColorNameManager): ContentValues {
|
||||
fun createActivity(activity: ParcelableActivity, details: AccountDetails): ContentValues {
|
||||
val values = ContentValues()
|
||||
val status = activity.getActivityStatus()
|
||||
|
||||
|
|
Loading…
Reference in New Issue