Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import android.view.View
import android.widget.RemoteViews
import androidx.compose.ui.graphics.toArgb
import com.ahu.ahutong.R
import com.ahu.ahutong.data.AHURepository
import com.ahu.ahutong.data.debug.DebugClock
import com.ahu.ahutong.data.dao.AHUCache
import com.ahu.ahutong.data.schedule.CurrentWeekResolver
import com.ahu.ahutong.ui.state.ScheduleViewModel
import kotlinx.coroutines.runBlocking
import java.text.SimpleDateFormat
import java.util.Locale

Expand Down Expand Up @@ -114,12 +113,15 @@ class ScheduleAdaptiveWidgetProvider : AppWidgetProvider() {
} else {
R.id.adaptive_test_items_small
}
val scheduleConfig = runBlocking { CurrentWeekResolver.resolveLocalFirst().config }
// AppWidgetProvider callbacks run on the broadcast thread. Keep this path cache-only;
// remote semester synchronization is handled by the app and the suspend Glance widget.
val scheduleConfig = CurrentWeekResolver.resolveLocalConfig()?.config
?: CurrentWeekResolver.defaultConfig().config
val currentWeek = scheduleConfig.week
val weekDay = scheduleConfig.weekDay
val schedule = runCatching {
runBlocking { AHURepository.getSchedule(false) }
}.getOrNull()?.getOrNull().orEmpty()
val schedule = AHUCache.getSchoolTerm()
?.let(AHUCache::getSchedule)
.orEmpty()
val currentMinutes = DebugClock.currentMinutes()
val todayCourses = if (scheduleConfig.isInSemester) {
schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ private val Context.dataStore by preferencesDataStore(name = "user_pref")

class PreferencesManager @Inject constructor(@param:ApplicationContext private val context: Context) {

suspend fun clearAll() {
context.dataStore.edit { preferences -> preferences.clear() }
}

val personalizationEnabled: Flow<Boolean> = context.dataStore.data.map { prefs ->
prefs[PreferencesKeys.PERSONALIZATION_ENABLED] ?: true
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/ahu/ahutong/ui/screen/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ import androidx.navigation.NavHostController
import com.ahu.ahutong.AHUApplication
import com.ahu.ahutong.R
import com.ahu.ahutong.data.dao.AHUCache
import com.ahu.ahutong.data.dao.PreferencesManager
import com.ahu.ahutong.data.crawler.manager.CookieManager
import com.ahu.ahutong.data.server.AhuTong
import com.ahu.ahutong.notification.CourseReminderScheduler
import com.ahu.ahutong.personalization.runtime.BehaviorPredictionRuntime
import com.ahu.ahutong.sdk.RustSDK
import com.ahu.ahutong.ui.components.SettingsActionRow
Expand All @@ -79,6 +81,9 @@ fun Settings(
) {
val context = LocalContext.current as ComponentActivity
val scope = rememberCoroutineScope()
val preferencesManager = remember(context) {
PreferencesManager(context.applicationContext)
}
var isClearDataDialogShown by rememberSaveable { mutableStateOf(false) }
var isUpdateLogDialogShown by rememberSaveable { mutableStateOf(false) }
var updateLog by remember { mutableStateOf("") }
Expand Down Expand Up @@ -255,6 +260,8 @@ fun Settings(
TextButton(
onClick = {
scope.launch {
CourseReminderScheduler.cancel(context)
preferencesManager.clearAll()
behaviorRuntime.logoutAndClear()
mainViewModel.logout()
AHUCache.clearAll()
Expand Down
Loading