-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04c1193
commit d6dcb6e
Showing
4 changed files
with
53 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/kotlin/app/fyreplace/fyreplace/data/Module.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app.fyreplace.fyreplace.data | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Suppress("unused") | ||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
interface Module { | ||
@Binds | ||
fun bindConnectionStoreResolver(resolver: StoreResolverImpl): StoreResolver | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/kotlin/app/fyreplace/fyreplace/data/StoreResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package app.fyreplace.fyreplace.data | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.Serializer | ||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler | ||
import androidx.datastore.dataStore | ||
import app.fyreplace.fyreplace.protos.Connection | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.CoroutineScope | ||
import javax.inject.Inject | ||
|
||
interface StoreResolver { | ||
fun connectionStoreIn(scope: CoroutineScope): DataStore<Connection> | ||
} | ||
|
||
class StoreResolverImpl @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
) : StoreResolver { | ||
override fun connectionStoreIn(scope: CoroutineScope) = | ||
StoreWrapper(context, ConnectionSerializer, scope).store | ||
|
||
class StoreWrapper<T>(context: Context, serializer: Serializer<T>, scope: CoroutineScope) { | ||
private val Context.store by dataStore( | ||
fileName = "connection.pb", | ||
serializer = serializer, | ||
corruptionHandler = ReplaceFileCorruptionHandler { serializer.defaultValue }, | ||
scope = scope | ||
) | ||
|
||
val store = context.store | ||
} | ||
} |
12 changes: 6 additions & 6 deletions
12
...c/main/kotlin/app/fyreplace/fyreplace/viewmodels/settings/EnvironmentSelectorViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters