Set date format according to api version.

This commit is contained in:
davidoskky 2021-03-19 15:46:13 +01:00
parent 626c9e2797
commit 5b70ae138e
4 changed files with 40 additions and 1 deletions

View File

@ -92,6 +92,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var displayUnreadCount = false private var displayUnreadCount = false
private var displayAllCount = false private var displayAllCount = false
private var fullHeightCards: Boolean = false private var fullHeightCards: Boolean = false
private var apiVersionMajor: Int = 0
private var itemsNumber: Int = 200 private var itemsNumber: Int = 200
private var elementsShown: Int = 0 private var elementsShown: Int = 0
private var maybeTagFilter: Tag? = null private var maybeTagFilter: Tag? = null
@ -108,7 +109,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var periodicRefresh = false private var periodicRefresh = false
private var refreshMinutes: Long = 360L private var refreshMinutes: Long = 360L
private var refreshWhenChargingOnly = false private var refreshWhenChargingOnly = false
private val dateTimeFormatter = "yyyy-MM-dd HH:mm:ss" private var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
private lateinit var tabNewBadge: TextBadgeItem private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem private lateinit var tabArchiveBadge: TextBadgeItem
@ -195,6 +196,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
handleSharedPrefs() handleSharedPrefs()
getApiMajorVersion()
if (apiVersionMajor > 2) {
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
}
getElementsAccordingToTab() getElementsAccordingToTab()
} }
@ -412,6 +419,19 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
} }
} }
private fun getApiMajorVersion() {
api.apiVersion.enqueue(object : Callback<ApiVersion> {
override fun onFailure(call: Call<ApiVersion>, t: Throwable) {
}
override fun onResponse(call: Call<ApiVersion>, response: Response<ApiVersion>) {
val version = response.body() as ApiVersion
apiVersionMajor = version.getApiMajorVersion()
}
})
}
override fun onStop() { override fun onStop() {
super.onStop() super.onStop()
customTabActivityHelper.unbindCustomTabsService(this) customTabActivityHelper.unbindCustomTabsService(this)

View File

@ -215,6 +215,9 @@ class SelfossApi(
fun update(): Call<String> = fun update(): Call<String> =
service.update(userName, password) service.update(userName, password)
val apiVersion: Call<ApiVersion>
get() = service.version()
val sources: Call<List<Source>> val sources: Call<List<Source>>
get() = service.sources(userName, password) get() = service.sources(userName, password)

View File

@ -48,6 +48,19 @@ data class Spout(
@SerializedName("description") val description: String @SerializedName("description") val description: String
) )
data class ApiVersion(
@SerializedName("version") val version: String,
@SerializedName("apiversion") val apiversion: String
) {
fun getApiMajorVersion() : Int {
var versionNumber = 0
if (apiversion != null) {
versionNumber = apiversion.substringBefore(".").toInt()
}
return versionNumber
}
}
data class Source( data class Source(
@SerializedName("id") val id: String, @SerializedName("id") val id: String,
@SerializedName("title") val title: String, @SerializedName("title") val title: String,

View File

@ -103,6 +103,9 @@ internal interface SelfossService {
@Query("password") password: String @Query("password") password: String
): Call<List<Source>> ): Call<List<Source>>
@GET("api/about")
fun version(): Call<ApiVersion>
@DELETE("source/{id}") @DELETE("source/{id}")
fun deleteSource( fun deleteSource(
@Path("id") id: String, @Path("id") id: String,