Skip to content

Commit

Permalink
fix dumb bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Sep 21, 2023
1 parent 274c34a commit 0918776
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 14 deletions.
62 changes: 62 additions & 0 deletions app/src/main/java/io/github/jan/kex/ui/icons/Back.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.jan.kex.ui.icons

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

@Composable
fun rememberArrowBackIcon(): ImageVector {
return remember {
ImageVector.Builder(
name = "arrow_back",
defaultWidth = 24.0.dp,
defaultHeight = 24.0.dp,
viewportWidth = 40.0f,
viewportHeight = 40.0f
).apply {
path(
fill = SolidColor(Color.Black),
fillAlpha = 1f,
stroke = null,
strokeAlpha = 1f,
strokeLineWidth = 1.0f,
strokeLineCap = StrokeCap.Butt,
strokeLineJoin = StrokeJoin.Miter,
strokeLineMiter = 1f,
pathFillType = PathFillType.NonZero
) {
moveTo(18.542f, 32.208f)
lineTo(7.25f, 20.917f)
quadToRelative(-0.208f, -0.209f, -0.292f, -0.438f)
quadToRelative(-0.083f, -0.229f, -0.083f, -0.479f)
quadToRelative(0f, -0.25f, 0.083f, -0.479f)
quadToRelative(0.084f, -0.229f, 0.292f, -0.438f)
lineTo(18.583f, 7.75f)
quadToRelative(0.375f, -0.333f, 0.896f, -0.333f)
reflectiveQuadToRelative(0.938f, 0.375f)
quadToRelative(0.375f, 0.416f, 0.375f, 0.937f)
quadToRelative(0f, 0.521f, -0.375f, 0.938f)
lineToRelative(-9.042f, 9f)
horizontalLineToRelative(19.917f)
quadToRelative(0.541f, 0f, 0.916f, 0.395f)
quadToRelative(0.375f, 0.396f, 0.375f, 0.938f)
quadToRelative(0f, 0.542f, -0.375f, 0.917f)
reflectiveQuadToRelative(-0.916f, 0.375f)
horizontalLineTo(11.375f)
lineToRelative(9.083f, 9.083f)
quadToRelative(0.334f, 0.375f, 0.334f, 0.896f)
reflectiveQuadToRelative(-0.375f, 0.937f)
quadToRelative(-0.417f, 0.375f, -0.938f, 0.375f)
quadToRelative(-0.521f, 0f, -0.937f, -0.375f)
close()
}
}.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.github.jan.kex.ui.screen.exam.importer

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -18,9 +22,10 @@ import androidx.compose.ui.unit.dp
import io.github.jan.kex.R
import io.github.jan.kex.data.remote.ExamPlan
import io.github.jan.kex.ui.components.ExamPlanCard
import io.github.jan.kex.ui.icons.rememberArrowBackIcon

@Composable
fun ExamImportSelector(plan: ExamPlan, onImport: (List<String>) -> Unit) {
fun ExamImportSelector(plan: ExamPlan, onImport: (List<String>) -> Unit, onBack: () -> Unit) {
val subjects = remember(plan) {
plan.examsByDate.toList().map { (_, exams) ->
exams.map { it }
Expand Down Expand Up @@ -50,4 +55,9 @@ fun ExamImportSelector(plan: ExamPlan, onImport: (List<String>) -> Unit) {
Text(stringResource(id = R.string.importA))
}
}
Box(contentAlignment = Alignment.BottomStart, modifier = Modifier.fillMaxSize().padding(8.dp)) {
IconButton(onClick = onBack) {
Icon(rememberArrowBackIcon(), contentDescription = null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ fun ExamImporterScreen(
)
}
else -> {
ExamImportSelector(examPlan!!) { selectedSubjects ->
val exams = examPlan!!.examsByDate.toList().map { (date, exams) ->
exams.map {
ExamData(it.subject, date)
}
}.flatten().filter { it.subject in selectedSubjects }
examVm.importExams(exams)
navigator.navigate(NavigationTarget.Exams.destination)
}
ExamImportSelector(
plan = examPlan!!,
onImport = { selectedSubjects ->
val exams = examPlan!!.examsByDate.toList().map { (date, exams) ->
exams.map {
ExamData(it.subject, date)
}
}.flatten().filter { it.subject in selectedSubjects }
examVm.importExams(exams)
navigator.navigate(NavigationTarget.Exams.destination)
},
onBack = {
examPlanVm.examPlan.value = null
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun ExamPlanKeySelection(
}
}
Spacer(Modifier.height(16.dp))
Button(onClick = { onSubmit(selectedKey) }) {
Button(onClick = { onSubmit(selectedKey) }, enabled = selectedKey.isNotBlank()) {
Text(stringResource(R.string.continueA))
}
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/io/github/jan/kex/vm/ExamViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDate
import kotlinx.datetime.toLocalDateTime

class ExamViewModel(
Expand Down Expand Up @@ -119,6 +120,11 @@ class ExamViewModel(
fun createExam(subject: String, date: String, theme: String, type: Exam.Type) {
viewModelScope.launch(Dispatchers.IO) {
subjectSuggestionDataSource.insert(subject)
val currentExams = examApi.retrieveExamData()
if(currentExams.any { it.subject == subject && it.date == date.toLocalDate() }) {
//error.value = R.string.exam_already_exists
return@launch
}
kotlin.runCatching {
examApi.createExam(subject, date, theme, type)
}.onSuccess {
Expand Down Expand Up @@ -149,7 +155,9 @@ class ExamViewModel(
fun importExams(exams: List<ExamData>) {
viewModelScope.launch(Dispatchers.IO) {
kotlin.runCatching {
examApi.createExams(exams)
val currentExams = examApi.retrieveExamData()
val noDuplicates = exams.filter { exam -> currentExams.none { it.id == exam.id } }
examApi.createExams(noDuplicates)
}.onSuccess {
examDataSource.insertExams(it)
scheduleOrUpdateNotifications(it)
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ kotlin.experimental.tryK2=true
android.lint.useK2Uast=true

# App settings
app.versionName=0.1.0
app.versionCode=6
app.versionName=0.1.1
app.versionCode=7

0 comments on commit 0918776

Please sign in to comment.