Skip to content

Commit 8902b45

Browse files
committed
Updated gradle and added a few more tutorials
1 parent bad6538 commit 8902b45

File tree

7 files changed

+177
-13
lines changed

7 files changed

+177
-13
lines changed

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ plugins {
44
}
55

66
android {
7-
compileSdk 32
7+
compileSdk 33
88

99
defaultConfig {
1010
applicationId "com.aliazaz.composeapp"
1111
minSdk 22
12-
targetSdk 32
12+
targetSdk 33
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -50,6 +50,8 @@ dependencies {
5050
implementation 'androidx.core:core-ktx:1.7.0'
5151
implementation "androidx.compose.ui:ui:$compose_version"
5252
implementation "androidx.compose.material:material:$compose_version"
53+
implementation "androidx.compose.material3:material3:1.1.0"
54+
implementation "androidx.compose.material3:material3-window-size-class:1.1.0"
5355
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
5456
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
5557
implementation 'androidx.activity:activity-compose:1.3.1'

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414
android:theme="@style/Theme.FirstComposeApp"
1515
tools:targetApi="31">
1616
<activity
17-
android:name=".LemonadeActivity"
17+
android:name=".CalculateTipActivity"
1818
android:exported="true"
19-
android:label="@string/title_activity_dice_roller"
19+
android:label="@string/title_activity_calculate_tip"
2020
android:theme="@style/Theme.FirstComposeApp">
21+
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />
2324

2425
<category android:name="android.intent.category.LAUNCHER" />
2526
</intent-filter>
2627
</activity>
28+
<activity
29+
android:name=".LemonadeActivity"
30+
android:exported="true"
31+
android:label="@string/title_activity_dice_roller"
32+
android:theme="@style/Theme.FirstComposeApp" />
2733
<activity
2834
android:name=".DiceRollerActivity"
2935
android:exported="false"
@@ -48,7 +54,7 @@
4854
android:name=".MainActivity"
4955
android:exported="true"
5056
android:label="@string/app_name"
51-
android:theme="@style/Theme.FirstComposeApp"></activity>
57+
android:theme="@style/Theme.FirstComposeApp" />
5258
</application>
5359

5460
</manifest>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.aliazaz.composeapp
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.*
7+
import androidx.compose.foundation.rememberScrollState
8+
import androidx.compose.foundation.text.KeyboardOptions
9+
import androidx.compose.foundation.verticalScroll
10+
import androidx.compose.material.MaterialTheme
11+
import androidx.compose.material.Surface
12+
import androidx.compose.material.Text
13+
import androidx.compose.runtime.*
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.text.input.ImeAction
17+
import androidx.compose.ui.text.input.KeyboardType
18+
import androidx.compose.ui.tooling.preview.Preview
19+
import androidx.compose.ui.unit.dp
20+
import com.aliazaz.composeapp.components.EditableTextView
21+
import com.aliazaz.composeapp.ui.theme.FirstComposeAppTheme
22+
23+
class CalculateTipActivity : ComponentActivity() {
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
setContent {
27+
FirstComposeAppTheme {
28+
// A surface container using the 'background' color from the theme
29+
Surface(
30+
modifier = Modifier
31+
.fillMaxSize(),
32+
color = MaterialTheme.colors.background
33+
) {
34+
CalculateTip()
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
@Composable
42+
fun CalculateTip() {
43+
var amount by remember { mutableStateOf("") }
44+
var tip by remember { mutableStateOf("") }
45+
46+
val resultAmount = amount.toDoubleOrNull() ?: 0.0
47+
val resultTip = tip.toDoubleOrNull() ?: 0.0
48+
49+
val resultantTip = tipCalculator(resultAmount, resultTip)
50+
51+
Column(
52+
modifier = Modifier
53+
.fillMaxSize()
54+
.wrapContentSize(Alignment.Center)
55+
.verticalScroll(rememberScrollState())
56+
) {
57+
EditableTextView(
58+
text = "Total Amount",
59+
value = amount,
60+
onValueChange = { amount = it },
61+
KeyboardOptions(keyboardType = KeyboardType.Number).copy(
62+
imeAction = ImeAction.Next
63+
)
64+
)
65+
66+
Spacer(modifier = Modifier.height(5.dp))
67+
68+
EditableTextView(
69+
text = "Tip Percentage",
70+
value = tip,
71+
onValueChange = { tip = it },
72+
KeyboardOptions(keyboardType = KeyboardType.Number)
73+
)
74+
75+
Spacer(modifier = Modifier.height(30.dp))
76+
77+
Text(
78+
text = "Tip Amount: $${String.format("%.02f", resultantTip)}",
79+
style = MaterialTheme.typography.h6
80+
)
81+
}
82+
83+
}
84+
85+
fun tipCalculator(no1: Double, no2: Double): Double {
86+
return no1 / 100 * no2
87+
}
88+
89+
@Preview(showBackground = true)
90+
@Composable
91+
fun DefaultPreview5() {
92+
FirstComposeAppTheme {
93+
CalculateTip()
94+
}
95+
}

app/src/main/java/com/aliazaz/composeapp/LemonadeActivity.kt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
package com.aliazaz.composeapp
22

33
import android.os.Bundle
4-
import android.widget.Toast
54
import androidx.activity.ComponentActivity
65
import androidx.activity.compose.setContent
76
import androidx.compose.foundation.Image
87
import androidx.compose.foundation.clickable
98
import androidx.compose.foundation.layout.*
10-
import androidx.compose.material.Button
119
import androidx.compose.material.MaterialTheme
1210
import androidx.compose.material.Surface
1311
import androidx.compose.material.Text
12+
import androidx.compose.material3.CenterAlignedTopAppBar
13+
import androidx.compose.material3.ExperimentalMaterial3Api
14+
import androidx.compose.material3.Scaffold
15+
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
1416
import androidx.compose.runtime.*
1517
import androidx.compose.ui.Alignment
1618
import androidx.compose.ui.Modifier
17-
import androidx.compose.ui.platform.LocalContext
1819
import androidx.compose.ui.res.painterResource
19-
import androidx.compose.ui.res.stringResource
20+
import androidx.compose.ui.text.font.FontWeight
2021
import androidx.compose.ui.tooling.preview.Preview
2122
import androidx.compose.ui.unit.dp
22-
import com.aliazaz.composeapp.R
2323
import com.aliazaz.composeapp.ui.theme.FirstComposeAppTheme
2424

2525
class LemonadeActivity : ComponentActivity() {
@@ -28,7 +28,7 @@ class LemonadeActivity : ComponentActivity() {
2828
super.onCreate(savedInstanceState)
2929
setContent {
3030
FirstComposeAppTheme {
31-
LemonadeApp()
31+
ScaffoldComponent(modifier = Modifier)
3232
}
3333
}
3434
}
@@ -98,6 +98,40 @@ private val lemonadeMapping: (Int) -> Pair<Int, String> = {
9898
}
9999
}
100100

101+
@OptIn(ExperimentalMaterial3Api::class)
102+
@Composable
103+
fun ScaffoldComponent(
104+
modifier: Modifier
105+
) {
106+
Scaffold(modifier = modifier,
107+
topBar = {
108+
CenterAlignedTopAppBar(
109+
title = {
110+
androidx.compose.material3.Text(
111+
text = "Lemonade",
112+
fontWeight = FontWeight.Bold
113+
)
114+
},
115+
colors = topAppBarColors(
116+
containerColor = androidx.compose.material3.MaterialTheme.colorScheme.primaryContainer,
117+
scrolledContainerColor = MaterialTheme.colorScheme.applyTonalElevation(
118+
backgroundColor = containerColor,
119+
elevation = TopAppBarSmallTokens.OnScrollContainerElevation
120+
),
121+
navigationIconContentColor = androidx.compose.material3.MaterialTheme.colorScheme.onPrimaryContainer,
122+
titleContentColor = androidx.compose.material3.MaterialTheme.colorScheme.onPrimaryContainer,
123+
actionIconContentColor = androidx.compose.material3.MaterialTheme.colorScheme.onPrimaryContainer
124+
)
125+
)
126+
127+
}, bottomBar = {
128+
129+
}
130+
) {
131+
LemonadeApp()
132+
}
133+
}
134+
101135
@Preview(showBackground = true)
102136
@Composable
103137
fun LemonadeAppPreview() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.aliazaz.composeapp.components
2+
3+
import androidx.compose.foundation.text.KeyboardOptions
4+
import androidx.compose.material.Text
5+
import androidx.compose.material.TextField
6+
import androidx.compose.runtime.Composable
7+
8+
@Composable
9+
fun EditableTextView(
10+
text: String,
11+
value: String,
12+
onValueChange: (String) -> Unit,
13+
keyboardOptions: KeyboardOptions
14+
) {
15+
TextField(
16+
value = value,
17+
onValueChange = onValueChange,
18+
label = {
19+
Text(text = text)
20+
},
21+
keyboardOptions = keyboardOptions,
22+
singleLine = true
23+
)
24+
}

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<string name="title_activity_dice_roller">DiceRollerActivity</string>
88
<string name="title_activity_lemonade">LemondeActivity</string>
99
<string name="roll">Roll</string>
10+
<string name="title_activity_calculator">CalculatorActivity</string>
11+
<string name="title_activity_main2">MainActivity2</string>
12+
<string name="title_activity_calculate_tip">CalculateTipActivity</string>
1013
</resources>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
22
ext {
3-
compose_version = '1.1.0-beta01'
3+
compose_version = '1.4.3'
44
}
55
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
66
plugins {
77
id 'com.android.application' version '7.2.2' apply false
88
id 'com.android.library' version '7.2.2' apply false
9-
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
9+
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
1010
}
1111

1212
task clean(type: Delete) {

0 commit comments

Comments
 (0)