Skip to content

Commit 8729730

Browse files
committed
Added lazy column and click listeners
1 parent 81c22c5 commit 8729730

File tree

13 files changed

+107
-20
lines changed

13 files changed

+107
-20
lines changed

.idea/.name

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetSelector.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ plugins {
44
}
55

66
android {
7-
namespace = "com.educational.jetpackcomposebasics_master"
7+
namespace = "com.educational.jetpackbasic"
88
compileSdk = 35
99

1010
defaultConfig {
11-
applicationId = "com.educational.jetpackcomposebasics_master"
11+
applicationId = "com.educational.jetpackbasic"
1212
minSdk = 24
1313
targetSdk = 34
1414
versionCode = 1

app/src/main/java/com/educational/jetpackbasic/MainActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.tooling.preview.Preview
1313
import androidx.core.view.WindowCompat
1414
import androidx.navigation.compose.rememberNavController
15-
import com.educational.jetpackbasic.component.BottomView
15+
import com.educational.jetpackbasic.component.bottomView.BottomView
1616
import com.educational.jetpackbasic.component.Toolbar
1717
import com.educational.jetpackbasic.component.bottomView.BottomNavigationItem
1818
import com.educational.jetpackbasic.navigation.SamNavigation

app/src/main/java/com/educational/jetpackbasic/Screens.kt

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package com.educational.jetpackbasic
22

3+
import android.widget.Toast
34
import androidx.compose.foundation.background
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.PaddingValues
67
import androidx.compose.foundation.layout.fillMaxSize
78
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.foundation.lazy.LazyColumn
10+
import androidx.compose.foundation.lazy.items
11+
import androidx.compose.foundation.lazy.itemsIndexed
812
import androidx.compose.material3.Text
913
import androidx.compose.runtime.Composable
1014
import androidx.compose.ui.Alignment
1115
import androidx.compose.ui.Modifier
1216
import androidx.compose.ui.graphics.Color
17+
import androidx.compose.ui.platform.LocalContext
1318
import androidx.compose.ui.text.font.FontWeight
1419
import androidx.compose.ui.text.style.TextAlign
1520
import androidx.compose.ui.unit.sp
21+
import com.educational.jetpackbasic.component.coreComp.CardView
22+
import com.educational.jetpackbasic.utils.DataSource
1623

1724
/**
1825
* Created by Samset on 2/27/25.
@@ -22,14 +29,14 @@ Copyright (c) 2025 All rights reserved.
2229
@Composable
2330
fun HomeScreen(padding: PaddingValues) {
2431
Column(modifier = Modifier.fillMaxSize().padding(bottom = padding.calculateBottomPadding(), top = padding.calculateTopPadding())){
25-
Text(
26-
text = "Home Screen",
27-
fontWeight = FontWeight.Bold,
28-
color = Color.Black,
29-
modifier = Modifier.align(Alignment.CenterHorizontally),
30-
textAlign = TextAlign.Center,
31-
fontSize = 25.sp
32-
)
32+
val context = LocalContext.current
33+
LazyColumn {
34+
itemsIndexed(items = DataSource.getListData()) { index, data ->
35+
CardView(data.res,data.title, onItemClick = { item ->
36+
Toast.makeText(context,"You click on ${item}", Toast.LENGTH_SHORT).show()
37+
})
38+
}
39+
}
3340

3441
}
3542

app/src/main/java/com/educational/jetpackbasic/component/Toolbar.kt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.ui.unit.dp
1818
import androidx.compose.ui.unit.sp
1919
import com.educational.jetpackbasic.R
2020

21+
2122
/**
2223
* Created by Samset on 2/27/25.
2324
Copyright (c) 2025 All rights reserved.

app/src/main/java/com/educational/jetpackbasic/component/bottomView/BottomNavigationItem.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import androidx.compose.ui.graphics.vector.ImageVector
1212
Copyright (c) 2025 All rights reserved.
1313
*/
1414
sealed class BottomNavigationItem(val route:String, val resource: ImageVector, val title:String){
15-
object Home : BottomNavigationItem("One",Icons.Filled.Home,"Home")
16-
object Profile : BottomNavigationItem("Two",Icons.Filled.AccountCircle,"Profile")
17-
object Settings : BottomNavigationItem("Three",Icons.Filled.Settings,"Settings")
18-
object More : BottomNavigationItem("Four",Icons.Filled.MoreVert,"More")
15+
object Home : BottomNavigationItem("Home",Icons.Filled.Home,"Home")
16+
object Profile : BottomNavigationItem("Profile",Icons.Filled.AccountCircle,"Profile")
17+
object Settings : BottomNavigationItem("Settings",Icons.Filled.Settings,"Settings")
18+
object More : BottomNavigationItem("More",Icons.Filled.MoreVert,"More")
1919
}

app/src/main/java/com/educational/jetpackbasic/component/BottomView.kt renamed to app/src/main/java/com/educational/jetpackbasic/component/bottomView/BottomView.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.educational.jetpackbasic.component
1+
package com.educational.jetpackbasic.component.bottomView
22

33
import androidx.compose.foundation.layout.height
44
import androidx.compose.material3.Icon
@@ -13,7 +13,6 @@ import androidx.compose.ui.graphics.Color
1313
import androidx.compose.ui.unit.dp
1414
import androidx.navigation.NavController
1515
import androidx.navigation.compose.currentBackStackEntryAsState
16-
import com.educational.jetpackbasic.component.bottomView.BottomNavigationItem
1716

1817
/**
1918
* Created by Samset on 2/27/25.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.educational.jetpackbasic.component.coreComp
2+
3+
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.fillMaxWidth
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.foundation.layout.size
10+
import androidx.compose.foundation.shape.CornerSize
11+
import androidx.compose.foundation.shape.RoundedCornerShape
12+
import androidx.compose.material3.Card
13+
import androidx.compose.material3.CardDefaults
14+
import androidx.compose.material3.Text
15+
import androidx.compose.runtime.Composable
16+
import androidx.compose.ui.Alignment
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.draw.clip
19+
import androidx.compose.ui.res.painterResource
20+
import androidx.compose.ui.text.font.FontWeight
21+
import androidx.compose.ui.unit.dp
22+
import androidx.compose.ui.unit.sp
23+
24+
/**
25+
* Created by Samset on 2/28/25.
26+
Copyright (c) 2025 All rights reserved.
27+
*/
28+
29+
@Composable
30+
fun CardView( icon:Int, details:String,onItemClick:(String) -> Unit) {
31+
Card(modifier = Modifier.fillMaxSize(), shape = RoundedCornerShape(8.dp), elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)) {
32+
Row(modifier = Modifier.fillMaxWidth().clickable { onItemClick(details) }) {
33+
Image(
34+
painter = painterResource(id = icon),
35+
contentDescription = "image",
36+
modifier = Modifier
37+
.padding(8.dp)
38+
.size(60.dp)
39+
.clip(RoundedCornerShape(CornerSize(6.dp)))
40+
.align(alignment = Alignment.CenterVertically)
41+
)
42+
Text(text = details, fontSize = 18.sp, fontWeight = FontWeight.Normal)
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.educational.jetpackbasic.model
2+
3+
/**
4+
* Created by Samset on 2/28/25.
5+
Copyright (c) 2025 All rights reserved.
6+
*/
7+
data class UserData(val res:Int,val title:String)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.educational.jetpackbasic.utils
2+
3+
import com.educational.jetpackbasic.R
4+
import com.educational.jetpackbasic.model.UserData
5+
import java.util.ArrayList
6+
7+
/**
8+
* Created by Samset on 2/28/25.
9+
Copyright (c) 2025 All rights reserved.
10+
*/
11+
object DataSource {
12+
val dataList: ArrayList<UserData> = ArrayList()
13+
fun getListData() : ArrayList<UserData>{
14+
dataList.clear()
15+
for (i in 1..50){
16+
val data= UserData(R.drawable.ic_launcher_background,"Item "+i)
17+
dataList.add(data)
18+
}
19+
return dataList
20+
}
21+
22+
}

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ dependencyResolutionManagement {
1919
}
2020
}
2121

22-
rootProject.name = "JetpackComposeBasics-master"
22+
rootProject.name = "JetpackComposeBasics"
2323
include(":app")

0 commit comments

Comments
 (0)