Polls part 1 - displaying in timelines and voting (#1200)
* add entity classes * change data models and add database migration * add polls to StatusViewData * show poll results * add methods for vote handling * add voting interface * enable voting in TimelineFragment * update polls immediately * enable custom emojis for poll options * enable voting from search fragment * add voting layout to detailed statuses * fix tests * enable voting in ViewThreadFragment * enable voting in ConversationsFragment * small refactor for StatusBaseViewHolder
This commit is contained in:
parent
82d547caf8
commit
fd7471f2ab
36 changed files with 1637 additions and 68 deletions
33
app/src/main/java/com/keylesspalace/tusky/entity/Poll.kt
Normal file
33
app/src/main/java/com/keylesspalace/tusky/entity/Poll.kt
Normal file
|
@ -0,0 +1,33 @@
|
|||
package com.keylesspalace.tusky.entity
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import java.util.*
|
||||
|
||||
data class Poll(
|
||||
val id: String,
|
||||
@SerializedName("expires_at") val expiresAt: Date?,
|
||||
val expired: Boolean,
|
||||
val multiple: Boolean,
|
||||
@SerializedName("votes_count") val votesCount: Int,
|
||||
val options: List<PollOption>,
|
||||
val voted: Boolean
|
||||
) {
|
||||
|
||||
fun votedCopy(choices: List<Int>): Poll {
|
||||
val newOptions = options.mapIndexed { index, option ->
|
||||
if(choices.contains(index)) {
|
||||
option.copy(votesCount = option.votesCount + 1)
|
||||
} else {
|
||||
option
|
||||
}
|
||||
}
|
||||
|
||||
return copy(options = newOptions, votesCount = votesCount + 1, voted = true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class PollOption(
|
||||
val title: String,
|
||||
@SerializedName("votes_count") val votesCount: Int
|
||||
)
|
|
@ -39,7 +39,8 @@ data class Status(
|
|||
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>,
|
||||
val mentions: Array<Mention>,
|
||||
val application: Application?,
|
||||
var pinned: Boolean?
|
||||
var pinned: Boolean?,
|
||||
val poll: Poll?
|
||||
) {
|
||||
|
||||
val actionableId: String
|
||||
|
@ -161,5 +162,6 @@ data class Status(
|
|||
|
||||
companion object {
|
||||
const val MAX_MEDIA_ATTACHMENTS = 4
|
||||
const val MAX_POLL_OPTIONS = 4
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue