automated scale range setting
This commit is contained in:
parent
d8139f2140
commit
182f0b29b0
4 changed files with 14 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package com.mirenkov.ktheightmap
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
|
@ -84,6 +85,7 @@ class MainActivity : ComponentActivity() {
|
||||||
@Composable
|
@Composable
|
||||||
fun Main(vm: TileViewModel = viewModel()) {
|
fun Main(vm: TileViewModel = viewModel()) {
|
||||||
var scale by rememberSaveable { vm.scale }
|
var scale by rememberSaveable { vm.scale }
|
||||||
|
val maxScale by rememberSaveable { vm.maxLevel }
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val tileContainer = TileContainer(vm, coroutineScope)
|
val tileContainer = TileContainer(vm, coroutineScope)
|
||||||
KtHeightMapTheme {
|
KtHeightMapTheme {
|
||||||
|
|
@ -111,7 +113,7 @@ fun Main(vm: TileViewModel = viewModel()) {
|
||||||
Slider(
|
Slider(
|
||||||
value = scale,
|
value = scale,
|
||||||
onValueChange = { scale = it },
|
onValueChange = { scale = it },
|
||||||
valueRange = 1F..14F,
|
valueRange = 2F..maxScale.toFloat(),
|
||||||
modifier = Modifier.align(Alignment.CenterStart)
|
modifier = Modifier.align(Alignment.CenterStart)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,7 @@ interface TileDao {
|
||||||
|
|
||||||
@Query("delete from tiles")
|
@Query("delete from tiles")
|
||||||
fun clearTiles()
|
fun clearTiles()
|
||||||
|
|
||||||
|
@Query("select max(level) from tiles")
|
||||||
|
fun maxLevel(): Int?
|
||||||
}
|
}
|
||||||
|
|
@ -21,4 +21,8 @@ class TileRepository(private val tileDao: TileDao) {
|
||||||
fun clearTiles() {
|
fun clearTiles() {
|
||||||
coroutineScope.launch(Dispatchers.IO) { tileDao.clearTiles() }
|
coroutineScope.launch(Dispatchers.IO) { tileDao.clearTiles() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getMaxLevel(): Int {
|
||||||
|
return coroutineScope.future(Dispatchers.IO){ tileDao.maxLevel() }.join() ?: 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.mirenkov.ktheightmap
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.compose.runtime.mutableFloatStateOf
|
import androidx.compose.runtime.mutableFloatStateOf
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
@ -17,7 +18,8 @@ class TileViewModel(application: Application): ViewModel() {
|
||||||
|
|
||||||
val mapOffsetX = mutableFloatStateOf(-646.65625F)
|
val mapOffsetX = mutableFloatStateOf(-646.65625F)
|
||||||
val mapOffsetY = mutableFloatStateOf(-1157.2814F)
|
val mapOffsetY = mutableFloatStateOf(-1157.2814F)
|
||||||
val scale = mutableFloatStateOf(1F)
|
val scale = mutableFloatStateOf(2F)
|
||||||
|
var maxLevel = mutableIntStateOf(1)
|
||||||
|
|
||||||
var halvedOffsetX: Float? = null
|
var halvedOffsetX: Float? = null
|
||||||
var halvedOffsetY: Float? = null
|
var halvedOffsetY: Float? = null
|
||||||
|
|
@ -29,5 +31,6 @@ class TileViewModel(application: Application): ViewModel() {
|
||||||
val tileDb = TileDB.getInstance(application)
|
val tileDb = TileDB.getInstance(application)
|
||||||
val tileDao = tileDb.tileDao()
|
val tileDao = tileDb.tileDao()
|
||||||
repository = TileRepository(tileDao)
|
repository = TileRepository(tileDao)
|
||||||
|
maxLevel.intValue = repository.getMaxLevel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue