Create polls (#1452)
* add AddPollDialog * add support for pleroma poll options * add PollPreviewView * add Poll support to drafts * add license header, cleanup * rename drawable files to correct size * fix tests * fix bug with Poll having wrong duration after delete&redraft * add input validation * grey out poll button when its disabled * code cleanup & small improvements
This commit is contained in:
parent
444df322a7
commit
51c6852492
61 changed files with 1540 additions and 76 deletions
|
@ -29,7 +29,8 @@ data class Instance (
|
|||
val languages: List<String>,
|
||||
@SerializedName("contact_account") val contactAccount: Account,
|
||||
@SerializedName("max_toot_chars") val maxTootChars: Int?,
|
||||
@SerializedName("max_bio_chars") val maxBioChars: Int?
|
||||
@SerializedName("max_bio_chars") val maxBioChars: Int?,
|
||||
@SerializedName("poll_limits") val pollLimits: PollLimits?
|
||||
) {
|
||||
override fun hashCode(): Int {
|
||||
return uri.hashCode()
|
||||
|
@ -44,3 +45,7 @@ data class Instance (
|
|||
}
|
||||
}
|
||||
|
||||
data class PollLimits (
|
||||
@SerializedName("max_options") val maxOptions: Int?,
|
||||
@SerializedName("max_option_chars") val maxOptionChars: Int?
|
||||
)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* Copyright 2019 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.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
data class NewStatus(
|
||||
val status: String,
|
||||
@SerializedName("spoiler_text") val warningText: String,
|
||||
@SerializedName("in_reply_to_id") val inReplyToId: String?,
|
||||
val visibility: String,
|
||||
val sensitive: Boolean,
|
||||
@SerializedName("media_ids") val mediaIds: List<String>?,
|
||||
val poll: NewPoll?
|
||||
)
|
||||
|
||||
@Parcelize
|
||||
data class NewPoll(
|
||||
val options: List<String>,
|
||||
@SerializedName("expires_in") val expiresIn: Int,
|
||||
val multiple: Boolean
|
||||
): Parcelable
|
|
@ -25,6 +25,14 @@ data class Poll(
|
|||
return copy(options = newOptions, votesCount = votesCount + choices.size, voted = true)
|
||||
}
|
||||
|
||||
fun toNewPoll(creationDate: Date) = NewPoll(
|
||||
options.map { it.title },
|
||||
expiresAt?.let {
|
||||
((it.time - creationDate.time) / 1000).toInt() + 1
|
||||
}?: 3600,
|
||||
multiple
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
data class PollOption(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue