Compare commits

...

5 Commits

3 changed files with 48 additions and 22 deletions

View File

@ -92,7 +92,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var displayUnreadCount = false
private var displayAllCount = false
private var fullHeightCards: Boolean = false
private var apiVersionMajor: Int = 0
private var itemsNumber: Int = 200
private var elementsShown: Int = 0
private var maybeTagFilter: Tag? = null
@ -109,7 +108,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var periodicRefresh = false
private var refreshMinutes: Long = 360L
private var refreshWhenChargingOnly = false
private var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
private lateinit var tabNewBadge: TextBadgeItem
private lateinit var tabArchiveBadge: TextBadgeItem
@ -196,12 +194,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
handleSharedPrefs()
getApiMajorVersion()
if (apiVersionMajor > 2) {
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
}
getElementsAccordingToTab()
}
@ -419,19 +411,6 @@ 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() {
super.onStop()
customTabActivityHelper.unbindCustomTabsService(this)

View File

@ -3,12 +3,15 @@ package apps.amine.bou.readerforselfoss
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.SharedPreferences
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.preference.PreferenceManager
import android.widget.ImageView
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.glide.loadMaybeBasicAuth
import com.bumptech.glide.Glide
@ -16,10 +19,20 @@ import com.bumptech.glide.request.RequestOptions
import com.ftinc.scoop.Scoop
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.UUID.randomUUID
var dateTimeFormatter = "yyyy-MM-dd HH:mm:ss"
class MyApp : MultiDexApplication() {
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() {
super.onCreate()
@ -39,6 +52,19 @@ class MyApp : MultiDexApplication() {
tryToHandleBug()
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() {
@ -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"
}
}
})
}
}

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.text.format.DateUtils
import apps.amine.bou.readerforselfoss.api.selfoss.Item
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossTagType
import apps.amine.bou.readerforselfoss.dateTimeFormatter
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
@ -22,7 +23,7 @@ fun String.toTextDrawableString(c: Context): String {
fun Item.sourceAndDateText(): String {
val formattedDate: String = try {
" " + DateUtils.getRelativeTimeSpanString(
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(this.datetime).time,
SimpleDateFormat(dateTimeFormatter).parse(this.datetime).time,
Date().time,
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE