diff --git a/app/build.gradle b/app/build.gradle index e1a3b54..bff0a6d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ plugins { id "org.sonarqube" version "4.4.1.3373" id 'com.google.devtools.ksp' version '2.0.0-1.0.21' + alias(libs.plugins.compose.compiler) } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' @@ -25,6 +26,9 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" namespace 'com.example.ToDo' + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -44,19 +48,46 @@ android { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } + + buildFeatures { + compose true + } + + composeOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = '17' + } + + packaging { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.core:core-ktx:1.13.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.1' + implementation 'androidx.activity:activity-compose:1.9.0' + implementation 'androidx.compose.ui:ui-graphics' + implementation 'androidx.compose.material3:material3' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation 'androidx.recyclerview:recyclerview:1.3.2' implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'com.google.android.material:material:1.12.0' + + // kotlin dependency implementation "org.jetbrains.kotlin:kotlin-stdlib:2.0.0" + + // room dependency def room_version = "2.6.1" implementation "androidx.room:room-runtime:$room_version" implementation("androidx.room:room-ktx:$room_version") @@ -69,4 +100,22 @@ dependencies { // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.1" + + androidTestImplementation platform('androidx.compose:compose-bom:2024.05.00') + androidTestImplementation 'androidx.compose.ui:ui-test-junit4' + + + def composeBom = platform('androidx.compose:compose-bom:2024.05.00') + implementation composeBom + + implementation 'androidx.compose.ui:ui' + + // Android Studio Preview support + implementation 'androidx.compose.ui:ui-tooling-preview' + debugImplementation 'androidx.compose.ui:ui-tooling' + debugImplementation 'androidx.compose.ui:ui-test-manifest' + + //icon + implementation "androidx.compose.material:material-icons-extended:1.6.7" + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e6f1ef0..4571bca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,14 +9,22 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + + - + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/HomeActivity.kt b/app/src/main/java/com/example/ToDo/compose/HomeActivity.kt new file mode 100644 index 0000000..a5cc0bf --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/HomeActivity.kt @@ -0,0 +1,58 @@ +package com.example.ToDo.compose + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.tooling.preview.Preview +import com.example.ToDo.TodoViewmodel +import com.example.ToDo.compose.ui.ToDoScreens.AddNewTask +import com.example.ToDo.compose.ui.ToDoScreens.LoadUI +import com.example.ToDo.compose.ui.theme.ToDoTheme +import com.example.ToDo.data.source.TodoRepository +import com.example.ToDo.data.source.local.db.TodoDatabase.Companion.getDataBase + +class HomeActivity : ComponentActivity() { + + private lateinit var todoViewmodel : TodoViewmodel + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + todoViewmodel = TodoViewmodel(TodoRepository(getDataBase(this.applicationContext).UserTodoDao())) + setContent { + App() + } + } + + @Composable + private fun App() { + var selected by remember { mutableStateOf(false) } + if (selected) { + AddNewTask(onDismiss = { + selected = !selected + }, todoViewmodel) + } else { + LoadUI(onClick = { + selected = !selected + }, todoViewmodel) + } + + } + + @Preview(showBackground = true) + @Composable + fun LoadUIPreview() { + ToDoTheme { + LoadUI({ + + }, todoViewmodel) + } + } +} + diff --git a/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/AddTaskUI.kt b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/AddTaskUI.kt new file mode 100644 index 0000000..ce267f3 --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/AddTaskUI.kt @@ -0,0 +1,97 @@ +package com.example.ToDo.compose.ui.ToDoScreens + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.sharp.Clear +import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextField +import androidx.compose.material3.TextFieldDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import com.example.ToDo.TodoViewmodel +import com.example.ToDo.data.source.local.db.UserTodo + +@Composable +fun AddNewTask(onDismiss: () -> Unit, todoViewmodel: TodoViewmodel) { + Dialog(onDismissRequest = { onDismiss()}) { + Card( + elevation = CardDefaults.cardElevation(defaultElevation = 3.dp), + colors = CardDefaults.cardColors( + containerColor = Color.White + ), + border = BorderStroke(width = 2.dp, color = Color.LightGray), + modifier = Modifier + .clip(RectangleShape) + ) { + val state = remember { + mutableStateOf("") + } + Column( + modifier = Modifier + .padding(5.dp) + .background(color = Color.White), + ) { + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier + .fillMaxWidth() + .padding(10.dp)) { + Text( + text = "Add a new task", + style = MaterialTheme.typography.headlineSmall, + fontWeight = FontWeight.SemiBold + ) + Icon( + imageVector = Icons.Sharp.Clear, + contentDescription = "dismiss UI", + tint = Color.Black, + modifier = Modifier.background(color = Color.LightGray, shape = CircleShape) + ) + } + TextField(value = state.value, onValueChange = { + state.value = it + }, colors = TextFieldDefaults.colors( + unfocusedContainerColor = Color.White, + focusedContainerColor = Color.White, + cursorColor = Color.Black + ), modifier = Modifier + .fillMaxWidth()) + + Spacer(modifier = Modifier.padding(5.dp)) + + Button(onClick = { + todoViewmodel.createTodo(UserTodo(0, state.value, 0)) + onDismiss() + }, modifier = Modifier + .width(200.dp) + .align(Alignment.CenterHorizontally)) { + Text(text = "Add task") + } + + } + + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoHomeScreen.kt b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoHomeScreen.kt new file mode 100644 index 0000000..89ba1ee --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoHomeScreen.kt @@ -0,0 +1,70 @@ +package com.example.ToDo.compose.ui.ToDoScreens + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Add +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.example.ToDo.TodoViewmodel +import com.example.ToDo.compose.ui.theme.Purple80 + +@Composable +fun LoadUI(onClick: () -> Unit, todoViewmodel: TodoViewmodel) { + Column(modifier = Modifier.padding(5.dp).fillMaxSize(1f)) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier + .fillMaxWidth() + .padding(top = 5.dp), horizontalArrangement = Arrangement.SpaceBetween) { + Text( + text = "Tasks", + textAlign = TextAlign.Center, + modifier = Modifier + .background(Color.Transparent) + .weight(.8f), + style = MaterialTheme.typography.headlineSmall, + fontWeight = FontWeight.SemiBold + ) + //val context = LocalContext.current + Icon( + imageVector = Icons.Filled.Add, + contentDescription = "create a new task", + modifier = Modifier + .background(color = Purple80, shape = CircleShape) + .size(30.dp) + .clickable { + onClick() + } + ) + } + Spacer(modifier = Modifier + .fillMaxWidth() + .height(20.dp)) + + LazyColumn { + items(items = listOf("Item 1 hjghj fvhjrvfhjj hfhsjfvh vfhjvhjfhj vhfvjfvhjfh vhjvhjdvfjh bjvfhjdvfhjd vjd fhgvfhdvhjf vghfvhjvf", "Item 2", "Item 3")) { item -> + ToDoListItem(item) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoListItem.kt b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoListItem.kt new file mode 100644 index 0000000..0be9fa0 --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/ToDoScreens/ToDoListItem.kt @@ -0,0 +1,97 @@ +package com.example.ToDo.compose.ui.ToDoScreens + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.rounded.TaskAlt +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.example.ToDo.compose.ui.theme.TodoSelectedColor + +@Composable +fun ToDoListItem(item : String) { + Card ( + elevation = CardDefaults.cardElevation( + defaultElevation = 2.dp + ), + border = BorderStroke(width = 0.1.dp, color = Color.Gray), + modifier = Modifier.padding(8.dp)) + { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .background(color = Color.White) + .padding(8.dp), + horizontalArrangement = Arrangement.Start + ) { + var selected by remember { mutableStateOf(false) } + Icon( + imageVector = Icons.Rounded.TaskAlt, + contentDescription = "add task", + tint = if(selected) { + Color.White + } else { + Color.LightGray + }, + modifier = Modifier + .background( + color = if (selected) { + TodoSelectedColor + } else { + Color.White + }, shape = CircleShape + ) + .size(26.dp) + .padding(2.dp) + .clickable { + selected = !selected + } + ) + Spacer(modifier = Modifier.padding(4.dp)) + Text( + text = item, + fontFamily = FontFamily.SansSerif, + modifier = Modifier.weight(.8f), + style = MaterialTheme.typography.bodyLarge + ) + + Icon( + imageVector = Icons.Default.Delete, + tint = Color.Red, + contentDescription = "delete task", + modifier = Modifier + .size(22.dp) + ) + } + } +} + +@Preview(showBackground = true) +@Composable +private fun previewListItem() { + ToDoListItem(item = "Akansha") +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/ui/theme/Color.kt b/app/src/main/java/com/example/ToDo/compose/ui/theme/Color.kt new file mode 100644 index 0000000..0917f15 --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/theme/Color.kt @@ -0,0 +1,12 @@ +package com.example.ToDo.compose.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) +val TodoSelectedColor = Color(0xFF8ED74F) \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/ui/theme/Theme.kt b/app/src/main/java/com/example/ToDo/compose/ui/theme/Theme.kt new file mode 100644 index 0000000..78441d3 --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/theme/Theme.kt @@ -0,0 +1,57 @@ +package com.example.ToDo.compose.ui.theme + +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun ToDoTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ToDo/compose/ui/theme/Type.kt b/app/src/main/java/com/example/ToDo/compose/ui/theme/Type.kt new file mode 100644 index 0000000..3648739 --- /dev/null +++ b/app/src/main/java/com/example/ToDo/compose/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.example.ToDo.compose.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42730b3..6813b00 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Save New Task Tasks + HomeActivity \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..4ac2d6f --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +