Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Inject
class DeclineAndBlockPresenter(
class DeclineAndBlockPresenter(
@Assisted private val inviteData: InviteData,
private val declineInvite: DeclineInvite,
private val snackbarDispatcher: SnackbarDispatcher,
) : Presenter<DeclineAndBlockState> {
) : Presenter<DeclineAndBlockState> {
@AssistedFactory
interface Factory {
fun create(inviteData: InviteData): DeclineAndBlockPresenter
Expand Down Expand Up @@ -90,4 +90,4 @@ import kotlinx.coroutines.launch
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.element.android.libraries.architecture.inputs
class ViewFolderNode(
@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
// presenterFactory: ViewFolderPresenter.Factory,
presenterFactory: ViewFolderPresenter.Factory,
) : Node(buildContext, plugins = plugins) {
data class Inputs(
val canGoUp: Boolean,
Expand All @@ -40,10 +40,10 @@ class ViewFolderNode(

private val inputs: Inputs = inputs()

// private val presenter = presenterFactory.create(
// canGoUp = inputs.canGoUp,
// path = inputs.path,
// )
private val presenter = presenterFactory.create(
canGoUp = inputs.canGoUp,
path = inputs.path,
)

private fun onBackClick() {
plugins<Callback>().forEach { it.onBackClick() }
Expand All @@ -55,12 +55,12 @@ class ViewFolderNode(

@Composable
override fun View(modifier: Modifier) {
// val state = presenter.present()
// ViewFolderView(
// state = state,
// modifier = modifier,
// onNavigateTo = ::onNavigateTo,
// onBackClick = ::onBackClick,
// )
val state = presenter.present()
ViewFolderView(
state = state,
modifier = modifier,
onNavigateTo = ::onNavigateTo,
onBackClick = ::onBackClick,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,42 @@ 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 kotlinx.collections.immutable.toImmutableList
import io.element.android.libraries.core.meta.BuildMeta
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList

@Inject
class ViewFolderPresenter(
class ViewFolderPresenter(
@Assisted val canGoUp: Boolean,
@Assisted val path: String,
private val folderExplorer: FolderExplorer,
) : Presenter<ViewFolderState> {
private val buildMeta: BuildMeta,
) : Presenter<ViewFolderState> {
@AssistedFactory
interface Factory {
fun create(canGoUp: Boolean, path: String): ViewFolderPresenter
}

@Composable
override fun present(): ViewFolderState {
var content by remember { mutableStateOf(emptyList<Item>()) }
var content by remember { mutableStateOf(persistentListOf<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)
addAll(folderExplorer.getItems(path))
}
}.toPersistentList()
}
return ViewFolderState(
path = path,
content = content.toImmutableList(),
title = title,
content = content,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun ViewFolderView(
navigationIcon = {
BackButton(onClick = onBackClick)
},
titleStr = state.path,
titleStr = state.title,
)
},
content = { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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,
)
}