Don't regenerate dateutils each time it's needed

This commit is contained in:
davide 2022-08-13 18:00:51 +02:00
parent 3e97ee30a1
commit 88c5c6ff4b

View File

@ -18,6 +18,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
set(value) { field = ArrayList(value) }
override var baseUrl = apiDetails.getBaseUrl()
private lateinit var dateUtils: DateUtils
override var displayedItems = "unread"
set(value) {
@ -48,6 +49,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
CoroutineScope(Dispatchers.Main).launch {
updateApiVersion()
dateUtils = DateUtils(apiMajorVersion)
reloadBadges()
}
}
@ -94,7 +96,6 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
}
private fun sortItems(items: ArrayList<SelfossModel.Item>) {
val dateUtils = DateUtils(apiMajorVersion)
items.sortByDescending { dateUtils.parseDate(it.datetime) }
}