Move api check to MyApp.
This commit is contained in:
parent
1f20e19a97
commit
4bb20a75d7
@ -92,7 +92,6 @@ 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
|
||||||
@ -195,8 +194,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
|
|
||||||
handleSharedPrefs()
|
handleSharedPrefs()
|
||||||
|
|
||||||
getApiMajorVersion()
|
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
getElementsAccordingToTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,23 +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()
|
|
||||||
|
|
||||||
if (apiVersionMajor > 2) {
|
|
||||||
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
customTabActivityHelper.unbindCustomTabsService(this)
|
customTabActivityHelper.unbindCustomTabsService(this)
|
||||||
|
@ -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,12 +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"
|
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()
|
||||||
@ -41,6 +52,18 @@ class MyApp : MultiDexApplication() {
|
|||||||
tryToHandleBug()
|
tryToHandleBug()
|
||||||
|
|
||||||
handleNotificationChannels()
|
handleNotificationChannels()
|
||||||
|
|
||||||
|
sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
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() {
|
||||||
@ -105,4 +128,20 @@ class MyApp : MultiDexApplication() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
if (apiVersionMajor >= 4) {
|
||||||
|
dateTimeFormatter = "yyyy-MM-dd'T'HH:mm:ssXXX"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user