parent
4b1f3abc4e
commit
b448dfaab7
@ -0,0 +1,49 @@ |
||||
package net.pokeranalytics.android.api |
||||
|
||||
import android.content.Context |
||||
import com.android.volley.Request |
||||
import com.android.volley.toolbox.JsonArrayRequest |
||||
import com.android.volley.toolbox.Volley |
||||
import org.json.JSONArray |
||||
import timber.log.Timber |
||||
|
||||
data class BlogPost(var id: Int, var content: String) |
||||
|
||||
private fun JSONArray.toBlogPosts(): List<BlogPost> { |
||||
|
||||
val posts = mutableListOf<BlogPost>() |
||||
(0 until this.length()).forEach { index -> |
||||
val jo = this.getJSONObject(index) |
||||
val post = BlogPost(jo.getInt("id"), jo.getJSONObject("content").getString("rendered")) |
||||
posts.add(post) |
||||
} |
||||
return posts |
||||
} |
||||
|
||||
class BlogPostApi { |
||||
|
||||
companion object { |
||||
|
||||
private const val tipsLastPostsURL = "https://www.poker-analytics.net/blog/wp-json/wp/v2/posts/?categories=109\n" |
||||
|
||||
fun getLatestPosts(context: Context, callback: (List<BlogPost>) -> (Unit)) { |
||||
|
||||
val queue = Volley.newRequestQueue(context) |
||||
|
||||
val jsonObjectRequest = JsonArrayRequest( |
||||
Request.Method.GET, tipsLastPostsURL, null, |
||||
{ response -> |
||||
// Timber.d("posts = $response") |
||||
callback(response.toBlogPosts()) |
||||
}, |
||||
{ error -> |
||||
Timber.w("Error while retrieving blog posts: $error") |
||||
} |
||||
) |
||||
|
||||
queue.add(jsonObjectRequest) |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
package net.pokeranalytics.android.model.blogpost |
||||
|
||||
import com.google.gson.annotations.SerializedName |
||||
|
||||
class BlogPost { |
||||
|
||||
@SerializedName("id") |
||||
var id: Int = 0 |
||||
|
||||
@SerializedName("level") |
||||
var content: String = "" |
||||
|
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24" |
||||
android:viewportHeight="24"> |
||||
<path |
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM11,19.93c-3.95,-0.49 -7,-3.85 -7,-7.93 0,-0.62 0.08,-1.21 0.21,-1.79L9,15v1c0,1.1 0.9,2 2,2v1.93zM17.9,17.39c-0.26,-0.81 -1,-1.39 -1.9,-1.39h-1v-3c0,-0.55 -0.45,-1 -1,-1L8,12v-2h2c0.55,0 1,-0.45 1,-1L11,7h2c1.1,0 2,-0.9 2,-2v-0.41c2.93,1.19 5,4.06 5,7.41 0,2.08 -0.8,3.97 -2.1,5.39z" |
||||
android:fillColor="#000000"/> |
||||
</vector> |
||||
Loading…
Reference in new issue