2022-01-11 19:00:29 +01:00
|
|
|
/* Copyright 2021 Tusky Contributors
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky.components.timeline
|
|
|
|
|
Keep scroll position when loading missing statuses (#3000)
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Ensure the user can't have two simultaneous "Load more" coroutines
Having two simultanous coroutines would break the calculation used to figure
out which item in the list to scroll to after a "Load more" in the timeline.
Do this by:
- Creating a TimelineUiState and associated flow that tracks the "Load more"
state
- Updating this in the (Cached|Network)TimelineViewModel
- Listening for changes to it in TimelineFragment, and notifying the adapter
- The adapter will disable any placeholder views while "Load more" is active
* Revert changes that loaded the oldest statuses instead of the newest
* Be more robust about locating the status to scroll to
Weirdness with the PagingData library meant that positionStart could still be
wrong after "Load more" was clicked.
Instead, remember the position of the "Load more" item and the ID of the
status immediately after it.
When new items are added, search for the remembered status at the position of
the "Load more" item. This is quick, testing at most LOAD_AT_ONCE items in
the adapter.
If the remembered status is not visible on screen then scroll to it.
* Lint
* Add a preference to specify the reading order
Default behaviour (oldest first) is for "load more" to load statuses and
stay at the oldest of the new statuses.
Alternative behaviour (if the user is reading from top to bottom) is to
stay at the newest of the new statuses.
* Move ReadingOrder enum construction logic in to the enum
* Jump to top if swipe/refresh while preferring newest-first order
* Show a circular progress spinner during "Load more" operations
Remove a dedicated view, and use an icon on the button instead.
Adjust the placeholder attributes and styles accordingly.
* Remove the "loadMoreActive" property
Complicates the code and doesn't really achieve the desired effect. If the
user wants to tap multiple "Load more" buttons they can.
* Update comments in TimelineFragment
* Respect the user's reading order preference if it changes
* Add developer tools
This is for functionality that makes it easier for developers to interact
with the app, or get it in to a known-state.
These features are for use by users, so are only visible in debug builds.
* Adjust how content is loaded based on preferred reading order
- Add the readingOrder to TimelineViewModel so derived classes can use it.
- Update the homeTimeline API to support the `minId` parameter and update
calls in NetworkTimelineViewModel
In CachedTimelineViewModel:
- Set the bounds of the load to be the status IDs on either side of the
placeholder ID (update TimelineDao with a new query for this)
- Load statuses using either minId or sinceId depending on the reading order
- Is there was no overlap then insert the new placeholder at the start/end
of the list depending on reading order
* Lint
* Rename unused dialog parameter to _
* Update API arguments in tests
* Simplify ReadingOrder preference handling
* Fix bug with Placeholder and the "expanded" property
If a status is a Placeholder the "expanded" propery is used to indicate
whether or not it is loading.
replaceStatusRange() set this property based on the old value, and the user's
alwaysOpenSpoiler preference setting.
This shouldn't have been used if the status is a Placeholder, as it can lead
to incorrect loading states.
Fix this.
While I'm here, introduce an explicit computed property for whether a
TimelineStatusEntity is a placeholder, and use that for code clarity.
* Set the "Load more" button background to transparent
* Fix typo.
* Inline spec, update comment
* Revert 1480c6aa3ac5c0c2d362fb271f47ea2259ab14e2
Turns out the behaviour is not desired.
* Remove unnecessary Log call
* Extract function
* Change default to newest first
2023-01-13 19:26:24 +01:00
|
|
|
import android.util.Log
|
2022-01-11 19:00:29 +01:00
|
|
|
import com.google.gson.Gson
|
|
|
|
import com.google.gson.reflect.TypeToken
|
|
|
|
import com.keylesspalace.tusky.db.TimelineAccountEntity
|
|
|
|
import com.keylesspalace.tusky.db.TimelineStatusEntity
|
|
|
|
import com.keylesspalace.tusky.db.TimelineStatusWithAccount
|
|
|
|
import com.keylesspalace.tusky.entity.Attachment
|
2022-05-05 18:27:05 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Card
|
2022-01-11 19:00:29 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Emoji
|
2022-02-25 18:56:21 +01:00
|
|
|
import com.keylesspalace.tusky.entity.HashTag
|
2022-01-11 19:00:29 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Poll
|
|
|
|
import com.keylesspalace.tusky.entity.Status
|
2022-03-15 21:34:57 +01:00
|
|
|
import com.keylesspalace.tusky.entity.TimelineAccount
|
2022-01-11 19:00:29 +01:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData
|
|
|
|
import java.util.Date
|
|
|
|
|
Keep scroll position when loading missing statuses (#3000)
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Ensure the user can't have two simultaneous "Load more" coroutines
Having two simultanous coroutines would break the calculation used to figure
out which item in the list to scroll to after a "Load more" in the timeline.
Do this by:
- Creating a TimelineUiState and associated flow that tracks the "Load more"
state
- Updating this in the (Cached|Network)TimelineViewModel
- Listening for changes to it in TimelineFragment, and notifying the adapter
- The adapter will disable any placeholder views while "Load more" is active
* Revert changes that loaded the oldest statuses instead of the newest
* Be more robust about locating the status to scroll to
Weirdness with the PagingData library meant that positionStart could still be
wrong after "Load more" was clicked.
Instead, remember the position of the "Load more" item and the ID of the
status immediately after it.
When new items are added, search for the remembered status at the position of
the "Load more" item. This is quick, testing at most LOAD_AT_ONCE items in
the adapter.
If the remembered status is not visible on screen then scroll to it.
* Lint
* Add a preference to specify the reading order
Default behaviour (oldest first) is for "load more" to load statuses and
stay at the oldest of the new statuses.
Alternative behaviour (if the user is reading from top to bottom) is to
stay at the newest of the new statuses.
* Move ReadingOrder enum construction logic in to the enum
* Jump to top if swipe/refresh while preferring newest-first order
* Show a circular progress spinner during "Load more" operations
Remove a dedicated view, and use an icon on the button instead.
Adjust the placeholder attributes and styles accordingly.
* Remove the "loadMoreActive" property
Complicates the code and doesn't really achieve the desired effect. If the
user wants to tap multiple "Load more" buttons they can.
* Update comments in TimelineFragment
* Respect the user's reading order preference if it changes
* Add developer tools
This is for functionality that makes it easier for developers to interact
with the app, or get it in to a known-state.
These features are for use by users, so are only visible in debug builds.
* Adjust how content is loaded based on preferred reading order
- Add the readingOrder to TimelineViewModel so derived classes can use it.
- Update the homeTimeline API to support the `minId` parameter and update
calls in NetworkTimelineViewModel
In CachedTimelineViewModel:
- Set the bounds of the load to be the status IDs on either side of the
placeholder ID (update TimelineDao with a new query for this)
- Load statuses using either minId or sinceId depending on the reading order
- Is there was no overlap then insert the new placeholder at the start/end
of the list depending on reading order
* Lint
* Rename unused dialog parameter to _
* Update API arguments in tests
* Simplify ReadingOrder preference handling
* Fix bug with Placeholder and the "expanded" property
If a status is a Placeholder the "expanded" propery is used to indicate
whether or not it is loading.
replaceStatusRange() set this property based on the old value, and the user's
alwaysOpenSpoiler preference setting.
This shouldn't have been used if the status is a Placeholder, as it can lead
to incorrect loading states.
Fix this.
While I'm here, introduce an explicit computed property for whether a
TimelineStatusEntity is a placeholder, and use that for code clarity.
* Set the "Load more" button background to transparent
* Fix typo.
* Inline spec, update comment
* Revert 1480c6aa3ac5c0c2d362fb271f47ea2259ab14e2
Turns out the behaviour is not desired.
* Remove unnecessary Log call
* Extract function
* Change default to newest first
2023-01-13 19:26:24 +01:00
|
|
|
private const val TAG = "TimelineTypeMappers"
|
|
|
|
|
2022-01-11 19:00:29 +01:00
|
|
|
data class Placeholder(
|
|
|
|
val id: String,
|
|
|
|
val loading: Boolean
|
|
|
|
)
|
|
|
|
|
|
|
|
private val attachmentArrayListType = object : TypeToken<ArrayList<Attachment>>() {}.type
|
|
|
|
private val emojisListType = object : TypeToken<List<Emoji>>() {}.type
|
|
|
|
private val mentionListType = object : TypeToken<List<Status.Mention>>() {}.type
|
2022-02-25 18:56:21 +01:00
|
|
|
private val tagListType = object : TypeToken<List<HashTag>>() {}.type
|
2022-01-11 19:00:29 +01:00
|
|
|
|
2022-03-15 21:34:57 +01:00
|
|
|
fun TimelineAccount.toEntity(accountId: Long, gson: Gson): TimelineAccountEntity {
|
2022-01-11 19:00:29 +01:00
|
|
|
return TimelineAccountEntity(
|
|
|
|
serverId = id,
|
|
|
|
timelineUserId = accountId,
|
|
|
|
localUsername = localUsername,
|
|
|
|
username = username,
|
|
|
|
displayName = name,
|
|
|
|
url = url,
|
|
|
|
avatar = avatar,
|
|
|
|
emojis = gson.toJson(emojis),
|
|
|
|
bot = bot
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-15 21:34:57 +01:00
|
|
|
fun TimelineAccountEntity.toAccount(gson: Gson): TimelineAccount {
|
|
|
|
return TimelineAccount(
|
2022-01-11 19:00:29 +01:00
|
|
|
id = serverId,
|
|
|
|
localUsername = localUsername,
|
|
|
|
username = username,
|
|
|
|
displayName = displayName,
|
|
|
|
url = url,
|
|
|
|
avatar = avatar,
|
|
|
|
bot = bot,
|
2022-03-15 21:34:57 +01:00
|
|
|
emojis = gson.fromJson(emojis, emojisListType)
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Placeholder.toEntity(timelineUserId: Long): TimelineStatusEntity {
|
|
|
|
return TimelineStatusEntity(
|
|
|
|
serverId = this.id,
|
|
|
|
url = null,
|
|
|
|
timelineUserId = timelineUserId,
|
|
|
|
authorServerId = null,
|
|
|
|
inReplyToId = null,
|
|
|
|
inReplyToAccountId = null,
|
|
|
|
content = null,
|
|
|
|
createdAt = 0L,
|
2022-12-03 12:15:54 +01:00
|
|
|
editedAt = 0L,
|
2022-01-11 19:00:29 +01:00
|
|
|
emojis = null,
|
|
|
|
reblogsCount = 0,
|
|
|
|
favouritesCount = 0,
|
|
|
|
reblogged = false,
|
|
|
|
favourited = false,
|
|
|
|
bookmarked = false,
|
|
|
|
sensitive = false,
|
|
|
|
spoilerText = "",
|
|
|
|
visibility = Status.Visibility.UNKNOWN,
|
|
|
|
attachments = null,
|
|
|
|
mentions = null,
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = null,
|
2022-01-11 19:00:29 +01:00
|
|
|
application = null,
|
|
|
|
reblogServerId = null,
|
|
|
|
reblogAccountId = null,
|
|
|
|
poll = null,
|
|
|
|
muted = false,
|
|
|
|
expanded = loading,
|
|
|
|
contentCollapsed = false,
|
|
|
|
contentShowing = false,
|
2022-05-05 18:27:05 +02:00
|
|
|
pinned = false,
|
|
|
|
card = null,
|
2022-08-31 18:53:57 +02:00
|
|
|
repliesCount = 0,
|
|
|
|
language = null,
|
2023-03-11 13:12:50 +01:00
|
|
|
filtered = null,
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Status.toEntity(
|
|
|
|
timelineUserId: Long,
|
|
|
|
gson: Gson,
|
|
|
|
expanded: Boolean,
|
|
|
|
contentShowing: Boolean,
|
|
|
|
contentCollapsed: Boolean
|
|
|
|
): TimelineStatusEntity {
|
|
|
|
return TimelineStatusEntity(
|
|
|
|
serverId = this.id,
|
|
|
|
url = actionableStatus.url,
|
|
|
|
timelineUserId = timelineUserId,
|
|
|
|
authorServerId = actionableStatus.account.id,
|
|
|
|
inReplyToId = actionableStatus.inReplyToId,
|
|
|
|
inReplyToAccountId = actionableStatus.inReplyToAccountId,
|
2022-04-15 13:20:27 +02:00
|
|
|
content = actionableStatus.content,
|
2022-01-11 19:00:29 +01:00
|
|
|
createdAt = actionableStatus.createdAt.time,
|
2022-12-03 12:15:54 +01:00
|
|
|
editedAt = actionableStatus.editedAt?.time,
|
2022-01-11 19:00:29 +01:00
|
|
|
emojis = actionableStatus.emojis.let(gson::toJson),
|
|
|
|
reblogsCount = actionableStatus.reblogsCount,
|
|
|
|
favouritesCount = actionableStatus.favouritesCount,
|
|
|
|
reblogged = actionableStatus.reblogged,
|
|
|
|
favourited = actionableStatus.favourited,
|
|
|
|
bookmarked = actionableStatus.bookmarked,
|
|
|
|
sensitive = actionableStatus.sensitive,
|
|
|
|
spoilerText = actionableStatus.spoilerText,
|
|
|
|
visibility = actionableStatus.visibility,
|
|
|
|
attachments = actionableStatus.attachments.let(gson::toJson),
|
|
|
|
mentions = actionableStatus.mentions.let(gson::toJson),
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = actionableStatus.tags.let(gson::toJson),
|
2022-01-11 19:00:29 +01:00
|
|
|
application = actionableStatus.application.let(gson::toJson),
|
|
|
|
reblogServerId = reblog?.id,
|
|
|
|
reblogAccountId = reblog?.let { this.account.id },
|
|
|
|
poll = actionableStatus.poll.let(gson::toJson),
|
|
|
|
muted = actionableStatus.muted,
|
|
|
|
expanded = expanded,
|
|
|
|
contentShowing = contentShowing,
|
|
|
|
contentCollapsed = contentCollapsed,
|
2022-05-05 18:27:05 +02:00
|
|
|
pinned = actionableStatus.pinned == true,
|
|
|
|
card = actionableStatus.card?.let(gson::toJson),
|
2022-08-31 18:53:57 +02:00
|
|
|
repliesCount = actionableStatus.repliesCount,
|
|
|
|
language = actionableStatus.language,
|
2023-03-11 13:12:50 +01:00
|
|
|
filtered = actionableStatus.filtered,
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
Improve the actual and perceived speed of thread loading (#3118)
* Improve the actual and perceived speed of thread loading
To improve the actual speed, note that if the user has opened a thread from
their home timeline then the initial status is cached in the database. Other
statuses in the same thread may be cached as well.
So try and load the initial status from the database, falling back to the
network if it's not present (e.g., the user has opened a thread from the
local or federated timelines, or a search).
Introduce a new loading state to deal with this case.
In typical cases this allows the UI to display the initial status immediately
with no need to show a progress indicator.
To improve the perceived speed, delay showing the initial loading circular
progress indicators by 500ms. If loading the initial status completes within
that time no spinner is shown and the user will perceive the action as
close-to-immediate
(https://www.nngroup.com/articles/response-times-3-important-limits/).
Additionally, introduce an extra indeterminate progress indicator.
The new indicator is linear, anchored to the bottom of the screen, and shows
progress loading ancestor/descendant statuses. Like the other indicator is
also delayed 500ms from when ancestor/descendant status information is
fetched, and if the fetch completes in that time it will not be shown.
* Mark `getStatus` as suspend so it doesn't run on the main thread
* Save an allocation, use an isDetailed parameter to TimelineStatusWithAccount.toViewData
Rename Status.toViewData's "detailed" parameter to "isDetailed" for
consistency with other uses.
* Ensure suspend functions run to completion when testing
* Delay-load the status from the network even if it's cached
This speeds up the UI while ensuring it will eventually contain accurate data
from the remote.
* Load the network status before updating the list
Avoids excess animations if the network copy has changes
* Fix UI flicker when loading reblogged statuses
* Lint
* Fixup tests
2023-01-09 21:31:31 +01:00
|
|
|
fun TimelineStatusWithAccount.toViewData(gson: Gson, isDetailed: Boolean = false): StatusViewData {
|
2023-02-04 20:22:29 +01:00
|
|
|
if (this.account == null) {
|
Keep scroll position when loading missing statuses (#3000)
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Change "Load more" to load oldest statuses first in home timeline
Previous behaviour loaded missing statuses by using "since_id" and "max_id".
This loads the most recent N statuses, looking backwards from "max_id".
Change to load the oldest statuses first, assuming the user is scrolling
up through the timeline and will want to load statuses in reverse
chronological order.
* Scroll to the bottom of new entries added by "Load more"
- Remember the position of the "Load more" placeholder
- Check the position of inserted entries
- If they match, scroll to the bottom
* Ensure the user can't have two simultaneous "Load more" coroutines
Having two simultanous coroutines would break the calculation used to figure
out which item in the list to scroll to after a "Load more" in the timeline.
Do this by:
- Creating a TimelineUiState and associated flow that tracks the "Load more"
state
- Updating this in the (Cached|Network)TimelineViewModel
- Listening for changes to it in TimelineFragment, and notifying the adapter
- The adapter will disable any placeholder views while "Load more" is active
* Revert changes that loaded the oldest statuses instead of the newest
* Be more robust about locating the status to scroll to
Weirdness with the PagingData library meant that positionStart could still be
wrong after "Load more" was clicked.
Instead, remember the position of the "Load more" item and the ID of the
status immediately after it.
When new items are added, search for the remembered status at the position of
the "Load more" item. This is quick, testing at most LOAD_AT_ONCE items in
the adapter.
If the remembered status is not visible on screen then scroll to it.
* Lint
* Add a preference to specify the reading order
Default behaviour (oldest first) is for "load more" to load statuses and
stay at the oldest of the new statuses.
Alternative behaviour (if the user is reading from top to bottom) is to
stay at the newest of the new statuses.
* Move ReadingOrder enum construction logic in to the enum
* Jump to top if swipe/refresh while preferring newest-first order
* Show a circular progress spinner during "Load more" operations
Remove a dedicated view, and use an icon on the button instead.
Adjust the placeholder attributes and styles accordingly.
* Remove the "loadMoreActive" property
Complicates the code and doesn't really achieve the desired effect. If the
user wants to tap multiple "Load more" buttons they can.
* Update comments in TimelineFragment
* Respect the user's reading order preference if it changes
* Add developer tools
This is for functionality that makes it easier for developers to interact
with the app, or get it in to a known-state.
These features are for use by users, so are only visible in debug builds.
* Adjust how content is loaded based on preferred reading order
- Add the readingOrder to TimelineViewModel so derived classes can use it.
- Update the homeTimeline API to support the `minId` parameter and update
calls in NetworkTimelineViewModel
In CachedTimelineViewModel:
- Set the bounds of the load to be the status IDs on either side of the
placeholder ID (update TimelineDao with a new query for this)
- Load statuses using either minId or sinceId depending on the reading order
- Is there was no overlap then insert the new placeholder at the start/end
of the list depending on reading order
* Lint
* Rename unused dialog parameter to _
* Update API arguments in tests
* Simplify ReadingOrder preference handling
* Fix bug with Placeholder and the "expanded" property
If a status is a Placeholder the "expanded" propery is used to indicate
whether or not it is loading.
replaceStatusRange() set this property based on the old value, and the user's
alwaysOpenSpoiler preference setting.
This shouldn't have been used if the status is a Placeholder, as it can lead
to incorrect loading states.
Fix this.
While I'm here, introduce an explicit computed property for whether a
TimelineStatusEntity is a placeholder, and use that for code clarity.
* Set the "Load more" button background to transparent
* Fix typo.
* Inline spec, update comment
* Revert 1480c6aa3ac5c0c2d362fb271f47ea2259ab14e2
Turns out the behaviour is not desired.
* Remove unnecessary Log call
* Extract function
* Change default to newest first
2023-01-13 19:26:24 +01:00
|
|
|
Log.d(TAG, "Constructing Placeholder(${this.status.serverId}, ${this.status.expanded})")
|
2022-01-11 19:00:29 +01:00
|
|
|
return StatusViewData.Placeholder(this.status.serverId, this.status.expanded)
|
|
|
|
}
|
|
|
|
|
|
|
|
val attachments: ArrayList<Attachment> = gson.fromJson(status.attachments, attachmentArrayListType) ?: arrayListOf()
|
|
|
|
val mentions: List<Status.Mention> = gson.fromJson(status.mentions, mentionListType) ?: emptyList()
|
2022-02-27 20:16:41 +01:00
|
|
|
val tags: List<HashTag>? = gson.fromJson(status.tags, tagListType)
|
2022-01-11 19:00:29 +01:00
|
|
|
val application = gson.fromJson(status.application, Status.Application::class.java)
|
|
|
|
val emojis: List<Emoji> = gson.fromJson(status.emojis, emojisListType) ?: emptyList()
|
|
|
|
val poll: Poll? = gson.fromJson(status.poll, Poll::class.java)
|
2022-05-05 18:27:05 +02:00
|
|
|
val card: Card? = gson.fromJson(status.card, Card::class.java)
|
2022-01-11 19:00:29 +01:00
|
|
|
|
|
|
|
val reblog = status.reblogServerId?.let { id ->
|
|
|
|
Status(
|
|
|
|
id = id,
|
|
|
|
url = status.url,
|
|
|
|
account = account.toAccount(gson),
|
|
|
|
inReplyToId = status.inReplyToId,
|
|
|
|
inReplyToAccountId = status.inReplyToAccountId,
|
|
|
|
reblog = null,
|
2022-04-15 13:20:27 +02:00
|
|
|
content = status.content.orEmpty(),
|
2022-01-11 19:00:29 +01:00
|
|
|
createdAt = Date(status.createdAt),
|
2022-12-03 12:15:54 +01:00
|
|
|
editedAt = status.editedAt?.let { Date(it) },
|
2022-01-11 19:00:29 +01:00
|
|
|
emojis = emojis,
|
|
|
|
reblogsCount = status.reblogsCount,
|
|
|
|
favouritesCount = status.favouritesCount,
|
|
|
|
reblogged = status.reblogged,
|
|
|
|
favourited = status.favourited,
|
|
|
|
bookmarked = status.bookmarked,
|
|
|
|
sensitive = status.sensitive,
|
|
|
|
spoilerText = status.spoilerText,
|
|
|
|
visibility = status.visibility,
|
|
|
|
attachments = attachments,
|
|
|
|
mentions = mentions,
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = tags,
|
2022-01-11 19:00:29 +01:00
|
|
|
application = application,
|
|
|
|
pinned = false,
|
|
|
|
muted = status.muted,
|
|
|
|
poll = poll,
|
2022-05-05 18:27:05 +02:00
|
|
|
card = card,
|
2022-08-31 18:53:57 +02:00
|
|
|
repliesCount = status.repliesCount,
|
|
|
|
language = status.language,
|
2023-03-11 13:12:50 +01:00
|
|
|
filtered = status.filtered,
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
val status = if (reblog != null) {
|
|
|
|
Status(
|
|
|
|
id = status.serverId,
|
|
|
|
url = null, // no url for reblogs
|
|
|
|
account = this.reblogAccount!!.toAccount(gson),
|
|
|
|
inReplyToId = null,
|
|
|
|
inReplyToAccountId = null,
|
|
|
|
reblog = reblog,
|
2022-04-15 13:20:27 +02:00
|
|
|
content = "",
|
2022-01-11 19:00:29 +01:00
|
|
|
createdAt = Date(status.createdAt), // lie but whatever?
|
2022-12-03 12:15:54 +01:00
|
|
|
editedAt = null,
|
2022-01-11 19:00:29 +01:00
|
|
|
emojis = listOf(),
|
|
|
|
reblogsCount = 0,
|
|
|
|
favouritesCount = 0,
|
|
|
|
reblogged = false,
|
|
|
|
favourited = false,
|
|
|
|
bookmarked = false,
|
|
|
|
sensitive = false,
|
|
|
|
spoilerText = "",
|
|
|
|
visibility = status.visibility,
|
|
|
|
attachments = ArrayList(),
|
|
|
|
mentions = listOf(),
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = listOf(),
|
2022-01-11 19:00:29 +01:00
|
|
|
application = null,
|
|
|
|
pinned = status.pinned,
|
|
|
|
muted = status.muted,
|
|
|
|
poll = null,
|
2022-05-20 16:47:45 +02:00
|
|
|
card = null,
|
|
|
|
repliesCount = status.repliesCount,
|
2022-08-31 18:53:57 +02:00
|
|
|
language = status.language,
|
2023-03-11 13:12:50 +01:00
|
|
|
filtered = status.filtered,
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Status(
|
|
|
|
id = status.serverId,
|
|
|
|
url = status.url,
|
|
|
|
account = account.toAccount(gson),
|
|
|
|
inReplyToId = status.inReplyToId,
|
|
|
|
inReplyToAccountId = status.inReplyToAccountId,
|
|
|
|
reblog = null,
|
2022-04-15 13:20:27 +02:00
|
|
|
content = status.content.orEmpty(),
|
2022-01-11 19:00:29 +01:00
|
|
|
createdAt = Date(status.createdAt),
|
2022-12-03 12:15:54 +01:00
|
|
|
editedAt = status.editedAt?.let { Date(it) },
|
2022-01-11 19:00:29 +01:00
|
|
|
emojis = emojis,
|
|
|
|
reblogsCount = status.reblogsCount,
|
|
|
|
favouritesCount = status.favouritesCount,
|
|
|
|
reblogged = status.reblogged,
|
|
|
|
favourited = status.favourited,
|
|
|
|
bookmarked = status.bookmarked,
|
|
|
|
sensitive = status.sensitive,
|
|
|
|
spoilerText = status.spoilerText,
|
|
|
|
visibility = status.visibility,
|
|
|
|
attachments = attachments,
|
|
|
|
mentions = mentions,
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = tags,
|
2022-01-11 19:00:29 +01:00
|
|
|
application = application,
|
|
|
|
pinned = status.pinned,
|
|
|
|
muted = status.muted,
|
|
|
|
poll = poll,
|
2022-05-05 18:27:05 +02:00
|
|
|
card = card,
|
2022-05-20 16:47:45 +02:00
|
|
|
repliesCount = status.repliesCount,
|
2022-08-31 18:53:57 +02:00
|
|
|
language = status.language,
|
2023-03-11 13:12:50 +01:00
|
|
|
filtered = status.filtered,
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return StatusViewData.Concrete(
|
|
|
|
status = status,
|
|
|
|
isExpanded = this.status.expanded,
|
|
|
|
isShowingContent = this.status.contentShowing,
|
Improve the actual and perceived speed of thread loading (#3118)
* Improve the actual and perceived speed of thread loading
To improve the actual speed, note that if the user has opened a thread from
their home timeline then the initial status is cached in the database. Other
statuses in the same thread may be cached as well.
So try and load the initial status from the database, falling back to the
network if it's not present (e.g., the user has opened a thread from the
local or federated timelines, or a search).
Introduce a new loading state to deal with this case.
In typical cases this allows the UI to display the initial status immediately
with no need to show a progress indicator.
To improve the perceived speed, delay showing the initial loading circular
progress indicators by 500ms. If loading the initial status completes within
that time no spinner is shown and the user will perceive the action as
close-to-immediate
(https://www.nngroup.com/articles/response-times-3-important-limits/).
Additionally, introduce an extra indeterminate progress indicator.
The new indicator is linear, anchored to the bottom of the screen, and shows
progress loading ancestor/descendant statuses. Like the other indicator is
also delayed 500ms from when ancestor/descendant status information is
fetched, and if the fetch completes in that time it will not be shown.
* Mark `getStatus` as suspend so it doesn't run on the main thread
* Save an allocation, use an isDetailed parameter to TimelineStatusWithAccount.toViewData
Rename Status.toViewData's "detailed" parameter to "isDetailed" for
consistency with other uses.
* Ensure suspend functions run to completion when testing
* Delay-load the status from the network even if it's cached
This speeds up the UI while ensuring it will eventually contain accurate data
from the remote.
* Load the network status before updating the list
Avoids excess animations if the network copy has changes
* Fix UI flicker when loading reblogged statuses
* Lint
* Fixup tests
2023-01-09 21:31:31 +01:00
|
|
|
isCollapsed = this.status.contentCollapsed,
|
|
|
|
isDetailed = isDetailed
|
2022-01-11 19:00:29 +01:00
|
|
|
)
|
|
|
|
}
|