mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-22 23:58:47 +01:00
Timeline: get better perf
This commit is contained in:
parent
f06211ce4f
commit
6c7bc2b40c
@ -17,12 +17,9 @@
|
||||
package im.vector.riotredesign.core.extensions
|
||||
|
||||
import im.vector.matrix.android.api.session.events.model.Event
|
||||
import org.threeten.bp.Instant
|
||||
import im.vector.riotredesign.core.resources.DateProvider
|
||||
import org.threeten.bp.LocalDateTime
|
||||
import org.threeten.bp.ZoneId
|
||||
|
||||
|
||||
fun Event.localDateTime(): LocalDateTime {
|
||||
val instant = Instant.ofEpochMilli(originServerTs ?: 0)
|
||||
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault())
|
||||
return DateProvider.toLocalDateTime(originServerTs)
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.riotredesign.core.resources
|
||||
|
||||
import org.threeten.bp.Instant
|
||||
import org.threeten.bp.LocalDateTime
|
||||
import org.threeten.bp.ZoneId
|
||||
|
||||
object DateProvider {
|
||||
|
||||
private val zoneId = ZoneId.systemDefault()
|
||||
|
||||
fun toLocalDateTime(timestamp: Long?): LocalDateTime {
|
||||
val instant = Instant.ofEpochMilli(timestamp ?: 0)
|
||||
return LocalDateTime.ofInstant(instant, zoneId)
|
||||
}
|
||||
|
||||
}
|
@ -30,13 +30,13 @@ class HomeNavigator {
|
||||
|
||||
var activity: HomeActivity? = null
|
||||
|
||||
private var currentRoomId: String? = null
|
||||
private var rootRoomId: String? = null
|
||||
|
||||
fun openRoomDetail(roomId: String,
|
||||
eventId: String?,
|
||||
addToBackstack: Boolean = false) {
|
||||
Timber.v("Open room detail $roomId - $eventId - $addToBackstack")
|
||||
if (!addToBackstack && isRoomOpened(roomId)) {
|
||||
if (!addToBackstack && isRoot(roomId)) {
|
||||
return
|
||||
}
|
||||
activity?.let {
|
||||
@ -46,7 +46,7 @@ class HomeNavigator {
|
||||
if (addToBackstack) {
|
||||
it.addFragmentToBackstack(roomDetailFragment, R.id.homeDetailFragmentContainer, roomId)
|
||||
} else {
|
||||
currentRoomId = roomId
|
||||
rootRoomId = roomId
|
||||
clearBackStack(it.supportFragmentManager)
|
||||
it.replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer)
|
||||
}
|
||||
@ -61,9 +61,7 @@ class HomeNavigator {
|
||||
Timber.v("Open user detail $userId")
|
||||
}
|
||||
|
||||
fun isRoomOpened(roomId: String): Boolean {
|
||||
return currentRoomId == roomId
|
||||
}
|
||||
// Private Methods *****************************************************************************
|
||||
|
||||
private fun clearBackStack(fragmentManager: FragmentManager) {
|
||||
if (fragmentManager.backStackEntryCount > 0) {
|
||||
@ -72,4 +70,8 @@ class HomeNavigator {
|
||||
}
|
||||
}
|
||||
|
||||
private fun isRoot(roomId: String): Boolean {
|
||||
return rootRoomId == roomId
|
||||
}
|
||||
|
||||
}
|
@ -37,9 +37,6 @@ class TimelineEventController(private val roomId: String,
|
||||
EpoxyAsyncUtil.getAsyncBackgroundHandler(),
|
||||
EpoxyAsyncUtil.getAsyncBackgroundHandler()
|
||||
) {
|
||||
init {
|
||||
setFilterDuplicates(true)
|
||||
}
|
||||
|
||||
private var isLoadingForward: Boolean = false
|
||||
private var isLoadingBackward: Boolean = false
|
||||
|
@ -34,22 +34,23 @@ internal class RoomMemberExtractor(private val monarchy: Monarchy,
|
||||
private val cached = HashMap<String, RoomMember?>()
|
||||
|
||||
fun extractFrom(event: EventEntity): RoomMember? {
|
||||
if (cached.containsKey(event.eventId)) {
|
||||
return cached[event.eventId]
|
||||
}
|
||||
val sender = event.sender ?: return null
|
||||
val cacheKey = sender + event.stateIndex
|
||||
if (cached.containsKey(cacheKey)) {
|
||||
return cached[cacheKey]
|
||||
}
|
||||
// If the event is unlinked we want to fetch unlinked state events
|
||||
val unlinked = event.isUnlinked
|
||||
// When stateIndex is negative, we try to get the next stateEvent prevContent()
|
||||
// If prevContent is null we fallback to the Int.MIN state events content()
|
||||
val content = if (event.stateIndex <= 0) {
|
||||
baseQuery(monarchy, roomId, sender, unlinked).next(from = event.stateIndex)?.prevContent
|
||||
?: baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content
|
||||
?: baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content
|
||||
} else {
|
||||
baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content
|
||||
}
|
||||
val roomMember: RoomMember? = ContentMapper.map(content).toModel()
|
||||
cached[event.eventId] = roomMember
|
||||
cached[cacheKey] = roomMember
|
||||
return roomMember
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user