Remove legacy poll ui.
This commit is contained in:
parent
06485cf5e4
commit
32e8a7e886
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home.room.detail.timeline.item
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
import im.vector.app.core.extensions.setTextOrHide
|
||||
import im.vector.app.features.home.room.detail.RoomDetailAction
|
||||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
|
||||
abstract class MessageOptionsItem : AbsMessageItem<MessageOptionsItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute
|
||||
var optionsContent: MessageOptionsContent? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var callback: TimelineEventController.Callback? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var informationData: MessageInformationData? = null
|
||||
|
||||
override fun getViewType() = STUB_ID
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
|
||||
renderSendState(holder.view, holder.labelText)
|
||||
|
||||
holder.labelText.setTextOrHide(optionsContent?.label)
|
||||
|
||||
holder.buttonContainer.removeAllViews()
|
||||
|
||||
val relatedEventId = informationData?.eventId ?: return
|
||||
val options = optionsContent?.options?.takeIf { it.isNotEmpty() } ?: return
|
||||
// Now add back the buttons
|
||||
options.forEachIndexed { index, option ->
|
||||
val materialButton = LayoutInflater.from(holder.view.context).inflate(R.layout.option_buttons, holder.buttonContainer, false)
|
||||
as MaterialButton
|
||||
holder.buttonContainer.addView(materialButton, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
materialButton.text = option.label
|
||||
materialButton.onClick {
|
||||
callback?.onTimelineItemAction(RoomDetailAction.ReplyToOptions(relatedEventId, index, option.value ?: "$index"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Holder : AbsMessageItem.Holder(STUB_ID) {
|
||||
|
||||
val labelText by bind<TextView>(R.id.optionLabelText)
|
||||
|
||||
val buttonContainer by bind<ViewGroup>(R.id.optionsButtonContainer)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val STUB_ID = R.id.messageOptionsStub
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home.room.detail.timeline.item
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.epoxy.ClickListener
|
||||
import im.vector.app.core.epoxy.onClick
|
||||
import im.vector.app.core.extensions.setTextOrHide
|
||||
import im.vector.app.features.home.room.detail.RoomDetailAction
|
||||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
|
||||
abstract class MessagePollItem : AbsMessageItem<MessagePollItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute
|
||||
var optionsContent: MessageOptionsContent? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var callback: TimelineEventController.Callback? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var informationData: MessageInformationData? = null
|
||||
|
||||
override fun getViewType() = STUB_ID
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
|
||||
holder.pollId = informationData?.eventId
|
||||
holder.callback = callback
|
||||
holder.optionValues = optionsContent?.options?.map { it.value ?: it.label }
|
||||
|
||||
renderSendState(holder.view, holder.labelText)
|
||||
|
||||
holder.labelText.setTextOrHide(optionsContent?.label)
|
||||
|
||||
val buttons = listOf(holder.button1, holder.button2, holder.button3, holder.button4, holder.button5)
|
||||
val resultLines = listOf(holder.result1, holder.result2, holder.result3, holder.result4, holder.result5)
|
||||
|
||||
buttons.forEach { it.isVisible = false }
|
||||
resultLines.forEach { it.isVisible = false }
|
||||
|
||||
val myVote = informationData?.pollResponseAggregatedSummary?.myVote
|
||||
val iHaveVoted = myVote != null
|
||||
val votes = informationData?.pollResponseAggregatedSummary?.votes
|
||||
val totalVotes = votes?.values
|
||||
?.fold(0) { acc, count -> acc + count } ?: 0
|
||||
val percentMode = totalVotes > 100
|
||||
|
||||
if (!iHaveVoted) {
|
||||
// Show buttons if i have not voted
|
||||
holder.resultWrapper.isVisible = false
|
||||
optionsContent?.options?.forEachIndexed { index, item ->
|
||||
if (index < buttons.size) {
|
||||
buttons[index].let {
|
||||
// current limitation, have to wait for event to be sent in order to reply
|
||||
it.isEnabled = informationData?.sendState?.isSent() ?: false
|
||||
it.text = item.label
|
||||
it.isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.resultWrapper.isVisible = true
|
||||
val maxCount = votes?.maxByOrNull { it.value }?.value ?: 0
|
||||
optionsContent?.options?.forEachIndexed { index, item ->
|
||||
if (index < resultLines.size) {
|
||||
val optionCount = votes?.get(index) ?: 0
|
||||
val count = if (percentMode) {
|
||||
if (totalVotes > 0) {
|
||||
(optionCount / totalVotes.toFloat() * 100).roundToInt().let { "$it%" }
|
||||
} else {
|
||||
""
|
||||
}
|
||||
} else {
|
||||
optionCount.toString()
|
||||
}
|
||||
resultLines[index].let {
|
||||
it.label = item.label
|
||||
it.isWinner = optionCount == maxCount
|
||||
it.optionSelected = index == myVote
|
||||
it.percent = count
|
||||
it.isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
holder.infoText.text = holder.view.context.resources.getQuantityString(R.plurals.poll_info, totalVotes, totalVotes)
|
||||
}
|
||||
|
||||
override fun unbind(holder: Holder) {
|
||||
holder.pollId = null
|
||||
holder.callback = null
|
||||
holder.optionValues = null
|
||||
super.unbind(holder)
|
||||
}
|
||||
|
||||
class Holder : AbsMessageItem.Holder(STUB_ID) {
|
||||
|
||||
var pollId: String? = null
|
||||
var optionValues: List<String?>? = null
|
||||
var callback: TimelineEventController.Callback? = null
|
||||
|
||||
val button1 by bind<Button>(R.id.pollButton1)
|
||||
val button2 by bind<Button>(R.id.pollButton2)
|
||||
val button3 by bind<Button>(R.id.pollButton3)
|
||||
val button4 by bind<Button>(R.id.pollButton4)
|
||||
val button5 by bind<Button>(R.id.pollButton5)
|
||||
|
||||
val result1 by bind<PollResultLineView>(R.id.pollResult1)
|
||||
val result2 by bind<PollResultLineView>(R.id.pollResult2)
|
||||
val result3 by bind<PollResultLineView>(R.id.pollResult3)
|
||||
val result4 by bind<PollResultLineView>(R.id.pollResult4)
|
||||
val result5 by bind<PollResultLineView>(R.id.pollResult5)
|
||||
|
||||
val labelText by bind<TextView>(R.id.pollLabelText)
|
||||
val infoText by bind<TextView>(R.id.pollInfosText)
|
||||
|
||||
val resultWrapper by bind<ViewGroup>(R.id.pollResultsWrapper)
|
||||
|
||||
override fun bindView(itemView: View) {
|
||||
super.bindView(itemView)
|
||||
val buttons = listOf(button1, button2, button3, button4, button5)
|
||||
val clickListener = object : ClickListener {
|
||||
override fun invoke(p1: View) {
|
||||
val optionIndex = buttons.indexOf(p1)
|
||||
if (optionIndex != -1 && pollId != null) {
|
||||
val compatValue = if (optionIndex < optionValues?.size ?: 0) optionValues?.get(optionIndex) else null
|
||||
callback?.onTimelineItemAction(RoomDetailAction.ReplyToOptions(pollId!!, optionIndex, compatValue ?: "$optionIndex"))
|
||||
}
|
||||
}
|
||||
}
|
||||
buttons.forEach { it.onClick(clickListener) }
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val STUB_ID = R.id.messagePollStub
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/optionLabelText"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
tools:text="What would you like to do?" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/optionsButtonContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Filled at runtime with buttons -->
|
||||
<!--Button
|
||||
android:id="@+id/pollButton1"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Create Github issue" /-->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -1,146 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="4dp"
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/ic_poll"
|
||||
app:tint="?colorPrimary"
|
||||
tools:ignore="MissingPrefix" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pollLabelText"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="4dp"
|
||||
android:textColor="?vctr_content_primary"
|
||||
android:textStyle="bold"
|
||||
tools:text="What would you like to do?" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/pollButton1"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="Create Github issue"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pollButton2"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="Search Github"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pollButton3"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="Logout"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pollButton4"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="Option 4"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pollButton5"
|
||||
style="@style/Widget.Vector.Button.Outlined.Poll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="Option 5"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/pollResultsWrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_attachment_type_selector"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<im.vector.app.features.home.room.detail.timeline.item.PollResultLineView
|
||||
android:id="@+id/pollResult1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:optionCount="40%"
|
||||
tools:optionName="Create Github issue"
|
||||
tools:optionSelected="true" />
|
||||
|
||||
<im.vector.app.features.home.room.detail.timeline.item.PollResultLineView
|
||||
android:id="@+id/pollResult2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:optionCount="60%"
|
||||
tools:optionIsWinner="true"
|
||||
tools:optionName="Search Github"
|
||||
tools:optionSelected="false" />
|
||||
|
||||
<im.vector.app.features.home.room.detail.timeline.item.PollResultLineView
|
||||
android:id="@+id/pollResult3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:optionCount="0%"
|
||||
tools:optionName="Logout"
|
||||
tools:optionSelected="false" />
|
||||
|
||||
<im.vector.app.features.home.room.detail.timeline.item.PollResultLineView
|
||||
android:id="@+id/pollResult4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:optionCount="0%"
|
||||
tools:optionName="Option 4"
|
||||
tools:optionSelected="false" />
|
||||
|
||||
<im.vector.app.features.home.room.detail.timeline.item.PollResultLineView
|
||||
android:id="@+id/pollResult5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
tools:optionCount="0%"
|
||||
tools:optionName="Option 5"
|
||||
tools:optionSelected="false" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pollInfosText"
|
||||
style="@style/Widget.Vector.TextView.Caption"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="?vctr_content_secondary"
|
||||
android:visibility="gone"
|
||||
tools:text="12 votes - Final Results"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue