refactor : réécriture du contrôleur des chapters
continuous-integration/drone/push Build is passing Details

optimisationAndroid
Damien NORTIER 1 year ago
parent 58a7c00376
commit 81fc8a62b5

@ -11,14 +11,15 @@ import java.io.IOException
class ControllerChapter { class ControllerChapter {
companion object { companion object {
// Client HTTP API
val client = OkHttpClient()
fun getChapters(): ArrayList<Chapter>? { fun getChapters(): ArrayList<Chapter>? {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy) StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access // API Access
val request = Request.Builder() val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/all/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO/1") .url("https://trusting-panini.87-106-126-109.plesk.page/api/all/chapters/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO/1")
@ -45,9 +46,6 @@ class ControllerChapter {
val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() val policy = StrictMode.ThreadPolicy.Builder().permitAll().build()
StrictMode.setThreadPolicy(policy) StrictMode.setThreadPolicy(policy)
// Client HTTP API
val client = OkHttpClient()
// API Access // API Access
val request = Request.Builder() val request = Request.Builder()
.url("https://trusting-panini.87-106-126-109.plesk.page/api/chapters/$idchapter/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO") .url("https://trusting-panini.87-106-126-109.plesk.page/api/chapters/$idchapter/qUOGkWdoPCgbmuqxIC8xiaX0rV1Pw1LoPafkaoHOgszEyD9P2vcOu493xCDZpAqO")
@ -62,8 +60,7 @@ class ControllerChapter {
val typeTokenProduct = object : TypeToken<ArrayList<Chapter>>() {}.type val typeTokenProduct = object : TypeToken<ArrayList<Chapter>>() {}.type
// Parse API response and return the list of chapters // Parse API response and return the list of chapters
val chapter: ArrayList<Chapter> = gson.fromJson(response.body!!.string(), typeTokenProduct) return (gson.fromJson(response.body!!.string(), typeTokenProduct) as ArrayList<Chapter>)[0].name
return chapter[0].name
} }
return null return null

Loading…
Cancel
Save