Skip to content

Commit d6b6d97

Browse files
committed
Bug 2010700 - Created public compose root and store primitives for s2s
1 parent 19e291c commit d6b6d97

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed

mobile/android/android-components/.buildconfig.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,8 @@ projects:
13911391
publish: true
13921392
upstream_dependencies:
13931393
- components:tooling-lint
1394+
- components:lib-state
1395+
- components:compose-base
13941396
components:feature-syncedtabs:
13951397
description: Feature that provides access to other devices' tabs in the same account.
13961398
path: components/feature/syncedtabs

mobile/android/android-components/components/feature/summarize/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
plugins {
66
alias(libs.plugins.dependency.analysis)
7+
alias(libs.plugins.kotlin.compose)
78
}
89

910
apply plugin: 'com.android.library'
@@ -16,13 +17,23 @@ android {
1617

1718
buildFeatures {
1819
buildConfig = true
20+
compose = true
1921
}
2022

2123
namespace = 'mozilla.components.feature.summarize'
2224
}
2325

2426
dependencies {
27+
implementation project(':components:lib-state')
28+
2529
testImplementation libs.androidx.test.junit
30+
31+
implementation libs.androidx.compose.foundation
32+
implementation libs.androidx.compose.ui.tooling.preview
33+
implementation libs.androidx.compose.ui
34+
implementation libs.androidx.compose.material3
35+
debugImplementation libs.androidx.compose.ui.tooling
36+
2637
}
2738

2839
apply from: '../../../common-config.gradle'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.summarize
6+
7+
import mozilla.components.lib.state.Middleware
8+
import mozilla.components.lib.state.Store
9+
10+
internal class SummarizationMiddleware : Middleware<SummarizationState, SummarizationAction> {
11+
override fun invoke(
12+
store: Store<SummarizationState, SummarizationAction>,
13+
next: (SummarizationAction) -> Unit,
14+
action: SummarizationAction,
15+
) {
16+
TODO("Not yet implemented")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.summarize
6+
7+
internal fun summarizationReducer(state: SummarizationState, action: SummarizationAction) = when (action) {
8+
else -> { state }
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.summarize
6+
7+
import androidx.compose.material3.Text
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.tooling.preview.Preview
10+
import androidx.compose.ui.tooling.preview.PreviewParameter
11+
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
12+
13+
/**
14+
* Composable function that renders the summarized text of a webpage.
15+
**/
16+
@Composable
17+
fun SummarizationUi() {
18+
SummarizationScreen(
19+
SummarizationStore(
20+
initialState = SummarizationState(
21+
pageSummarizationState = PageSummarizationState.Inert,
22+
),
23+
reducer = ::summarizationReducer,
24+
middleware = listOf(SummarizationMiddleware()),
25+
),
26+
)
27+
}
28+
29+
@Composable
30+
private fun SummarizationScreen(store: SummarizationStore) {
31+
Text(store.state.summarizedText)
32+
}
33+
34+
private class SummarizationStatePreviewProvider : PreviewParameterProvider<SummarizationState> {
35+
override val values: Sequence<SummarizationState> = sequenceOf(
36+
SummarizationState(
37+
PageSummarizationState.Summarizing,
38+
summarizedText = "Lorem Ipsum",
39+
),
40+
SummarizationState(
41+
PageSummarizationState.Error(SummarizationError.ContentTooLong),
42+
),
43+
SummarizationState(
44+
PageSummarizationState.WaitingForPermission,
45+
),
46+
)
47+
}
48+
49+
@Preview
50+
@Composable
51+
private fun SummarizationScreenPreview(
52+
@PreviewParameter(SummarizationStatePreviewProvider::class) state: SummarizationState,
53+
) {
54+
SummarizationScreen(
55+
SummarizationStore(
56+
initialState = state,
57+
reducer = ::summarizationReducer,
58+
middleware = listOf(SummarizationMiddleware()),
59+
),
60+
)
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.summarize
6+
7+
import mozilla.components.lib.state.Action
8+
import mozilla.components.lib.state.State
9+
import mozilla.components.lib.state.Store
10+
11+
internal typealias SummarizationStore = Store<SummarizationState, SummarizationAction>
12+
13+
internal interface SummarizationAction : Action
14+
15+
internal data class SummarizationState(
16+
val pageSummarizationState: PageSummarizationState,
17+
val summarizedText: String = "",
18+
) : State
19+
20+
internal sealed class PageSummarizationState {
21+
data object Inert : PageSummarizationState()
22+
data object WaitingForPermission : PageSummarizationState()
23+
data object Summarizing : PageSummarizationState()
24+
data class Summarized(val text: String) : PageSummarizationState()
25+
data class Error(val error: SummarizationError) : PageSummarizationState()
26+
}
27+
28+
internal sealed class SummarizationError {
29+
object PermissionDenied : SummarizationError()
30+
object ContentUnavailable : SummarizationError()
31+
object ContentTooShort : SummarizationError()
32+
object ContentTooLong : SummarizationError()
33+
object SummarizationFailed : SummarizationError()
34+
object InvalidSummary : SummarizationError()
35+
object NetworkError : SummarizationError()
36+
}

0 commit comments

Comments
 (0)