feature: lab3 is done
This commit is contained in:
parent
471645fb6e
commit
d88daf5fd7
@ -9,36 +9,7 @@
|
||||
<option name="autoReloadType" value="NONE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="7c94e195-a540-483e-9a1c-11797aeb1741" name="Changes" comment="empty activity test">
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Basket/BasketItem.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/List_of_Services/AddService.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/List_of_Services/Service.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Orders/OrderItem.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Orders/Orders.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/Login.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/ProfileChange.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/ProfileNotAuth.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/Registration.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/TestServiceItem.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/UIComponents/MyTextField.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/res/drawable/icon_calendar.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/res/drawable/image_service.png" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/app/src/main/res/drawable/upload.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/AndroidManifest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/AndroidManifest.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/App.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/App.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Basket/Basket.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Basket/Basket.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/List_of_Services/ListOfServices.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/List_of_Services/ListOfServices.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavBar.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavBar.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavController.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavController.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavItem.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Navbar/NavItem.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/Profile.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/Profile/Profile.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/UIComponents/Button.kt" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/UIComponents/SearchBar.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/UIComponents/SearchBar.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Color.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Color.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Theme.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Theme.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Type.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/myapplication/ui/theme/Type.kt" afterDir="false" />
|
||||
</list>
|
||||
<list default="true" id="7c94e195-a540-483e-9a1c-11797aeb1741" name="Changes" comment="feature: lab3 is done" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -53,8 +24,8 @@
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="resourceFile" />
|
||||
<option value="Class" />
|
||||
<option value="Kotlin Class" />
|
||||
</list>
|
||||
</option>
|
||||
@ -67,11 +38,14 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
<entry key="$PROJECT_DIR$" value="LabWork02" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="KotlinCodeInsightWorkspaceSettings">
|
||||
<option name="optimizeImportsOnTheFly" value="true" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
@ -84,16 +58,17 @@
|
||||
"keyToString": {
|
||||
"ApkExportedModule": "My_Application.app",
|
||||
"ExportApk.ApkPathForMy_Application.app": "C:\\Users\\Danil\\Desktop\\MDP\\labs\\app",
|
||||
"PROJECT_TRUSTED_KEY": "true",
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.cidr.known.project.marker": "true",
|
||||
"cidr.known.project.marker": "true",
|
||||
"com.android.tools.idea.devicemanager.tab": "Physical",
|
||||
"last_opened_file_path": "C:/Users/Danil/Downloads/test",
|
||||
"project.structure.last.edited": "Build Variants",
|
||||
"project.structure.last.edited": "Modules",
|
||||
"project.structure.proportion": "0.17",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "trusted.hosts"
|
||||
"settings.editor.selected.configurable": "reference.settings.ide.settings.new.ui"
|
||||
},
|
||||
"keyToStringList": {
|
||||
"ExportApk.BuildVariants": [
|
||||
@ -102,6 +77,8 @@
|
||||
}
|
||||
}</component>
|
||||
<component name="PsdUISettings">
|
||||
<option name="MODULE_TAB" value="Signing Configs" />
|
||||
<option name="LAST_EDITED_SIGNING_CONFIG" value="debug" />
|
||||
<option name="LAST_EDITED_BUILD_TYPE" value="release" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
@ -113,7 +90,7 @@
|
||||
<recent name="C:\Users\Danil\Desktop\MDP\labs\app\src\main\java\com\example\myapplication\UIComponents" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager" selected="Android App.App">
|
||||
<component name="RunManager" selected="Android App.app">
|
||||
<configuration name="App" type="AndroidRunConfigurationType" factoryName="Android App" temporary="true">
|
||||
<module name="My_Application.app.main" />
|
||||
<option name="DEPLOY" value="true" />
|
||||
@ -246,8 +223,16 @@
|
||||
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="build.gradle.kts" type="KotlinStandaloneScriptRunConfigurationType" temporary="true" nameIsGenerated="true">
|
||||
<module name="My_Application" />
|
||||
<option name="filePath" value="$PROJECT_DIR$/app/build.gradle.kts" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Kotlin script (Beta).build.gradle.kts" />
|
||||
<item itemvalue="Android App.App" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
@ -275,7 +260,21 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1696755925297</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="3" />
|
||||
<task id="LOCAL-00003" summary="feature: UI, lab2 maybe done">
|
||||
<created>1698677204522</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1698677204522</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00004" summary="feature: lab3 is done">
|
||||
<created>1699943645305</created>
|
||||
<option name="number" value="00004" />
|
||||
<option name="presentableId" value="LOCAL-00004" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1699943645305</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="5" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
@ -291,6 +290,8 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="empty activity test" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="empty activity test" />
|
||||
<MESSAGE value="feature: UI, lab2 maybe done" />
|
||||
<MESSAGE value="feature: lab3 is done" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="feature: lab3 is done" />
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id ("kotlin-kapt")
|
||||
}
|
||||
|
||||
android {
|
||||
@ -9,7 +10,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "com.example.myapplication"
|
||||
minSdk = 29
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
@ -30,11 +31,11 @@ android {
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "17"
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
@ -49,26 +50,42 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
implementation("androidx.core:core-ktx:1.9.0")
|
||||
apply(plugin = "kotlin-kapt")
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
|
||||
implementation("androidx.activity:activity-compose:1.7.2")
|
||||
implementation("androidx.activity:activity-compose:1.8.0")
|
||||
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
|
||||
implementation("androidx.compose.ui:ui")
|
||||
implementation("androidx.compose.ui:ui-graphics")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||
implementation("androidx.compose.material3:material3")
|
||||
//
|
||||
implementation("androidx.compose.material:material:1.5.2")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.3")
|
||||
|
||||
implementation("androidx.compose.material:material")
|
||||
implementation("androidx.navigation:navigation-runtime-ktx:2.7.5")
|
||||
implementation("androidx.compose.material3:material3:1.1.2")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
|
||||
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
|
||||
|
||||
debugImplementation("androidx.compose.ui:ui-tooling")
|
||||
debugImplementation("androidx.compose.ui:ui-test-manifest")
|
||||
implementation ("androidx.activity:activity-ktx:1.8.0")
|
||||
implementation ("androidx.fragment:fragment-ktx:1.6.2")
|
||||
implementation ("io.coil-kt:coil-compose:1.4.0")
|
||||
implementation ("com.google.code.gson:gson:2.9.0")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.5")
|
||||
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0-beta01")
|
||||
|
||||
|
||||
//ROOM
|
||||
val room_version = "2.5.2"
|
||||
implementation("androidx.room:room-runtime:$room_version")
|
||||
annotationProcessor("androidx.room:room-compiler:$room_version")
|
||||
kapt("androidx.room:room-compiler:$room_version")
|
||||
implementation("androidx.room:room-ktx:$room_version")
|
||||
implementation("androidx.room:room-paging:$room_version")
|
||||
}
|
@ -4,19 +4,26 @@ import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.SnackbarDefaults.backgroundColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.example.myapplication.Navbar.NavBar
|
||||
import com.example.myapplication.composeui.Navbar.NavBar
|
||||
import com.example.myapplication.database.AppDatabase
|
||||
import com.example.myapplication.model.User
|
||||
import com.example.myapplication.ui.theme.AppTheme
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class App : ComponentActivity() {
|
||||
val database by lazy { AppDatabase.getInstance(this) }
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
this.deleteDatabase("my-db")
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
AppDatabase.populateDatabase()
|
||||
}
|
||||
setContent {
|
||||
AppTheme (darkTheme = false){
|
||||
// A surface container using the 'background' color from the theme
|
||||
@ -31,3 +38,24 @@ class App : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
class GlobalUser private constructor() {
|
||||
private var user: User? = null
|
||||
|
||||
fun setUser(user: User?) {
|
||||
this.user = user
|
||||
}
|
||||
|
||||
fun getUser(): User? {
|
||||
return user
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var instance: GlobalUser? = null
|
||||
|
||||
fun getInstance(): GlobalUser {
|
||||
return instance ?: synchronized(this) {
|
||||
instance ?: GlobalUser().also { instance = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
package com.example.myapplication.Orders
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
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.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.modifier.modifierLocalConsumer
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.myapplication.ui.theme.TextPrimary
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
||||
import java.util.Date
|
||||
|
||||
@Composable
|
||||
fun OrderItem (orderId: Int, date: String, price: Double, list: String){
|
||||
Column(modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(15.dp))){
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.padding(0.dp, 0.dp, 0.dp, 0.dp)
|
||||
.shadow(
|
||||
elevation = 4.dp,
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
clip = false
|
||||
)
|
||||
){
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 15.dp, vertical = 10.dp),
|
||||
){
|
||||
Text(text = "Order:$orderId", modifier = Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium)
|
||||
Text(text = "$price$", style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
Row (
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 15.dp),
|
||||
){
|
||||
Text(text = date, style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
}
|
||||
Row (
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxWidth()
|
||||
.padding(15.dp)
|
||||
){
|
||||
Text(text = list, style = MaterialTheme.typography.bodyMedium.copy(TextSecondary))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.example.myapplication.Orders
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import java.util.Date
|
||||
|
||||
@Composable
|
||||
fun Orders (navController: NavController){
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(BlueMain)
|
||||
.padding(15.dp)
|
||||
.padding(bottom = 60.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
){
|
||||
OrderItem(orderId = 1, date = "11.11.2023", price = 40.0, list = "Inoculation x2")
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.example.myapplication
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
data class TestServiceItem(
|
||||
val image: Int,
|
||||
@ -43,17 +42,8 @@ data class TestServiceItem(
|
||||
|
||||
fun getServices(): List<TestServiceItem>{
|
||||
return listOf(
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats","Dogs", "Cats","Dogs", "Cats","Dogs", "Cats","Dogs", "Cats","Dogs", "Cats","Dogs", "Cats",), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
TestServiceItem(R.drawable.image_service, "Inoculation", arrayListOf("Dogs", "Cats"), 20.0),
|
||||
|
||||
)
|
||||
|
||||
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package com.example.myapplication.Basket
|
||||
package com.example.myapplication.composeui.Basket
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -12,11 +11,8 @@ 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.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
@ -24,21 +20,42 @@ import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||
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.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.myapplication.R
|
||||
import com.example.myapplication.TestServiceItem
|
||||
import com.example.myapplication.getServices
|
||||
import com.example.myapplication.database.AppDatabase
|
||||
import com.example.myapplication.model.Service
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun Basket(navController : NavHostController){
|
||||
val basketList = remember { mutableStateMapOf<Service, Int>() }
|
||||
val context = LocalContext.current
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).basketDao().getBasketWithServices(1).collect { data ->
|
||||
basketList.clear()
|
||||
for (item in data.services){
|
||||
basketList[item] = (basketList[item] ?: 0) + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -53,11 +70,13 @@ fun Basket(navController : NavHostController){
|
||||
modifier = Modifier
|
||||
.padding(5.dp)
|
||||
)
|
||||
LazyColumn(){
|
||||
val items = listOf<TestServiceItem>(getServices()[1])
|
||||
itemsIndexed(items){
|
||||
_, item ->
|
||||
BasketItem(item = item)
|
||||
LazyColumn {
|
||||
items(basketList.toList()) { (service, count) ->
|
||||
key(service.serviceId) {
|
||||
BasketItemUI(service, count){ newCount ->
|
||||
basketList[service] = newCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(modifier = Modifier
|
||||
@ -75,12 +94,12 @@ fun Basket(navController : NavHostController){
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
){
|
||||
Text(
|
||||
text = "Total:",
|
||||
text = "Total: ",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Text(
|
||||
text = "40$",
|
||||
text = (getTotalPrice(basketList)).toString(),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
@ -115,4 +134,12 @@ fun Basket(navController : NavHostController){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getTotalPrice(basketList: SnapshotStateMap<Service, Int>): Double {
|
||||
var price = 0.00
|
||||
for (item in basketList){
|
||||
price += item.key.price * item.value
|
||||
}
|
||||
return (price*100).roundToInt() / 100.0
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Basket
|
||||
package com.example.myapplication.composeui.Basket
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
@ -13,11 +13,9 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@ -25,7 +23,6 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -36,15 +33,15 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.myapplication.TestServiceItem
|
||||
import com.example.myapplication.model.Service
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.TextPrimary
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
||||
|
||||
@Composable
|
||||
fun BasketItem(item: TestServiceItem){
|
||||
fun BasketItemUI(item: Service, count: Int, onCountChanged: (newCount: Int) -> Unit
|
||||
) {
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(0.dp, 0.dp, 0.dp, 10.dp)
|
||||
@ -54,7 +51,7 @@ fun BasketItem(item: TestServiceItem){
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
clip = false
|
||||
),
|
||||
){
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -63,34 +60,28 @@ fun BasketItem(item: TestServiceItem){
|
||||
.padding(15.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
){
|
||||
Image(
|
||||
painter = painterResource(id = item.image),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.heightIn(min = 100.dp)
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
contentScale = ContentScale.FillHeight,
|
||||
)
|
||||
) {
|
||||
item.photo?.let { painterResource(id = it) }?.let {
|
||||
Image(
|
||||
painter = it,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.heightIn(min = 100.dp)
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
contentScale = ContentScale.FillHeight,
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
){
|
||||
var animalsString = ""
|
||||
item.name?.let {
|
||||
Text(
|
||||
text = it,
|
||||
color = TextPrimary,
|
||||
style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
item.animals?.forEach { animal -> animalsString += "$animal, " }
|
||||
) {
|
||||
Text(
|
||||
text = animalsString,
|
||||
color = TextSecondary,
|
||||
text = item.name,
|
||||
color = TextPrimary,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
@ -101,21 +92,24 @@ fun BasketItem(item: TestServiceItem){
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
verticalArrangement = Arrangement.SpaceBetween,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
){
|
||||
) {
|
||||
Text(
|
||||
text = "$${item.price}",
|
||||
color = TextPrimary,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Row(verticalAlignment = Alignment.CenterVertically){
|
||||
var num by remember { mutableIntStateOf(5) }
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
var num by remember { mutableIntStateOf(count) }
|
||||
Text(
|
||||
text = num.toString(),
|
||||
color = TextPrimary
|
||||
)
|
||||
Column(verticalArrangement = Arrangement.SpaceAround){
|
||||
Column(verticalArrangement = Arrangement.SpaceAround) {
|
||||
Button(
|
||||
onClick = { num+=1 },
|
||||
onClick = {
|
||||
num += 1
|
||||
onCountChanged(num)
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.fillMaxWidth()
|
||||
@ -129,7 +123,10 @@ fun BasketItem(item: TestServiceItem){
|
||||
Text(text = "+")
|
||||
}
|
||||
Button(
|
||||
onClick = { num-=1 },
|
||||
onClick = {
|
||||
num -= 1
|
||||
onCountChanged(num)
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.fillMaxWidth()
|
@ -1,13 +1,7 @@
|
||||
package com.example.myapplication.List_of_Services
|
||||
package com.example.myapplication.composeui.List_of_Services
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.provider.MediaStore
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@ -18,23 +12,16 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.DropdownMenuItem
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.ExposedDropdownMenuBox
|
||||
import androidx.compose.material.ExposedDropdownMenuDefaults
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -47,17 +34,13 @@ import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.UIComponents.MyTextField
|
||||
import com.example.myapplication.composeui.UIComponents.MyTextField
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.TextPrimary
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@ -66,8 +49,6 @@ import kotlinx.coroutines.withContext
|
||||
fun AddService (navController: NavController){
|
||||
var serviceName = ""
|
||||
var price = ""
|
||||
var animals = ""
|
||||
val availableAnimals = listOf("Dogs", "Cats")
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Column (
|
||||
modifier = Modifier
|
||||
@ -112,19 +93,12 @@ fun AddService (navController: NavController){
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
){
|
||||
var animalsString = ""
|
||||
serviceName?.let {
|
||||
Text(
|
||||
text = it,
|
||||
color = TextPrimary,
|
||||
style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
animals?.forEach { animal -> animalsString += "$animal, " }
|
||||
Text(
|
||||
text = animalsString,
|
||||
color = TextSecondary,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -148,18 +122,6 @@ fun AddService (navController: NavController){
|
||||
serviceName = newValue
|
||||
}
|
||||
}
|
||||
Row (modifier = Modifier.padding(vertical = 5.dp)){
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
) {
|
||||
availableAnimals.forEach {
|
||||
DropdownMenuItem(onClick = { animals += "$it, " }) {
|
||||
Text(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row (modifier = Modifier.padding(vertical = 5.dp)){
|
||||
MyTextField(label = "Price"){
|
||||
newValue ->
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.List_of_Services
|
||||
package com.example.myapplication.composeui.List_of_Services
|
||||
|
||||
import SearchBar
|
||||
import androidx.compose.foundation.background
|
||||
@ -7,20 +7,32 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.myapplication.getServices
|
||||
import com.example.myapplication.database.AppDatabase
|
||||
import com.example.myapplication.model.Service
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun ListOfServices(navController: NavHostController){
|
||||
val serviceList = remember { mutableStateListOf<Service>() }
|
||||
val context = LocalContext.current
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).serviceDao().getAllServices().collect { data ->
|
||||
serviceList.clear()
|
||||
serviceList.addAll(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -34,7 +46,6 @@ fun ListOfServices(navController: NavHostController){
|
||||
//TODO search logic
|
||||
}
|
||||
LazyColumn(modifier = Modifier.padding(15.dp, 0.dp)){
|
||||
var serviceList = getServices()
|
||||
itemsIndexed(serviceList){_, item ->
|
||||
Service(item)
|
||||
}
|
@ -1,56 +1,41 @@
|
||||
package com.example.myapplication.List_of_Services
|
||||
package com.example.myapplication.composeui.List_of_Services
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material.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.draw.clip
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.painterResource
|
||||
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.TextUnit
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.myapplication.TestServiceItem
|
||||
import com.example.myapplication.model.Service
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.TextPrimary
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
||||
import java.security.Provider.Service
|
||||
|
||||
@Composable
|
||||
fun Service(item: TestServiceItem){
|
||||
fun Service(item: Service){
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(0.dp, 0.dp, 0.dp, 10.dp)
|
||||
@ -70,15 +55,17 @@ fun Service(item: TestServiceItem){
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
){
|
||||
Image(
|
||||
painter = painterResource(id = item.image),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.heightIn(min = 100.dp)
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
contentScale = ContentScale.FillHeight,
|
||||
)
|
||||
item.photo?.let { painterResource(id = it) }?.let {
|
||||
Image(
|
||||
painter = it,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.heightIn(min = 100.dp)
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
contentScale = ContentScale.FillHeight,
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -86,19 +73,12 @@ fun Service(item: TestServiceItem){
|
||||
.widthIn(max = (LocalConfiguration.current.screenWidthDp / 3).dp),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
){
|
||||
var animalsString = ""
|
||||
item.name?.let {
|
||||
Text(
|
||||
text = it,
|
||||
color = TextPrimary,
|
||||
style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
item.animals?.forEach { animal -> animalsString += "$animal, " }
|
||||
Text(
|
||||
text = animalsString,
|
||||
color = TextSecondary,
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Navbar
|
||||
package com.example.myapplication.composeui.Navbar
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
@ -67,26 +67,32 @@ fun NavBar(){
|
||||
.clip(RoundedCornerShape(15.dp, 15.dp, 0.dp, 0.dp)),
|
||||
){
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
val currentDestination = navBackStackEntry
|
||||
|
||||
items.forEach { screen ->
|
||||
val isSelected = currentDestination?.destination?.route == screen.route
|
||||
|
||||
BottomNavigationItem(
|
||||
selected = isSelected,
|
||||
icon = {
|
||||
Icon(painterResource(screen.icon),
|
||||
null,
|
||||
modifier = Modifier,
|
||||
GreenBtn)
|
||||
},
|
||||
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
||||
modifier = Modifier
|
||||
.padding(15.dp),
|
||||
onClick = {
|
||||
navController.navigate(screen.route){
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
if (!isSelected) {
|
||||
navController.graph.startDestinationRoute?.let {
|
||||
navController.popBackStack(it, inclusive = true)
|
||||
}
|
||||
navController.navigate(screen.route) {
|
||||
launchSingleTop
|
||||
}
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
navController.navigate(screen.route)
|
||||
}
|
||||
}
|
||||
)
|
@ -1,25 +1,26 @@
|
||||
package com.example.myapplication.Navbar
|
||||
package com.example.myapplication.composeui.Navbar
|
||||
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import com.example.myapplication.Basket.Basket
|
||||
import com.example.myapplication.List_of_Services.AddService
|
||||
import com.example.myapplication.List_of_Services.ListOfServices
|
||||
import com.example.myapplication.Orders.Orders
|
||||
import com.example.myapplication.Profile.Login
|
||||
import com.example.myapplication.Profile.Profile
|
||||
import com.example.myapplication.Profile.ProfileChange
|
||||
import com.example.myapplication.Profile.ProfileNotAuth
|
||||
import com.example.myapplication.Profile.Registration
|
||||
import com.example.myapplication.composeui.Basket.Basket
|
||||
import com.example.myapplication.composeui.List_of_Services.AddService
|
||||
import com.example.myapplication.composeui.List_of_Services.ListOfServices
|
||||
import com.example.myapplication.composeui.Orders.Orders
|
||||
import com.example.myapplication.composeui.Profile.Login
|
||||
import com.example.myapplication.composeui.Profile.Profile
|
||||
import com.example.myapplication.composeui.Profile.ProfileChange
|
||||
import com.example.myapplication.composeui.Profile.ProfileNotAuth
|
||||
import com.example.myapplication.composeui.Profile.Registration
|
||||
|
||||
@Composable
|
||||
fun NavController(navController : NavHostController){
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = NavItem.Profile.route
|
||||
startDestination = NavItem.ListOfServices.route,
|
||||
|
||||
){
|
||||
composable(
|
||||
NavItem.ListOfServices.route
|
@ -1,10 +1,6 @@
|
||||
package com.example.myapplication.Navbar
|
||||
package com.example.myapplication.composeui.Navbar
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import com.example.myapplication.R
|
||||
|
||||
sealed class NavItem(
|
@ -0,0 +1,49 @@
|
||||
package com.example.myapplication.composeui.Orders
|
||||
|
||||
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.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.myapplication.model.Order
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
@Composable
|
||||
fun OrderItem (order: Order){
|
||||
val dateFormat = SimpleDateFormat("dd-MM-yyyy")
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
.clip(RoundedCornerShape(15.dp))
|
||||
){
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 15.dp, vertical = 10.dp),
|
||||
){
|
||||
Text(text = "Order:${order.orderId}", modifier = Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium)
|
||||
Text(text = "${order.total}", style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
Row (
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 15.dp),
|
||||
){
|
||||
Text(text = dateFormat.format(Date(order.date)), style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.example.myapplication.composeui.Orders
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.database.AppDatabase
|
||||
import com.example.myapplication.model.Order
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun Orders (navController: NavController){
|
||||
val ordersList = remember { mutableStateListOf<Order>() }
|
||||
val context = LocalContext.current
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).orderDao().getAllOrder().collect { data ->
|
||||
ordersList.clear()
|
||||
ordersList.addAll(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(BlueMain)
|
||||
.padding(15.dp)
|
||||
.padding(bottom = 60.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
){
|
||||
itemsIndexed(ordersList){_, item ->
|
||||
OrderItem(item)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Profile
|
||||
package com.example.myapplication.composeui.Profile
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
@ -24,8 +24,8 @@ import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.TextUnitType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.Navbar.NavItem
|
||||
import com.example.myapplication.UIComponents.MyTextField
|
||||
import com.example.myapplication.composeui.Navbar.NavItem
|
||||
import com.example.myapplication.composeui.UIComponents.MyTextField
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
@ -1,7 +1,6 @@
|
||||
package com.example.myapplication.Profile
|
||||
package com.example.myapplication.composeui.Profile
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@ -19,21 +18,35 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.myapplication.Navbar.NavItem
|
||||
import com.example.myapplication.composeui.Navbar.NavItem
|
||||
import com.example.myapplication.database.AppDatabase
|
||||
import com.example.myapplication.model.User
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.RedBtn
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun Profile(navController: NavHostController){
|
||||
val context = LocalContext.current
|
||||
val user = remember { mutableStateOf<User?>(null)}
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
user.value = AppDatabase.getInstance(context).userDao().getUserById(2)
|
||||
}
|
||||
}
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -51,7 +64,7 @@ fun Profile(navController: NavHostController){
|
||||
}
|
||||
Box(modifier = Modifier.padding(15.dp)){
|
||||
Text(
|
||||
text = "Name Surname",
|
||||
text = user.value?.name + " " + user.value?.surname,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -60,14 +73,16 @@ fun Profile(navController: NavHostController){
|
||||
)
|
||||
}
|
||||
Box(modifier = Modifier.padding(15.dp)){
|
||||
Text(
|
||||
text = "example@mail.ex",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.Center),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
user.value?.email?.let {
|
||||
Text(
|
||||
text = it,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.Center),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = { navController.navigate(NavItem.ProfileChange.route) },
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Profile
|
||||
package com.example.myapplication.composeui.Profile
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
@ -41,7 +41,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.myapplication.R
|
||||
import com.example.myapplication.UIComponents.MyTextField
|
||||
import com.example.myapplication.composeui.UIComponents.MyTextField
|
||||
import com.example.myapplication.ui.theme.BlueBorder
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Profile
|
||||
package com.example.myapplication.composeui.Profile
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@ -21,7 +21,7 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.Navbar.NavItem
|
||||
import com.example.myapplication.composeui.Navbar.NavItem
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.Profile
|
||||
package com.example.myapplication.composeui.Profile
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
@ -24,8 +24,8 @@ import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.TextUnitType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.example.myapplication.Navbar.NavItem
|
||||
import com.example.myapplication.UIComponents.MyTextField
|
||||
import com.example.myapplication.composeui.Navbar.NavItem
|
||||
import com.example.myapplication.composeui.UIComponents.MyTextField
|
||||
import com.example.myapplication.ui.theme.BlueMain
|
||||
import com.example.myapplication.ui.theme.GreenBtn
|
||||
import com.example.myapplication.ui.theme.TextSecondary
|
||||
@ -69,7 +69,7 @@ fun Registration (navController: NavController){
|
||||
}
|
||||
}
|
||||
Button(
|
||||
onClick = { navController.navigate(NavItem.ListOfServices.route) },
|
||||
onClick = { navController.navigate(NavItem.ListOfServices.route)},
|
||||
modifier = Modifier
|
||||
.height(60.dp)
|
||||
.padding(top = 10.dp)
|
@ -1,4 +1,4 @@
|
||||
package com.example.myapplication.UIComponents
|
||||
package com.example.myapplication.composeui.UIComponents
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
@ -1,20 +1,16 @@
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
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.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.TextFieldDefaults.indicatorLine
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -23,6 +19,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.example.myapplication.R
|
||||
@ -61,9 +58,7 @@ fun SearchBar(
|
||||
.clip(RoundedCornerShape(15.dp)),
|
||||
singleLine = true,
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
textColor = Color.Black,
|
||||
containerColor = Color.White,
|
||||
placeholderColor = TextSecondary,
|
||||
focusedIndicatorColor = Color.Transparent,
|
||||
disabledIndicatorColor = Color.Transparent,
|
||||
unfocusedIndicatorColor = Color.Transparent,
|
29
app/src/main/java/com/example/myapplication/dao/BasketDao.kt
Normal file
29
app/src/main/java/com/example/myapplication/dao/BasketDao.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package com.example.myapplication.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import com.example.myapplication.model.Basket
|
||||
import com.example.myapplication.model.BasketService
|
||||
import com.example.myapplication.model.BasketWithServices
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface BasketDao {
|
||||
|
||||
@Insert
|
||||
suspend fun createBasket(basket: Basket):Long
|
||||
|
||||
@Insert
|
||||
suspend fun insertBasketService(basketService: BasketService)
|
||||
|
||||
@Query("SELECT * FROM tbl_basket WHERE creatorUserId = :id")
|
||||
fun getBasketWithServices(id: Int): Flow<BasketWithServices>
|
||||
|
||||
@Query("SELECT * FROM tbl_basket")
|
||||
fun getAllBasket(): Flow<List<Basket>>
|
||||
|
||||
@Delete
|
||||
suspend fun delete(basket: Basket)
|
||||
}
|
29
app/src/main/java/com/example/myapplication/dao/OrderDao.kt
Normal file
29
app/src/main/java/com/example/myapplication/dao/OrderDao.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package com.example.myapplication.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import com.example.myapplication.model.Order
|
||||
import com.example.myapplication.model.OrderService
|
||||
import com.example.myapplication.model.OrderWithServices
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface OrderDao {
|
||||
|
||||
@Insert
|
||||
suspend fun createOrder(order: Order):Long
|
||||
|
||||
@Insert
|
||||
suspend fun insertOrderService(orderService: OrderService)
|
||||
|
||||
@Query("SELECT * FROM tbl_order WHERE orderId = :id")
|
||||
fun getOrderWithServices(id: Int): Flow<OrderWithServices>
|
||||
|
||||
@Query("SELECT * FROM tbl_order")
|
||||
fun getAllOrder(): Flow<List<Order>>
|
||||
|
||||
@Delete
|
||||
suspend fun delete(order: Order)
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.example.myapplication.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.example.myapplication.model.Service
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ServiceDao {
|
||||
@Insert
|
||||
suspend fun insert(service: Service) : Long
|
||||
|
||||
@Update
|
||||
suspend fun update(service: Service)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(service: Service)
|
||||
|
||||
@Query("SELECT*FROM tbl_service")
|
||||
fun getAllServices(): Flow<List<Service>>
|
||||
|
||||
@Query("SELECT * FROM tbl_service WHERE serviceId = :id")
|
||||
suspend fun getServiceById(id: Int): Service
|
||||
}
|
31
app/src/main/java/com/example/myapplication/dao/UserDao.kt
Normal file
31
app/src/main/java/com/example/myapplication/dao/UserDao.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package com.example.myapplication.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.example.myapplication.model.User
|
||||
import com.example.myapplication.model.UserWithOrder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface UserDao {
|
||||
@Insert
|
||||
suspend fun createUser(user: User)
|
||||
|
||||
@Update
|
||||
suspend fun updateUser(user: User)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteUser(user: User)
|
||||
|
||||
@Query("SELECT * FROM tbl_user WHERE userId = :id")
|
||||
fun getUserById(id: Int): User
|
||||
|
||||
@Query("SELECT * FROM tbl_user WHERE email = :email")
|
||||
fun getUserByEmail(email: String): User
|
||||
|
||||
@Query("SELECT * FROM tbl_user WHERE userId =:id")
|
||||
fun getUserOrders(id: Int) : Flow<UserWithOrder>
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.example.myapplication.database
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.example.myapplication.R
|
||||
import com.example.myapplication.dao.BasketDao
|
||||
import com.example.myapplication.dao.OrderDao
|
||||
import com.example.myapplication.dao.ServiceDao
|
||||
import com.example.myapplication.dao.UserDao
|
||||
import com.example.myapplication.model.Basket
|
||||
import com.example.myapplication.model.BasketService
|
||||
import com.example.myapplication.model.Order
|
||||
import com.example.myapplication.model.OrderService
|
||||
import com.example.myapplication.model.RoleEnum
|
||||
import com.example.myapplication.model.Service
|
||||
import com.example.myapplication.model.User
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Date
|
||||
|
||||
@Database(entities = [User::class, Service::class, Order::class, OrderService::class, Basket::class, BasketService::class], version = 4)
|
||||
abstract class AppDatabase : RoomDatabase(){
|
||||
abstract fun serviceDao(): ServiceDao
|
||||
abstract fun userDao(): UserDao
|
||||
abstract fun orderDao(): OrderDao
|
||||
abstract fun basketDao(): BasketDao
|
||||
|
||||
companion object {
|
||||
private const val DB_NAME: String = "my-db"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
|
||||
suspend fun populateDatabase() {
|
||||
INSTANCE?.let { database ->
|
||||
// User
|
||||
val userDao = database.userDao()
|
||||
val user1 = User(null, "Artem", "Emelyanov", "artem@mail.ru", "123", RoleEnum.User)
|
||||
val user2 = User(null, "Danil", "Markov", "danil@mail.ru", "123", RoleEnum.Admin)
|
||||
val user3 = User(null, "Viktoria", "Presnyakova", "vika@mail.ru", "123", RoleEnum.User)
|
||||
userDao.createUser(user1)
|
||||
userDao.createUser(user2)
|
||||
userDao.createUser(user3)
|
||||
// Service
|
||||
val serviceDao = database.serviceDao()
|
||||
val service1 = Service(null, "Test", 19.09, R.drawable.image_service)
|
||||
val service2 = Service(null, "Test", 19.09, R.drawable.image_service)
|
||||
val service3 = Service(null, "Test", 19.09, R.drawable.image_service)
|
||||
val service4 = Service(null, "Test", 19.09, R.drawable.image_service)
|
||||
val serviceId1 = serviceDao.insert(service1).toInt()
|
||||
val serviceId2 = serviceDao.insert(service2).toInt()
|
||||
serviceDao.insert(service3)
|
||||
serviceDao.insert(service4)
|
||||
// Order
|
||||
val orderDao = database.orderDao()
|
||||
val order1 = Order(null, Date().time, 200.00, 1)
|
||||
val order2 = Order(null, Date().time, 200.00, 1)
|
||||
val orderId1 = orderDao.createOrder(order1).toInt()
|
||||
val orderId2 = orderDao.createOrder(order2).toInt()
|
||||
orderDao.insertOrderService(OrderService(orderId1, serviceId1))
|
||||
orderDao.insertOrderService(OrderService(orderId2, serviceId2))
|
||||
// Basket
|
||||
val basketDao = database.basketDao()
|
||||
val basket = Basket(null, Date().time, 200.00, 1)
|
||||
val basketId = basketDao.createBasket(basket).toInt()
|
||||
basketDao.insertBasketService(BasketService(null, basketId, serviceId1))
|
||||
basketDao.insertBasketService(BasketService(null, basketId, serviceId1))
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstance(appContext: Context): AppDatabase {
|
||||
return INSTANCE ?: synchronized(this) {
|
||||
Room.databaseBuilder(
|
||||
appContext,
|
||||
AppDatabase::class.java,
|
||||
DB_NAME
|
||||
)
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
populateDatabase()
|
||||
}
|
||||
}
|
||||
})
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
.also { INSTANCE = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
app/src/main/java/com/example/myapplication/model/Basket.kt
Normal file
13
app/src/main/java/com/example/myapplication/model/Basket.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "tbl_basket")
|
||||
data class Basket(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val basketId: Int? = null,
|
||||
val date: Long,
|
||||
val total: Double,
|
||||
val creatorUserId: Int
|
||||
)
|
@ -0,0 +1,6 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
data class BasketItem (
|
||||
val service: Service,
|
||||
val count: Int
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "tbl_basket_service")
|
||||
data class BasketService(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val basketServiceId: Int? = null,
|
||||
val basketId: Int,
|
||||
val serviceId: Int,
|
||||
)
|
@ -0,0 +1,15 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
data class BasketWithServices(
|
||||
@Embedded val basket: Basket,
|
||||
@Relation(
|
||||
parentColumn = "basketId",
|
||||
entityColumn = "serviceId",
|
||||
associateBy = Junction(BasketService::class)
|
||||
)
|
||||
val services: List<Service>
|
||||
)
|
13
app/src/main/java/com/example/myapplication/model/Order.kt
Normal file
13
app/src/main/java/com/example/myapplication/model/Order.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "tbl_order")
|
||||
data class Order(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val orderId: Int? = null,
|
||||
val date: Long,
|
||||
val total: Double,
|
||||
val creatorUserId: Int
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(primaryKeys = ["orderId", "serviceId"], tableName = "tbl_order_service")
|
||||
data class OrderService(
|
||||
val orderId: Int,
|
||||
val serviceId: Int
|
||||
)
|
@ -0,0 +1,15 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Junction
|
||||
import androidx.room.Relation
|
||||
|
||||
data class OrderWithServices(
|
||||
@Embedded val order: Order,
|
||||
@Relation(
|
||||
parentColumn = "orderId",
|
||||
entityColumn = "serviceId",
|
||||
associateBy = Junction(OrderService::class)
|
||||
)
|
||||
val services: List<Service>
|
||||
)
|
@ -0,0 +1,6 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
enum class RoleEnum {
|
||||
Admin,
|
||||
User
|
||||
}
|
13
app/src/main/java/com/example/myapplication/model/Service.kt
Normal file
13
app/src/main/java/com/example/myapplication/model/Service.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName="tbl_service")
|
||||
data class Service (
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val serviceId: Int? = null,
|
||||
val name: String,
|
||||
val price: Double,
|
||||
val photo: Int? = null
|
||||
)
|
16
app/src/main/java/com/example/myapplication/model/User.kt
Normal file
16
app/src/main/java/com/example/myapplication/model/User.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "tbl_user")
|
||||
data class User(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val userId: Int? = null,
|
||||
val name: String,
|
||||
val surname: String,
|
||||
val email: String,
|
||||
val password: String,
|
||||
val role: RoleEnum,
|
||||
val photo: Int? = null
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
package com.example.myapplication.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class UserWithOrder(
|
||||
@Embedded val user: User,
|
||||
@Relation(
|
||||
parentColumn = "userId",
|
||||
entityColumn = "creatorUserId"
|
||||
)
|
||||
val orders: List<Order>
|
||||
)
|
Loading…
Reference in New Issue
Block a user