FilePicker and basic zip handling
This commit is contained in:
parent
783a700f04
commit
ea08a1317a
6 changed files with 59 additions and 11 deletions
|
|
@ -29,11 +29,8 @@ android {
|
|||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
|
|
@ -51,6 +48,8 @@ dependencies {
|
|||
|
||||
ksp("androidx.room:room-compiler:$room_version")
|
||||
|
||||
implementation("io.github.chochanaresh:filepicker:0.6.0")
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ fun Main(vm: TileViewModel = viewModel()) {
|
|||
Box(modifier = Modifier.safeDrawingPadding()
|
||||
.align(Alignment.CenterEnd)
|
||||
.rotate(-90F)
|
||||
.size(240.dp, 40.dp)
|
||||
.offset(0.dp, 80.dp)
|
||||
.size(200.dp, 40.dp)
|
||||
.offset(0.dp, 60.dp)
|
||||
) {
|
||||
Slider(
|
||||
value = sliderValue.floatValue,
|
||||
|
|
|
|||
|
|
@ -1,18 +1,66 @@
|
|||
package com.mirenkov.ktheightmap
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.mirenkov.ktheightmap.ui.theme.KtHeightMapTheme
|
||||
import com.nareshchocha.filepickerlibrary.FilePickerResultContracts
|
||||
import com.nareshchocha.filepickerlibrary.models.PickerData
|
||||
import com.nareshchocha.filepickerlibrary.models.PopUpConfig
|
||||
import java.io.FileInputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class SettingsActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val launcher = registerForActivityResult(FilePickerResultContracts.PickDocumentFile()) { result ->
|
||||
if (result.errorMessage != null) {
|
||||
Log.e("Picker", result.errorMessage ?: "")
|
||||
} else {
|
||||
val filePath = result.selectedFilePath
|
||||
filePath?.let {
|
||||
if (!it.endsWith(".zip"))
|
||||
return@let
|
||||
ZipInputStream(FileInputStream(it)).use { zipInputStream ->
|
||||
var entry = zipInputStream.nextEntry
|
||||
while (entry != null) {
|
||||
with(entry.name) {
|
||||
if (count { it == '/' } == 4 && endsWith(".jpg"))
|
||||
processEntry(entry)
|
||||
}
|
||||
entry = zipInputStream.nextEntry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
KtHeightMapTheme {
|
||||
Column(Modifier.fillMaxSize()
|
||||
.safeDrawingPadding()) {
|
||||
Button(onClick = {
|
||||
launcher.launch(null)
|
||||
}) { Text(text = "Load database") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun processEntry(entry: ZipEntry) {
|
||||
Log.i(TAG, entry.name)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue