Improve rendering of title of the folder view
This commit is contained in:
@@ -18,6 +18,7 @@ import dev.zacsweers.metro.AssistedFactory
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.features.viewfolder.impl.model.Item
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@Inject
|
||||
@@ -25,6 +26,7 @@ class ViewFolderPresenter(
|
||||
@Assisted val canGoUp: Boolean,
|
||||
@Assisted val path: String,
|
||||
private val folderExplorer: FolderExplorer,
|
||||
private val buildMeta: BuildMeta,
|
||||
) : Presenter<ViewFolderState> {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
@@ -34,6 +36,14 @@ class ViewFolderPresenter(
|
||||
@Composable
|
||||
override fun present(): ViewFolderState {
|
||||
var content by remember { mutableStateOf(emptyList<Item>()) }
|
||||
val title = remember {
|
||||
buildString {
|
||||
if (path.contains(buildMeta.applicationId)) {
|
||||
append("…")
|
||||
}
|
||||
append(path.substringAfter(buildMeta.applicationId))
|
||||
}
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
content = buildList {
|
||||
if (canGoUp) add(Item.Parent)
|
||||
@@ -41,7 +51,7 @@ class ViewFolderPresenter(
|
||||
}
|
||||
}
|
||||
return ViewFolderState(
|
||||
path = path,
|
||||
title = title,
|
||||
content = content.toImmutableList(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ import io.element.android.features.viewfolder.impl.model.Item
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
data class ViewFolderState(
|
||||
val path: String,
|
||||
val title: String,
|
||||
val content: ImmutableList<Item>,
|
||||
)
|
||||
|
||||
@@ -26,9 +26,9 @@ open class ViewFolderStateProvider : PreviewParameterProvider<ViewFolderState> {
|
||||
}
|
||||
|
||||
fun aViewFolderState(
|
||||
path: String = "aPath",
|
||||
title: String = "aPath",
|
||||
content: List<Item> = emptyList(),
|
||||
) = ViewFolderState(
|
||||
path = path,
|
||||
title = title,
|
||||
content = content.toImmutableList(),
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ fun ViewFolderView(
|
||||
navigationIcon = {
|
||||
BackButton(onClick = onBackClick)
|
||||
},
|
||||
titleStr = state.path,
|
||||
titleStr = state.title,
|
||||
)
|
||||
},
|
||||
content = { padding ->
|
||||
|
||||
@@ -14,7 +14,10 @@ import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.viewfolder.impl.folder.FolderExplorer
|
||||
import io.element.android.features.viewfolder.impl.folder.ViewFolderPresenter
|
||||
import io.element.android.features.viewfolder.impl.model.Item
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.test
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@@ -30,11 +33,25 @@ class ViewFolderPresenterTest {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.path).isEqualTo("aPath")
|
||||
assertThat(initialState.title).isEqualTo("aPath")
|
||||
assertThat(initialState.content).isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - title is built regarding the applicationId`() = runTest {
|
||||
val presenter = createPresenter(
|
||||
path = "/data/user/O/appId/cache/logs",
|
||||
buildMeta = aBuildMeta(
|
||||
applicationId = "appId",
|
||||
)
|
||||
)
|
||||
presenter.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.title).isEqualTo("…/cache/logs")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - list items from root`() = runTest {
|
||||
val items = listOf(
|
||||
@@ -50,7 +67,7 @@ class ViewFolderPresenterTest {
|
||||
}.test {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.path).isEqualTo("aPath")
|
||||
assertThat(initialState.title).isEqualTo("aPath")
|
||||
assertThat(initialState.content.toList()).isEqualTo(items)
|
||||
}
|
||||
}
|
||||
@@ -73,7 +90,7 @@ class ViewFolderPresenterTest {
|
||||
}.test {
|
||||
skipItems(1)
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.path).isEqualTo("aPath")
|
||||
assertThat(initialState.title).isEqualTo("aPath")
|
||||
assertThat(initialState.content.toList()).isEqualTo(listOf(Item.Parent) + items)
|
||||
}
|
||||
}
|
||||
@@ -82,9 +99,13 @@ class ViewFolderPresenterTest {
|
||||
canGoUp: Boolean = false,
|
||||
path: String = "aPath",
|
||||
folderExplorer: FolderExplorer = FakeFolderExplorer(),
|
||||
buildMeta: BuildMeta = aBuildMeta(
|
||||
applicationId = "appId",
|
||||
),
|
||||
) = ViewFolderPresenter(
|
||||
path = path,
|
||||
canGoUp = canGoUp,
|
||||
folderExplorer = folderExplorer,
|
||||
buildMeta = buildMeta,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user