Compare commits
6 Commits
master
...
dateFormat
Author | SHA1 | Date | |
---|---|---|---|
1c57435f54 | |||
4bb20a75d7 | |||
1f20e19a97 | |||
9b372a45ce | |||
f4f8503037 | |||
5b70ae138e |
@ -108,7 +108,6 @@ 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 lateinit var tabNewBadge: TextBadgeItem
|
private lateinit var tabNewBadge: TextBadgeItem
|
||||||
private lateinit var tabArchiveBadge: TextBadgeItem
|
private lateinit var tabArchiveBadge: TextBadgeItem
|
||||||
|
@ -3,12 +3,15 @@ package apps.amine.bou.readerforselfoss
|
|||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.multidex.MultiDexApplication
|
import androidx.multidex.MultiDexApplication
|
||||||
|
import apps.amine.bou.readerforselfoss.api.selfoss.ApiVersion
|
||||||
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||||
import apps.amine.bou.readerforselfoss.utils.Config
|
import apps.amine.bou.readerforselfoss.utils.Config
|
||||||
import apps.amine.bou.readerforselfoss.utils.glide.loadMaybeBasicAuth
|
import apps.amine.bou.readerforselfoss.utils.glide.loadMaybeBasicAuth
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
@ -16,10 +19,20 @@ import com.bumptech.glide.request.RequestOptions
|
|||||||
import com.ftinc.scoop.Scoop
|
import com.ftinc.scoop.Scoop
|
||||||
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||||
|
import retrofit2.Call
|
||||||
|
import retrofit2.Callback
|
||||||
|
import retrofit2.Response
|
||||||
import java.util.UUID.randomUUID
|
import java.util.UUID.randomUUID
|
||||||
|
|
||||||
|
var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
|
||||||
|
|
||||||
class MyApp : MultiDexApplication() {
|
class MyApp : MultiDexApplication() {
|
||||||
private lateinit var config: Config
|
private lateinit var config: Config
|
||||||
|
private lateinit var api: SelfossApi
|
||||||
|
private lateinit var settings: SharedPreferences
|
||||||
|
private lateinit var sharedPref: SharedPreferences
|
||||||
|
|
||||||
|
private var apiVersionMajor: Int = 0
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
@ -39,6 +52,19 @@ class MyApp : MultiDexApplication() {
|
|||||||
tryToHandleBug()
|
tryToHandleBug()
|
||||||
|
|
||||||
handleNotificationChannels()
|
handleNotificationChannels()
|
||||||
|
|
||||||
|
sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
apiVersionMajor = sharedPref.getInt("apiVersionMajor", 0)
|
||||||
|
settings = getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
api = SelfossApi(
|
||||||
|
this,
|
||||||
|
null,
|
||||||
|
settings.getBoolean("isSelfSignedCert", false),
|
||||||
|
sharedPref.getString("api_timeout", "-1")!!.toLong()
|
||||||
|
)
|
||||||
|
|
||||||
|
getApiMajorVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleNotificationChannels() {
|
private fun handleNotificationChannels() {
|
||||||
@ -103,4 +129,24 @@ class MyApp : MultiDexApplication() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getApiMajorVersion() {
|
||||||
|
api.apiVersion.enqueue(object : Callback<ApiVersion> {
|
||||||
|
override fun onFailure(call: Call<ApiVersion>, t: Throwable) {
|
||||||
|
if (apiVersionMajor >= 4) {
|
||||||
|
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call<ApiVersion>, response: Response<ApiVersion>) {
|
||||||
|
val version = response.body() as ApiVersion
|
||||||
|
apiVersionMajor = version.getApiMajorVersion()
|
||||||
|
sharedPref.edit().putInt("apiVersionMajor", apiVersionMajor).commit()
|
||||||
|
|
||||||
|
if (apiVersionMajor >= 4) {
|
||||||
|
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
@ -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)
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
|
||||||
|
import apps.amine.bou.readerforselfoss.dateTimeFormatter
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -22,7 +23,7 @@ fun String.toTextDrawableString(c: Context): String {
|
|||||||
fun Item.sourceAndDateText(): String {
|
fun Item.sourceAndDateText(): String {
|
||||||
val formattedDate: String = try {
|
val formattedDate: String = try {
|
||||||
" " + DateUtils.getRelativeTimeSpanString(
|
" " + DateUtils.getRelativeTimeSpanString(
|
||||||
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime).time,
|
SimpleDateFormat(dateTimeFormatter).parse(this.datetime).time,
|
||||||
Date().time,
|
Date().time,
|
||||||
DateUtils.MINUTE_IN_MILLIS,
|
DateUtils.MINUTE_IN_MILLIS,
|
||||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||||
|
Loading…
Reference in New Issue
Block a user