Skip to content

Commit

Permalink
fix: Fix ConnectionInfo DataStore initialised again
Browse files Browse the repository at this point in the history
If the activity is killed via swipe back and recreated the
ConnectionInfoRepository is also recreated resulting into a crash.

close #81
  • Loading branch information
Chrylo committed Feb 27, 2024
1 parent 5b92b2b commit 30927ef
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfoSerializer

class ConnectionInfoRepository(context: Context) {

private val Context.dataStore: DataStore<ConnectionInfo> by dataStore(PREFERENCES_NAME, ConnectionInfoSerializer)
private val dataStore = context.dataStore

val connectionInfoFlow: Flow<ConnectionInfo> = dataStore.data
Expand All @@ -39,5 +37,9 @@ class ConnectionInfoRepository(context: Context) {

private companion object {
private const val PREFERENCES_NAME = "connection_info"
private val Context.dataStore: DataStore<ConnectionInfo> by dataStore(
PREFERENCES_NAME,
ConnectionInfoSerializer,
)
}
}

0 comments on commit 30927ef

Please sign in to comment.