не работает ничего
This commit is contained in:
parent
d73bb9f1aa
commit
2b9cd69ccb
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
<bytecodeTargetLevel target="19" />
|
||||
</component>
|
||||
</project>
|
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@ -7,7 +7,7 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="gradleJvm" value="19" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id ("kotlin-kapt")
|
||||
}
|
||||
|
||||
android {
|
||||
@ -10,7 +11,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId = "com.example.androidlabs"
|
||||
minSdk = 24
|
||||
targetSdk = 33
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
@ -23,15 +24,18 @@ android {
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_19
|
||||
targetCompatibility = JavaVersion.VERSION_19
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
jvmTarget = "19"
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
@ -45,7 +49,7 @@ android {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apply(plugin = "kotlin-kapt")
|
||||
dependencies {
|
||||
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
@ -56,6 +60,7 @@ dependencies {
|
||||
implementation("androidx.compose.ui:ui-graphics")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview")
|
||||
implementation("androidx.compose.material:material")
|
||||
implementation("androidx.navigation:navigation-runtime-ktx:2.7.4")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
@ -63,7 +68,19 @@ dependencies {
|
||||
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.1")
|
||||
implementation ("io.coil-kt:coil-compose:1.4.0")
|
||||
implementation ("com.google.code.gson:gson:2.8.8")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.3")
|
||||
implementation("androidx.navigation:navigation-compose:2.7.4")
|
||||
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0-alpha02")
|
||||
|
||||
|
||||
//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")
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
19
app/src/main/java/com/example/androidlabs/App.kt
Normal file
19
app/src/main/java/com/example/androidlabs/App.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package com.example.androidlabs
|
||||
|
||||
import android.app.Application
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class App : Application() {
|
||||
val database by lazy { AppDatabase.getInstance(this)}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
// this.deleteDatabase("my-db")
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
AppDatabase.populateDatabase()
|
||||
}
|
||||
}
|
||||
}
|
77
app/src/main/java/com/example/androidlabs/DB/AppDatabase.kt
Normal file
77
app/src/main/java/com/example/androidlabs/DB/AppDatabase.kt
Normal file
@ -0,0 +1,77 @@
|
||||
package com.example.androidlabs.DB
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.example.androidlabs.DB.dao.HotelDao
|
||||
import com.example.androidlabs.DB.dao.OrderDao
|
||||
import com.example.androidlabs.DB.dao.UserDao
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.DB.models.Order
|
||||
import com.example.androidlabs.DB.models.RoleEnum
|
||||
import com.example.androidlabs.DB.models.User
|
||||
import com.example.androidlabs.R
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Database(entities = [Hotel::class, User::class, Order::class], version = 5)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun hotelDao(): HotelDao
|
||||
abstract fun userDao(): UserDao
|
||||
abstract fun orderDao(): OrderDao
|
||||
|
||||
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.Admin)
|
||||
val user2 = User(null, "Danil", "Markov", "danil@mail.ru", "123", RoleEnum.User)
|
||||
val user3 = User(null, "Viktoria", "Presnyakova", "vika@mail.ru", "123", RoleEnum.User)
|
||||
userDao.createUser(user1)
|
||||
userDao.createUser(user2)
|
||||
userDao.createUser(user3)
|
||||
// Sneaker
|
||||
val hotelDao = database.hotelDao()
|
||||
val hotel1 = Hotel(null, "Hotel1", 1000.0, R.drawable.img, 1, "location1", "info1")
|
||||
val hotel2 = Hotel(null, "Hotel2", 2000.0, R.drawable.img_2, 2, "location2", "info2")
|
||||
val hotel3 = Hotel(null, "Hotel3", 3000.0, R.drawable.img_3, 3, "location3", "info3")
|
||||
val hotel4 = Hotel(null, "Hotel4", 4000.0, R.drawable.img_4, 4, "location4", "info4")
|
||||
hotelDao.insert(hotel1)
|
||||
hotelDao.insert(hotel2)
|
||||
hotelDao.insert(hotel3)
|
||||
hotelDao.insert(hotel4)
|
||||
// Order
|
||||
}
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
app/src/main/java/com/example/androidlabs/DB/dao/HotelDao.kt
Normal file
26
app/src/main/java/com/example/androidlabs/DB/dao/HotelDao.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package com.example.androidlabs.DB.dao
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface HotelDao {
|
||||
@Insert
|
||||
suspend fun insert(hotel: Hotel)
|
||||
|
||||
@Update
|
||||
suspend fun update(hotel: Hotel)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(hotel: Hotel)
|
||||
|
||||
@Query("SELECT*FROM Hotel")
|
||||
fun getAllHotelss(): Flow<List<Hotel>>
|
||||
|
||||
@Query("SELECT * FROM Hotel WHERE hotelId = :id")
|
||||
suspend fun getHotelById(id: Int): Hotel
|
||||
}
|
24
app/src/main/java/com/example/androidlabs/DB/dao/OrderDao.kt
Normal file
24
app/src/main/java/com/example/androidlabs/DB/dao/OrderDao.kt
Normal file
@ -0,0 +1,24 @@
|
||||
package com.example.androidlabs.DB.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import com.example.androidlabs.DB.models.Order
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface OrderDao {
|
||||
|
||||
@Insert
|
||||
suspend fun createOrder(order: Order): Long
|
||||
|
||||
@Query("SELECT * FROM 'Order' WHERE orderId = :id")
|
||||
fun getOrder(id: Int): Order
|
||||
|
||||
@Query("SELECT * FROM `Order`")
|
||||
fun getAllOrder(): Flow<List<Order>>
|
||||
|
||||
@Delete
|
||||
suspend fun delete(order: Order)
|
||||
}
|
31
app/src/main/java/com/example/androidlabs/DB/dao/UserDao.kt
Normal file
31
app/src/main/java/com/example/androidlabs/DB/dao/UserDao.kt
Normal file
@ -0,0 +1,31 @@
|
||||
package com.example.androidlabs.DB.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.example.androidlabs.DB.models.User
|
||||
import com.example.androidlabs.DB.models.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 users WHERE userId = :id")
|
||||
suspend fun getUserById(id: Int): User
|
||||
|
||||
@Query("SELECT * FROM users WHERE email = :email")
|
||||
suspend fun getUserByEmail(email: String): User
|
||||
|
||||
@Query("SELECT * FROM users WHERE userId =:id")
|
||||
fun getUserOrders(id: Int) : Flow<UserWithOrder>
|
||||
}
|
29
app/src/main/java/com/example/androidlabs/DB/models/Hotel.kt
Normal file
29
app/src/main/java/com/example/androidlabs/DB/models/Hotel.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Hotel (
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val hotelId: Int? = null,
|
||||
|
||||
@ColumnInfo(name = "Name")
|
||||
val name: String,
|
||||
|
||||
@ColumnInfo(name = "Price")
|
||||
val price: Double,
|
||||
|
||||
@ColumnInfo(name = "Img")
|
||||
val img: Int,
|
||||
|
||||
@ColumnInfo(name = "Stars")
|
||||
val stars: Int,
|
||||
|
||||
@ColumnInfo(name = "Location")
|
||||
val location: String,
|
||||
|
||||
@ColumnInfo(name = "Info")
|
||||
val info: String,
|
||||
)
|
23
app/src/main/java/com/example/androidlabs/DB/models/Order.kt
Normal file
23
app/src/main/java/com/example/androidlabs/DB/models/Order.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Order(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val orderId: Int? = null,
|
||||
@ColumnInfo(name = "DateFrom")
|
||||
val dateFrom: Long,
|
||||
@ColumnInfo(name = "DateTo")
|
||||
val dateTo: Long,
|
||||
@ColumnInfo(name = "Rooms")
|
||||
val rooms: Int,
|
||||
@ColumnInfo(name = "Total")
|
||||
val total: Double,
|
||||
@ColumnInfo(name = "CreatorUserId")
|
||||
val creatorUserId: Int,
|
||||
@ColumnInfo(name = "BookedHotelId")
|
||||
val bookedHotelId: Int
|
||||
)
|
@ -0,0 +1,29 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
import com.example.androidlabs.R
|
||||
|
||||
class PhotoManager {
|
||||
private val photos = listOf(
|
||||
R.drawable.img,
|
||||
R.drawable.img_1,
|
||||
R.drawable.img_2,
|
||||
R.drawable.img_3,
|
||||
R.drawable.img_4,
|
||||
)
|
||||
|
||||
private var currentIndex = 0
|
||||
|
||||
fun changePhoto(int: Int): Int {
|
||||
currentIndex = photos.indexOf(int)
|
||||
if (photos.isNotEmpty()) {
|
||||
if(currentIndex + 1 >= photos.size){
|
||||
currentIndex = 0
|
||||
}else{
|
||||
currentIndex += 1
|
||||
}
|
||||
return photos[currentIndex]
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
enum class RoleEnum {
|
||||
Admin,
|
||||
User
|
||||
}
|
23
app/src/main/java/com/example/androidlabs/DB/models/User.kt
Normal file
23
app/src/main/java/com/example/androidlabs/DB/models/User.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "users")
|
||||
data class User(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val userId: Int? = null,
|
||||
@ColumnInfo(name = "Name")
|
||||
val name: String,
|
||||
@ColumnInfo(name = "Surname")
|
||||
val surname: String,
|
||||
@ColumnInfo(name = "Email")
|
||||
val email: String,
|
||||
@ColumnInfo(name = "Password")
|
||||
val password: String,
|
||||
@ColumnInfo(name = "Role")
|
||||
val role: RoleEnum,
|
||||
@ColumnInfo(name = "Photo")
|
||||
val photo: Int? = null,
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
package com.example.androidlabs.DB.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class UserWithOrder(
|
||||
@Embedded val user: User,
|
||||
@Relation(
|
||||
parentColumn = "userId",
|
||||
entityColumn = "CreatorUserId"
|
||||
)
|
||||
val orders: List<Order>
|
||||
)
|
@ -3,18 +3,40 @@ package com.example.androidlabs
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import com.example.androidlabs.DB.models.User
|
||||
import com.example.androidlabs.Navigation.Navigate
|
||||
import com.example.androidlabs.hotelScreen.HotelInfo
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
Navigate()
|
||||
//HotelInfo(Hotel("hotel", R.drawable.img_1, 4, "location"))
|
||||
setContent {
|
||||
Navigate()
|
||||
//HotelInfo(Hotel("hotel", R.drawable.img_1, 4, "location"))
|
||||
}
|
||||
}
|
||||
}
|
||||
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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@ 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.platform.LocalContext
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
@ -20,6 +21,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.homeScreen.CardItem.HotelCard
|
||||
import com.example.androidlabs.Hotel
|
||||
@ -27,6 +29,9 @@ import com.example.androidlabs.homeScreen.SearchField.SearchField
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(navController: NavHostController) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val List = AppDatabase.getInstance(context).hotelDao()
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
|
BIN
app/src/main/res/drawable/img_2.png
Normal file
BIN
app/src/main/res/drawable/img_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
BIN
app/src/main/res/drawable/img_3.png
Normal file
BIN
app/src/main/res/drawable/img_3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
BIN
app/src/main/res/drawable/img_4.png
Normal file
BIN
app/src/main/res/drawable/img_4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
Loading…
x
Reference in New Issue
Block a user