Breadcrumbs: auto-review

This commit is contained in:
Benoit Marty 2019-12-05 22:38:49 +01:00
parent aef76241a3
commit 9a4d8f87f6
11 changed files with 31 additions and 30 deletions

View file

@ -17,7 +17,7 @@ Client request the sign-up flows, once the homeserver is chosen by the user and
}
```
We get the flows with a 401, which also means the the registration is possible on this homeserver.
We get the flows with a 401, which also means that the registration is possible on this homeserver.
```json
{

View file

@ -35,11 +35,11 @@ internal abstract class AccountDataModule {
}
@Binds
abstract fun bindUpdateUserAccountDataTask(updateUserAccountDataTask: DefaultUpdateUserAccountDataTask): UpdateUserAccountDataTask
abstract fun bindUpdateUserAccountDataTask(task: DefaultUpdateUserAccountDataTask): UpdateUserAccountDataTask
@Binds
abstract fun bindSaveBreadcrumbsTask(saveBreadcrumbsTask: DefaultSaveBreadcrumbsTask): SaveBreadcrumbsTask
abstract fun bindSaveBreadcrumbsTask(task: DefaultSaveBreadcrumbsTask): SaveBreadcrumbsTask
@Binds
abstract fun bindUpdateBreadcrumsTask(saveBreadcrumbsTask: DefaultUpdateBreadcrumbsTask): UpdateBreadcrumbsTask
abstract fun bindUpdateBreadcrumsTask(task: DefaultUpdateBreadcrumbsTask): UpdateBreadcrumbsTask
}

View file

@ -46,9 +46,9 @@ internal class DefaultUpdateBreadcrumbsTask @Inject constructor(
?.recentRoomIds
?.apply {
// Modify the list to add the newTopRoomId first
// Ensure the roomId is not already in the list
// Ensure the newTopRoomId is not already in the list
remove(params.newTopRoomId)
// Add the room at first position
// Add the newTopRoomId at first position
add(0, params.newTopRoomId)
}
?.take(MAX_BREADCRUMBS_ROOMS_NUMBER)

View file

@ -18,7 +18,6 @@ package im.vector.riotx.features.home.room.breadcrumbs
import android.view.View
import com.airbnb.epoxy.EpoxyController
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotx.core.utils.DebouncedClickListener
import im.vector.riotx.features.home.AvatarRenderer
import javax.inject.Inject
@ -33,7 +32,7 @@ class BreadcrumbsController @Inject constructor(
init {
// We are requesting a model build directly as the first build of epoxy is on the main thread.
// It avoids to build the the whole list of rooms on the main thread.
// It avoids to build the whole list of breadcrumbs on the main thread.
requestModelBuild()
}
@ -43,11 +42,12 @@ class BreadcrumbsController @Inject constructor(
}
override fun buildModels() {
val nonNullViewState = viewState ?: return
val safeViewState = viewState ?: return
// TODO Display a loading, or an empty state
// An empty breadcrumbs list can only be temporary because when entering in a room,
// this one is added to the breadcrumbs
nonNullViewState.asyncRooms.invoke()
safeViewState.asyncBreadcrumbs.invoke()
?.forEach {
breadcrumbsItem {
id(it.roomId)
@ -61,7 +61,7 @@ class BreadcrumbsController @Inject constructor(
hasDraft(it.userDrafts.isNotEmpty())
itemClickListener(
DebouncedClickListener(View.OnClickListener { _ ->
listener?.onRoomClicked(it)
listener?.onBreadcrumbClicked(it.roomId)
})
)
}
@ -69,6 +69,6 @@ class BreadcrumbsController @Inject constructor(
}
interface Listener {
fun onRoomClicked(room: RoomSummary)
fun onBreadcrumbClicked(roomId: String)
}
}

View file

@ -20,7 +20,6 @@ import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.mvrx.fragmentViewModel
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotx.R
import im.vector.riotx.core.platform.VectorBaseFragment
import im.vector.riotx.features.home.room.detail.RoomDetailSharedAction
@ -65,7 +64,7 @@ class BreadcrumbsFragment @Inject constructor(
// BreadcrumbsController.Listener **************************************************************
override fun onRoomClicked(room: RoomSummary) {
sharedActionViewModel.post(RoomDetailSharedAction.OpenRoom(room.roomId))
override fun onBreadcrumbClicked(roomId: String) {
sharedActionViewModel.post(RoomDetailSharedAction.SwitchToRoom(roomId))
}
}

View file

@ -59,8 +59,8 @@ class BreadcrumbsViewModel @AssistedInject constructor(@Assisted initialState: B
session.rx()
.liveBreadcrumbs()
.observeOn(Schedulers.computation())
.execute { asyncRooms ->
copy(asyncRooms = asyncRooms)
.execute { asyncBreadcrumbs ->
copy(asyncBreadcrumbs = asyncBreadcrumbs)
}
}
}

View file

@ -22,5 +22,5 @@ import com.airbnb.mvrx.Uninitialized
import im.vector.matrix.android.api.session.room.model.RoomSummary
data class BreadcrumbsViewState(
val asyncRooms: Async<List<RoomSummary>> = Uninitialized
val asyncBreadcrumbs: Async<List<RoomSummary>> = Uninitialized
) : MvRxState

View file

@ -57,14 +57,7 @@ class RoomDetailActivity : VectorBaseActivity(), ToolbarConfigurable {
.observe()
.subscribe { sharedAction ->
when (sharedAction) {
is RoomDetailSharedAction.OpenRoom -> {
drawerLayout.closeDrawer(GravityCompat.START)
// Do not replace the Fragment if it's the same roomId
if (currentRoomId != sharedAction.roomId) {
currentRoomId = sharedAction.roomId
replaceFragment(R.id.roomDetailContainer, RoomDetailFragment::class.java, RoomDetailArgs(sharedAction.roomId))
}
}
is RoomDetailSharedAction.SwitchToRoom -> switchToRoom(sharedAction)
}
}
.disposeOnDestroy()
@ -72,6 +65,15 @@ class RoomDetailActivity : VectorBaseActivity(), ToolbarConfigurable {
drawerLayout.addDrawerListener(drawerListener)
}
private fun switchToRoom(switchToRoom: RoomDetailSharedAction.SwitchToRoom) {
drawerLayout.closeDrawer(GravityCompat.START)
// Do not replace the Fragment if it's the same roomId
if (currentRoomId != switchToRoom.roomId) {
currentRoomId = switchToRoom.roomId
replaceFragment(R.id.roomDetailContainer, RoomDetailFragment::class.java, RoomDetailArgs(switchToRoom.roomId))
}
}
override fun onDestroy() {
drawerLayout.removeDrawerListener(drawerListener)
super.onDestroy()

View file

@ -22,5 +22,5 @@ import im.vector.riotx.core.platform.VectorSharedAction
* Supported navigation actions for [RoomDetailActivity]
*/
sealed class RoomDetailSharedAction : VectorSharedAction {
data class OpenRoom(val roomId: String) : RoomDetailSharedAction()
data class SwitchToRoom(val roomId: String) : RoomDetailSharedAction()
}

View file

@ -42,7 +42,7 @@ class RoomSummaryController @Inject constructor(private val stringProvider: Stri
init {
// We are requesting a model build directly as the first build of epoxy is on the main thread.
// It avoids to build the the whole list of rooms on the main thread.
// It avoids to build the whole list of rooms on the main thread.
requestModelBuild()
}

View file

@ -5,4 +5,4 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?riotx_background"
tools:listitem="@layout/item_breadcrumbs" />
tools:listitem="@layout/item_breadcrumbs" />