Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 987f8a0a authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

feature: Add InstantJsonParser class, to let moshi parse date from gitlab release API

parent 5108c9ad
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
package foundation.e.apps.di.network

import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
import java.time.Instant
import java.time.format.DateTimeFormatter

//todo Instant is not available in Android API 25 which is the minimum used.
// 3 option: replace Instant by another class, use a third party library to make retrocompatibility
// or update android minimum api to at least API 26
class InstantJsonAdapter {
    @ToJson
    fun toJson(instant: Instant): String {
        return DateTimeFormatter.ISO_INSTANT.format(instant)
    }

    @FromJson
    fun fromJson(instantString: String): Instant {
        return Instant.parse(instantString)
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ object NetworkModule {
    @Provides
    fun getMoshi(): Moshi {
        return Moshi.Builder()
            .add(InstantJsonAdapter())
            .add(KotlinJsonAdapterFactory())
            .build()
    }