Skip to content

Commit ff08991

Browse files
committed
Initial commit
0 parents  commit ff08991

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1086
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

.idea/.gitignore

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

.idea/.name

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

.idea/compiler.xml

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

.idea/gradle.xml

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

.idea/inspectionProfiles/Project_Default.xml

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

.idea/misc.xml

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

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'com.seda.basic_android_kotlin_compose_lazygrid'
8+
compileSdk 32
9+
10+
defaultConfig {
11+
applicationId "com.seda.basic_android_kotlin_compose_lazygrid"
12+
minSdk 26
13+
targetSdk 32
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
minifyEnabled false
26+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = '1.8'
35+
}
36+
buildFeatures {
37+
compose true
38+
}
39+
composeOptions {
40+
kotlinCompilerExtensionVersion '1.1.1'
41+
}
42+
packagingOptions {
43+
resources {
44+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
45+
}
46+
}
47+
}
48+
49+
dependencies {
50+
51+
implementation 'androidx.core:core-ktx:1.7.0'
52+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
53+
implementation 'androidx.activity:activity-compose:1.3.1'
54+
implementation "androidx.compose.ui:ui:$compose_ui_version"
55+
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
56+
implementation 'androidx.compose.material:material:1.1.1'
57+
testImplementation 'junit:junit:4.13.2'
58+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
59+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
60+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
61+
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
62+
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
63+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.seda.basic_android_kotlin_compose_lazygrid
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.seda.basic_android_kotlin_compose_lazygrid", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.BasicandroidkotlincomposeLazyGrid"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true"
18+
android:label="@string/app_name"
19+
android:theme="@style/Theme.BasicandroidkotlincomposeLazyGrid">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
26+
<meta-data
27+
android:name="android.app.lib_name"
28+
android:value="" />
29+
</activity>
30+
</application>
31+
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.seda.basic_android_kotlin_compose_lazygrid
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.ExperimentalFoundationApi
7+
import androidx.compose.foundation.Image
8+
import androidx.compose.foundation.background
9+
import androidx.compose.foundation.layout.*
10+
import androidx.compose.foundation.lazy.GridCells
11+
import androidx.compose.foundation.lazy.LazyVerticalGrid
12+
import androidx.compose.foundation.lazy.items
13+
import androidx.compose.material.*
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.ui.Alignment
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.graphics.Color
18+
import androidx.compose.ui.layout.ContentScale
19+
import androidx.compose.ui.res.painterResource
20+
import androidx.compose.ui.res.stringResource
21+
import androidx.compose.ui.tooling.preview.Preview
22+
import androidx.compose.ui.unit.dp
23+
import com.seda.basic_android_kotlin_compose_lazygrid.data.DataSource
24+
import com.seda.basic_android_kotlin_compose_lazygrid.model.Topic
25+
import com.seda.basic_android_kotlin_compose_lazygrid.ui.theme.BasicandroidkotlincomposeLazyGridTheme
26+
27+
class MainActivity : ComponentActivity() {
28+
override fun onCreate(savedInstanceState: Bundle?) {
29+
super.onCreate(savedInstanceState)
30+
setContent {
31+
BasicandroidkotlincomposeLazyGridTheme {
32+
// A surface container using the 'background' color from the theme
33+
Surface(
34+
modifier = Modifier.fillMaxSize(),
35+
color = MaterialTheme.colors.background
36+
) {
37+
TopicGrid()
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
@OptIn(ExperimentalFoundationApi::class)
45+
@Composable
46+
fun TopicGrid(modifier: Modifier=Modifier) {
47+
LazyVerticalGrid(cells = GridCells.Adaptive(128.dp), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier.padding(8.dp) ){
48+
items(DataSource.topics){topic ->
49+
TopicCard(topic = topic)
50+
}
51+
}
52+
}
53+
@Composable
54+
fun TopicCard(topic: Topic,modifier: Modifier=Modifier){
55+
Card() {
56+
Row(modifier =Modifier.wrapContentHeight().height(98.dp)) {
57+
Box(modifier =Modifier.wrapContentHeight().height(98.dp) ) {
58+
Image(painter = painterResource(id = topic.imageRes), contentDescription = stringResource(
59+
id = topic.name
60+
), modifier = modifier
61+
.size(width = 98.dp, height = 98.dp)
62+
.aspectRatio(1f),
63+
contentScale = ContentScale.Crop)
64+
}
65+
Column() {
66+
Text(
67+
text = stringResource(id = topic.name),
68+
style = MaterialTheme.typography.body2,
69+
modifier = Modifier.padding(
70+
start = 16.dp,
71+
top = 16.dp,
72+
end = 16.dp,
73+
bottom = 8.dp
74+
))
75+
76+
Row(verticalAlignment = Alignment.CenterVertically) {
77+
Icon(painter = painterResource(id = R.drawable.ic_grain), contentDescription ="",
78+
modifier= Modifier
79+
.padding(start = 16.dp)
80+
.size(22.dp))
81+
Text(text = topic.availableCourses.toString(),modifier=modifier.padding(start = 8.dp))
82+
}
83+
}
84+
85+
86+
}
87+
88+
}
89+
90+
}
91+
92+
@Preview(showBackground = true, showSystemUi = true)
93+
@Composable
94+
fun DefaultPreview() {
95+
BasicandroidkotlincomposeLazyGridTheme {
96+
TopicGrid()
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.seda.basic_android_kotlin_compose_lazygrid.data
2+
3+
import com.seda.basic_android_kotlin_compose_lazygrid.R
4+
import com.seda.basic_android_kotlin_compose_lazygrid.model.Topic
5+
6+
object DataSource {
7+
8+
val topics = listOf(
9+
Topic(R.string.architecture, 58, R.drawable.architecture),
10+
Topic(R.string.crafts, 121, R.drawable.crafts),
11+
Topic(R.string.business, 78, R.drawable.business),
12+
Topic(R.string.culinary, 118, R.drawable.culinary),
13+
Topic(R.string.design, 423, R.drawable.design),
14+
Topic(R.string.fashion, 92, R.drawable.fashion),
15+
Topic(R.string.film, 165, R.drawable.film),
16+
Topic(R.string.gaming, 164, R.drawable.gaming),
17+
Topic(R.string.drawing, 326, R.drawable.drawing),
18+
Topic(R.string.lifestyle, 305, R.drawable.lifestyle),
19+
Topic(R.string.music, 212, R.drawable.music),
20+
Topic(R.string.painting, 172, R.drawable.painting),
21+
Topic(R.string.photography, 321, R.drawable.photography),
22+
Topic(R.string.tech, 118, R.drawable.tech)
23+
)
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.seda.basic_android_kotlin_compose_lazygrid.model
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.annotation.StringRes
5+
6+
data class Topic(@StringRes val name: Int,
7+
val availableCourses: Int,
8+
@DrawableRes val imageRes: Int)

0 commit comments

Comments
 (0)