-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore
: Re-update to serialization based navigation (#118)
Co-authored-by: Tim Ortel <100865202+TimOrtel@users.noreply.github.com>
- Loading branch information
1 parent
f4f2d94
commit 8ceddfd
Showing
17 changed files
with
247 additions
and
246 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
30 changes: 30 additions & 0 deletions
30
...lin/de/tum/informatics/www1/artemis/native_app/core/ui/navigation/KSerializableNavType.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,30 @@ | ||
package de.tum.informatics.www1.artemis.native_app.core.ui.navigation | ||
|
||
import android.os.Bundle | ||
import androidx.navigation.NavType | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.json.Json | ||
|
||
class KSerializableNavType<T>( | ||
isNullableAllowed: Boolean, | ||
private val serializer: KSerializer<T> | ||
) : NavType<T>(isNullableAllowed) { | ||
|
||
companion object { | ||
private val json = Json { | ||
coerceInputValues = true | ||
} | ||
} | ||
|
||
override fun get(bundle: Bundle, key: String): T? { | ||
return parseValue(bundle.getString(key) ?: return null) | ||
} | ||
|
||
override fun parseValue(value: String): T { | ||
return json.decodeFromString(serializer, value) | ||
} | ||
|
||
override fun put(bundle: Bundle, key: String, value: T) { | ||
bundle.putString(key, json.encodeToString(serializer, value)) | ||
} | ||
} |
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
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.