This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 280
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
622bd78
commit 65af565
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/huanchengfly/tieba/post/components/NavSerializer.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,24 @@ | ||
package com.huanchengfly.tieba.post.components | ||
|
||
import android.util.Log | ||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo | ||
import com.huanchengfly.tieba.post.api.urlDecode | ||
import com.huanchengfly.tieba.post.api.urlEncode | ||
import com.ramcosta.composedestinations.navargs.DestinationsNavTypeSerializer | ||
import com.ramcosta.composedestinations.navargs.NavTypeSerializer | ||
import com.ramcosta.composedestinations.navargs.utils.base64ToByteArray | ||
import com.ramcosta.composedestinations.navargs.utils.toBase64Str | ||
|
||
@NavTypeSerializer | ||
class ThreadInfoSerializer : DestinationsNavTypeSerializer<ThreadInfo> { | ||
override fun toRouteString(value: ThreadInfo): String { | ||
val routeStr = ThreadInfo.ADAPTER.encode(value).toBase64Str().urlEncode() | ||
Log.d("ThreadInfoSerializer", "toRouteString: $routeStr") | ||
return routeStr | ||
} | ||
|
||
override fun fromRouteString(routeStr: String): ThreadInfo { | ||
Log.d("ThreadInfoSerializer", "fromRouteString: $routeStr") | ||
return ThreadInfo.ADAPTER.decode(routeStr.urlDecode().base64ToByteArray()) | ||
} | ||
} |