Skip to content

Commit 5635deb

Browse files
[Jetsurvey] Update to alpha12 snapshot
1 parent a83f238 commit 5635deb

File tree

12 files changed

+68
-50
lines changed

12 files changed

+68
-50
lines changed

Jetsurvey/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ dependencies {
9595
implementation Libs.AndroidX.Material.material
9696
implementation Libs.material
9797

98+
implementation Libs.AndroidX.Lifecycle.viewmodel
99+
implementation Libs.AndroidX.Lifecycle.viewModelCompose
100+
98101
implementation Libs.AndroidX.Compose.layout
99102
implementation Libs.AndroidX.Compose.material
100103
implementation Libs.AndroidX.Compose.materialIconsExtended

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/SignInFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import android.view.ViewGroup
2323
import androidx.compose.ui.platform.ComposeView
2424
import androidx.fragment.app.Fragment
2525
import androidx.fragment.app.viewModels
26-
import androidx.lifecycle.observe
2726
import com.example.compose.jetsurvey.R
2827
import com.example.compose.jetsurvey.Screen
2928
import com.example.compose.jetsurvey.navigate
@@ -41,7 +40,7 @@ class SignInFragment : Fragment() {
4140
container: ViewGroup?,
4241
savedInstanceState: Bundle?
4342
): View? {
44-
viewModel.navigateTo.observe(owner = viewLifecycleOwner) { navigateToEvent ->
43+
viewModel.navigateTo.observe(viewLifecycleOwner) { navigateToEvent ->
4544
navigateToEvent.getContentIfNotHandled()?.let { navigateTo ->
4645
navigate(navigateTo, Screen.SignIn)
4746
}

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/SignInSignUp.kt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import androidx.compose.foundation.layout.preferredHeight
2727
import androidx.compose.foundation.layout.preferredWidth
2828
import androidx.compose.foundation.layout.wrapContentSize
2929
import androidx.compose.foundation.lazy.LazyColumn
30+
import androidx.compose.foundation.text.KeyboardActions
3031
import androidx.compose.foundation.text.KeyboardOptions
31-
import androidx.compose.material.AmbientContentAlpha
32-
import androidx.compose.material.AmbientTextStyle
3332
import androidx.compose.material.ContentAlpha
3433
import androidx.compose.material.Icon
3534
import androidx.compose.material.IconButton
35+
import androidx.compose.material.LocalContentAlpha
36+
import androidx.compose.material.LocalTextStyle
3637
import androidx.compose.material.MaterialTheme
3738
import androidx.compose.material.OutlinedButton
3839
import androidx.compose.material.OutlinedTextField
@@ -52,6 +53,7 @@ import androidx.compose.ui.Modifier
5253
import androidx.compose.ui.focus.FocusState
5354
import androidx.compose.ui.focus.onFocusChanged
5455
import androidx.compose.ui.res.stringResource
56+
import androidx.compose.ui.text.SoftwareKeyboardController
5557
import androidx.compose.ui.text.input.ImeAction
5658
import androidx.compose.ui.text.input.PasswordVisualTransformation
5759
import androidx.compose.ui.text.input.VisualTransformation
@@ -122,13 +124,14 @@ fun Email(
122124
imeAction: ImeAction = ImeAction.Next,
123125
onImeAction: () -> Unit = {}
124126
) {
127+
lateinit var softwareKeyboardController: SoftwareKeyboardController
125128
OutlinedTextField(
126129
value = emailState.text,
127130
onValueChange = {
128131
emailState.text = it
129132
},
130133
label = {
131-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
134+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
132135
Text(
133136
text = stringResource(id = R.string.email),
134137
style = MaterialTheme.typography.body2
@@ -146,13 +149,14 @@ fun Email(
146149
},
147150
textStyle = MaterialTheme.typography.body2,
148151
isErrorValue = emailState.showErrors(),
152+
onTextInputStarted = { softwareKeyboardController = it },
149153
keyboardOptions = KeyboardOptions.Default.copy(imeAction = imeAction),
150-
onImeActionPerformed = { action, softKeyboardController ->
151-
if (action == ImeAction.Done) {
152-
softKeyboardController?.hideSoftwareKeyboard()
154+
keyboardActions = KeyboardActions(
155+
onDone = {
156+
onImeAction()
157+
softwareKeyboardController.hideSoftwareKeyboard()
153158
}
154-
onImeAction()
155-
}
159+
)
156160
)
157161

158162
emailState.getError()?.let { error -> TextFieldError(textError = error) }
@@ -166,6 +170,7 @@ fun Password(
166170
imeAction: ImeAction = ImeAction.Done,
167171
onImeAction: () -> Unit = {}
168172
) {
173+
lateinit var softwareKeyboardController: SoftwareKeyboardController
169174
val showPassword = remember { mutableStateOf(false) }
170175
OutlinedTextField(
171176
value = passwordState.text,
@@ -184,7 +189,7 @@ fun Password(
184189
},
185190
textStyle = MaterialTheme.typography.body2,
186191
label = {
187-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
192+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
188193
Text(
189194
text = label,
190195
style = MaterialTheme.typography.body2
@@ -214,13 +219,14 @@ fun Password(
214219
PasswordVisualTransformation()
215220
},
216221
isErrorValue = passwordState.showErrors(),
222+
onTextInputStarted = { softwareKeyboardController = it },
217223
keyboardOptions = KeyboardOptions.Default.copy(imeAction = imeAction),
218-
onImeActionPerformed = { action, softKeyboardController ->
219-
if (action == ImeAction.Done) {
220-
softKeyboardController?.hideSoftwareKeyboard()
224+
keyboardActions = KeyboardActions(
225+
onDone = {
226+
onImeAction()
227+
softwareKeyboardController.hideSoftwareKeyboard()
221228
}
222-
onImeAction()
223-
}
229+
)
224230
)
225231

226232
passwordState.getError()?.let { error -> TextFieldError(textError = error) }
@@ -236,7 +242,7 @@ fun TextFieldError(textError: String) {
236242
Text(
237243
text = textError,
238244
modifier = Modifier.fillMaxWidth(),
239-
style = AmbientTextStyle.current.copy(color = MaterialTheme.colors.error)
245+
style = LocalTextStyle.current.copy(color = MaterialTheme.colors.error)
240246
)
241247
}
242248
}
@@ -251,7 +257,7 @@ fun OrSignInAsGuest(
251257
horizontalAlignment = Alignment.CenterHorizontally
252258
) {
253259
Surface {
254-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
260+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
255261
Text(
256262
text = stringResource(id = R.string.or),
257263
style = MaterialTheme.typography.subtitle2

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/SignUpFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import android.view.ViewGroup
2323
import androidx.compose.ui.platform.ComposeView
2424
import androidx.fragment.app.Fragment
2525
import androidx.fragment.app.viewModels
26-
import androidx.lifecycle.observe
2726
import com.example.compose.jetsurvey.R
2827
import com.example.compose.jetsurvey.Screen
2928
import com.example.compose.jetsurvey.navigate
@@ -41,7 +40,7 @@ class SignUpFragment : Fragment() {
4140
container: ViewGroup?,
4241
savedInstanceState: Bundle?
4342
): View {
44-
viewModel.navigateTo.observe(owner = viewLifecycleOwner) { navigateToEvent ->
43+
viewModel.navigateTo.observe(viewLifecycleOwner) { navigateToEvent ->
4544
navigateToEvent.getContentIfNotHandled()?.let { navigateTo ->
4645
navigate(navigateTo, Screen.SignUp)
4746
}

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/SignUpScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import androidx.compose.foundation.layout.Column
2020
import androidx.compose.foundation.layout.Spacer
2121
import androidx.compose.foundation.layout.fillMaxWidth
2222
import androidx.compose.foundation.layout.preferredHeight
23-
import androidx.compose.material.AmbientContentAlpha
2423
import androidx.compose.material.Button
2524
import androidx.compose.material.ContentAlpha
25+
import androidx.compose.material.LocalContentAlpha
2626
import androidx.compose.material.MaterialTheme
2727
import androidx.compose.material.Scaffold
2828
import androidx.compose.material.Text
@@ -102,7 +102,7 @@ fun SignUpContent(
102102
)
103103

104104
Spacer(modifier = Modifier.preferredHeight(16.dp))
105-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
105+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
106106
Text(
107107
text = stringResource(id = R.string.terms_and_conditions),
108108
style = MaterialTheme.typography.caption

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/WelcomeFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import android.view.ViewGroup
2323
import androidx.compose.ui.platform.ComposeView
2424
import androidx.fragment.app.Fragment
2525
import androidx.fragment.app.viewModels
26-
import androidx.lifecycle.observe
2726
import com.example.compose.jetsurvey.Screen
2827
import com.example.compose.jetsurvey.navigate
2928
import com.example.compose.jetsurvey.theme.JetsurveyTheme
@@ -40,7 +39,7 @@ class WelcomeFragment : Fragment() {
4039
container: ViewGroup?,
4140
savedInstanceState: Bundle?
4241
): View? {
43-
viewModel.navigateTo.observe(owner = viewLifecycleOwner) { navigateToEvent ->
42+
viewModel.navigateTo.observe(viewLifecycleOwner) { navigateToEvent ->
4443
navigateToEvent.getContentIfNotHandled()?.let { navigateTo ->
4544
navigate(navigateTo, Screen.Welcome)
4645
}

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/signinsignup/WelcomeScreen.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import androidx.compose.foundation.layout.offset
2525
import androidx.compose.foundation.layout.padding
2626
import androidx.compose.foundation.layout.preferredHeight
2727
import androidx.compose.foundation.layout.wrapContentHeight
28-
import androidx.compose.material.AmbientContentAlpha
2928
import androidx.compose.material.Button
3029
import androidx.compose.material.ContentAlpha
30+
import androidx.compose.material.LocalContentAlpha
3131
import androidx.compose.material.MaterialTheme
3232
import androidx.compose.material.Surface
3333
import androidx.compose.material.Text
@@ -42,9 +42,9 @@ import androidx.compose.ui.Modifier
4242
import androidx.compose.ui.layout.boundsInParent
4343
import androidx.compose.ui.layout.onGloballyPositioned
4444
import androidx.compose.ui.layout.onSizeChanged
45-
import androidx.compose.ui.platform.AmbientDensity
45+
import androidx.compose.ui.platform.LocalDensity
46+
import androidx.compose.ui.res.painterResource
4647
import androidx.compose.ui.res.stringResource
47-
import androidx.compose.ui.res.vectorResource
4848
import androidx.compose.ui.text.input.ImeAction
4949
import androidx.compose.ui.text.style.TextAlign
5050
import androidx.compose.ui.tooling.preview.Preview
@@ -67,8 +67,8 @@ fun WelcomeScreen(onEvent: (WelcomeEvent) -> Unit) {
6767
val currentOffsetHolder = remember { mutableStateOf(0f) }
6868
currentOffsetHolder.value = if (showBranding) 0f else -brandingBottom
6969
val currentOffsetHolderDp =
70-
with(AmbientDensity.current) { currentOffsetHolder.value.toDp() }
71-
val heightDp = with(AmbientDensity.current) { heightWithBranding.toDp() }
70+
with(LocalDensity.current) { currentOffsetHolder.value.toDp() }
71+
val heightDp = with(LocalDensity.current) { heightWithBranding.toDp() }
7272
Surface(modifier = Modifier.fillMaxSize()) {
7373
val offset by animateDpAsState(targetValue = currentOffsetHolderDp)
7474
Column(
@@ -148,7 +148,7 @@ private fun Logo(
148148
R.drawable.ic_logo_dark
149149
}
150150
Image(
151-
imageVector = vectorResource(id = assetId),
151+
painter = painterResource(id = assetId),
152152
modifier = modifier,
153153
contentDescription = null
154154
)
@@ -162,7 +162,7 @@ private fun SignInCreateAccount(
162162
) {
163163
val emailState = remember { EmailState() }
164164
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
165-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
165+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
166166
Text(
167167
text = stringResource(id = R.string.sign_in_create_account),
168168
style = MaterialTheme.typography.subtitle2,

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/survey/SurveyQuestions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ import androidx.compose.foundation.layout.width
3434
import androidx.compose.foundation.layout.wrapContentSize
3535
import androidx.compose.foundation.lazy.LazyColumn
3636
import androidx.compose.foundation.selection.selectable
37-
import androidx.compose.material.AmbientContentAlpha
3837
import androidx.compose.material.Button
3938
import androidx.compose.material.Checkbox
4039
import androidx.compose.material.CheckboxDefaults
4140
import androidx.compose.material.ContentAlpha
4241
import androidx.compose.material.Icon
42+
import androidx.compose.material.LocalContentAlpha
4343
import androidx.compose.material.MaterialTheme
4444
import androidx.compose.material.OutlinedButton
4545
import androidx.compose.material.RadioButton
@@ -58,8 +58,8 @@ import androidx.compose.runtime.remember
5858
import androidx.compose.runtime.setValue
5959
import androidx.compose.ui.Alignment
6060
import androidx.compose.ui.Modifier
61+
import androidx.compose.ui.res.painterResource
6162
import androidx.compose.ui.res.stringResource
62-
import androidx.compose.ui.res.vectorResource
6363
import androidx.compose.ui.tooling.preview.Preview
6464
import androidx.compose.ui.unit.dp
6565
import com.example.compose.jetsurvey.R
@@ -103,7 +103,7 @@ fun Question(
103103
}
104104
Spacer(modifier = Modifier.preferredHeight(24.dp))
105105
if (question.description != null) {
106-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
106+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
107107
Text(
108108
text = stringResource(id = question.description),
109109
style = MaterialTheme.typography.caption,
@@ -384,7 +384,7 @@ private fun PhotoDefaultImage(
384384
R.drawable.ic_selfie_dark
385385
}
386386
Image(
387-
imageVector = vectorResource(id = assetId),
387+
painter = painterResource(id = assetId),
388388
modifier = modifier,
389389
contentDescription = null
390390
)

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/survey/SurveyScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import androidx.compose.foundation.layout.padding
2626
import androidx.compose.foundation.layout.preferredHeight
2727
import androidx.compose.foundation.layout.width
2828
import androidx.compose.foundation.lazy.LazyColumn
29-
import androidx.compose.material.AmbientContentAlpha
3029
import androidx.compose.material.Button
3130
import androidx.compose.material.ContentAlpha
3231
import androidx.compose.material.Icon
3332
import androidx.compose.material.IconButton
3433
import androidx.compose.material.LinearProgressIndicator
34+
import androidx.compose.material.LocalContentAlpha
3535
import androidx.compose.material.MaterialTheme
3636
import androidx.compose.material.OutlinedButton
3737
import androidx.compose.material.Scaffold
@@ -174,6 +174,7 @@ private fun TopAppBarTitle(
174174
)
175175
}
176176

177+
@Suppress("DEPRECATION") // ConstraintLayout
177178
@OptIn(ExperimentalLayout::class)
178179
@Composable
179180
private fun SurveyTopAppBar(
@@ -191,7 +192,7 @@ private fun SurveyTopAppBar(
191192
.constrainAs(text) { centerHorizontallyTo(parent) }
192193
)
193194

194-
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
195+
Providers(LocalContentAlpha provides ContentAlpha.medium) {
195196
IconButton(
196197
onClick = onBackPressed,
197198
modifier = Modifier

Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/theme/Typography.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import androidx.compose.ui.text.TextStyle
2121
import androidx.compose.ui.text.font.Font
2222
import androidx.compose.ui.text.font.FontFamily
2323
import androidx.compose.ui.text.font.FontWeight
24-
import androidx.compose.ui.text.font.font
2524
import androidx.compose.ui.unit.sp
2625
import com.example.compose.jetsurvey.R
2726

0 commit comments

Comments
 (0)