Skip to content

Commit c32053c

Browse files
author
Farhan Arshad
committed
refactor: standardized styling button system in the app
- Define styling for buttons types (primary, secondary, tertiary, error, etc.) to make button styles configurable. fixes: LEARNER-10140
1 parent b892560 commit c32053c

File tree

36 files changed

+470
-421
lines changed

36 files changed

+470
-421
lines changed

auth/src/main/java/org/openedx/auth/presentation/restore/RestorePasswordFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import org.openedx.core.R
6161
import org.openedx.core.presentation.global.appupgrade.AppUpgradeRequiredScreen
6262
import org.openedx.core.ui.BackBtn
6363
import org.openedx.core.ui.HandleUIMessage
64-
import org.openedx.core.ui.OpenEdXButton
64+
import org.openedx.core.ui.OpenEdXPrimaryButton
6565
import org.openedx.core.ui.displayCutoutForLandscape
6666
import org.openedx.core.ui.statusBarsInset
6767
import org.openedx.core.ui.theme.OpenEdXTheme
@@ -186,7 +186,7 @@ private fun RestorePasswordScreen(
186186
modifier = Modifier
187187
.fillMaxWidth()
188188
.height(200.dp),
189-
painter = painterResource(id = org.openedx.core.R.drawable.core_top_header),
189+
painter = painterResource(id = R.drawable.core_top_header),
190190
contentScale = ContentScale.FillBounds,
191191
contentDescription = null
192192
)
@@ -297,7 +297,7 @@ private fun RestorePasswordScreen(
297297
CircularProgressIndicator(color = MaterialTheme.appColors.primary)
298298
}
299299
} else {
300-
OpenEdXButton(
300+
OpenEdXPrimaryButton(
301301
modifier = buttonWidth.testTag("btn_reset_password"),
302302
text = stringResource(id = authR.string.auth_reset_password),
303303
onClick = {
@@ -350,7 +350,7 @@ private fun RestorePasswordScreen(
350350
color = MaterialTheme.appColors.textPrimary
351351
)
352352
Spacer(Modifier.height(48.dp))
353-
OpenEdXButton(
353+
OpenEdXPrimaryButton(
354354
modifier = buttonWidth,
355355
text = stringResource(id = R.string.core_sign_in),
356356
onClick = {

auth/src/main/java/org/openedx/auth/presentation/signin/compose/SignInView.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import org.openedx.core.extension.TextConverter
6666
import org.openedx.core.ui.BackBtn
6767
import org.openedx.core.ui.HandleUIMessage
6868
import org.openedx.core.ui.HyperlinkText
69-
import org.openedx.core.ui.OpenEdXButton
69+
import org.openedx.core.ui.OpenEdXPrimaryButton
7070
import org.openedx.core.ui.displayCutoutForLandscape
7171
import org.openedx.core.ui.noRippleClickable
7272
import org.openedx.core.ui.theme.OpenEdXTheme
@@ -292,11 +292,9 @@ private fun AuthForm(
292292
if (state.showProgress) {
293293
CircularProgressIndicator(color = MaterialTheme.appColors.primary)
294294
} else {
295-
OpenEdXButton(
295+
OpenEdXPrimaryButton(
296296
modifier = buttonWidth.testTag("btn_sign_in"),
297297
text = stringResource(id = coreR.string.core_sign_in),
298-
textColor = MaterialTheme.appColors.primaryButtonText,
299-
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
300298
onClick = {
301299
keyboardController?.hide()
302300
if (login.isNotEmpty() && password.isNotEmpty()) {

auth/src/main/java/org/openedx/auth/presentation/signup/compose/SignUpView.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import org.openedx.core.domain.model.RegistrationField
7171
import org.openedx.core.domain.model.RegistrationFieldType
7272
import org.openedx.core.ui.BackBtn
7373
import org.openedx.core.ui.HandleUIMessage
74-
import org.openedx.core.ui.OpenEdXButton
74+
import org.openedx.core.ui.OpenEdXPrimaryButton
7575
import org.openedx.core.ui.SheetContent
7676
import org.openedx.core.ui.displayCutoutForLandscape
7777
import org.openedx.core.ui.isImeVisibleState
@@ -434,11 +434,9 @@ internal fun SignUpView(
434434
CircularProgressIndicator(color = MaterialTheme.appColors.primary)
435435
}
436436
} else {
437-
OpenEdXButton(
437+
OpenEdXPrimaryButton(
438438
modifier = buttonWidth.testTag("btn_create_account"),
439439
text = stringResource(id = R.string.auth_create_account),
440-
textColor = MaterialTheme.appColors.primaryButtonText,
441-
backgroundColor = MaterialTheme.appColors.secondaryButtonBackground,
442440
onClick = {
443441
keyboardController?.hide()
444442
showErrorMap.clear()

auth/src/main/java/org/openedx/auth/presentation/ui/SocialAuthView.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import androidx.compose.ui.tooling.preview.Preview
1919
import androidx.compose.ui.unit.dp
2020
import org.openedx.auth.R
2121
import org.openedx.auth.data.model.AuthType
22-
import org.openedx.core.ui.OpenEdXButton
23-
import org.openedx.core.ui.OpenEdXOutlinedButton
22+
import org.openedx.core.ui.OpenEdXPrimaryButton
23+
import org.openedx.core.ui.OpenEdXPrimaryOutlinedButton
2424
import org.openedx.core.ui.theme.OpenEdXTheme
2525
import org.openedx.core.ui.theme.appColors
2626

@@ -40,7 +40,7 @@ internal fun SocialAuthView(
4040
} else {
4141
R.string.auth_continue_google
4242
}
43-
OpenEdXOutlinedButton(
43+
OpenEdXPrimaryOutlinedButton(
4444
modifier = Modifier
4545
.testTag("btn_google_auth")
4646
.padding(top = 24.dp)
@@ -74,7 +74,7 @@ internal fun SocialAuthView(
7474
} else {
7575
R.string.auth_continue_facebook
7676
}
77-
OpenEdXButton(
77+
OpenEdXPrimaryButton(
7878
modifier = Modifier
7979
.testTag("btn_facebook_auth")
8080
.padding(top = 12.dp)
@@ -106,7 +106,7 @@ internal fun SocialAuthView(
106106
} else {
107107
R.string.auth_continue_microsoft
108108
}
109-
OpenEdXButton(
109+
OpenEdXPrimaryButton(
110110
modifier = Modifier
111111
.testTag("btn_microsoft_auth")
112112
.padding(top = 12.dp)

core/src/main/java/org/openedx/core/presentation/dialog/alert/ActionDialogFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import org.openedx.core.config.Config
3434
import org.openedx.core.presentation.CoreAnalytics
3535
import org.openedx.core.presentation.CoreAnalyticsEvent
3636
import org.openedx.core.presentation.CoreAnalyticsKey
37-
import org.openedx.core.presentation.global.appupgrade.DefaultTextButton
38-
import org.openedx.core.presentation.global.appupgrade.TransparentTextButton
37+
import org.openedx.core.ui.DefaultTextButton
38+
import org.openedx.core.ui.TransparentTextButton
3939
import org.openedx.core.ui.theme.OpenEdXTheme
4040
import org.openedx.core.ui.theme.appColors
4141
import org.openedx.core.ui.theme.appShapes

core/src/main/java/org/openedx/core/presentation/dialog/alert/InfoDialogFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import androidx.compose.ui.unit.dp
2727
import androidx.core.os.bundleOf
2828
import androidx.fragment.app.DialogFragment
2929
import org.openedx.core.R
30-
import org.openedx.core.presentation.global.appupgrade.DefaultTextButton
30+
import org.openedx.core.ui.DefaultTextButton
3131
import org.openedx.core.ui.theme.OpenEdXTheme
3232
import org.openedx.core.ui.theme.appColors
3333
import org.openedx.core.ui.theme.appShapes

core/src/main/java/org/openedx/core/presentation/dialog/appreview/AppReviewUI.kt

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
1313
import androidx.compose.foundation.layout.height
1414
import androidx.compose.foundation.layout.padding
1515
import androidx.compose.foundation.layout.size
16-
import androidx.compose.material.Button
17-
import androidx.compose.material.ButtonDefaults
1816
import androidx.compose.material.Icon
1917
import androidx.compose.material.MaterialTheme
2018
import androidx.compose.material.OutlinedTextField
@@ -48,6 +46,8 @@ import androidx.compose.ui.tooling.preview.Preview
4846
import androidx.compose.ui.unit.dp
4947
import org.openedx.core.R
5048
import org.openedx.core.presentation.dialog.DefaultDialogBox
49+
import org.openedx.core.ui.DefaultTextButton
50+
import org.openedx.core.ui.TransparentTextButton
5151
import org.openedx.core.ui.theme.OpenEdXTheme
5252
import org.openedx.core.ui.theme.appColors
5353
import org.openedx.core.ui.theme.appShapes
@@ -213,7 +213,10 @@ fun RateDialog(
213213
verticalArrangement = Arrangement.spacedBy(20.dp)
214214
) {
215215
Text(
216-
text = stringResource(R.string.core_rate_dialog_title, stringResource(R.string.app_name)),
216+
text = stringResource(
217+
R.string.core_rate_dialog_title,
218+
stringResource(R.string.app_name)
219+
),
217220
color = MaterialTheme.appColors.textPrimary,
218221
style = MaterialTheme.appTypography.titleMedium
219222
)
@@ -245,69 +248,6 @@ fun RateDialog(
245248
}
246249
}
247250

248-
@Composable
249-
fun TransparentTextButton(
250-
text: String,
251-
onClick: () -> Unit
252-
) {
253-
Button(
254-
modifier = Modifier
255-
.height(42.dp),
256-
colors = ButtonDefaults.buttonColors(
257-
backgroundColor = Color.Transparent
258-
),
259-
elevation = null,
260-
shape = MaterialTheme.appShapes.navigationButtonShape,
261-
onClick = onClick
262-
) {
263-
Text(
264-
color = MaterialTheme.appColors.textAccent,
265-
style = MaterialTheme.appTypography.labelLarge,
266-
text = text
267-
)
268-
}
269-
}
270-
271-
@Composable
272-
fun DefaultTextButton(
273-
isEnabled: Boolean = true,
274-
text: String,
275-
onClick: () -> Unit
276-
) {
277-
val textColor: Color
278-
val backgroundColor: Color
279-
if (isEnabled) {
280-
textColor = MaterialTheme.appColors.primaryButtonText
281-
backgroundColor = MaterialTheme.appColors.primaryButtonBackground
282-
} else {
283-
textColor = MaterialTheme.appColors.inactiveButtonText
284-
backgroundColor = MaterialTheme.appColors.inactiveButtonBackground
285-
}
286-
287-
Button(
288-
modifier = Modifier
289-
.height(42.dp),
290-
colors = ButtonDefaults.buttonColors(
291-
backgroundColor = backgroundColor,
292-
contentColor = textColor
293-
),
294-
elevation = null,
295-
shape = MaterialTheme.appShapes.navigationButtonShape,
296-
enabled = isEnabled,
297-
onClick = onClick
298-
) {
299-
Row(
300-
verticalAlignment = Alignment.CenterVertically,
301-
horizontalArrangement = Arrangement.Center
302-
) {
303-
Text(
304-
text = text,
305-
style = MaterialTheme.appTypography.labelLarge
306-
)
307-
}
308-
}
309-
}
310-
311251
@Composable
312252
fun RatingBar(
313253
modifier: Modifier = Modifier,

core/src/main/java/org/openedx/core/presentation/global/appupgrade/AppUpdateUI.kt

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ import androidx.compose.foundation.layout.Column
1212
import androidx.compose.foundation.layout.Row
1313
import androidx.compose.foundation.layout.fillMaxSize
1414
import androidx.compose.foundation.layout.fillMaxWidth
15-
import androidx.compose.foundation.layout.height
1615
import androidx.compose.foundation.layout.padding
1716
import androidx.compose.foundation.layout.size
1817
import androidx.compose.foundation.layout.widthIn
19-
import androidx.compose.material.Button
20-
import androidx.compose.material.ButtonDefaults
2118
import androidx.compose.material.Card
2219
import androidx.compose.material.Icon
2320
import androidx.compose.material.MaterialTheme
@@ -39,6 +36,8 @@ import androidx.compose.ui.text.style.TextAlign
3936
import androidx.compose.ui.tooling.preview.Preview
4037
import androidx.compose.ui.unit.dp
4138
import org.openedx.core.R
39+
import org.openedx.core.ui.DefaultTextButton
40+
import org.openedx.core.ui.TransparentTextButton
4241
import org.openedx.core.ui.noRippleClickable
4342
import org.openedx.core.ui.statusBarsInset
4443
import org.openedx.core.ui.theme.OpenEdXTheme
@@ -257,61 +256,6 @@ fun AppUpgradeDialogButtons(
257256
}
258257
}
259258

260-
@Composable
261-
fun TransparentTextButton(
262-
text: String,
263-
onClick: () -> Unit
264-
) {
265-
Button(
266-
modifier = Modifier
267-
.testTag("btn_secondary")
268-
.height(42.dp),
269-
colors = ButtonDefaults.buttonColors(
270-
backgroundColor = Color.Transparent
271-
),
272-
elevation = null,
273-
shape = MaterialTheme.appShapes.navigationButtonShape,
274-
onClick = onClick
275-
) {
276-
Text(
277-
modifier = Modifier.testTag("txt_secondary"),
278-
color = MaterialTheme.appColors.textAccent,
279-
style = MaterialTheme.appTypography.labelLarge,
280-
text = text
281-
)
282-
}
283-
}
284-
285-
@Composable
286-
fun DefaultTextButton(
287-
text: String,
288-
onClick: () -> Unit
289-
) {
290-
Button(
291-
modifier = Modifier
292-
.testTag("btn_primary")
293-
.height(42.dp),
294-
colors = ButtonDefaults.buttonColors(
295-
backgroundColor = MaterialTheme.appColors.primaryButtonBackground
296-
),
297-
elevation = null,
298-
shape = MaterialTheme.appShapes.navigationButtonShape,
299-
onClick = onClick
300-
) {
301-
Row(
302-
verticalAlignment = Alignment.CenterVertically,
303-
horizontalArrangement = Arrangement.Center
304-
) {
305-
Text(
306-
modifier = Modifier.testTag("txt_primary"),
307-
text = text,
308-
color = MaterialTheme.appColors.primaryButtonText,
309-
style = MaterialTheme.appTypography.labelLarge
310-
)
311-
}
312-
}
313-
}
314-
315259
@Composable
316260
fun AppUpgradeRecommendedBox(
317261
modifier: Modifier = Modifier,

core/src/main/java/org/openedx/core/presentation/settings/calendarsync/CalendarSyncDialog.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
2424
import androidx.compose.ui.unit.dp
2525
import androidx.compose.ui.window.Dialog
2626
import org.openedx.core.R
27-
import org.openedx.core.presentation.global.appupgrade.TransparentTextButton
27+
import org.openedx.core.ui.TransparentTextButton
2828
import org.openedx.core.ui.theme.OpenEdXTheme
2929
import org.openedx.core.ui.theme.appColors
3030
import org.openedx.core.ui.theme.appShapes
@@ -44,7 +44,7 @@ fun CalendarSyncDialog(
4444
when (syncDialogType) {
4545
CalendarSyncDialogType.SYNC_DIALOG,
4646
CalendarSyncDialogType.UN_SYNC_DIALOG,
47-
-> {
47+
-> {
4848
CalendarAlertDialog(
4949
dialogProperties = DialogProperties(
5050
title = stringResource(syncDialogType.titleResId),

0 commit comments

Comments
 (0)