Skip to content

Commit

Permalink
fix tons of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiebe committed Feb 10, 2024
1 parent 59d661d commit c60d4b1
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 183 deletions.
4 changes: 2 additions & 2 deletions iosApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- shared (4.0.0)
- shared (4.1.0)

DEPENDENCIES:
- shared (from `../shared`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../shared"

SPEC CHECKSUMS:
shared: 53f432c474abfdeb9dbfed8fa438cb73d4c17cec
shared: c712c3afb7af22f1475435acf8333cbc0e45bed6

PODFILE CHECKSUM: c12a7abff35ee3f072d38976340e7906474f416f

Expand Down
2 changes: 1 addition & 1 deletion iosApp/Pods/Local Podspecs/shared.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions iosApp/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions shared/src/androidMain/kotlin/nl/tiebe/otarium/MainAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import nl.tiebe.otarium.utils.ui.Android.context


actual fun setupNotifications() {
createNotificationChannel(context)
val name = context.getString(R.string.grades_channel)
val descriptionText = context.getString(R.string.grades_channel_description)

createNotificationChannel(context, "grades", name, descriptionText)
askNotificationPermission(context)

askBatteryOptimizationPermission(context)
Expand All @@ -35,13 +38,11 @@ fun askNotificationPermission(context: Context) {
}
}

fun createNotificationChannel(context: Context) {
fun createNotificationChannel(context: Context, id: String, name: String, description: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = context.getString(R.string.grades_channel)
val descriptionText = context.getString(R.string.grades_channel_description)
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel("grades", name, importance).apply {
description = descriptionText
val channel = NotificationChannel(id, name, importance).apply {
this.description = description
}
channel.enableVibration(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.HtmlCompat

@Composable
actual fun HtmlView(html: String, textColor: Int, linkColor: Int, backgroundColor: Int, maxLines: Int) {
actual fun HtmlView(html: String, textColor: Int, linkColor: Int, backgroundColor: Int, maxLines: Int, onClick: () -> Unit) {
val color = if (textColor == -1) {
LocalTextStyle.current.color.takeOrElse { LocalContentColor.current }.toArgb()
} else textColor
Expand Down
9 changes: 8 additions & 1 deletion shared/src/commonMain/kotlin/nl/tiebe/otarium/Data.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package nl.tiebe.otarium

import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import nl.tiebe.otarium.magister.MagisterAccount
Expand Down Expand Up @@ -62,10 +61,18 @@ object Data {
get() = settings.getBoolean("mark_grades", false)
set(value) = settings.putBoolean("mark_grades", value)

var timetableContrast: Boolean
get() = settings.getBoolean("timetable_contrast", false)
set(value) = settings.putBoolean("timetable_contrast", value)

var passingGrade: Float
get() = settings.getFloat("passing_grade", 5.5f)
set(value) = settings.putFloat("passing_grade", value)

var timetableRounding: Int
get() = settings.getInt("timetable_rounding", 0)
set(value) = settings.putInt("timetable_rounding", value)

var debugNotifications: Boolean
get() = settings.getBoolean("debug_notifications", false)
set(value) = settings.putBoolean("debug_notifications", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.arkivanov.decompose.value.MutableValue
import dev.tiebe.magisterapi.api.assignment.AssignmentFlow
import dev.tiebe.magisterapi.api.general.GeneralFlow
import dev.tiebe.magisterapi.response.assignment.Assignment
import io.ktor.http.*
import kotlinx.coroutines.launch
import nl.tiebe.otarium.Data
import nl.tiebe.otarium.logic.default.componentCoroutineScope
import nl.tiebe.otarium.logic.root.home.children.elo.children.assignments.AssignmentsChildComponent
import nl.tiebe.otarium.logic.root.home.children.elo.children.assignments.children.list.AssignmentListComponent
import io.ktor.http.*
import kotlinx.coroutines.launch

class DefaultAssignmentListComponent(
componentContext: ComponentContext,
Expand Down Expand Up @@ -40,7 +40,7 @@ class DefaultAssignmentListComponent(
250,
year.start,
year.end
)
).sortedBy { it.title }

isRefreshing.value = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.value.MutableValue
import dev.tiebe.magisterapi.api.learningresource.LearningResourceFlow
import dev.tiebe.magisterapi.response.learningresource.LearningResource
import io.ktor.http.*
import kotlinx.coroutines.launch
import nl.tiebe.otarium.Data
import nl.tiebe.otarium.logic.default.componentCoroutineScope
import nl.tiebe.otarium.logic.root.home.children.elo.children.learningresources.LearningResourcesChildComponent
import io.ktor.http.*
import kotlinx.coroutines.launch

class DefaultLearningResourcesChildComponent(componentContext: ComponentContext) : LearningResourcesChildComponent, ComponentContext by componentContext {
override val learningResources: MutableValue<List<LearningResource>> = MutableValue(emptyList())
Expand All @@ -19,7 +19,7 @@ class DefaultLearningResourcesChildComponent(componentContext: ComponentContext)
override fun refreshLearningResources() {
scope.launch {
isRefreshing.value = true
learningResources.value = LearningResourceFlow.getLearningResources(Url(Data.selectedAccount.tenantUrl), Data.selectedAccount.tokens.accessToken, Data.selectedAccount.accountId)
learningResources.value = LearningResourceFlow.getLearningResources(Url(Data.selectedAccount.tenantUrl), Data.selectedAccount.tokens.accessToken, Data.selectedAccount.accountId).sortedBy { it.title }
isRefreshing.value = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class DefaultUIChildComponent(
showCancelledLessons.value = value
}

override val timetableContrast: MutableValue<Boolean> = MutableValue(Data.timetableContrast)

override fun timetableContrast(value: Boolean) {
Data.timetableContrast = value
timetableContrast.value = value
}

override val markGrades: MutableValue<Boolean> = MutableValue(Data.markGrades)
override fun markGrades(value: Boolean) {
Data.markGrades = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ interface UIChildComponent {

val markGrades: Value<Boolean>

val timetableContrast: Value<Boolean>

fun timetableContrast(value: Boolean)

fun markGrades(value: Boolean)

val passingGrade: Value<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class StoreAveragesComponent(componentContext: ComponentContext): AveragesCompon
is AveragesComponent.Config.Subject -> AveragesComponent.Child.SubjectChild(this, config.subjectId)
}


override val gradesList: MutableValue<List<GradeWithGradeInfo>> = MutableValue(
emptyList()
)
Expand Down
13 changes: 8 additions & 5 deletions shared/src/commonMain/kotlin/nl/tiebe/otarium/magister/Grades.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ suspend fun MagisterAccount.getRecentGrades(amount: Int, skip: Int): List<Recent
suspend fun MagisterAccount.refreshGrades(notification: (String, String) -> Unit = { title, message -> sendNotification(title, message) }): List<GradeWithGradeInfo> {
val years = GeneralFlow.getYears(tenantUrl, tokens.accessToken, accountId)
val grades = GradeFlow.getGrades(Url(tenantUrl), tokens.accessToken, accountId, years[0]).filter {
it.gradeColumn.type == GradeColumn.Type.Grade ||
it.gradeColumn.type == GradeColumn.Type.Text
(it.gradeColumn.type == GradeColumn.Type.Grade ||
it.gradeColumn.type == GradeColumn.Type.Text)
}

val newFullGradeList: MutableList<GradeWithGradeInfo> = fullGradeList.toMutableList()
Expand Down Expand Up @@ -70,15 +70,18 @@ suspend fun MagisterAccount.refreshGrades(notification: (String, String) -> Unit
} catch (e: Exception) { e.printStackTrace() }
}

fullGradeList = newFullGradeList
fullGradeList = newFullGradeList.sortedBy { it.grade.dateEntered }
return fullGradeList
}

@Serializable
data class GradeWithGradeInfo(
val grade: Grade,
val gradeInfo: GradeInfo
)
val gradeInfo: GradeInfo,
) {
val isPTA get() = grade.gradeSemester?.name == "PTA"

}

@Serializable
data class ManualGrade(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@ import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.unit.dp
Expand All @@ -34,7 +25,8 @@ internal fun StudyGuideFolderItem(component: StudyGuideFolderComponent, item: St
overlineContent = { HtmlView(
item.description,
maxLines = 1,
backgroundColor = ListItemDefaults.containerColor.toArgb()
backgroundColor = ListItemDefaults.containerColor.toArgb(),
onClick = { showContents = !showContents }
) },
colors = ListItemDefaults.colors(
containerColor = MaterialTheme.colorScheme.inverseOnSurface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import androidx.compose.ui.unit.sp
import kotlinx.coroutines.launch
import nl.tiebe.otarium.MR
import nl.tiebe.otarium.ui.home.grades.averages.AveragesScreen
import nl.tiebe.otarium.ui.home.grades.averages.AveragesScreenTopBar
import nl.tiebe.otarium.ui.home.grades.grades.RecentGradesScreen
import nl.tiebe.otarium.ui.home.grades.grades.RecentGradesTopBar
import nl.tiebe.otarium.utils.ui.getLocalizedString

@OptIn(ExperimentalFoundationApi::class)
Expand All @@ -30,6 +32,11 @@ internal fun GradesScreen(component: GradesComponent) {
val coroutineScope = rememberCoroutineScope()

Column(modifier = Modifier.fillMaxSize()) {
when (pagerState.currentPage) {
0 -> RecentGradesTopBar(component.recentGradeComponent)
1 -> AveragesScreenTopBar(component.averagesComponent)
}

TabRow(
selectedTabIndex = pagerState.currentPage,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package nl.tiebe.otarium.ui.home.grades.averages

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -24,6 +21,19 @@ import nl.tiebe.otarium.ui.home.grades.averages.subject.AverageSubjectPopup
import nl.tiebe.otarium.ui.home.grades.averages.subject.AverageSubjectPopupTopAppBar
import nl.tiebe.otarium.utils.ui.getLocalizedString

@Composable
fun AveragesScreenTopBar(component: AveragesComponent) {
val subjects = listOf(Subject(-1, abbreviation = "global", description = getLocalizedString(MR.strings.global_averages), index = -1)) +
component.gradesList.subscribeAsState().value.map { it.grade.subject }.distinct().sortedBy { it.description.lowercase() }

when (val instance = component.childStack.subscribeAsState().value.active.instance) {
is AveragesComponent.Child.ListChild -> AveragesListScreenTopAppBar(component)
is AveragesComponent.Child.SubjectChild -> AverageSubjectPopupTopAppBar(
instance.component,
subjects.first { it.id == instance.subjectId })
}
}

@OptIn(ExperimentalDecomposeApi::class)
@Composable
internal fun AveragesScreen(component: AveragesComponent) {
Expand All @@ -38,26 +48,14 @@ internal fun AveragesScreen(component: AveragesComponent) {
onBack = component::back,
)
) { child ->
Scaffold(
topBar = {
when (val instance = child.instance) {
is AveragesComponent.Child.ListChild -> AveragesListScreenTopAppBar(component)
is AveragesComponent.Child.SubjectChild -> AverageSubjectPopupTopAppBar(
instance.component,
subjects.first { it.id == instance.subjectId })
}
},
contentWindowInsets = WindowInsets(0)
) {
Surface(modifier = Modifier.fillMaxSize().padding(it)) {
when (val instance = child.instance) {
is AveragesComponent.Child.ListChild -> AveragesListScreen(instance.component, subjects)
is AveragesComponent.Child.SubjectChild -> AverageSubjectPopup(
instance.component,
subjects.first { it.id == instance.subjectId },
component.gradesList.subscribeAsState().value
)
}
Surface(modifier = Modifier.fillMaxSize()) {
when (val instance = child.instance) {
is AveragesComponent.Child.ListChild -> AveragesListScreen(instance.component, subjects)
is AveragesComponent.Child.SubjectChild -> AverageSubjectPopup(
instance.component,
subjects.first { it.id == instance.subjectId },
component.gradesList.subscribeAsState().value
)
}
}
}
Expand Down
Loading

0 comments on commit c60d4b1

Please sign in to comment.