implement a lot of the API, a lot of the plumbing that is required
This commit is contained in:
parent
aa788f9720
commit
b3e4525e85
@ -44,7 +44,6 @@ dependencies {
|
|||||||
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
|
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.7.1'
|
||||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.16'
|
implementation 'io.reactivex.rxjava2:rxjava:2.2.16'
|
||||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||||
|
|
||||||
testImplementation "com.github.tomakehurst:wiremock-jre8:2.26.2"
|
testImplementation "com.github.tomakehurst:wiremock-jre8:2.26.2"
|
||||||
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||||
testImplementation 'junit:junit:4.13'
|
testImplementation 'junit:junit:4.13'
|
||||||
|
@ -14,9 +14,49 @@ import retrofit2.converter.gson.GsonConverterFactory
|
|||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private var statuses: ArrayList<Status>? = null
|
||||||
|
private val BASE_URL = "https://pixelfed.de/"
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
loadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadData() {
|
||||||
|
|
||||||
|
//Define the Retrofit request//
|
||||||
|
|
||||||
|
val pixelfedAPI = Retrofit.Builder()
|
||||||
|
|
||||||
|
//Set the API’s base URL//
|
||||||
|
|
||||||
|
.baseUrl(BASE_URL)
|
||||||
|
|
||||||
|
//Specify the converter factory to use for serialization and deserialization//
|
||||||
|
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
|
||||||
|
//Add a call adapter factory to support RxJava return types//
|
||||||
|
|
||||||
|
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||||
|
|
||||||
|
//Build the Retrofit instance//
|
||||||
|
|
||||||
|
.build().create(PixelfedAPI::class.java)
|
||||||
|
|
||||||
|
pixelfedAPI.timelinePublic(null, null, null, null, null)
|
||||||
|
.enqueue(object : Callback<List<Status>> {
|
||||||
|
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
|
||||||
|
if (response.code() == 200) {
|
||||||
|
Log.e("OK", response.body().toString())
|
||||||
|
statuses = response.body() as ArrayList<Status>?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<List<Status>>, t: Throwable) {
|
||||||
|
Log.e("Ouch, not OK", t.toString())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.h.pixeldroid.api
|
package com.h.pixeldroid.api
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import com.h.pixeldroid.objects.*
|
import com.h.pixeldroid.objects.*
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
|
||||||
import retrofit2.Response
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.h.pixeldroid.objects
|
package com.h.pixeldroid.objects
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Represents a user and their associated profile.
|
Represents a user and their associated profile.
|
||||||
https://docs.joinmastodon.org/entities/account/
|
https://docs.joinmastodon.org/entities/account/
|
||||||
|
@ -7,3 +7,4 @@ data class Application (
|
|||||||
val website: String? = null,
|
val website: String? = null,
|
||||||
val vapid_key: String? = null
|
val vapid_key: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,3 +9,4 @@ data class Emoji(
|
|||||||
//Optional attributes
|
//Optional attributes
|
||||||
val category: String? = null
|
val category: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.h.pixeldroid.objects
|
package com.h.pixeldroid.objects
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Represents a status posted by an account.
|
Represents a status posted by an account.
|
||||||
https://docs.joinmastodon.org/entities/status/
|
https://docs.joinmastodon.org/entities/status/
|
||||||
@ -15,12 +14,12 @@ data class Status(
|
|||||||
val visibility: Visibility,
|
val visibility: Visibility,
|
||||||
val sensitive: Boolean,
|
val sensitive: Boolean,
|
||||||
val spoiler_text: String,
|
val spoiler_text: String,
|
||||||
val media_attachments: List<Attachment>,
|
val media_attachments: ArrayList<Attachment>,
|
||||||
val application: Application,
|
val application: Application,
|
||||||
//Rendering attributes
|
//Rendering attributes
|
||||||
val mentions: List<Mention>,
|
val mentions: ArrayList<Mention>,
|
||||||
val tags: List<Tag>,
|
val tags: ArrayList<Tag>,
|
||||||
val emojis: List<Emoji>,
|
val emojis: ArrayList<Emoji>,
|
||||||
//Informational attributes
|
//Informational attributes
|
||||||
val reblogs_count: Int,
|
val reblogs_count: Int,
|
||||||
val favourites_count: Int,
|
val favourites_count: Int,
|
||||||
|
@ -7,3 +7,4 @@ data class Tag(
|
|||||||
//Optional attributes
|
//Optional attributes
|
||||||
val history: List<History>? = emptyList()
|
val history: List<History>? = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user