Некоторые продвижения
This commit is contained in:
parent
40f2191753
commit
348e6a0b57
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,7 @@ plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("com.google.devtools.ksp")
|
||||
id("org.jetbrains.kotlin.plugin.serialization")
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -2,10 +2,13 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:name=".TankApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
@ -78,6 +78,9 @@ interface ServerService {
|
||||
@Query("_limit") limit: Int
|
||||
): List<NationRemote>
|
||||
|
||||
@GET(ApiRoutes.NATION)
|
||||
suspend fun getAllNations(): List<NationRemote>
|
||||
|
||||
@GET("${ApiRoutes.NATION}/{id}")
|
||||
suspend fun getNation(
|
||||
@Path("id") id: Long
|
||||
|
@ -29,14 +29,17 @@ class RestNationRepository(
|
||||
private val database: AppDatabase
|
||||
) : NationRepository {
|
||||
override suspend fun getAllNations(): List<Nation> {
|
||||
TODO("Not yet implemented")
|
||||
dbNationRepository.deleteNations()
|
||||
val nations = service.getAllNations().map { it.toNation() }
|
||||
dbNationRepository.insertNations(nations)
|
||||
return nations
|
||||
}
|
||||
|
||||
override suspend fun getAll(): Flow<PagingData<Nation>> {
|
||||
@OptIn(ExperimentalPagingApi::class)
|
||||
return Pager(
|
||||
config = PagingConfig(
|
||||
pageSize = 10,
|
||||
pageSize = AppContainer.LIMIT,
|
||||
enablePlaceholders = false
|
||||
),
|
||||
remoteMediator = NationRemoteMediator(
|
||||
|
@ -1,22 +1,16 @@
|
||||
package ru.ulstu.`is`.pmu.tank.api.repository
|
||||
|
||||
import android.graphics.Bitmap
|
||||
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.toTank
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toTankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.api.model.toUser
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankWithNationAndLevel
|
||||
import ru.ulstu.`is`.pmu.tank.model.User
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineTankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.OfflineUserRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.TankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
|
||||
class RestTankReppository (
|
||||
class RestTankRepository (
|
||||
private val service: ServerService,
|
||||
private val dbTankRepository: OfflineTankRepository,
|
||||
) : TankRepository {
|
@ -1,39 +1,80 @@
|
||||
package ru.ulstu.`is`.pmu.tank.database
|
||||
|
||||
import android.content.Context
|
||||
import ru.ulstu.`is`.pmu.tank.api.ServerService
|
||||
import ru.ulstu.`is`.pmu.tank.api.repository.RestLevelRepository
|
||||
import ru.ulstu.`is`.pmu.tank.api.repository.RestNationRepository
|
||||
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.TankRepository
|
||||
import ru.ulstu.`is`.pmu.tank.repository.UserRepository
|
||||
|
||||
interface AppContainer {
|
||||
val levelRepository: LevelRepository
|
||||
val nationRepository: NationRepository
|
||||
val tankRepository: TankRepository
|
||||
val userRepository: UserRepository
|
||||
val levelRestRepository: RestLevelRepository
|
||||
val nationRestRepository: RestNationRepository
|
||||
val userRestRepository: RestUserRepository
|
||||
val tankRestRepository: RestTankRepository
|
||||
|
||||
companion object {
|
||||
const val TIMEOUT = 5000L
|
||||
const val LIMIT = 10
|
||||
}
|
||||
}
|
||||
|
||||
class AppDataContainer(private val context: Context) : AppContainer {
|
||||
override val levelRepository: LevelRepository by lazy {
|
||||
private val levelRepository: OfflineLevelRepository by lazy {
|
||||
OfflineLevelRepository(AppDatabase.getInstance(context).levelDao())
|
||||
}
|
||||
override val nationRepository: NationRepository by lazy {
|
||||
private val nationRepository: OfflineNationRepository by lazy {
|
||||
OfflineNationRepository(AppDatabase.getInstance(context).nationDao())
|
||||
}
|
||||
override val tankRepository: TankRepository by lazy {
|
||||
private val tankRepository: OfflineTankRepository by lazy {
|
||||
OfflineTankRepository(
|
||||
AppDatabase.getInstance(context).tankDao(),
|
||||
tankImageDao = AppDatabase.getInstance(context).tankImageDao())
|
||||
}
|
||||
override val userRepository: UserRepository by lazy {
|
||||
private val userRepository: OfflineUserRepository by lazy {
|
||||
OfflineUserRepository(AppDatabase.getInstance(context).userDao())
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TIMEOUT = 5000L
|
||||
private val remoteKeyRepository: OfflineRemoteKeyRepository by lazy {
|
||||
OfflineRemoteKeyRepository(AppDatabase.getInstance(context).remoteKeysDao())
|
||||
}
|
||||
|
||||
override val levelRestRepository: RestLevelRepository by lazy {
|
||||
RestLevelRepository(
|
||||
service = ServerService.getInstance(),
|
||||
dbLevelRepository = levelRepository
|
||||
)
|
||||
}
|
||||
|
||||
override val nationRestRepository: RestNationRepository by lazy {
|
||||
RestNationRepository(
|
||||
service = ServerService.getInstance(),
|
||||
dbNationRepository = nationRepository,
|
||||
dbRemoteKeyRepository = remoteKeyRepository,
|
||||
database = AppDatabase.getInstance(context)
|
||||
)
|
||||
}
|
||||
|
||||
override val userRestRepository: RestUserRepository by lazy {
|
||||
RestUserRepository(
|
||||
service = ServerService.getInstance(),
|
||||
dbUserRepository = userRepository,
|
||||
)
|
||||
}
|
||||
|
||||
override val tankRestRepository: RestTankRepository by lazy {
|
||||
RestTankRepository(
|
||||
service = ServerService.getInstance(),
|
||||
dbTankRepository = tankRepository
|
||||
)
|
||||
}
|
||||
}
|
@ -12,11 +12,13 @@ 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
|
||||
import ru.ulstu.`is`.pmu.tank.dao.TankDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.TankImageDao
|
||||
import ru.ulstu.`is`.pmu.tank.dao.UserDao
|
||||
import ru.ulstu.`is`.pmu.tank.model.Level
|
||||
import ru.ulstu.`is`.pmu.tank.model.Nation
|
||||
import ru.ulstu.`is`.pmu.tank.model.RemoteKeys
|
||||
import ru.ulstu.`is`.pmu.tank.model.Tank
|
||||
import ru.ulstu.`is`.pmu.tank.model.TankImage
|
||||
import ru.ulstu.`is`.pmu.tank.model.User
|
||||
@ -24,7 +26,19 @@ import ru.ulstu.`is`.pmu.tank.model.UserRole
|
||||
import ru.ulstu.`is`.pmu.tank.model.UserTankCrossRef
|
||||
|
||||
//тут, собственно говоря, всё и мутится с БД :)))
|
||||
@Database(entities = [Nation::class, Level::class, Tank::class, User::class, UserTankCrossRef::class, TankImage::class], version = 1, exportSchema = false)
|
||||
@Database(
|
||||
entities = [
|
||||
Nation::class,
|
||||
Level::class,
|
||||
Tank::class,
|
||||
User::class,
|
||||
UserTankCrossRef::class,
|
||||
TankImage::class,
|
||||
RemoteKeys::class
|
||||
],
|
||||
version = 1,
|
||||
exportSchema = false
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun nationDao(): NationDao
|
||||
@ -32,9 +46,10 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun tankDao() : TankDao
|
||||
abstract fun userDao() : UserDao
|
||||
abstract fun tankImageDao() : TankImageDao
|
||||
abstract fun remoteKeysDao(): RemoteKeysDao
|
||||
|
||||
companion object {
|
||||
private const val DB_NAME: String = "20-db"
|
||||
private const val DB_NAME: String = "21-db"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: AppDatabase? = null
|
||||
|
@ -17,28 +17,28 @@ import ru.ulstu.`is`.pmu.tank.composeui.list.TankListViewModel
|
||||
object AppViewModelProvider {
|
||||
val Factory = viewModelFactory {
|
||||
initializer {
|
||||
TankListViewModel(tankApplication().container.tankRepository)
|
||||
TankListViewModel(tankApplication().container.tankRestRepository)
|
||||
}
|
||||
initializer {
|
||||
TankEditViewModel(
|
||||
this.createSavedStateHandle(),
|
||||
tankApplication().container.tankRepository
|
||||
tankApplication().container.tankRestRepository
|
||||
)
|
||||
}
|
||||
initializer {
|
||||
UserEditViewModel(
|
||||
this.createSavedStateHandle(),
|
||||
tankApplication().container.userRepository
|
||||
tankApplication().container.userRestRepository
|
||||
)
|
||||
}
|
||||
initializer {
|
||||
LevelDropDownViewModel(tankApplication().container.levelRepository)
|
||||
LevelDropDownViewModel(tankApplication().container.levelRestRepository)
|
||||
}
|
||||
initializer {
|
||||
NationDropDownViewModel(tankApplication().container.nationRepository)
|
||||
NationDropDownViewModel(tankApplication().container.nationRestRepository)
|
||||
}
|
||||
initializer {
|
||||
NationListViewModel(tankApplication().container.nationRepository)
|
||||
NationListViewModel(tankApplication().container.nationRestRepository)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
compose/app/src/main/res/xml/network_security_config.xml
Normal file
8
compose/app/src/main/res/xml/network_security_config.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">10.0.2.2</domain>
|
||||
<domain includeSubdomains="true">192.168.1.100</domain>
|
||||
<domain includeSubdomains="true">192.168.1.107</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
@ -4,4 +4,5 @@ plugins {
|
||||
id("com.android.application") version "8.1.2" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
|
||||
id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false
|
||||
id("org.jetbrains.kotlin.plugin.serialization") version "1.8.20" apply false
|
||||
}
|
@ -1,101 +1,101 @@
|
||||
{
|
||||
"nations": [
|
||||
{
|
||||
"id": 1,
|
||||
"uid": 1,
|
||||
"nationName": "СССР"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"uid": 2,
|
||||
"nationName": "Германия"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"uid": 3,
|
||||
"nationName": "США"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"uid": 4,
|
||||
"nationName": "Великобритания"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"uid": 5,
|
||||
"nationName": "Франция"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"uid": 6,
|
||||
"nationName": "Чехословакия"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"uid": 7,
|
||||
"nationName": "Швеция"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"uid": 8,
|
||||
"nationName": "Китай"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"uid": 9,
|
||||
"nationName": "Япония"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"uid": 10,
|
||||
"nationName": "Италия"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"uid": 11,
|
||||
"nationName": "Бангладеш"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"uid": 12,
|
||||
"nationName": "Зимбамбве"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"uid": 13,
|
||||
"nationName": "Гондурас"
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"uid": 14,
|
||||
"nationName": "Майами"
|
||||
}
|
||||
],
|
||||
"levels": [
|
||||
{
|
||||
"id": 1,
|
||||
"uid": 1,
|
||||
"level": 1
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"uid": 2,
|
||||
"level": 2
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"uid": 3,
|
||||
"level": 3
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"uid": 4,
|
||||
"level": 4
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"uid": 5,
|
||||
"level": 5
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"uid": 6,
|
||||
"level": 6
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"uid": 7,
|
||||
"level": 7
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"uid": 8,
|
||||
"level": 8
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"uid": 9,
|
||||
"level": 9
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"uid": 10,
|
||||
"level": 10
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user