Skip to content

Commit 32dfef6

Browse files
committed
chore: format
1 parent 148d90e commit 32dfef6

File tree

12 files changed

+1532
-1513
lines changed

12 files changed

+1532
-1513
lines changed

app/src/main/java/dev/davwheat/railway/gateline_errors/MainActivity.kt

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,89 @@ import com.google.android.ump.ConsentRequestParameters
1717
import com.google.android.ump.UserMessagingPlatform
1818
import dev.davwheat.railway.gateline_errors.composable.MainUi
1919
import dev.davwheat.railway.gateline_errors.ui.theme.AppTheme
20-
import timber.log.Timber
2120
import java.util.concurrent.atomic.AtomicBoolean
21+
import timber.log.Timber
2222

2323
class MainActivity : ComponentActivity() {
24-
private lateinit var consentInformation: ConsentInformation
25-
private var isMobileAdsInitializeCalled = AtomicBoolean(false)
24+
private lateinit var consentInformation: ConsentInformation
25+
private var isMobileAdsInitializeCalled = AtomicBoolean(false)
2626

27-
override fun onCreate(savedInstanceState: Bundle?) {
28-
super.onCreate(savedInstanceState)
27+
override fun onCreate(savedInstanceState: Bundle?) {
28+
super.onCreate(savedInstanceState)
2929

30-
setContent {
31-
enableEdgeToEdge()
30+
setContent {
31+
enableEdgeToEdge()
3232

33-
var showAds by rememberSaveable { mutableStateOf(false) }
33+
var showAds by rememberSaveable { mutableStateOf(false) }
3434

35-
LaunchedEffect(true) {
36-
obtainAdsConsent {
37-
Timber.d("Ads consent obtained")
38-
showAds = true
39-
}
40-
}
35+
LaunchedEffect(true) {
36+
obtainAdsConsent {
37+
Timber.d("Ads consent obtained")
38+
showAds = true
39+
}
40+
}
4141

42-
AppTheme { MainUi(modifier = Modifier, showAds = showAds) }
42+
AppTheme { MainUi(modifier = Modifier, showAds = showAds) }
43+
}
4344
}
44-
}
4545

46-
private fun obtainAdsConsent(callback: () -> Unit) {
47-
val params = ConsentRequestParameters.Builder().setTagForUnderAgeOfConsent(false).build()
46+
private fun obtainAdsConsent(callback: () -> Unit) {
47+
val params = ConsentRequestParameters.Builder().setTagForUnderAgeOfConsent(false).build()
4848

49-
consentInformation = UserMessagingPlatform.getConsentInformation(this)
50-
consentInformation.requestConsentInfoUpdate(
51-
this,
52-
params,
53-
{
54-
UserMessagingPlatform.loadAndShowConsentFormIfRequired(this@MainActivity) { loadAndShowError ->
55-
// Consent gathering failed.
56-
Timber.w(
57-
String.format("%s: %s", loadAndShowError?.errorCode, loadAndShowError?.message)
58-
)
49+
consentInformation = UserMessagingPlatform.getConsentInformation(this)
50+
consentInformation.requestConsentInfoUpdate(
51+
this,
52+
params,
53+
{
54+
UserMessagingPlatform.loadAndShowConsentFormIfRequired(this@MainActivity) {
55+
loadAndShowError ->
56+
// Consent gathering failed.
57+
Timber.w(
58+
String.format(
59+
"%s: %s",
60+
loadAndShowError?.errorCode,
61+
loadAndShowError?.message,
62+
)
63+
)
5964

60-
// Consent has been gathered.
61-
initializeMobileAdsSdk(callback)
62-
}
63-
},
64-
{ requestConsentError ->
65-
// Consent gathering failed.
66-
Timber.w(
67-
String.format("%s: %s", requestConsentError.errorCode, requestConsentError.message)
65+
// Consent has been gathered.
66+
initializeMobileAdsSdk(callback)
67+
}
68+
},
69+
{ requestConsentError ->
70+
// Consent gathering failed.
71+
Timber.w(
72+
String.format(
73+
"%s: %s",
74+
requestConsentError.errorCode,
75+
requestConsentError.message,
76+
)
77+
)
78+
},
6879
)
69-
})
7080

71-
if (consentInformation.canRequestAds()) {
72-
initializeMobileAdsSdk(callback)
81+
if (consentInformation.canRequestAds()) {
82+
initializeMobileAdsSdk(callback)
83+
}
7384
}
74-
}
7585

76-
private fun initializeMobileAdsSdk(callback: () -> Unit) {
77-
if (isMobileAdsInitializeCalled.getAndSet(true)) {
78-
callback()
79-
return
80-
}
86+
private fun initializeMobileAdsSdk(callback: () -> Unit) {
87+
if (isMobileAdsInitializeCalled.getAndSet(true)) {
88+
callback()
89+
return
90+
}
8191

82-
// Initialize the Google Mobile Ads SDK.
83-
MobileAds.initialize(this)
92+
// Initialize the Google Mobile Ads SDK.
93+
MobileAds.initialize(this)
8494

85-
MobileAds.setRequestConfiguration(
86-
RequestConfiguration.Builder()
87-
.setTestDeviceIds(
88-
if (BuildConfig.DEBUG)
89-
listOf(
90-
"077F865A83D45A5C09CB4C8C845ADCA1",
91-
)
92-
else null,
95+
MobileAds.setRequestConfiguration(
96+
RequestConfiguration.Builder()
97+
.setTestDeviceIds(
98+
if (BuildConfig.DEBUG) listOf("077F865A83D45A5C09CB4C8C845ADCA1") else null
99+
)
100+
.build()
93101
)
94-
.build(),
95-
)
96102

97-
callback()
98-
}
103+
callback()
104+
}
99105
}

app/src/main/java/dev/davwheat/railway/gateline_errors/composable/AdmobBanner.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import com.google.android.gms.ads.AdView
1010

1111
@Composable
1212
fun AdmobBanner(modifier: Modifier = Modifier) {
13-
AndroidView(
14-
modifier = modifier.fillMaxWidth(),
15-
factory = { context ->
16-
// on below line specifying ad view.
17-
AdView(context).apply {
18-
// on below line specifying ad size
19-
// adSize = AdSize.BANNER
20-
// on below line specifying ad unit id
21-
// currently added a test ad unit id.
22-
setAdSize(AdSize.BANNER)
23-
adUnitId = "ca-app-pub-2701335557132384/6293742813"
24-
// calling load ad to load our ad.
25-
loadAd(AdRequest.Builder().build())
26-
}
27-
},
28-
)
13+
AndroidView(
14+
modifier = modifier.fillMaxWidth(),
15+
factory = { context ->
16+
// on below line specifying ad view.
17+
AdView(context).apply {
18+
// on below line specifying ad size
19+
// adSize = AdSize.BANNER
20+
// on below line specifying ad unit id
21+
// currently added a test ad unit id.
22+
setAdSize(AdSize.BANNER)
23+
adUnitId = "ca-app-pub-2701335557132384/6293742813"
24+
// calling load ad to load our ad.
25+
loadAd(AdRequest.Builder().build())
26+
}
27+
},
28+
)
2929
}

app/src/main/java/dev/davwheat/railway/gateline_errors/composable/ErrorCodeDetail.kt

Lines changed: 66 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,97 +22,91 @@ import dev.davwheat.railway.gateline_errors.ui.theme.AppTheme
2222
import dev.davwheat.railway.gateline_errors.ui.theme.LcdDisplayFont
2323

2424
@Composable
25-
fun ErrorCodeDetail(
26-
modifier: Modifier = Modifier,
27-
errorCode: Rejection,
28-
) {
29-
Column(
30-
modifier,
31-
verticalArrangement = Arrangement.spacedBy(8.dp),
32-
) {
33-
Text(
34-
stringResource(R.string.seek_assistance, errorCode.code),
35-
modifier = Modifier.fillMaxWidth(),
36-
fontFamily = LcdDisplayFont,
37-
fontSize = 28.sp,
38-
color = MaterialTheme.colorScheme.onSurfaceVariant,
39-
textAlign = TextAlign.Center,
40-
)
41-
42-
errorCode.textCode?.let { code ->
43-
DataPair(
44-
heading = "Text Error",
45-
text = { _modifier, style, align ->
46-
Text(
47-
modifier = _modifier,
48-
text = code,
49-
style = style,
25+
fun ErrorCodeDetail(modifier: Modifier = Modifier, errorCode: Rejection) {
26+
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
27+
Text(
28+
stringResource(R.string.seek_assistance, errorCode.code),
29+
modifier = Modifier.fillMaxWidth(),
5030
fontFamily = LcdDisplayFont,
31+
fontSize = 28.sp,
5132
color = MaterialTheme.colorScheme.onSurfaceVariant,
52-
fontSize = 18.sp,
53-
textAlign = align,
54-
)
55-
},
56-
modifier = Modifier.align(Alignment.CenterHorizontally),
57-
align = TextAlign.Center,
58-
)
59-
}
33+
textAlign = TextAlign.Center,
34+
)
6035

61-
DataPair(heading = "Definition") { _modifier, style, align ->
62-
Text(
63-
modifier = _modifier,
64-
text = errorCode.definition,
65-
style = style,
66-
textAlign = align,
67-
fontWeight = FontWeight.Bold,
68-
)
69-
}
36+
errorCode.textCode?.let { code ->
37+
DataPair(
38+
heading = "Text Error",
39+
text = { _modifier, style, align ->
40+
Text(
41+
modifier = _modifier,
42+
text = code,
43+
style = style,
44+
fontFamily = LcdDisplayFont,
45+
color = MaterialTheme.colorScheme.onSurfaceVariant,
46+
fontSize = 18.sp,
47+
textAlign = align,
48+
)
49+
},
50+
modifier = Modifier.align(Alignment.CenterHorizontally),
51+
align = TextAlign.Center,
52+
)
53+
}
7054

71-
DataPair(heading = "Explanation", text = errorCode.helpText)
55+
DataPair(heading = "Definition") { _modifier, style, align ->
56+
Text(
57+
modifier = _modifier,
58+
text = errorCode.definition,
59+
style = style,
60+
textAlign = align,
61+
fontWeight = FontWeight.Bold,
62+
)
63+
}
7264

73-
errorCode.laymansReason?.let { DataPair(heading = "Possible reason(s)", text = it) }
65+
DataPair(heading = "Explanation", text = errorCode.helpText)
7466

75-
DataPair(heading = "Action needed", text = errorCode.actionByStaff)
76-
}
67+
errorCode.laymansReason?.let { DataPair(heading = "Possible reason(s)", text = it) }
68+
69+
DataPair(heading = "Action needed", text = errorCode.actionByStaff)
70+
}
7771
}
7872

7973
@Composable
8074
private fun DataPair(
81-
modifier: Modifier = Modifier,
82-
align: TextAlign = TextAlign.Start,
83-
heading: String,
84-
text: String,
75+
modifier: Modifier = Modifier,
76+
align: TextAlign = TextAlign.Start,
77+
heading: String,
78+
text: String,
8579
) {
86-
DataPair(
87-
modifier = modifier,
88-
heading = heading,
89-
text = { _modifier, style, _ ->
90-
Text(modifier = _modifier, text = text, style = style, textAlign = align)
91-
},
92-
align = align,
93-
)
80+
DataPair(
81+
modifier = modifier,
82+
heading = heading,
83+
text = { _modifier, style, _ ->
84+
Text(modifier = _modifier, text = text, style = style, textAlign = align)
85+
},
86+
align = align,
87+
)
9488
}
9589

9690
@Composable
9791
private fun DataPair(
98-
modifier: Modifier = Modifier,
99-
align: TextAlign = TextAlign.Start,
100-
heading: String,
101-
text: @Composable (modifier: Modifier, defaultStyle: TextStyle, textAlign: TextAlign) -> Unit,
92+
modifier: Modifier = Modifier,
93+
align: TextAlign = TextAlign.Start,
94+
heading: String,
95+
text: @Composable (modifier: Modifier, defaultStyle: TextStyle, textAlign: TextAlign) -> Unit,
10296
) {
103-
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
104-
Text(
105-
modifier = Modifier.fillMaxWidth(),
106-
text = heading,
107-
style = MaterialTheme.typography.bodySmall,
108-
textAlign = align,
109-
)
110-
text(Modifier.fillMaxWidth(), MaterialTheme.typography.bodyMedium, align)
111-
}
97+
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(4.dp)) {
98+
Text(
99+
modifier = Modifier.fillMaxWidth(),
100+
text = heading,
101+
style = MaterialTheme.typography.bodySmall,
102+
textAlign = align,
103+
)
104+
text(Modifier.fillMaxWidth(), MaterialTheme.typography.bodyMedium, align)
105+
}
112106
}
113107

114108
@Preview(showBackground = true)
115109
@Composable
116110
private fun ErrorCodeDetailPreview() {
117-
AppTheme { ErrorCodeDetail(errorCode = ErrorCodes[1]!!) }
111+
AppTheme { ErrorCodeDetail(errorCode = ErrorCodes[1]!!) }
118112
}

0 commit comments

Comments
 (0)