Restore view log code (#5294)
* Restore commented out code. Fix regression from #5253 * Format files. * Improve rendering of title of the folder view * Compute the content in the LaunchEffect
This commit is contained in:
commit
7a230ebfa7
7 changed files with 62 additions and 30 deletions
|
|
@ -29,11 +29,11 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
class DeclineAndBlockPresenter(
|
class DeclineAndBlockPresenter(
|
||||||
@Assisted private val inviteData: InviteData,
|
@Assisted private val inviteData: InviteData,
|
||||||
private val declineInvite: DeclineInvite,
|
private val declineInvite: DeclineInvite,
|
||||||
private val snackbarDispatcher: SnackbarDispatcher,
|
private val snackbarDispatcher: SnackbarDispatcher,
|
||||||
) : Presenter<DeclineAndBlockState> {
|
) : Presenter<DeclineAndBlockState> {
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(inviteData: InviteData): DeclineAndBlockPresenter
|
fun create(inviteData: InviteData): DeclineAndBlockPresenter
|
||||||
|
|
@ -90,4 +90,4 @@ import kotlinx.coroutines.launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import io.element.android.libraries.architecture.inputs
|
||||||
class ViewFolderNode(
|
class ViewFolderNode(
|
||||||
@Assisted buildContext: BuildContext,
|
@Assisted buildContext: BuildContext,
|
||||||
@Assisted plugins: List<Plugin>,
|
@Assisted plugins: List<Plugin>,
|
||||||
// presenterFactory: ViewFolderPresenter.Factory,
|
presenterFactory: ViewFolderPresenter.Factory,
|
||||||
) : Node(buildContext, plugins = plugins) {
|
) : Node(buildContext, plugins = plugins) {
|
||||||
data class Inputs(
|
data class Inputs(
|
||||||
val canGoUp: Boolean,
|
val canGoUp: Boolean,
|
||||||
|
|
@ -40,10 +40,10 @@ class ViewFolderNode(
|
||||||
|
|
||||||
private val inputs: Inputs = inputs()
|
private val inputs: Inputs = inputs()
|
||||||
|
|
||||||
// private val presenter = presenterFactory.create(
|
private val presenter = presenterFactory.create(
|
||||||
// canGoUp = inputs.canGoUp,
|
canGoUp = inputs.canGoUp,
|
||||||
// path = inputs.path,
|
path = inputs.path,
|
||||||
// )
|
)
|
||||||
|
|
||||||
private fun onBackClick() {
|
private fun onBackClick() {
|
||||||
plugins<Callback>().forEach { it.onBackClick() }
|
plugins<Callback>().forEach { it.onBackClick() }
|
||||||
|
|
@ -55,12 +55,12 @@ class ViewFolderNode(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun View(modifier: Modifier) {
|
override fun View(modifier: Modifier) {
|
||||||
// val state = presenter.present()
|
val state = presenter.present()
|
||||||
// ViewFolderView(
|
ViewFolderView(
|
||||||
// state = state,
|
state = state,
|
||||||
// modifier = modifier,
|
modifier = modifier,
|
||||||
// onNavigateTo = ::onNavigateTo,
|
onNavigateTo = ::onNavigateTo,
|
||||||
// onBackClick = ::onBackClick,
|
onBackClick = ::onBackClick,
|
||||||
// )
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,17 @@ import dev.zacsweers.metro.AssistedFactory
|
||||||
import dev.zacsweers.metro.Inject
|
import dev.zacsweers.metro.Inject
|
||||||
import io.element.android.features.viewfolder.impl.model.Item
|
import io.element.android.features.viewfolder.impl.model.Item
|
||||||
import io.element.android.libraries.architecture.Presenter
|
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
|
@Inject
|
||||||
class ViewFolderPresenter(
|
class ViewFolderPresenter(
|
||||||
@Assisted val canGoUp: Boolean,
|
@Assisted val canGoUp: Boolean,
|
||||||
@Assisted val path: String,
|
@Assisted val path: String,
|
||||||
private val folderExplorer: FolderExplorer,
|
private val folderExplorer: FolderExplorer,
|
||||||
) : Presenter<ViewFolderState> {
|
private val buildMeta: BuildMeta,
|
||||||
|
) : Presenter<ViewFolderState> {
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(canGoUp: Boolean, path: String): ViewFolderPresenter
|
fun create(canGoUp: Boolean, path: String): ViewFolderPresenter
|
||||||
|
|
@ -33,16 +36,24 @@ import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): ViewFolderState {
|
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) {
|
LaunchedEffect(Unit) {
|
||||||
content = buildList {
|
content = buildList {
|
||||||
if (canGoUp) add(Item.Parent)
|
if (canGoUp) add(Item.Parent)
|
||||||
addAll(folderExplorer.getItems(path))
|
addAll(folderExplorer.getItems(path))
|
||||||
}
|
}.toPersistentList()
|
||||||
}
|
}
|
||||||
return ViewFolderState(
|
return ViewFolderState(
|
||||||
path = path,
|
title = title,
|
||||||
content = content.toImmutableList(),
|
content = content,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ import io.element.android.features.viewfolder.impl.model.Item
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
|
||||||
data class ViewFolderState(
|
data class ViewFolderState(
|
||||||
val path: String,
|
val title: String,
|
||||||
val content: ImmutableList<Item>,
|
val content: ImmutableList<Item>,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ open class ViewFolderStateProvider : PreviewParameterProvider<ViewFolderState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aViewFolderState(
|
fun aViewFolderState(
|
||||||
path: String = "aPath",
|
title: String = "aPath",
|
||||||
content: List<Item> = emptyList(),
|
content: List<Item> = emptyList(),
|
||||||
) = ViewFolderState(
|
) = ViewFolderState(
|
||||||
path = path,
|
title = title,
|
||||||
content = content.toImmutableList(),
|
content = content.toImmutableList(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ fun ViewFolderView(
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
BackButton(onClick = onBackClick)
|
BackButton(onClick = onBackClick)
|
||||||
},
|
},
|
||||||
titleStr = state.path,
|
titleStr = state.title,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
content = { padding ->
|
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.FolderExplorer
|
||||||
import io.element.android.features.viewfolder.impl.folder.ViewFolderPresenter
|
import io.element.android.features.viewfolder.impl.folder.ViewFolderPresenter
|
||||||
import io.element.android.features.viewfolder.impl.model.Item
|
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.WarmUpRule
|
||||||
|
import io.element.android.tests.testutils.test
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
@ -30,11 +33,25 @@ class ViewFolderPresenterTest {
|
||||||
presenter.present()
|
presenter.present()
|
||||||
}.test {
|
}.test {
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
assertThat(initialState.path).isEqualTo("aPath")
|
assertThat(initialState.title).isEqualTo("aPath")
|
||||||
assertThat(initialState.content).isEmpty()
|
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
|
@Test
|
||||||
fun `present - list items from root`() = runTest {
|
fun `present - list items from root`() = runTest {
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
|
|
@ -50,7 +67,7 @@ class ViewFolderPresenterTest {
|
||||||
}.test {
|
}.test {
|
||||||
skipItems(1)
|
skipItems(1)
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
assertThat(initialState.path).isEqualTo("aPath")
|
assertThat(initialState.title).isEqualTo("aPath")
|
||||||
assertThat(initialState.content.toList()).isEqualTo(items)
|
assertThat(initialState.content.toList()).isEqualTo(items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +90,7 @@ class ViewFolderPresenterTest {
|
||||||
}.test {
|
}.test {
|
||||||
skipItems(1)
|
skipItems(1)
|
||||||
val initialState = awaitItem()
|
val initialState = awaitItem()
|
||||||
assertThat(initialState.path).isEqualTo("aPath")
|
assertThat(initialState.title).isEqualTo("aPath")
|
||||||
assertThat(initialState.content.toList()).isEqualTo(listOf(Item.Parent) + items)
|
assertThat(initialState.content.toList()).isEqualTo(listOf(Item.Parent) + items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,9 +99,13 @@ class ViewFolderPresenterTest {
|
||||||
canGoUp: Boolean = false,
|
canGoUp: Boolean = false,
|
||||||
path: String = "aPath",
|
path: String = "aPath",
|
||||||
folderExplorer: FolderExplorer = FakeFolderExplorer(),
|
folderExplorer: FolderExplorer = FakeFolderExplorer(),
|
||||||
|
buildMeta: BuildMeta = aBuildMeta(
|
||||||
|
applicationId = "appId",
|
||||||
|
),
|
||||||
) = ViewFolderPresenter(
|
) = ViewFolderPresenter(
|
||||||
path = path,
|
path = path,
|
||||||
canGoUp = canGoUp,
|
canGoUp = canGoUp,
|
||||||
folderExplorer = folderExplorer,
|
folderExplorer = folderExplorer,
|
||||||
|
buildMeta = buildMeta,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue