Browse Source

#119: Default deserializer has no string deserialization implementation

technical/upgrade-exoplayer
Ryan Harg 2 years ago committed by Ryan Harg
parent
commit
1b0381fde4
  1. 2
      app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt
  2. 2
      app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt
  3. 3
      app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt
  4. 17
      app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt
  5. 3
      app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt
  6. 13
      app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt
  7. 3
      app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt
  8. 13
      app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt
  9. 3
      app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt
  10. 18
      app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt

2
app/src/main/java/audio/funkwhale/ffa/repositories/AlbumsRepository.kt

@ -5,7 +5,7 @@ import audio.funkwhale.ffa.model.Album
import audio.funkwhale.ffa.model.AlbumsCache import audio.funkwhale.ffa.model.AlbumsCache
import audio.funkwhale.ffa.model.AlbumsResponse import audio.funkwhale.ffa.model.AlbumsResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.github.kittinunf.fuel.gson.gsonDeserializerOf import audio.funkwhale.ffa.utils.gsonDeserializerOf
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject

2
app/src/main/java/audio/funkwhale/ffa/repositories/ArtistTracksRepository.kt

@ -6,7 +6,7 @@ import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.model.TracksCache import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.github.kittinunf.fuel.gson.gsonDeserializerOf import audio.funkwhale.ffa.utils.gsonDeserializerOf
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject

3
app/src/main/java/audio/funkwhale/ffa/repositories/ArtistsRepository.kt

@ -6,10 +6,9 @@ import audio.funkwhale.ffa.model.ArtistsCache
import audio.funkwhale.ffa.model.ArtistsResponse import audio.funkwhale.ffa.model.ArtistsResponse
import audio.funkwhale.ffa.model.FFAResponse import audio.funkwhale.ffa.model.FFAResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.github.kittinunf.fuel.gson.gsonDeserializerOf import audio.funkwhale.ffa.utils.gsonDeserializerOf
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class ArtistsRepository(override val context: Context?) : Repository<Artist, ArtistsCache>() { class ArtistsRepository(override val context: Context?) : Repository<Artist, ArtistsCache>() {

17
app/src/main/java/audio/funkwhale/ffa/repositories/FavoritesRepository.kt

@ -1,22 +1,10 @@
package audio.funkwhale.ffa.repositories package audio.funkwhale.ffa.repositories
import android.content.Context import android.content.Context
import audio.funkwhale.ffa.model.FFAResponse import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.model.FavoritedCache import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.model.FavoritedResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import audio.funkwhale.ffa.utils.untilNetwork
import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.upstream.cache.Cache import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.gson.Gson import com.google.gson.Gson
@ -27,7 +15,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.koin.core.qualifier.named import org.koin.core.qualifier.named
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class FavoritesRepository(override val context: Context?) : Repository<Track, TracksCache>() { class FavoritesRepository(override val context: Context?) : Repository<Track, TracksCache>() {

3
app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistTracksRepository.kt

@ -6,13 +6,12 @@ import audio.funkwhale.ffa.model.PlaylistTrack
import audio.funkwhale.ffa.model.PlaylistTracksCache import audio.funkwhale.ffa.model.PlaylistTracksCache
import audio.funkwhale.ffa.model.PlaylistTracksResponse import audio.funkwhale.ffa.model.PlaylistTracksResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.github.kittinunf.fuel.gson.gsonDeserializerOf import audio.funkwhale.ffa.utils.gsonDeserializerOf
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class PlaylistTracksRepository(override val context: Context?, playlistId: Int) : class PlaylistTracksRepository(override val context: Context?, playlistId: Int) :
Repository<PlaylistTrack, PlaylistTracksCache>() { Repository<PlaylistTrack, PlaylistTracksCache>() {

13
app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt

@ -1,25 +1,16 @@
package audio.funkwhale.ffa.repositories package audio.funkwhale.ffa.repositories
import android.content.Context import android.content.Context
import audio.funkwhale.ffa.model.FFAResponse import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.model.Playlist import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.model.PlaylistsCache
import audio.funkwhale.ffa.model.PlaylistsResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.authorize
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult import com.github.kittinunf.fuel.coroutines.awaitByteArrayResponseResult
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
data class PlaylistAdd(val tracks: List<Int>, val allow_duplicates: Boolean) data class PlaylistAdd(val tracks: List<Int>, val allow_duplicates: Boolean)

3
app/src/main/java/audio/funkwhale/ffa/repositories/RadiosRepository.kt

@ -6,10 +6,9 @@ import audio.funkwhale.ffa.model.Radio
import audio.funkwhale.ffa.model.RadiosCache import audio.funkwhale.ffa.model.RadiosCache
import audio.funkwhale.ffa.model.RadiosResponse import audio.funkwhale.ffa.model.RadiosResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import com.github.kittinunf.fuel.gson.gsonDeserializerOf import audio.funkwhale.ffa.utils.gsonDeserializerOf
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class RadiosRepository(override val context: Context?) : Repository<Radio, RadiosCache>() { class RadiosRepository(override val context: Context?) : Repository<Radio, RadiosCache>() {

13
app/src/main/java/audio/funkwhale/ffa/repositories/SearchRepository.kt

@ -1,18 +1,10 @@
package audio.funkwhale.ffa.repositories package audio.funkwhale.ffa.repositories
import android.content.Context import android.content.Context
import audio.funkwhale.ffa.model.Album import audio.funkwhale.ffa.model.*
import audio.funkwhale.ffa.model.AlbumsCache
import audio.funkwhale.ffa.model.AlbumsResponse
import audio.funkwhale.ffa.model.Artist
import audio.funkwhale.ffa.model.ArtistsCache
import audio.funkwhale.ffa.model.ArtistsResponse
import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.gsonDeserializerOf
import audio.funkwhale.ffa.utils.mustNormalizeUrl import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.upstream.cache.Cache import com.google.android.exoplayer2.upstream.cache.Cache
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
@ -21,7 +13,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.koin.core.qualifier.named import org.koin.core.qualifier.named
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class TracksSearchRepository(override val context: Context?, var query: String) : class TracksSearchRepository(override val context: Context?, var query: String) :
Repository<Track, TracksCache>() { Repository<Track, TracksCache>() {

3
app/src/main/java/audio/funkwhale/ffa/repositories/TracksRepository.kt

@ -7,8 +7,8 @@ import audio.funkwhale.ffa.model.TracksCache
import audio.funkwhale.ffa.model.TracksResponse import audio.funkwhale.ffa.model.TracksResponse
import audio.funkwhale.ffa.utils.OAuth import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.getMetadata import audio.funkwhale.ffa.utils.getMetadata
import audio.funkwhale.ffa.utils.gsonDeserializerOf
import audio.funkwhale.ffa.utils.mustNormalizeUrl import audio.funkwhale.ffa.utils.mustNormalizeUrl
import com.github.kittinunf.fuel.gson.gsonDeserializerOf
import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.Download
import com.google.android.exoplayer2.offline.DownloadManager import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.upstream.cache.Cache import com.google.android.exoplayer2.upstream.cache.Cache
@ -18,7 +18,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.koin.core.qualifier.named import org.koin.core.qualifier.named
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
import java.io.BufferedReader
class TracksRepository(override val context: Context?, albumId: Int) : class TracksRepository(override val context: Context?, albumId: Int) :
Repository<Track, TracksCache>() { Repository<Track, TracksCache>() {

18
app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt

@ -10,20 +10,22 @@ import audio.funkwhale.ffa.model.DownloadInfo
import audio.funkwhale.ffa.repositories.Repository import audio.funkwhale.ffa.repositories.Repository
import com.github.kittinunf.fuel.core.FuelError import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.Request import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.google.android.exoplayer2.offline.Download import com.google.android.exoplayer2.offline.Download
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import com.squareup.picasso.RequestCreator import com.squareup.picasso.RequestCreator
import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.openid.appauth.ClientSecretPost import net.openid.appauth.ClientSecretPost
import java.io.Reader
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.*
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
inline fun <D> Flow<Repository.Response<D>>.untilNetwork( inline fun <D> Flow<Repository.Response<D>>.untilNetwork(
@ -113,3 +115,15 @@ val ISO_8601_DATE_TIME_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
fun Date.format(): String { fun Date.format(): String {
return ISO_8601_DATE_TIME_FORMAT.format(this) return ISO_8601_DATE_TIME_FORMAT.format(this)
} }
inline fun <reified T : Any> gsonDeserializerOf(clazz: Class<T>) = gsonDeserializer<T>()
inline fun <reified T : Any> gsonDeserializer(gson: Gson = Gson()) = object :
ResponseDeserializable<T> {
override fun deserialize(content: String): T? =
gson.fromJson<T>(content, object : TypeToken<T>() {}.type)
override fun deserialize(reader: Reader): T? =
gson.fromJson<T>(reader, object : TypeToken<T>() {}.type)
}

Loading…
Cancel
Save