Skip to content

Commit

Permalink
Add last read version code to UserPreferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jan 8, 2025
1 parent a3e0120 commit ce83061
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import java.io.IOException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import net.mullvad.mullvadvpn.lib.model.BuildVersion

class UserPreferencesRepository(private val userPreferences: DataStore<UserPreferences>) {
class UserPreferencesRepository(
private val userPreferencesStore: DataStore<UserPreferences>,
private val buildVersion: BuildVersion,
) {

// Note: this should not be made into a StateFlow. See:
// https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore#data()
val preferencesFlow: Flow<UserPreferences> =
userPreferences.data.catch { exception ->
userPreferencesStore.data.catch { exception ->
// dataStore.data throws an IOException when an error is encountered when reading data
if (exception is IOException) {
Logger.e("Error reading user preferences file, falling back to default.", exception)
Expand All @@ -25,8 +29,17 @@ class UserPreferencesRepository(private val userPreferences: DataStore<UserPrefe
suspend fun preferences(): UserPreferences = preferencesFlow.first()

suspend fun setPrivacyDisclosureAccepted() {
userPreferences.updateData { prefs ->
userPreferencesStore.updateData { prefs ->
prefs.toBuilder().setIsPrivacyDisclosureAccepted(true).build()
}
}

suspend fun setHasDisplayedChangelogNotification() {
userPreferencesStore.updateData { prefs ->
prefs
.toBuilder()
.setVersionCodeForLatestShownChangelogNotification(buildVersion.code)
.build()
}
}
}
5 changes: 4 additions & 1 deletion android/app/src/main/proto/user_prefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ syntax = "proto3";
option java_package = "net.mullvad.mullvadvpn.repository";
option java_multiple_files = true;

message UserPreferences { bool is_privacy_disclosure_accepted = 1; }
message UserPreferences {
bool is_privacy_disclosure_accepted = 1;
int32 version_code_for_latest_shown_changelog_notification = 2;
}

0 comments on commit ce83061

Please sign in to comment.