Skip to content

Commit 9e9bbad

Browse files
authored
Jetpack connection UI (#22079)
* Added shell for JetpackConnectionViewModel * Added shell for JetpackConnectionScreen * Fleshed out JetpackConnectionScreen * Minor tweaks * Added canInitiateJetpackConnection * Updated comment * Renamed const * Removed wpApiClient * Added activity shell * Added activity to manifest * Handle close * Pass states rather than the view model * Pass states rather than the view model,p2 * Dummy code to simulate login * Dummy code to simulate login, p2 * Added done button * Animate Done button, added Failed status * Use light MaterialTheme.colorScheme.error color background for failed steps * Animate changes to ConnectionStepItem * Added startNextStep * Added startNextStep, p2 * Added startNextStep, p3 * Fixed UI testing * Fixed UI testing, p2 * Changed color for completed and in-progress cards * Changed color for completed and in-progress cards again * Removed elevation and changed card to column * First pass at Retry * Second pass at Retry * Third pass at Retry * Added error states * Combined states * Fixed Detekt errors * Replaced hard-coded hex color values * Minor formatting changes * Minor formatting changes, p2 * Minor formatting changes, p3 * Updated preview to use JetpackConnectionScreen * Simplified ConnectionStepItem * Moved Screen to ScreenWithTopAppBarM3 * Added modifier * Changed two icons * Fix the done/retry button to the bottom * Removed the heading and changed the screen title * Increase elevation of in-progress step, remove elevation animation * First pass at confirming cancellation * Second pass at confirming cancellation * Fixed detekt warnings * Fixed detekt warnings * Changed fun name * Fixed isActive check * Use ErrorEvent instead of a string * Fixed new Detekt warnings * Renamed variable * Retry starts at the failed step * Moved getNextStep to its own fun * Simplified retrying from step * Added optional message to ErrorType * Updated wp.com error message * Moved color constants to color resources * Use existing color resources for in-progress step * Don't use !! for selected site * Replaced throwing exception with error() to resolve Detekt warning * Simplified JetpackConnectionViewModel * Simplified JetpackConnectionScreen * Simplified JetpackConnectionActivity
1 parent f737f55 commit 9e9bbad

File tree

8 files changed

+910
-1
lines changed

8 files changed

+910
-1
lines changed

WordPress/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,11 @@
849849
android:name=".ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallActivity"
850850
android:theme="@style/WordPress.NoActionBar" />
851851

852+
<!-- Jetpack connection -->
853+
<activity
854+
android:name=".ui.jetpackconnection.JetpackConnectionActivity"
855+
android:theme="@style/WordPress.NoActionBar" />
856+
852857
<!-- Domain Management -->
853858
<activity
854859
android:name=".ui.domains.management.DomainManagementActivity"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.wordpress.android.ui.compose.components
2+
3+
import androidx.annotation.StringRes
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.ColumnScope
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.imePadding
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.material.icons.Icons
10+
import androidx.compose.material.icons.filled.Close
11+
import androidx.compose.material3.ExperimentalMaterial3Api
12+
import androidx.compose.material3.Icon
13+
import androidx.compose.material3.IconButton
14+
import androidx.compose.material3.Scaffold
15+
import androidx.compose.material3.Text
16+
import androidx.compose.material3.TopAppBar
17+
import androidx.compose.runtime.Composable
18+
import androidx.compose.ui.Modifier
19+
import androidx.compose.ui.res.stringResource
20+
import org.wordpress.android.R
21+
import org.wordpress.android.ui.compose.theme.AppThemeM3
22+
23+
/**
24+
* Simple shell for a screen with a top app bar and a close button
25+
*/
26+
@OptIn(ExperimentalMaterial3Api::class)
27+
@Composable
28+
fun ScreenWithTopAppBarM3(
29+
@StringRes titleRes: Int,
30+
content: @Composable (ColumnScope.() -> Unit),
31+
onCloseClick: () -> Unit,
32+
modifier: Modifier = Modifier
33+
) {
34+
AppThemeM3 {
35+
Scaffold(
36+
topBar = {
37+
TopAppBar(
38+
title = { Text(stringResource(id = titleRes)) },
39+
navigationIcon = {
40+
IconButton(onClick = onCloseClick) {
41+
Icon(Icons.Filled.Close, stringResource(R.string.close))
42+
}
43+
},
44+
)
45+
},
46+
modifier = modifier,
47+
) { contentPadding ->
48+
Column(
49+
modifier = Modifier
50+
.fillMaxSize()
51+
.imePadding()
52+
.padding(contentPadding)
53+
) {
54+
content()
55+
}
56+
}
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.wordpress.android.ui.jetpackconnection
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import androidx.activity.viewModels
7+
import androidx.compose.runtime.collectAsState
8+
import androidx.lifecycle.lifecycleScope
9+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
10+
import dagger.hilt.android.AndroidEntryPoint
11+
import kotlinx.coroutines.flow.filterNotNull
12+
import kotlinx.coroutines.launch
13+
import org.wordpress.android.R
14+
import org.wordpress.android.ui.main.BaseAppCompatActivity
15+
import org.wordpress.android.util.extensions.setContent
16+
17+
@AndroidEntryPoint
18+
class JetpackConnectionActivity : BaseAppCompatActivity() {
19+
private val viewModel: JetpackConnectionViewModel by viewModels()
20+
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
23+
setContent {
24+
JetpackConnectionScreen(
25+
currentStep = viewModel.currentStep.collectAsState(),
26+
stepStates = viewModel.stepStates.collectAsState(),
27+
buttonType = viewModel.buttonType.collectAsState(),
28+
onCloseClick = viewModel::onCloseClick,
29+
onRetryClick = viewModel::onRetryClick
30+
)
31+
}
32+
33+
lifecycleScope.launch {
34+
viewModel.uiEvent.filterNotNull().collect { event ->
35+
when (event) {
36+
JetpackConnectionViewModel.UiEvent.Close -> finish()
37+
JetpackConnectionViewModel.UiEvent.ShowCancelConfirmation -> showCancelConfirmationDialog()
38+
}
39+
}
40+
}
41+
}
42+
43+
private fun showCancelConfirmationDialog() {
44+
MaterialAlertDialogBuilder(this)
45+
.setTitle(R.string.jetpack_connection_cancel_title)
46+
.setMessage(R.string.jetpack_connection_cancel_message)
47+
.setPositiveButton(R.string.yes) { _, _ -> viewModel.onCancelConfirmed() }
48+
.setNegativeButton(R.string.no) { _, _ -> viewModel.onCancelDismissed() }
49+
.setCancelable(false)
50+
.show()
51+
}
52+
53+
companion object {
54+
@JvmStatic
55+
fun createIntent(context: Context) =
56+
Intent(context, JetpackConnectionActivity::class.java)
57+
}
58+
}

0 commit comments

Comments
 (0)