mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
get rid of gson
This commit is contained in:
parent
56b7a8e5cc
commit
da38c83993
@ -90,5 +90,4 @@ dependencies {
|
||||
implementation libs.cronet.embedded
|
||||
implementation libs.cronet.okhttp
|
||||
implementation libs.coil
|
||||
implementation libs.gson
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ package com.github.libretube.preferences
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.github.libretube.obj.CustomInstance
|
||||
import com.github.libretube.obj.Streams
|
||||
import com.github.libretube.obj.WatchHistoryItem
|
||||
import com.github.libretube.obj.WatchPosition
|
||||
import com.google.common.reflect.TypeToken
|
||||
import com.google.gson.Gson
|
||||
import java.lang.reflect.Type
|
||||
|
||||
object PreferenceHelper {
|
||||
private val TAG = "PreferenceHelper"
|
||||
@ -92,21 +90,25 @@ object PreferenceHelper {
|
||||
}
|
||||
|
||||
fun saveCustomInstance(customInstance: CustomInstance) {
|
||||
val gson = Gson()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
val customInstancesList = getCustomInstances()
|
||||
customInstancesList += customInstance
|
||||
|
||||
val json = gson.toJson(customInstancesList)
|
||||
val json = mapper.writeValueAsString(customInstancesList)
|
||||
editor.putString("customInstances", json).apply()
|
||||
}
|
||||
|
||||
fun getCustomInstances(): ArrayList<CustomInstance> {
|
||||
val gson = Gson()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
val json: String = settings.getString("customInstances", "")!!
|
||||
val type: Type = object : TypeToken<List<CustomInstance?>?>() {}.type
|
||||
val type = mapper.typeFactory.constructCollectionType(
|
||||
List::class.java,
|
||||
CustomInstance::class.java
|
||||
)
|
||||
return try {
|
||||
gson.fromJson(json, type)
|
||||
mapper.readValue(json, type)
|
||||
} catch (e: Exception) {
|
||||
arrayListOf()
|
||||
}
|
||||
@ -127,7 +129,7 @@ object PreferenceHelper {
|
||||
}
|
||||
|
||||
fun addToWatchHistory(videoId: String, streams: Streams) {
|
||||
val gson = Gson()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
val watchHistoryItem = WatchHistoryItem(
|
||||
videoId,
|
||||
@ -151,16 +153,21 @@ object PreferenceHelper {
|
||||
|
||||
watchHistory += watchHistoryItem
|
||||
|
||||
val json = gson.toJson(watchHistory)
|
||||
val json = mapper.writeValueAsString(watchHistory)
|
||||
editor.putString("watch_history", json).apply()
|
||||
}
|
||||
|
||||
fun getWatchHistory(): ArrayList<WatchHistoryItem> {
|
||||
val gson = Gson()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
val json: String = settings.getString("watch_history", "")!!
|
||||
val type: Type = object : TypeToken<List<WatchHistoryItem?>?>() {}.type
|
||||
val type = mapper.typeFactory.constructCollectionType(
|
||||
List::class.java,
|
||||
WatchHistoryItem::class.java
|
||||
)
|
||||
|
||||
return try {
|
||||
gson.fromJson(json, type)
|
||||
mapper.readValue(json, type)
|
||||
} catch (e: Exception) {
|
||||
arrayListOf()
|
||||
}
|
||||
@ -179,8 +186,8 @@ object PreferenceHelper {
|
||||
|
||||
watchPositions += watchPositionItem
|
||||
|
||||
val gson = Gson()
|
||||
val json = gson.toJson(watchPositions)
|
||||
val mapper = ObjectMapper()
|
||||
val json = mapper.writeValueAsString(watchPositions)
|
||||
editor.putString("watch_positions", json).commit()
|
||||
}
|
||||
|
||||
@ -194,19 +201,22 @@ object PreferenceHelper {
|
||||
|
||||
if (indexToRemove != null) watchPositions.removeAt(indexToRemove!!)
|
||||
|
||||
val gson = Gson()
|
||||
val json = gson.toJson(watchPositions)
|
||||
val mapper = ObjectMapper()
|
||||
val json = mapper.writeValueAsString(watchPositions)
|
||||
editor.putString("watch_positions", json).commit()
|
||||
}
|
||||
|
||||
fun getWatchPositions(): ArrayList<WatchPosition> {
|
||||
val gson = Gson()
|
||||
val mapper = ObjectMapper()
|
||||
|
||||
val json: String = settings.getString("watch_positions", "")!!
|
||||
val type: Type = object : TypeToken<List<WatchPosition?>?>() {}.type
|
||||
val type = mapper.typeFactory.constructCollectionType(
|
||||
List::class.java,
|
||||
WatchPosition::class.java
|
||||
)
|
||||
|
||||
return try {
|
||||
gson.fromJson(json, type)
|
||||
mapper.readValue(json, type)
|
||||
} catch (e: Exception) {
|
||||
arrayListOf()
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.libretube.update
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.github.libretube.GITHUB_API_URL
|
||||
import com.google.gson.Gson
|
||||
import java.net.URL
|
||||
|
||||
object UpdateChecker {
|
||||
@ -29,7 +29,7 @@ object UpdateChecker {
|
||||
val json = latestVersionApiUrl.readText()
|
||||
|
||||
// Parse and return the json data
|
||||
val gson = Gson()
|
||||
return gson.fromJson(json, UpdateInfo::class.java)
|
||||
val mapper = ObjectMapper()
|
||||
return mapper.readValue(json, UpdateInfo::class.java)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ cronetEmbedded = "101.4951.41"
|
||||
cronetOkHttp = "0.1.0"
|
||||
coil = "2.1.0"
|
||||
leakcanary = "2.8.1"
|
||||
gson = "2.9.0"
|
||||
|
||||
[libraries]
|
||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||
@ -44,4 +43,3 @@ cronet-embedded = { group = "org.chromium.net", name = "cronet-embedded", versio
|
||||
cronet-okhttp = { group = "com.google.net.cronet", name = "cronet-okhttp", version.ref = "cronetOkHttp" }
|
||||
coil = { group = "io.coil-kt", name = "coil", version.ref="coil" }
|
||||
square-leakcanary = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" }
|
||||
gson = { group = "com.google.code.gson", name="gson", version.ref = "gson"}
|
Loading…
x
Reference in New Issue
Block a user