Cleaning. #88

Merged
AmineB merged 7 commits from cleaning into master 2022-10-31 20:42:23 +00:00
5 changed files with 4 additions and 13 deletions
Showing only changes of commit 7b40a31979 - Show all commits

View File

@ -10,9 +10,7 @@ import kotlinx.datetime.toInstant
import org.junit.Test
class DatesTest {
private val appSettingsService = mockk<AppSettingsService>()
private val dateUtils: DateUtils = DateUtils(appSettingsService)
private val dateUtils: DateUtils = DateUtils()
private val v3Date = "2013-04-07T13:43:00+01:00"
private val v4Date = "2013-04-07 13:43:00"

View File

@ -1,6 +1,5 @@
package bou.amine.apps.readerforselfossv2.repository
import bou.amine.apps.readerforselfossv2.dao.ITEM
import bou.amine.apps.readerforselfossv2.dao.ReaderForSelfossDB
import bou.amine.apps.readerforselfossv2.dao.SOURCE
import bou.amine.apps.readerforselfossv2.dao.TAG

View File

@ -1,12 +1,10 @@
package bou.amine.apps.readerforselfossv2.utils
import android.text.format.DateUtils
import bou.amine.apps.readerforselfossv2.service.AppSettingsService
import kotlinx.datetime.*
import java.time.format.DateTimeFormatter
actual class DateUtils actual constructor(actual val appSettingsService: AppSettingsService) {
actual class DateUtils {
Review

Since DateUtils does not need to store any data, wouldn't it be better to just have it as two expect functions?
In this way we remove the need of instantiating the object within the repository.
Moreover, if I'm not mistaken one of the two is full kotlin and could thus be in the common source.

Since DateUtils does not need to store any data, wouldn't it be better to just have it as two expect functions? In this way we remove the need of instantiating the object within the repository. Moreover, if I'm not mistaken one of the two is full kotlin and could thus be in the common source.
Review

Since DateUtils does not need to store any data, wouldn't it be better to just have it as two expect functions?

It is now.

In this way we remove the need of instantiating the object within the repository.

I cleaned a little bit.

> Since DateUtils does not need to store any data, wouldn't it be better to just have it as two expect functions? It is now. > In this way we remove the need of instantiating the object within the repository. I cleaned a little bit.
actual fun parseDate(dateString: String): Long {
return try {

View File

@ -11,7 +11,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class Repository(private val api: SelfossApi, private val appSettingsService: AppSettingsService, val isConnectionAvailable: MutableStateFlow<Boolean>, private val db: ReaderForSelfossDB) {
@ -19,7 +18,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
var connectionMonitored = false
var baseUrl = appSettingsService.getBaseUrl()
lateinit var dateUtils: DateUtils
var dateUtils: DateUtils = DateUtils()
var displayedItems = ItemType.UNREAD
@ -394,7 +393,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
appSettingsService.updateApiVersion(fetchedVersion.data.getApiMajorVersion())
}
}
dateUtils = DateUtils(appSettingsService)
}
fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride

View File

@ -7,9 +7,7 @@ import bou.amine.apps.readerforselfossv2.service.AppSettingsService
fun SelfossModel.Item.parseDate(dateUtils: DateUtils): Long =
dateUtils.parseDate(this.datetime)
expect class DateUtils constructor(appSettingsService: AppSettingsService) {
val appSettingsService: AppSettingsService // This is needed because of https://stackoverflow.com/a/65249085
expect class DateUtils() {
fun parseDate(dateString: String): Long
fun parseRelativeDate(dateString: String): String