Timeline refactor (#2175)
* Move Timeline files into their own package * Introduce TimelineViewModel, add coroutines * Simplify StatusViewData * Handle timeilne fetch errors * Rework filters, fix ViewThreadFragment * Fix NotificationsFragment * Simplify Notifications and Thread, handle pin * Redo loading in TimelineViewModel * Improve error handling in TimelineViewModel * Rewrite actions in TimelineViewModel * Apply feedback after timeline factoring review * Handle initial failure in timeline correctly
This commit is contained in:
parent
0a992480c2
commit
44a5b42cac
58 changed files with 3956 additions and 3618 deletions
|
@ -22,10 +22,11 @@ import com.google.gson.JsonParseException
|
|||
import com.google.gson.annotations.JsonAdapter
|
||||
|
||||
data class Notification(
|
||||
val type: Type,
|
||||
val id: String,
|
||||
val account: Account,
|
||||
val status: Status?) {
|
||||
val type: Type,
|
||||
val id: String,
|
||||
val account: Account,
|
||||
val status: Status?
|
||||
) {
|
||||
|
||||
@JsonAdapter(NotificationTypeAdapter::class)
|
||||
enum class Type(val presentation: String) {
|
||||
|
@ -71,18 +72,25 @@ data class Notification(
|
|||
class NotificationTypeAdapter : JsonDeserializer<Type> {
|
||||
|
||||
@Throws(JsonParseException::class)
|
||||
override fun deserialize(json: JsonElement, typeOfT: java.lang.reflect.Type, context: JsonDeserializationContext): Type {
|
||||
override fun deserialize(
|
||||
json: JsonElement,
|
||||
typeOfT: java.lang.reflect.Type,
|
||||
context: JsonDeserializationContext
|
||||
): Type {
|
||||
return Type.byString(json.asString)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** Helper for Java */
|
||||
fun copyWithStatus(status: Status?): Notification = copy(status = status)
|
||||
|
||||
// for Pleroma compatibility that uses Mention type
|
||||
fun rewriteToStatusTypeIfNeeded(accountId: String) : Notification {
|
||||
fun rewriteToStatusTypeIfNeeded(accountId: String): Notification {
|
||||
if (type == Type.MENTION && status != null) {
|
||||
return if (status.mentions.any {
|
||||
it.id == accountId
|
||||
}) this else copy(type = Type.STATUS)
|
||||
it.id == accountId
|
||||
}) this else copy(type = Type.STATUS)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ import com.google.gson.annotations.SerializedName
|
|||
import java.util.*
|
||||
|
||||
data class Status(
|
||||
var id: String,
|
||||
var url: String?, // not present if it's reblog
|
||||
val id: String,
|
||||
val url: String?, // not present if it's reblog
|
||||
val account: Account,
|
||||
@SerializedName("in_reply_to_id") var inReplyToId: String?,
|
||||
@SerializedName("in_reply_to_account_id") val inReplyToAccountId: String?,
|
||||
|
@ -40,10 +40,10 @@ data class Status(
|
|||
@SerializedName("spoiler_text") val spoilerText: String,
|
||||
val visibility: Visibility,
|
||||
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>,
|
||||
val mentions: Array<Mention>,
|
||||
val mentions: List<Mention>,
|
||||
val application: Application?,
|
||||
var pinned: Boolean?,
|
||||
var muted: Boolean?,
|
||||
val pinned: Boolean?,
|
||||
val muted: Boolean?,
|
||||
val poll: Poll?,
|
||||
val card: Card?
|
||||
) {
|
||||
|
@ -54,6 +54,11 @@ data class Status(
|
|||
val actionableStatus: Status
|
||||
get() = reblog ?: this
|
||||
|
||||
/** Helper for Java */
|
||||
fun copyWithPoll(poll: Poll?): Status = copy(poll = poll)
|
||||
|
||||
/** Helper for Java */
|
||||
fun copyWithPinned(pinned: Boolean): Status = copy(pinned = pinned)
|
||||
|
||||
enum class Visibility(val num: Int) {
|
||||
UNKNOWN(0),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue