Writing course work.
This commit is contained in:
parent
814364fccd
commit
20d2c1999d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -221,9 +221,10 @@ fun DropDownList(
|
||||
}
|
||||
|
||||
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MainNavbar(navController: NavController) {
|
||||
fun MainNavbar(
|
||||
navController: NavController
|
||||
) {
|
||||
val navController = rememberNavController()
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
|
@ -7,8 +7,8 @@ import androidx.navigation.compose.composable
|
||||
import ru.ulstu.`is`.pmu.screen.composeui.Login
|
||||
import ru.ulstu.`is`.pmu.screen.composeui.Register
|
||||
|
||||
@Composable
|
||||
fun NavGraph (navController: NavHostController){
|
||||
@Composable
|
||||
fun NavGraph (navController: NavHostController){
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Screen.Login.route)
|
||||
|
@ -36,9 +36,6 @@ enum class Screen(
|
||||
Account(
|
||||
"account", R.string.account, Icons.Filled.AccountCircle
|
||||
),
|
||||
StudentView(
|
||||
"student-view/{id}", R.string.student_view_title, showInBottomBar = false
|
||||
),
|
||||
Report(
|
||||
"report", R.string.report, showInBottomBar = false
|
||||
),
|
||||
|
@ -53,7 +53,6 @@ fun Hangar(
|
||||
Hangar(tankList = viewModel.usersTanksUiState.userTankList )
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun Hangar(
|
||||
tankList: List<TankWithNationAndLevel>
|
||||
|
@ -27,7 +27,6 @@ import ru.ulstu.`is`.pmu.screen.composeui.image.Dimensions
|
||||
import ru.ulstu.`is`.pmu.ui.AppViewModelProvider
|
||||
import androidx.compose.runtime.LaunchedEffect as LaunchedEffect
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun NationList(
|
||||
navController: NavController,
|
||||
|
@ -44,7 +44,6 @@ import ru.ulstu.`is`.pmu.ui.theme.CustomOrange
|
||||
import ru.ulstu.`is`.pmu.ui.theme.CustomRed
|
||||
import ru.ulstu.`is`.pmu.ui.theme.PmudemoTheme
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalTextApi::class)
|
||||
@Composable
|
||||
fun Register(navController: NavController) {
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
|
@ -49,8 +49,10 @@ import java.util.Date
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun Report (navController: NavController?,viewModel: ReportViewModel = viewModel(factory = AppViewModelProvider.Factory))
|
||||
{
|
||||
fun Report (
|
||||
navController: NavController?,
|
||||
viewModel: ReportViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
when (viewModel.apiStatus) {
|
||||
ApiStatus.DONE -> {
|
||||
val dateStateStart = rememberDatePickerState(initialDisplayMode = DisplayMode.Input)
|
||||
|
@ -194,7 +194,6 @@ fun ColumnItem(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun TankList(
|
||||
purchaseTankViewModel: PurchaseTankViewModel,
|
||||
|
@ -1,31 +0,0 @@
|
||||
package ru.ulstu.`is`.pmu.screen.composeui.image
|
||||
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun CuteImageButton(
|
||||
imageBitmap: ImageBitmap,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val cornerShape = RoundedCornerShape(Dimensions.cornerRadius)
|
||||
Button(
|
||||
onClick = { onClick() },
|
||||
modifier = modifier,
|
||||
shape = cornerShape,
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.Transparent
|
||||
)
|
||||
) {
|
||||
CuteImage(imageBitmap)
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package ru.ulstu.`is`.pmu.screen.composeui.image
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.gestures.detectTransformGestures
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
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.ImageBitmap
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
|
||||
@Composable
|
||||
fun CuteZoomableImage(
|
||||
imageBitmap: ImageBitmap
|
||||
) {
|
||||
val size = remember { mutableStateOf(IntSize.Zero) }
|
||||
val scale = remember { mutableFloatStateOf(1f) }
|
||||
val offsetX = remember { mutableFloatStateOf(0f) }
|
||||
val offsetY = remember { mutableFloatStateOf(0f) }
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(RectangleShape)
|
||||
.fillMaxSize()
|
||||
.pointerInput(Unit) {
|
||||
detectTransformGestures { _, pan, zoom, _ ->
|
||||
scale.floatValue = maxOf(1f, minOf(3f, scale.floatValue * zoom))
|
||||
val maxX = (size.value.width * (scale.floatValue - 1)) / 2
|
||||
val minX = -maxX
|
||||
offsetX.floatValue = maxOf(minX, minOf(maxX, offsetX.floatValue + pan.x))
|
||||
val maxY = (size.value.height * (scale.floatValue - 1)) / 2
|
||||
val minY = -maxY
|
||||
offsetY.floatValue = maxOf(minY, minOf(maxY, offsetY.floatValue + pan.y))
|
||||
}
|
||||
}.onSizeChanged {
|
||||
size.value = it
|
||||
}
|
||||
) {
|
||||
Image(
|
||||
bitmap = imageBitmap,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
.graphicsLayer(
|
||||
scaleX = scale.floatValue,
|
||||
scaleY = scale.floatValue,
|
||||
translationX = offsetX.floatValue,
|
||||
translationY = offsetY.floatValue
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@ -174,7 +174,6 @@ interface ServerService {
|
||||
|
||||
// ![USER_TANK_CROSS_REF]
|
||||
|
||||
|
||||
companion object {
|
||||
private const val BASE_URL = ApiRoutes.BASE
|
||||
|
||||
|
@ -7,14 +7,13 @@ import androidx.paging.RemoteMediator
|
||||
import androidx.room.withTransaction
|
||||
import retrofit2.HttpException
|
||||
import ru.ulstu.`is`.pmu.tank.api.ServerService
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toLevel
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toNation
|
||||
import ru.ulstu.`is`.pmu.tank.database.AppDatabase
|
||||
import ru.ulstu.`is`.pmu.tank.model.Nation
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeyType
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeys
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineRemoteKeyRepository
|
||||
import java.io.IOException
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
|
@ -12,8 +12,8 @@ import ru.ulstu.`is`.pmu.tank.database.AppDatabase
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeyType
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeys
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineTankRepository
|
||||
import java.io.IOException
|
||||
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
|
@ -7,7 +7,7 @@ import ru.ulstu.`is`.pmu.tank.api.model.toRemote
|
||||
import ru.ulstu.`is`.pmu.tank.model.Level
|
||||
import ru.ulstu.`is`.pmu.tank.model.LevelWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.repository.LevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineLevelRepository
|
||||
|
||||
class RestLevelRepository(
|
||||
private val service: ServerService,
|
||||
|
@ -1,17 +1,13 @@
|
||||
package ru.ulstu.`is`.pmu.tank.api.repository
|
||||
|
||||
import android.util.Log
|
||||
import androidx.paging.ExperimentalPagingApi
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.map
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import ru.ulstu.`is`.pmu.tank.api.ServerService
|
||||
import ru.ulstu.`is`.pmu.tank.api.mediator.NationRemoteMediator
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.NationRemote
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toNation
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toRemote
|
||||
import ru.ulstu.`is`.pmu.tank.database.AppContainer
|
||||
@ -19,8 +15,8 @@ import ru.ulstu.`is`.pmu.tank.database.AppDatabase
|
||||
import ru.ulstu.`is`.pmu.tank.model.Nation
|
||||
import ru.ulstu.`is`.pmu.tank.model.NationWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.repository.NationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineRemoteKeyRepository
|
||||
|
||||
class RestNationRepository(
|
||||
private val service: ServerService,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.ulstu.`is`.pmu.tank.api.repository
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.flatMapConcat
|
||||
@ -22,19 +23,14 @@ import ru.ulstu.`is`.pmu.tank.model.Report
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserTankCrossRef
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUsersTanksRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UsersTanksRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineTankRepository
|
||||
import java.nio.file.Files.find
|
||||
import java.util.Date
|
||||
|
||||
class RestTankRepository (
|
||||
private val service: ServerService,
|
||||
private val dbTankRepository: OfflineTankRepository,
|
||||
private val dbUsersTanksRepository: OfflineUsersTanksRepository
|
||||
private val dbTankRepository: OfflineTankRepository
|
||||
) : TankRepository {
|
||||
override suspend fun getAll(): List<Tank> {
|
||||
return service.getTanks().map { it.toTank() }
|
||||
@ -63,6 +59,7 @@ class RestTankRepository (
|
||||
}
|
||||
|
||||
//очень классная штука
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private suspend fun <T> Flow<List<T>>.flattenToList() =
|
||||
flatMapConcat { it.asFlow() }.toList()
|
||||
|
||||
@ -130,11 +127,6 @@ class RestTankRepository (
|
||||
service.deleteTank(tank.tankId!!)
|
||||
}
|
||||
|
||||
override suspend fun delete(tankId: Long) {
|
||||
service.deleteTank(tankId)
|
||||
dbTankRepository.delete(tankId)
|
||||
}
|
||||
|
||||
override suspend fun deleteAll() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
@ -2,16 +2,11 @@ package ru.ulstu.`is`.pmu.tank.api.repository
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.api.ServerService
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toLevel
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toRemote
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toUser
|
||||
import ru.ulstu.`is`.pmu.tank.model.Level
|
||||
import ru.ulstu.`is`.pmu.tank.model.LevelWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.model.User
|
||||
import ru.ulstu.`is`.pmu.tank.repository.LevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
|
||||
class RestUserRepository(
|
||||
|
@ -14,48 +14,9 @@ class PurchaseTankViewModel (
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val tankRepository: TankRepository
|
||||
) : ViewModel() {
|
||||
/*var purchaseUiState by mutableStateOf(PurchaseUiState())
|
||||
private set*/
|
||||
|
||||
suspend fun savePurchase(tankId: Long, userId: Long){
|
||||
if(tankId > 0 && userId > 0){
|
||||
tankRepository.buyTank(tankId, userId, Calendar.getInstance().time)
|
||||
}
|
||||
}
|
||||
|
||||
/*private fun validateInput(uiState: PurchaseDetails = purchaseUiState.purchaseDetails): Boolean {
|
||||
return with(uiState) {
|
||||
userId > 0
|
||||
&& tankId > 0
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
data class PurchaseUiState(
|
||||
val purchaseDetails: PurchaseDetails = PurchaseDetails(),
|
||||
val isEntryValid: Boolean = false
|
||||
)
|
||||
|
||||
data class PurchaseDetails(
|
||||
val userId: Long = 0,
|
||||
val tankId: Long = 0,
|
||||
val date: Date = Calendar.getInstance().time,
|
||||
)
|
||||
|
||||
fun PurchaseDetails.toUserTankCrossRef(): UserTankCrossRef = UserTankCrossRef(
|
||||
userId = userId,
|
||||
tankId = tankId,
|
||||
date = date
|
||||
)
|
||||
|
||||
fun UserTankCrossRef.toDetails(): PurchaseDetails = PurchaseDetails(
|
||||
userId = userId,
|
||||
tankId = tankId,
|
||||
date = date
|
||||
)
|
||||
|
||||
fun UserTankCrossRef.toUiState(isEntryValid: Boolean = false) : PurchaseUiState = PurchaseUiState(
|
||||
purchaseDetails = this.toDetails(),
|
||||
isEntryValid = isEntryValid
|
||||
)*/
|
@ -10,7 +10,9 @@ import ru.ulstu.`is`.pmu.tank.composeui.MyViewModel
|
||||
import ru.ulstu.`is`.pmu.tank.model.Report
|
||||
import java.util.Date
|
||||
|
||||
class ReportViewModel (private val tankRepository: RestTankRepository): MyViewModel()
|
||||
class ReportViewModel (
|
||||
private val tankRepository: RestTankRepository
|
||||
): MyViewModel()
|
||||
{
|
||||
var reportPageUiState by mutableStateOf(ReportPageUiState())
|
||||
private set
|
||||
|
@ -9,15 +9,9 @@ import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.application.ui.getEmptyBitmap
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.ulstu.`is`.pmu.tank.model.Level
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankExtra
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankImage
|
||||
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
|
||||
import kotlin.math.tan
|
||||
|
||||
class TankEditViewModel(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
|
@ -21,8 +21,6 @@ class UserEditViewModel(
|
||||
var userUiState by mutableStateOf(UserUiState())
|
||||
private set
|
||||
|
||||
//private val userUid: Long = checkNotNull(savedStateHandle["id"])
|
||||
|
||||
private val userId: Long = 100L
|
||||
|
||||
init {
|
||||
|
@ -1,18 +1,11 @@
|
||||
package ru.ulstu.`is`.pmu.tank.composeui.edit
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.ulstu.`is`.pmu.tank.model.User
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserRole
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserTankCrossRef
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUsersTanksRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UsersTanksRepository
|
||||
|
||||
class UsersTanksEditViewModel(
|
||||
@ -22,10 +15,6 @@ class UsersTanksEditViewModel(
|
||||
var usersTanksUiState by mutableStateOf(UserTankCrossRefUiState())
|
||||
private set
|
||||
|
||||
//val tankId: Long = checkNotNull(savedStateHandle["id"])
|
||||
|
||||
private val userId: Long = 100L
|
||||
|
||||
suspend fun saveUserTank() {
|
||||
//usersTanksRepository.insertUserTank(UserTankCrossRef(userId, tankId))
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import ru.ulstu.`is`.pmu.tank.repository.UsersTanksRepository
|
||||
|
||||
class TankListViewModel(
|
||||
private val tankRepository: TankRepository,
|
||||
private val usersTanksRepository: UsersTanksRepository,
|
||||
private var userId: Long = 100L
|
||||
) : ViewModel() {
|
||||
var tankListUiState by mutableStateOf(TankListUiState())
|
||||
|
@ -38,7 +38,6 @@ interface LevelDao {
|
||||
@Insert
|
||||
suspend fun insertMany(level: List<Level>)
|
||||
|
||||
|
||||
@Update
|
||||
suspend fun update(level: Level)
|
||||
|
||||
|
@ -4,13 +4,8 @@ import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Update
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.model.LevelWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.model.Nation
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankExtra
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
|
||||
@Dao
|
||||
@ -50,9 +45,6 @@ interface TankDao {
|
||||
@Delete
|
||||
suspend fun delete(tank: Tank)
|
||||
|
||||
@Query("DELETE FROM tanks WHERE tankId = :id")
|
||||
suspend fun delete(id: Long)
|
||||
|
||||
@Query("DELETE FROM tanks")
|
||||
suspend fun deleteAll()
|
||||
}
|
@ -10,16 +10,16 @@ import ru.ulstu.`is`.pmu.tank.model.TankImage
|
||||
@Dao
|
||||
interface TankImageDao {
|
||||
@Insert
|
||||
suspend fun insert(productImage: TankImage): Long
|
||||
suspend fun insert(tankImage: TankImage): Long
|
||||
|
||||
@Insert
|
||||
suspend fun insertMany(productImages: List<TankImage>)
|
||||
suspend fun insertMany(tankImages: List<TankImage>)
|
||||
|
||||
@Update
|
||||
suspend fun update(productImage: TankImage)
|
||||
suspend fun update(tankImage: TankImage)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(productImage: TankImage)
|
||||
suspend fun delete(tankImage: TankImage)
|
||||
|
||||
@Query("DELETE FROM tank_images WHERE image_id = :id")
|
||||
suspend fun delete(id: Long)
|
||||
|
@ -8,15 +8,15 @@ import ru.ulstu.`is`.pmu.tank.api.repository.RestTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.api.repository.RestUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.LevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.NationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUsersTanksRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UsersTanksRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineNationRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineRemoteKeyRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.offline.OfflineUsersTanksRepository
|
||||
|
||||
interface AppContainer {
|
||||
val levelRestRepository: RestLevelRepository
|
||||
@ -77,8 +77,7 @@ class AppDataContainer(private val context: Context) : AppContainer {
|
||||
override val tankRestRepository: RestTankRepository by lazy {
|
||||
RestTankRepository(
|
||||
service = ServerService.getInstance(),
|
||||
dbTankRepository = tankRepository,
|
||||
dbUsersTanksRepository = usersTanksRepository
|
||||
dbTankRepository = tankRepository
|
||||
)
|
||||
}
|
||||
}
|
@ -5,11 +5,6 @@ import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.ulstu.`is`.pmu.R
|
||||
import ru.ulstu.`is`.pmu.tank.dao.LevelDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.NationDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.RemoteKeysDao
|
||||
@ -52,7 +47,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun remoteKeysDao(): RemoteKeysDao
|
||||
|
||||
companion object {
|
||||
private const val DB_NAME: String = "27-db"
|
||||
private const val DB_NAME: String = "28-db"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
@ -117,21 +112,21 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
//images
|
||||
val tankImageDao = database.tankImageDao()
|
||||
tankImageDao.insertMany(PrepopulateStore.getProductImages(context))
|
||||
tankImageDao.insertMany(PrepopulateStore.getTankImages(context))
|
||||
|
||||
//Tanks
|
||||
val tankDao = database.tankDao()
|
||||
val tank1 = Tank(20L,"МС-1", 1000, PrepopulateStore.getProductMiniature(context, 1L), level1.uid, nation1.uid)
|
||||
val tank2 = Tank(21L, "Т-34-85", 960000, PrepopulateStore.getProductMiniature(context, 2L), level6.uid, nation1.uid)
|
||||
val tank10 = Tank(22L, "Pershing", 1260000, PrepopulateStore.getProductMiniature(context, 9L), level8.uid, nation3.uid)
|
||||
val tank6 = Tank(23L, "Ferdinand", 2500000, PrepopulateStore.getProductMiniature(context, 8L), level8.uid, nation2.uid)
|
||||
val tank3 = Tank(24L, "ИС-2", 1230000, PrepopulateStore.getProductMiniature(context, 3L), level7.uid, nation1.uid)
|
||||
val tank4 = Tank(25L, "ИСУ-152", 2350000, PrepopulateStore.getProductMiniature(context, 4L), level8.uid, nation1.uid)
|
||||
val tank5 = Tank(26L, "Tiger 1", 1430000,PrepopulateStore.getProductMiniature(context, 5L), level7.uid, nation2.uid)
|
||||
val tank7 = Tank(27L, "Tiger 2", 2500000, PrepopulateStore.getProductMiniature(context, 6L), level8.uid, nation2.uid)
|
||||
val tank8 = Tank(28L, "Panther", 1350000, PrepopulateStore.getProductMiniature(context, 7L), level7.uid, nation2.uid)
|
||||
val tank9 = Tank(29L, "M4A2E3", 990000, PrepopulateStore.getProductMiniature(context, 10L), level6.uid, nation3.uid)
|
||||
val tank11 = Tank(30L, "Hellcat", 940000, PrepopulateStore.getProductMiniature(context, 11L), level7.uid, nation3.uid)
|
||||
val tank1 = Tank(20L,"МС-1", 1000, PrepopulateStore.getTankMiniature(context, 1L), level1.uid, nation1.uid)
|
||||
val tank2 = Tank(21L, "Т-34-85", 960000, PrepopulateStore.getTankMiniature(context, 2L), level6.uid, nation1.uid)
|
||||
val tank10 = Tank(22L, "Pershing", 1260000, PrepopulateStore.getTankMiniature(context, 9L), level8.uid, nation3.uid)
|
||||
val tank6 = Tank(23L, "Ferdinand", 2500000, PrepopulateStore.getTankMiniature(context, 8L), level8.uid, nation2.uid)
|
||||
val tank3 = Tank(24L, "ИС-2", 1230000, PrepopulateStore.getTankMiniature(context, 3L), level7.uid, nation1.uid)
|
||||
val tank4 = Tank(25L, "ИСУ-152", 2350000, PrepopulateStore.getTankMiniature(context, 4L), level8.uid, nation1.uid)
|
||||
val tank5 = Tank(26L, "Tiger 1", 1430000,PrepopulateStore.getTankMiniature(context, 5L), level7.uid, nation2.uid)
|
||||
val tank7 = Tank(27L, "Tiger 2", 2500000, PrepopulateStore.getTankMiniature(context, 6L), level8.uid, nation2.uid)
|
||||
val tank8 = Tank(28L, "Panther", 1350000, PrepopulateStore.getTankMiniature(context, 7L), level7.uid, nation2.uid)
|
||||
val tank9 = Tank(29L, "M4A2E3", 990000, PrepopulateStore.getTankMiniature(context, 10L), level6.uid, nation3.uid)
|
||||
val tank11 = Tank(30L, "Hellcat", 940000, PrepopulateStore.getTankMiniature(context, 11L), level7.uid, nation3.uid)
|
||||
|
||||
tankDao.insert(tank1)
|
||||
tankDao.insert(tank2)
|
||||
|
@ -3,12 +3,11 @@ package ru.ulstu.`is`.pmu.tank.database
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import androidx.room.TypeConverter
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserRole
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.Date
|
||||
|
||||
class Converters {
|
||||
|
||||
/*
|
||||
@TypeConverter
|
||||
fun toUserRole(value: Int): UserRole {
|
||||
return enumValues<UserRole>()[value]
|
||||
@ -18,7 +17,6 @@ class Converters {
|
||||
fun fromUserRole(value: UserRole): Int {
|
||||
return value.ordinal
|
||||
}
|
||||
*/
|
||||
|
||||
@TypeConverter
|
||||
fun toDate(value: Long?): Date? {
|
||||
@ -30,15 +28,15 @@ class Converters {
|
||||
return date?.time
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toBitmap(byteArray: ByteArray): Bitmap {
|
||||
return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromBitmap(bitmap: Bitmap): ByteArray {
|
||||
val outputStream = ByteArrayOutputStream()
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 1, outputStream)
|
||||
return outputStream.toByteArray()
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toBitmap(byteArray: ByteArray): Bitmap {
|
||||
return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
|
||||
}
|
||||
}
|
@ -10,29 +10,29 @@ import ru.ulstu.`is`.pmu.tank.model.TankImage
|
||||
|
||||
class PrepopulateStore {
|
||||
companion object {
|
||||
fun getProductImages(context: Context): List<TankImage> {
|
||||
fun getTankImages(context: Context): List<TankImage> {
|
||||
return listOf(
|
||||
TankImage(id = 1, data = getProductImage(context, 1)),
|
||||
TankImage(id = 2, data = getProductImage(context, 2)),
|
||||
TankImage(id = 3, data = getProductImage(context, 3)),
|
||||
TankImage(id = 4, data = getProductImage(context, 4)),
|
||||
TankImage(id = 5, data = getProductImage(context, 5)),
|
||||
TankImage(id = 6, data = getProductImage(context, 6)),
|
||||
TankImage(id = 7, data = getProductImage(context, 7)),
|
||||
TankImage(id = 8, data = getProductImage(context, 8)),
|
||||
TankImage(id = 9, data = getProductImage(context, 9)),
|
||||
TankImage(id = 10, data = getProductImage(context, 10)),
|
||||
TankImage(id = 11, data = getProductImage(context, 11))
|
||||
TankImage(id = 1, data = getTankImage(context, 1)),
|
||||
TankImage(id = 2, data = getTankImage(context, 2)),
|
||||
TankImage(id = 3, data = getTankImage(context, 3)),
|
||||
TankImage(id = 4, data = getTankImage(context, 4)),
|
||||
TankImage(id = 5, data = getTankImage(context, 5)),
|
||||
TankImage(id = 6, data = getTankImage(context, 6)),
|
||||
TankImage(id = 7, data = getTankImage(context, 7)),
|
||||
TankImage(id = 8, data = getTankImage(context, 8)),
|
||||
TankImage(id = 9, data = getTankImage(context, 9)),
|
||||
TankImage(id = 10, data = getTankImage(context, 10)),
|
||||
TankImage(id = 11, data = getTankImage(context, 11))
|
||||
)
|
||||
}
|
||||
|
||||
fun getProductMiniature(context: Context, imageId: Long): Bitmap {
|
||||
fun getTankMiniature(context: Context, imageId: Long): Bitmap {
|
||||
val inputStream = context.assets.open("${imageId}.jpg")
|
||||
val bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
return bitmap.resize(miniatureBound)
|
||||
}
|
||||
|
||||
private fun getProductImage(context: Context, imageName: Int): Bitmap {
|
||||
private fun getTankImage(context: Context, imageName: Int): Bitmap {
|
||||
val inputStream = context.assets.open("${imageName}.jpg")
|
||||
val bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
return bitmap.resize(tankImageBound)
|
||||
|
@ -19,8 +19,6 @@ data class Level(
|
||||
level: Int
|
||||
) : this(null, level)
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
val DEMO_LEVEL = Level(
|
||||
0,
|
||||
|
@ -43,18 +43,3 @@ data class Nation(
|
||||
}
|
||||
}
|
||||
|
||||
fun getNations(): List<Nation> {
|
||||
return listOf(
|
||||
Nation("СССР"),
|
||||
Nation("Германия"),
|
||||
Nation("США"),
|
||||
Nation("Великобритания"),
|
||||
Nation("Франция"),
|
||||
Nation("Китай"),
|
||||
Nation("Япония"),
|
||||
Nation("Италия"),
|
||||
Nation("Польша"),
|
||||
Nation("Швеция")
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
package ru.ulstu.`is`.pmu.tank.model
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Embedded
|
||||
import com.application.ui.getEmptyBitmap
|
||||
|
||||
class TankExtra (
|
||||
@Embedded
|
||||
val tank: Tank,
|
||||
val image: Bitmap,
|
||||
) {
|
||||
companion object {
|
||||
fun getEmpty(): TankExtra {
|
||||
return TankExtra(
|
||||
tank = Tank.getTank(),
|
||||
image = getEmptyBitmap(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankExtra
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import java.util.Date
|
||||
|
||||
@ -17,6 +15,5 @@ interface TankRepository {
|
||||
suspend fun insertMany(tankList: List<Tank>)
|
||||
suspend fun updateTank(tank: Tank, image: Bitmap)
|
||||
suspend fun deleteTank(tank: Tank)
|
||||
suspend fun delete(tankId: Long)
|
||||
suspend fun deleteAll()
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.dao.LevelDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.Level
|
||||
import ru.ulstu.`is`.pmu.tank.model.LevelWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.repository.LevelRepository
|
||||
|
||||
class OfflineLevelRepository(private val levelDao: LevelDao) : LevelRepository {
|
||||
override suspend fun getAllLevels(): List<Level> = levelDao.getAll()
|
@ -1,4 +1,4 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.PagingSource
|
||||
@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.dao.NationDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.Nation
|
||||
import ru.ulstu.`is`.pmu.tank.model.NationWithTanks
|
||||
import ru.ulstu.`is`.pmu.tank.repository.NationRepository
|
||||
|
||||
class OfflineNationRepository(private val nationDao: NationDao) : NationRepository {
|
||||
override suspend fun getAllNations(): List<Nation> = nationDao.getAll()
|
@ -1,8 +1,9 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import ru.ulstu.`is`.pmu.tank.dao.RemoteKeysDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeyType
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeys
|
||||
import ru.ulstu.`is`.pmu.tank.repository.RemoteKeyRepository
|
||||
|
||||
class OfflineRemoteKeyRepository(private val remoteKeysDao: RemoteKeysDao) : RemoteKeyRepository {
|
||||
override suspend fun getAllRemoteKeys(id: Int, type: RemoteKeyType) =
|
@ -1,15 +1,12 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.dao.TankDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.TankImageDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.UsersTanksDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankExtra
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankImage
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserTankCrossRef
|
||||
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
|
||||
import java.util.Date
|
||||
|
||||
class OfflineTankRepository(
|
||||
@ -42,10 +39,6 @@ class OfflineTankRepository(
|
||||
|
||||
override suspend fun deleteTank(tank: Tank) = tankDao.delete(tank)
|
||||
|
||||
override suspend fun delete(tankId: Long) {
|
||||
tankDao.delete(tankId)
|
||||
}
|
||||
|
||||
override suspend fun deleteAll() {
|
||||
tankDao.deleteAll()
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.dao.UserDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.model.User
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
|
||||
class OfflineUserRepository(private val userDao: UserDao) : UserRepository {
|
||||
override fun getAllUsers(): Flow<List<User>> = userDao.getAll()
|
@ -1,8 +1,8 @@
|
||||
package ru.ulstu.`is`.pmu.tank.repository
|
||||
package ru.ulstu.`is`.pmu.tank.repository.offline
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import ru.ulstu.`is`.pmu.tank.dao.UsersTanksDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserTankCrossRef
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UsersTanksRepository
|
||||
|
||||
class OfflineUsersTanksRepository(
|
||||
private val usersTanksDao: UsersTanksDao
|
@ -21,8 +21,7 @@ object AppViewModelProvider {
|
||||
val Factory = viewModelFactory {
|
||||
initializer {
|
||||
TankListViewModel(
|
||||
tankApplication().container.tankRestRepository,
|
||||
tankApplication().container.usersTanksRepository
|
||||
tankApplication().container.tankRestRepository
|
||||
)
|
||||
}
|
||||
initializer {
|
||||
|
@ -27,16 +27,6 @@ private val LightColorScheme = lightColorScheme(
|
||||
secondary = CustomOrange,
|
||||
tertiary = CustomRed,
|
||||
background = CustomDark
|
||||
|
||||
/* 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
|
||||
|
Loading…
Reference in New Issue
Block a user