2021-06-12 04:15:40 +10:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
|
|
|
* 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.viewdata
|
|
|
|
|
|
|
|
import android.os.Build
|
|
|
|
import android.text.Spanned
|
|
|
|
import com.keylesspalace.tusky.entity.Status
|
2022-04-15 21:20:27 +10:00
|
|
|
import com.keylesspalace.tusky.util.parseAsMastodonHtml
|
|
|
|
import com.keylesspalace.tusky.util.replaceCrashingCharacters
|
|
|
|
import com.keylesspalace.tusky.util.shouldTrimStatus
|
2021-06-12 04:15:40 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by charlag on 11/07/2017.
|
|
|
|
*
|
|
|
|
* Class to represent data required to display either a notification or a placeholder.
|
|
|
|
* It is either a [StatusViewData.Concrete] or a [StatusViewData.Placeholder].
|
|
|
|
*/
|
2022-03-16 07:34:57 +11:00
|
|
|
sealed class StatusViewData {
|
|
|
|
abstract val id: String
|
2021-06-12 04:15:40 +10:00
|
|
|
|
|
|
|
data class Concrete(
|
|
|
|
val status: Status,
|
|
|
|
val isExpanded: Boolean,
|
|
|
|
val isShowingContent: Boolean,
|
|
|
|
/**
|
|
|
|
* Specifies whether the content of this post is currently limited in visibility to the first
|
|
|
|
* 500 characters or not.
|
|
|
|
*
|
|
|
|
* @return Whether the post is collapsed or fully expanded.
|
|
|
|
*/
|
|
|
|
/** Whether the status meets the requirement to be collapse */
|
|
|
|
val isCollapsed: Boolean,
|
2022-08-15 19:00:18 +10:00
|
|
|
val isDetailed: Boolean = false
|
2021-06-12 04:15:40 +10:00
|
|
|
) : StatusViewData() {
|
2022-03-16 07:34:57 +11:00
|
|
|
override val id: String
|
|
|
|
get() = status.id
|
2021-06-12 04:15:40 +10:00
|
|
|
|
2022-04-15 21:20:27 +10:00
|
|
|
/**
|
2022-06-25 05:47:49 +10:00
|
|
|
* Specifies whether the content of this post is long enough to be automatically
|
|
|
|
* collapsed or if it should show all content regardless.
|
2022-04-15 21:20:27 +10:00
|
|
|
*
|
|
|
|
* @return Whether the post is collapsible or never collapsed.
|
|
|
|
*/
|
|
|
|
val isCollapsible: Boolean
|
|
|
|
|
2021-06-12 04:15:40 +10:00
|
|
|
val content: Spanned
|
|
|
|
val spoilerText: String
|
|
|
|
val username: String
|
|
|
|
|
|
|
|
val actionable: Status
|
|
|
|
get() = status.actionableStatus
|
|
|
|
|
2021-06-29 05:41:18 +10:00
|
|
|
val actionableId: String
|
|
|
|
get() = status.actionableStatus.id
|
|
|
|
|
2021-06-12 04:15:40 +10:00
|
|
|
val rebloggedAvatar: String?
|
2021-06-14 18:22:08 +10:00
|
|
|
get() = if (status.reblog != null) {
|
|
|
|
status.account.avatar
|
|
|
|
} else {
|
|
|
|
null
|
|
|
|
}
|
2021-06-12 04:15:40 +10:00
|
|
|
|
|
|
|
val rebloggingStatus: Status?
|
|
|
|
get() = if (status.reblog != null) status else null
|
|
|
|
|
|
|
|
init {
|
|
|
|
if (Build.VERSION.SDK_INT == 23) {
|
|
|
|
// https://github.com/tuskyapp/Tusky/issues/563
|
2022-04-15 21:20:27 +10:00
|
|
|
this.content = replaceCrashingCharacters(status.actionableStatus.content.parseAsMastodonHtml())
|
2021-06-12 04:15:40 +10:00
|
|
|
this.spoilerText =
|
|
|
|
replaceCrashingCharacters(status.actionableStatus.spoilerText).toString()
|
|
|
|
this.username =
|
|
|
|
replaceCrashingCharacters(status.actionableStatus.account.username).toString()
|
|
|
|
} else {
|
2022-04-15 21:20:27 +10:00
|
|
|
this.content = status.actionableStatus.content.parseAsMastodonHtml()
|
2021-06-12 04:15:40 +10:00
|
|
|
this.spoilerText = status.actionableStatus.spoilerText
|
|
|
|
this.username = status.actionableStatus.account.username
|
|
|
|
}
|
2022-04-15 21:20:27 +10:00
|
|
|
this.isCollapsible = shouldTrimStatus(this.content)
|
2021-06-12 04:15:40 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Helper for Java */
|
|
|
|
fun copyWithStatus(status: Status): Concrete {
|
|
|
|
return copy(status = status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Helper for Java */
|
|
|
|
fun copyWithExpanded(isExpanded: Boolean): Concrete {
|
|
|
|
return copy(isExpanded = isExpanded)
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Helper for Java */
|
|
|
|
fun copyWithShowingContent(isShowingContent: Boolean): Concrete {
|
|
|
|
return copy(isShowingContent = isShowingContent)
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Helper for Java */
|
2022-06-25 05:47:49 +10:00
|
|
|
fun copyWithCollapsed(isCollapsed: Boolean): Concrete {
|
2021-06-12 04:15:40 +10:00
|
|
|
return copy(isCollapsed = isCollapsed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 07:34:57 +11:00
|
|
|
data class Placeholder(
|
|
|
|
override val id: String,
|
|
|
|
val isLoading: Boolean
|
|
|
|
) : StatusViewData()
|
2021-06-12 04:15:40 +10:00
|
|
|
|
|
|
|
fun asStatusOrNull() = this as? Concrete
|
|
|
|
|
|
|
|
fun asPlaceholderOrNull() = this as? Placeholder
|
|
|
|
}
|