自分が投票した選択肢にチェックマークを表示する
This commit is contained in:
parent
23a48cae0e
commit
d999fa0d1d
|
@ -2569,16 +2569,16 @@ internal class ItemViewHolder(
|
|||
TootPollsType.Mastodon -> when {
|
||||
enquete.expired -> false
|
||||
now >= enquete.expired_at -> false
|
||||
enquete.myVoted != null -> false
|
||||
enquete.ownVoted -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
TootPollsType.FriendsNico -> {
|
||||
val remain = enquete.time_start + TootPolls.ENQUETE_EXPIRE - now
|
||||
enquete.myVoted == null && remain > 0L
|
||||
remain > 0L && !enquete.ownVoted
|
||||
}
|
||||
|
||||
TootPollsType.Misskey -> enquete.myVoted == null
|
||||
TootPollsType.Misskey -> !enquete.ownVoted
|
||||
}
|
||||
|
||||
items.forEachIndexed { index, choice ->
|
||||
|
@ -2608,10 +2608,10 @@ internal class ItemViewHolder(
|
|||
val sb = SpannableStringBuilder()
|
||||
.append(item.decoded_text)
|
||||
|
||||
if(enquete.myVoted != null) {
|
||||
if( enquete.ownVoted ) {
|
||||
sb.append(" / ")
|
||||
sb.append(activity.getString(R.string.vote_count_text, item.votes))
|
||||
if(i == enquete.myVoted) sb.append(' ').append(0x2713.toChar())
|
||||
if( item.isVoted ) sb.append(' ').append(0x2713.toChar())
|
||||
}
|
||||
sb
|
||||
}
|
||||
|
@ -2633,6 +2633,7 @@ internal class ItemViewHolder(
|
|||
else -> activity.getString(R.string.vote_count_text, v)
|
||||
}
|
||||
)
|
||||
if( item.isVoted ) sb.append(' ').append(0x2713.toChar())
|
||||
}
|
||||
sb
|
||||
}
|
||||
|
@ -2813,7 +2814,7 @@ internal class ItemViewHolder(
|
|||
accessInfo : SavedAccount,
|
||||
idx : Int
|
||||
) {
|
||||
if(enquete.myVoted != null) {
|
||||
if(enquete.ownVoted) {
|
||||
showToast(context, false, R.string.already_voted)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ class TootInstance(parser : TootParser, src : JSONObject) {
|
|||
val VERSION_1_6 = VersionString("1.6")
|
||||
val VERSION_2_4_0_rc1 = VersionString("2.4.0rc1")
|
||||
val VERSION_2_4_0_rc2 = VersionString("2.4.0rc2")
|
||||
val VERSION_2_4_0 = VersionString("2.4.0")
|
||||
val VERSION_2_4_1_rc1 = VersionString("2.4.1rc1")
|
||||
// val VERSION_2_4_0 = VersionString("2.4.0")
|
||||
// val VERSION_2_4_1_rc1 = VersionString("2.4.1rc1")
|
||||
val VERSION_2_4_1 = VersionString("2.4.1")
|
||||
val VERSION_2_6_0 = VersionString("2.6.0")
|
||||
val VERSION_2_7_0_rc1 = VersionString("2.7.0rc1")
|
||||
|
|
|
@ -49,8 +49,6 @@ class TootPolls private constructor(
|
|||
// 結果の数値のテキスト // null or array of string
|
||||
private var ratios_text : MutableList<String>? = null
|
||||
|
||||
var myVoted : Int? = null
|
||||
|
||||
// 以下はJSONには存在しないが内部で使う
|
||||
val time_start : Long
|
||||
val status_id : EntityId
|
||||
|
@ -63,6 +61,8 @@ class TootPolls private constructor(
|
|||
var maxVotesCount : Int? = null
|
||||
var pollId : EntityId? = null
|
||||
|
||||
var ownVoted : Boolean
|
||||
|
||||
init {
|
||||
|
||||
this.time_start = status.time_created_at
|
||||
|
@ -78,12 +78,14 @@ class TootPolls private constructor(
|
|||
|
||||
val votesList = ArrayList<Int>()
|
||||
var votesMax = 1
|
||||
items?.forEachIndexed { index, choice ->
|
||||
if(choice.isVoted) this.myVoted = index
|
||||
var ownVoted = false
|
||||
items?.forEach { choice ->
|
||||
if(choice.isVoted) ownVoted = true
|
||||
val votes = choice.votes ?: 0
|
||||
votesList.add(votes)
|
||||
if(votes > votesMax) votesMax = votes
|
||||
}
|
||||
this.ownVoted = ownVoted
|
||||
|
||||
if(votesList.isNotEmpty()) {
|
||||
this.ratios =
|
||||
|
@ -141,7 +143,18 @@ class TootPolls private constructor(
|
|||
this.expired = src.optBoolean("expired", false)
|
||||
this.multiple = src.optBoolean("multiple", false)
|
||||
this.votes_count = src.parseInt("votes_count")
|
||||
this.myVoted = if(src.optBoolean("voted", false)) 1 else null
|
||||
|
||||
var ownVoted = src.optBoolean("voted", false)
|
||||
|
||||
src.optJSONArray("own_votes")?.forEach {
|
||||
if( it is Number){
|
||||
val i = it.toInt()
|
||||
items?.get(i)?.isVoted = true
|
||||
ownVoted = true
|
||||
}
|
||||
}
|
||||
|
||||
this.ownVoted = ownVoted
|
||||
|
||||
when {
|
||||
this.items == null -> maxVotesCount = null
|
||||
|
@ -192,6 +205,8 @@ class TootPolls private constructor(
|
|||
|
||||
this.ratios = src.parseFloatArrayList("ratios")
|
||||
this.ratios_text = src.parseStringArrayList("ratios_text")
|
||||
|
||||
this.ownVoted = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +348,7 @@ class TootPolls private constructor(
|
|||
synchronized(this) {
|
||||
try {
|
||||
// 既に投票済み状態なら何もしない
|
||||
if(myVoted != null) return false
|
||||
if(ownVoted) return false
|
||||
|
||||
val item = this.items?.get(argChoice) ?: return false
|
||||
item.votes = (item.votes ?: 0) + 1
|
||||
|
@ -343,7 +358,7 @@ class TootPolls private constructor(
|
|||
val votesList = ArrayList<Int>()
|
||||
var votesMax = 1
|
||||
items.forEachIndexed { index, choice ->
|
||||
if(choice.isVoted) this.myVoted = index
|
||||
if(choice.isVoted) ownVoted = true
|
||||
val votes = choice.votes ?: 0
|
||||
votesList.add(votes)
|
||||
if(votes > votesMax) votesMax = votes
|
||||
|
|
|
@ -144,11 +144,11 @@ object TootTextEncoder {
|
|||
TootPollsType.Mastodon -> when {
|
||||
enquete.expired -> false
|
||||
now >= enquete.expired_at -> false
|
||||
enquete.myVoted != null -> false
|
||||
enquete.ownVoted -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
TootPollsType.Misskey -> enquete.myVoted == null
|
||||
TootPollsType.Misskey -> enquete.ownVoted
|
||||
}
|
||||
|
||||
sb.addAfterLine("\n")
|
||||
|
@ -176,10 +176,10 @@ object TootTextEncoder {
|
|||
val text = when(enquete.pollType) {
|
||||
TootPollsType.Misskey -> {
|
||||
val sb2 = StringBuilder().append(item.decoded_text)
|
||||
if(enquete.myVoted != null) {
|
||||
if( enquete.ownVoted ) {
|
||||
sb2.append(" / ")
|
||||
sb2.append(context.getString(R.string.vote_count_text, item.votes))
|
||||
if(i == enquete.myVoted) sb2.append(' ').append(0x2713.toChar())
|
||||
if(item.isVoted ) sb2.append(' ').append(0x2713.toChar())
|
||||
}
|
||||
sb2
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ inline fun JSONArray.downForEachIndexed(block : (i : Int, v : Any?) -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
inline fun <T : Any?> JSONArray.map(block : (Any?) -> T) =
|
||||
(0 until length()).map { block(opt(it)) }
|
||||
|
||||
//fun JSONArray.toAnyList() : ArrayList<Any> {
|
||||
// val dst_list = ArrayList<Any>(length())
|
||||
// forEach { if(it != null) dst_list.add(it) }
|
||||
|
@ -119,23 +122,23 @@ fun String.toJsonArray() = JSONArray(this)
|
|||
fun JSONObject.parseBoolean(key : String) : Boolean? {
|
||||
val o = this.opt(key)
|
||||
if(o == null || o == JSONObject.NULL) return null
|
||||
|
||||
return when(o){
|
||||
|
||||
return when(o) {
|
||||
is Boolean -> o
|
||||
|
||||
is Int -> return o != 0
|
||||
is Long -> return o != 0L
|
||||
is Float -> return !(o.isFinite() && o == 0f)
|
||||
is Double -> return !(o.isFinite() && o == 0.0)
|
||||
|
||||
is String -> when(o){
|
||||
"", "0","false" ,"False" -> false
|
||||
else-> true
|
||||
is Float -> return ! (o.isFinite() && o == 0f)
|
||||
is Double -> return ! (o.isFinite() && o == 0.0)
|
||||
|
||||
is String -> when(o) {
|
||||
"", "0", "false", "False" -> false
|
||||
else -> true
|
||||
}
|
||||
|
||||
is JSONArray -> o.length() > 0
|
||||
is JSONObject -> o.length() > 0
|
||||
|
||||
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
@ -211,21 +214,20 @@ fun JSONObject.parseInt(key : String) : Int? {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fun jsonObject(initializer : JSONObject.() -> Unit) : JSONObject {
|
||||
val dst = JSONObject()
|
||||
dst.initializer()
|
||||
return dst
|
||||
}
|
||||
|
||||
fun Array<String>.toJsonArray() : JSONArray = JSONArray().also{
|
||||
for(s in this){
|
||||
fun Array<String>.toJsonArray() : JSONArray = JSONArray().also {
|
||||
for(s in this) {
|
||||
it.put(s)
|
||||
}
|
||||
}
|
||||
|
||||
fun jsonArray(vararg args:String) = JSONArray().also{
|
||||
for(s in args){
|
||||
fun jsonArray(vararg args : String) = JSONArray().also {
|
||||
for(s in args) {
|
||||
it.put(s)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue