From 27c55e59a1d5b294322436e50176c9138ed54279 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 31 Oct 2022 21:28:11 +0100 Subject: [PATCH] Cleaning still. --- .../android/adapters/ItemCardAdapter.kt | 7 ++-- .../android/adapters/ItemListAdapter.kt | 2 +- .../android/fragments/ArticleFragment.kt | 2 +- androidApp/src/test/kotlin/DatesTest.kt | 7 ++-- .../readerforselfossv2/utils/DateUtils.kt | 35 ++++++++++--------- .../readerforselfossv2/model/SelfossModel.kt | 4 +-- .../repository/RepositoryImpl.kt | 3 +- .../service/SearchService.kt | 27 -------------- .../readerforselfossv2/utils/DateUtils.kt | 13 +++---- .../readerforselfossv2/utils/DateUtils.kt | 13 +++---- .../readerforselfossv2/utils/DateUtils.kt | 12 ++++--- 11 files changed, 48 insertions(+), 77 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SearchService.kt diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index fa26bf4..cb2dcae 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -10,9 +10,12 @@ import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString -import bou.amine.apps.readerforselfossv2.android.utils.* +import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable +import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask +import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl +import bou.amine.apps.readerforselfossv2.android.utils.shareLink import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService @@ -59,7 +62,7 @@ class ItemCardAdapter( binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) - binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils) + binding.sourceTitleAndDate.text = itm.sourceAndDateText() if (!appSettingsService.isFullHeightCardsEnabled()) { binding.itemImage.maxHeight = imageMaxHeight diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index de6e91e..116c1e5 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -51,7 +51,7 @@ class ItemListAdapter( binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) - binding.sourceTitleAndDate.text = itm.sourceAndDateText(repository.dateUtils) + binding.sourceTitleAndDate.text = itm.sourceAndDateText() if (itm.getThumbnail(repository.baseUrl).isEmpty()) { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index cebefc9..5773335 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -101,7 +101,7 @@ class ArticleFragment : Fragment(), DIAware { contentText = item.content contentTitle = item.title.getHtmlDecoded() contentImage = item.getThumbnail(repository.baseUrl) - contentSource = item.sourceAndDateText(repository.dateUtils) + contentSource = item.sourceAndDateText() allImages = item.getImages() fontSize = appSettingsService.getFontSize() diff --git a/androidApp/src/test/kotlin/DatesTest.kt b/androidApp/src/test/kotlin/DatesTest.kt index 67d88d3..ad29ec7 100644 --- a/androidApp/src/test/kotlin/DatesTest.kt +++ b/androidApp/src/test/kotlin/DatesTest.kt @@ -1,8 +1,6 @@ package bou.amine.apps.readerforselfossv2.repository -import bou.amine.apps.readerforselfossv2.service.AppSettingsService import bou.amine.apps.readerforselfossv2.utils.DateUtils -import io.mockk.mockk import junit.framework.TestCase.assertEquals import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone @@ -10,14 +8,13 @@ import kotlinx.datetime.toInstant import org.junit.Test class DatesTest { - private val dateUtils: DateUtils = DateUtils() private val v3Date = "2013-04-07T13:43:00+01:00" private val v4Date = "2013-04-07 13:43:00" @Test fun v3_date_should_be_parsed() { - val date = dateUtils.parseDate(v3Date) + val date = DateUtils.parseDate(v3Date) val expected = LocalDateTime(2013, 4, 7, 13, 43, 0, 0).toInstant(TimeZone.of("UTC+1")) .toEpochMilliseconds() assertEquals(date, expected) @@ -25,7 +22,7 @@ class DatesTest { @Test fun v4_date_should_be_parsed() { - val date = dateUtils.parseDate(v4Date) + val date = DateUtils.parseDate(v4Date) val expected = LocalDateTime(2013, 4, 7, 13, 43, 0, 0).toInstant(TimeZone.currentSystemDefault()) .toEpochMilliseconds() diff --git a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index ef09558..3cde9e2 100644 --- a/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/androidMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -5,24 +5,25 @@ import kotlinx.datetime.* actual class DateUtils { + actual companion object { + actual fun parseDate(dateString: String): Long { + return try { + Instant.parse(dateString).toEpochMilliseconds() + } catch (e: Exception) { + LocalDateTime.parse(dateString.replace(" ", "T")).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() + } + } - actual fun parseDate(dateString: String): Long { - return try { - Instant.parse(dateString).toEpochMilliseconds() - } catch (e: Exception) { - LocalDateTime.parse(dateString.replace(" ", "T")).toInstant(TimeZone.currentSystemDefault()).toEpochMilliseconds() + actual fun parseRelativeDate(dateString: String): String { + + val date = parseDate(dateString) + + return " " + DateUtils.getRelativeTimeSpanString( + date, + Clock.System.now().toEpochMilliseconds(), + DateUtils.MINUTE_IN_MILLIS, + DateUtils.FORMAT_ABBREV_RELATIVE + ) } } - - actual fun parseRelativeDate(dateString: String): String { - - val date = parseDate(dateString) - - return " " + DateUtils.getRelativeTimeSpanString( - date, - Clock.System.now().toEpochMilliseconds(), - DateUtils.MINUTE_IN_MILLIS, - DateUtils.FORMAT_ABBREV_RELATIVE - ) - } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index e30d260..591ccdb 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -108,8 +108,8 @@ class SelfossModel { return stringUrl } - fun sourceAndDateText(dateUtils: DateUtils): String = - this.sourcetitle.getHtmlDecoded() + dateUtils.parseRelativeDate(this.datetime) + fun sourceAndDateText(): String = + this.sourcetitle.getHtmlDecoded() + DateUtils.parseRelativeDate(this.datetime) fun toggleStar(): Item { this.starred = !this.starred diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index bf48211..9b3b1ff 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -18,7 +18,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap var connectionMonitored = false var baseUrl = appSettingsService.getBaseUrl() - var dateUtils: DateUtils = DateUtils() var displayedItems = ItemType.UNREAD @@ -74,7 +73,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap if (fetchedItems.success && fetchedItems.data != null) { items = ArrayList(fetchedItems.data!!) if (fromDB) { - items.sortByDescending { dateUtils.parseDate(it.datetime) } + items.sortByDescending { DateUtils.parseDate(it.datetime) } } } return items diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SearchService.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SearchService.kt deleted file mode 100644 index 0530104..0000000 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SearchService.kt +++ /dev/null @@ -1,27 +0,0 @@ -package bou.amine.apps.readerforselfossv2.service - -import bou.amine.apps.readerforselfossv2.utils.DateUtils - -class SearchService(val dateUtils: DateUtils) { - var displayedItems: String = "unread" - set(value) { - field = when (value) { - "all" -> "all" - "unread" -> "unread" - "read" -> "read" - "starred" -> "starred" - else -> "all" - } - } - - var position = 0 - var searchFilter: String? = null - var sourceIDFilter: Long? = null - var sourceFilter: String? = null - var tagFilter: String? = null - var itemsCaching = false - - var badgeUnread = -1 - var badgeAll = -1 - var badgeStarred = -1 -} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 9856726..0645a66 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -1,14 +1,9 @@ package bou.amine.apps.readerforselfossv2.utils -import bou.amine.apps.readerforselfossv2.model.SelfossModel -import bou.amine.apps.readerforselfossv2.service.AppSettingsService - - -fun SelfossModel.Item.parseDate(dateUtils: DateUtils): Long = - dateUtils.parseDate(this.datetime) - expect class DateUtils() { - fun parseDate(dateString: String): Long + companion object { + fun parseDate(dateString: String): Long - fun parseRelativeDate(dateString: String): String + fun parseRelativeDate(dateString: String): String + } } diff --git a/shared/src/iosArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/iosArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 8ee7f57..f611167 100644 --- a/shared/src/iosArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/iosArm64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -1,12 +1,13 @@ package bou.amine.apps.readerforselfossv2.utils actual class DateUtils { - actual fun parseDate(dateString: String): Long { - TODO("Not yet implemented") - } + actual companion object { + actual fun parseDate(dateString: String): Long { + TODO("Not yet implemented") + } - actual fun parseRelativeDate(dateString: String): String { - TODO("Not yet implemented") + actual fun parseRelativeDate(dateString: String): String { + TODO("Not yet implemented") + } } - } \ No newline at end of file diff --git a/shared/src/iosX64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt b/shared/src/iosX64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt index 76ef202..df6a812 100644 --- a/shared/src/iosX64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt +++ b/shared/src/iosX64Main/kotlin/bou/amine/apps/readerforselfossv2/utils/DateUtils.kt @@ -3,12 +3,14 @@ package bou.amine.apps.readerforselfossv2.utils import bou.amine.apps.readerforselfossv2.service.AppSettingsService actual class DateUtils { - actual fun parseDate(dateString: String): Long { - TODO("Not yet implemented") - } + actual companion object { + actual fun parseDate(dateString: String): Long { + TODO("Not yet implemented") + } - actual fun parseRelativeDate(dateString: String): String { - TODO("Not yet implemented") + actual fun parseRelativeDate(dateString: String): String { + TODO("Not yet implemented") + } } } \ No newline at end of file