Skip to content

Commit

Permalink
fixed bug no longer crashes when toggling bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenLindstrom committed Nov 9, 2024
1 parent 351eafc commit 81b1fe7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class RealmManager {
}
}

suspend fun updateScheduleVisibility(scheduleId: String, visibility: Boolean){
realm.write {
val schedule: Schedule? = this.query<Schedule>("scheduleId == $0", scheduleId).first().find()
schedule?.toggled = visibility
}
}

fun getCourseColors(): MutableMap<String, String> {
val courses: RealmResults<Course> = realm.query<Course>().find()
val courseColors = mutableMapOf<String, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package tumble.app.tumble.presentation.viewmodels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.realm.kotlin.ext.copyFromRealm
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import tumble.app.tumble.data.api.Endpoint
import tumble.app.tumble.data.notifications.NotificationManager
import tumble.app.tumble.data.repository.preferences.CombinedData
import tumble.app.tumble.data.repository.preferences.DataStoreManager
import tumble.app.tumble.data.repository.realm.RealmManager
import tumble.app.tumble.datasource.SchoolManager
import tumble.app.tumble.domain.enums.Types.AppearanceType
import tumble.app.tumble.domain.enums.ViewType
import tumble.app.tumble.domain.models.realm.Event
import tumble.app.tumble.domain.models.realm.Schedule
import tumble.app.tumble.presentation.views.Settings.Notifications.NotificationOffset
Expand Down Expand Up @@ -110,6 +109,12 @@ class SettingsViewModel @Inject constructor(
//TODO
}

fun updateBookmarkVisibility(visibility: Boolean, schedule: Schedule){
viewModelScope.launch {
realmManager.updateScheduleVisibility(schedule.scheduleId, visibility)
}
}

fun deleteAllSchedules(){
//TODO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ fun BookmarksSettings(

if (schedules.value.isNotEmpty()) {
SettingsList {
schedules.value.forEachIndexed { index, schedule ->
schedules.value.forEach{ schedule ->
BookmarkSettingsRow(
schedule = schedule,
index = index,
onDelete = { offsets, id ->
onDelete = { offsets ->
parentViewModel.deleteBookmark(schedule)
},
onToggle = {visibility ->
parentViewModel.updateBookmarkVisibility(visibility, schedule)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import tumble.app.tumble.domain.models.realm.Schedule
@Composable
fun BookmarkSettingsRow(
schedule: Schedule,
index: Int,
onDelete: (Int, String) -> Unit
onDelete: (String) -> Unit,
onToggle: (Boolean) -> Unit,
) {
val scope = rememberCoroutineScope()

Expand All @@ -60,15 +60,12 @@ fun BookmarkSettingsRow(
checked = isToggled,
onCheckedChange = { checked ->
isToggled = checked
schedule.toggled = checked
onToggle(checked)
// Trigger the widget update when the toggle changes
},
colors = SwitchDefaults.colors(checkedThumbColor = MaterialTheme.colors.primary),
modifier = Modifier.scale(2f)
)



}
}

0 comments on commit 81b1fe7

Please sign in to comment.