pantasystem / Milktea

Misskey, MastodonのAndroidクライアント「Milktea」のソースコード
GNU General Public License v3.0
251 stars 22 forks source link

投票機能で現在の投票数を表示させて欲しい #1842

Closed sanao1006 closed 1 year ago

sanao1006 commented 1 year ago

概要

タイトルの通りです。 Web版のように現在何票投票されているかの表示がmilkteaにもあれば便利かなと思いました(画像赤線部分)。

具体的な実装方法などはまだ考えていないですが、もしこの機能がアリならば実装をしてみたいです! 「結果を見る」や「投票する・投票済み」などの機能はもしこのissueが採用されるなら合わせて実装すべきかもです(issueは分けるべきかも?)

追記

いつもmilktea使わせてもらっています!本当に使いやすくて最高です!

pantasystem commented 1 year ago

いいですね

pantasystem commented 1 year ago

一旦投票件数の実装の方針とか考えてここに書いてもらえますか?

sanao1006 commented 1 year ago

おおまかですが方針を考えてみました。 最初はPollListLinearLayoutBinder.bindPollChoicesにコードを書き足す方針で行こうかなと思ったのですが、うまくいかなかったので PollListLinearLayoutBinderに新しい関数作って投票件数を表示させる方針にしました

  1. PollListLinearLayoutBinderにこんな感じの実装の関数bindVoteResult()を追加

    fun bindVoteResult(
        layout: LinearLayout,
        totalVoteCount: Int
    ) {
        val binding = ItemVoteResultBinding.inflate(LayoutInflater.from(layout.context), layout, false)
    
        binding.voteResult.text = layout.context.getString(R.string.total_vote_count, totalVoteCount.toString())
        layout.addView(binding.root)
    }
    • features/noteのres/layoutにitem_vote_result.xmlレイアウト追加。左寄せのTextViewのみ設置 (idはvoteResult)
    • common_resourceのvalues/strings.xmlには%s votes in totalみたいなstringを追加 (nameはtotal_vote_count)
    • layout.context.getStringでtotalVoteCountを%sに代入
  2. PollHelperPollListLinearLayoutBinder.bindPollChoicesの真下あたりに以下のように実装して画面に投票数を反映させる

    PollListLinearLayoutBinder.bindVoteResult(this, poll.totalVoteCount)

いちおうこんな感じで実装してみたところ見た目はこんな感じになりました (命名は割と雑かもです)。

pantasystem commented 1 year ago

良いと思います🙆‍♀

pantasystem commented 1 year ago

引き続きよろしくお願いします🙇🙇

sanao1006 commented 1 year ago

とりあえずPR作成してみました。お手すきの際にご確認お願いします!