-
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
a1e642c
commit d4dd32a
Showing
17 changed files
with
441 additions
and
94 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
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
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,7 @@ | ||
package app.fyreplace.fyreplace | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class App : Application() |
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
38 changes: 38 additions & 0 deletions
38
app/src/main/kotlin/app/fyreplace/fyreplace/data/ConnectionSerializer.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,38 @@ | ||
package app.fyreplace.fyreplace.data | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.CorruptionException | ||
import androidx.datastore.core.Serializer | ||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler | ||
import androidx.datastore.dataStore | ||
import app.fyreplace.fyreplace.BuildConfig | ||
import app.fyreplace.fyreplace.protos.Connection | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
|
||
object ConnectionSerializer : Serializer<Connection> { | ||
override val defaultValue: Connection | ||
get() = Connection.getDefaultInstance() | ||
.toBuilder() | ||
.setEnvironment(BuildConfig.ENVIRONMENT_DEFAULT) | ||
.build() | ||
|
||
val corruptionHandler = ReplaceFileCorruptionHandler { defaultValue } | ||
|
||
override suspend fun readFrom(input: InputStream): Connection { | ||
try { | ||
return Connection.parseFrom(input) | ||
} catch (exception: IOException) { | ||
throw CorruptionException("Cannot read proto.", exception) | ||
} | ||
} | ||
|
||
override suspend fun writeTo(t: Connection, output: OutputStream) = t.writeTo(output) | ||
} | ||
|
||
val Context.connectionStore by dataStore( | ||
fileName = "connection.pb", | ||
serializer = ConnectionSerializer, | ||
corruptionHandler = ConnectionSerializer.corruptionHandler | ||
) |
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/app/fyreplace/fyreplace/extensions/Context.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,17 @@ | ||
package app.fyreplace.fyreplace.extensions | ||
|
||
import android.content.Context | ||
import android.content.ContextWrapper | ||
import androidx.activity.ComponentActivity | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
@Suppress("RecursivePropertyAccessor") | ||
val Context.activity | ||
get(): ComponentActivity? = when (this) { | ||
is ComponentActivity -> this | ||
is ContextWrapper -> baseContext.activity | ||
else -> null | ||
} | ||
|
||
val activity @Composable get() = LocalContext.current.activity |
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
Oops, something went wrong.