Adding load more item at the end of the list of polls

This commit is contained in:
Maxime NATUREL 2023-01-11 14:41:25 +01:00
parent 479b573dbb
commit e8e94b5189
5 changed files with 89 additions and 0 deletions

View File

@ -3201,6 +3201,7 @@
<string name="room_polls_active_no_item">There are no active polls in this room</string>
<string name="room_polls_ended">Past polls</string>
<string name="room_polls_ended_no_item">There are no past polls in this room</string>
<string name="room_polls_load_more">Load more polls</string>
<!-- Location -->
<string name="location_activity_title_static_sharing">Share location</string>

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 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.roomprofile.polls.list
import android.widget.Button
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.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.onClick
@EpoxyModelClass
abstract class RoomPollLoadMoreItem : VectorEpoxyModel<RoomPollLoadMoreItem.Holder>(R.layout.item_poll_load_more) {
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var clickListener: ClickListener? = null
override fun bind(holder: Holder) {
super.bind(holder)
holder.loadMoreButton.onClick(clickListener)
}
class Holder : VectorEpoxyHolder() {
val loadMoreButton by bind<Button>(R.id.roomPollsLoadMore)
}
}

View File

@ -31,6 +31,7 @@ class RoomPollsController @Inject constructor(
interface Listener {
fun onPollClicked(pollId: String)
fun onLoadMoreClicked()
}
var listener: Listener? = null
@ -46,6 +47,8 @@ class RoomPollsController @Inject constructor(
is PollSummary.EndedPoll -> buildEndedPollItem(poll)
}
}
buildLoadMoreItem()
}
private fun buildActivePollItem(poll: PollSummary.ActivePoll) {
@ -73,4 +76,12 @@ class RoomPollsController @Inject constructor(
}
}
}
private fun buildLoadMoreItem() {
val host = this
roomPollLoadMoreItem {
id("roomPollLoadMore")
host.listener?.onLoadMoreClicked()
}
}
}

View File

@ -33,6 +33,8 @@ import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
import timber.log.Timber
import javax.inject.Inject
// TODO add and render blocking loader view
// TODO add and render missing empty view when load more is possible
abstract class RoomPollsListFragment :
VectorBaseFragment<FragmentRoomPollsListBinding>(),
RoomPollsController.Listener {
@ -87,4 +89,8 @@ abstract class RoomPollsListFragment :
// TODO navigate to details
Timber.d("poll with id $pollId clicked")
}
override fun onLoadMoreClicked() {
// TODO call viewAction
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/roomPollsLoadMore"
style="@style/Widget.Vector.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="38dp"
android:layout_marginBottom="46dp"
android:padding="0dp"
android:text="@string/room_polls_load_more"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/roomPollsLoadMoreProgress"
style="?android:attr/progressBarStyle"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="9dp"
app:layout_constraintBottom_toBottomOf="@id/roomPollsLoadMore"
app:layout_constraintStart_toEndOf="@id/roomPollsLoadMore"
app:layout_constraintTop_toTopOf="@id/roomPollsLoadMore" />
</androidx.constraintlayout.widget.ConstraintLayout>