Skip to content

Commit

Permalink
[1.32.*] Pre-release merge (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Jan 6, 2024
2 parents a10c00a + f388291 commit 8ca0af2
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android_prod_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- name: Configure Tramline
id: tramline
uses: tramlinehq/[email protected].5
uses: tramlinehq/[email protected].6
with:
input: ${{ github.event.inputs.tramline-input }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios_prod_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- name: Configure Tramline
id: tramline
uses: tramlinehq/[email protected].5
uses: tramlinehq/[email protected].6
with:
input: ${{ github.event.inputs.tramline-input }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package dev.sasikanth.rss.reader.core.network.parser

import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoField
import java.time.temporal.UnsupportedTemporalTypeException
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDateTime
import kotlinx.datetime.toJavaZoneId
import kotlinx.datetime.toLocalDateTime

private val dateFormatters =
listOf(
Expand All @@ -45,13 +47,15 @@ private val dateFormatters =
)

@Throws(DateTimeFormatException::class)
internal actual fun String?.dateStringToEpochMillis(): Long? {
internal actual fun String?.dateStringToEpochMillis(clock: Clock): Long? {
if (this.isNullOrBlank()) return null

val currentDate =
clock.now().toLocalDateTime(TimeZone.currentSystemDefault()).toJavaLocalDateTime()

for (dateFormatter in dateFormatters) {
try {
val parsedValue = dateFormatter.parse(this)
val currentDate = LocalDateTime.now()

val year =
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package dev.sasikanth.rss.reader.core.network.parser

internal expect fun String?.dateStringToEpochMillis(): Long?
import kotlinx.datetime.Clock

internal expect fun String?.dateStringToEpochMillis(clock: Clock = Clock.System): Long?

data class DateTimeFormatException(val exception: Exception) : Exception()
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,40 @@ import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlHandler
internal class HtmlContentParser(private val onEnd: (HtmlContent) -> Unit) : KsoupHtmlHandler {

private val contentStringBuilder = StringBuilder()
private val currentData: MutableMap<String, String> = mutableMapOf()
private var currentTag: String? = null
private var imageUrl: String? = null

private var currentTagsStack: ArrayDeque<String> = ArrayDeque()

private val allowedContentTags = setOf("p", "a", "span", "em", "u", "b", "i", "strong")

override fun onText(text: String) {
when (currentTag) {
"p" -> contentStringBuilder.append("\n" + text.cleanWhitespaces())
"a",
"span",
"em",
"u",
"b",
"i",
"strong" -> {
contentStringBuilder.append(text.cleanWhitespaces())
}
val tag = currentTagsStack.firstOrNull()
if (tag in allowedContentTags || tag.isNullOrBlank()) {
contentStringBuilder.append(text.cleanWhitespaces())
}

currentData["content"] = contentStringBuilder.toString()
}

override fun onOpenTag(name: String, attributes: Map<String, String>, isImplied: Boolean) {
currentTag = name
when {
currentTag == "img" &&
attributes.containsKey("src") &&
!currentData.containsKey("imageUrl") -> {
val imageUrl = attributes["src"].toString()
if (!imageUrl.endsWith(".gif")) {
currentData["imageUrl"] = imageUrl
}
}
currentTagsStack.addFirst(name)

if (name == "p" || name == "br") {
contentStringBuilder.appendLine()
}

val srcAttr = attributes["src"].orEmpty()
if (
name == "img" && imageUrl.isNullOrBlank() && srcAttr.isNotBlank() && !srcAttr.endsWith(".gif")
) {
this.imageUrl = srcAttr
}
}

override fun onCloseTag(name: String, isImplied: Boolean) {
currentTagsStack.removeFirst()
}

override fun onEnd() {
onEnd(
HtmlContent(
imageUrl = currentData["imageUrl"],
content = currentData["content"].orEmpty().trim()
)
)
currentData.clear()
onEnd(HtmlContent(imageUrl = imageUrl, content = contentStringBuilder.toString()))
}

private fun String.cleanWhitespaces(): String {
Expand All @@ -76,6 +68,6 @@ internal class HtmlContentParser(private val onEnd: (HtmlContent) -> Unit) : Kso
}
return formattedText
}
}

internal data class HtmlContent(val imageUrl: String?, val content: String)
data class HtmlContent(val imageUrl: String?, val content: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DateTimeFormattersTest {
val epochMillis =
dates.map {
try {
it.dateStringToEpochMillis()
it.dateStringToEpochMillis(clock = TestClock)
} catch (e: Exception) {
// no-op
}
Expand All @@ -88,7 +88,7 @@ class DateTimeFormattersTest {
val invalidDate = "Invalid date"

// when
val epochMillis = invalidDate.dateStringToEpochMillis()
val epochMillis = invalidDate.dateStringToEpochMillis(clock = TestClock)

// then
assertEquals(null, epochMillis)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sasikanth.rss.reader.core.network.parser

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.Month
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant

object TestClock : Clock {

override fun now(): Instant {
return LocalDateTime(
year = 2023,
month = Month.JANUARY,
dayOfMonth = 1,
hour = 8,
minute = 0,
)
.toInstant(TimeZone.UTC)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package dev.sasikanth.rss.reader.core.network.parser

import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toNSDate
import kotlinx.datetime.toNSTimeZone
import platform.Foundation.NSCalendar
import platform.Foundation.NSCalendarIdentifierGregorian
Expand All @@ -27,7 +29,6 @@ import platform.Foundation.NSCalendarUnitMonth
import platform.Foundation.NSCalendarUnitNanosecond
import platform.Foundation.NSCalendarUnitSecond
import platform.Foundation.NSCalendarUnitYear
import platform.Foundation.NSDate
import platform.Foundation.NSDateFormatter
import platform.Foundation.NSLocale
import platform.Foundation.timeIntervalSince1970
Expand Down Expand Up @@ -68,7 +69,7 @@ private val dateFormatters =
)

@Throws(DateTimeFormatException::class)
internal actual fun String?.dateStringToEpochMillis(): Long? {
internal actual fun String?.dateStringToEpochMillis(clock: Clock): Long? {
if (this.isNullOrBlank()) return null

try {
Expand All @@ -78,7 +79,7 @@ internal actual fun String?.dateStringToEpochMillis(): Long? {
}

if (date != null) {
val currentDate = NSDate()
val currentDate = clock.now().toNSDate()
val calendar = NSCalendar(NSCalendarIdentifierGregorian)

val currentYear = calendar.component(NSCalendarUnitYear, currentDate)
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.9.21"
android_gradle_plugin = "8.2.0"
android_gradle_plugin = "8.2.1"
compose = "1.5.11"

android_sdk_compile = "34"
Expand All @@ -9,7 +9,7 @@ android_sdk_min = "26"

sqldelight = "2.0.1"
ktor = "2.3.7"
napier = "2.6.1"
napier = "2.7.1"
kotlinx_coroutines = "1.7.3"
kotlinx_date_time = "0.5.0"
kotlinx_immutable_collections = "0.3.7"
Expand All @@ -31,7 +31,7 @@ ktfmt = "0.44"
kotlininject = "0.6.3"
ksp = "1.9.21-1.0.16"
material_color_utilities = "1.0.0-alpha01"
ksoup = "0.3.0"
ksoup = "0.3.1"
sentry = "0.3.0"
sentry_android = "4.1.1"
buildKonfig = "0.15.1"
Expand Down

0 comments on commit 8ca0af2

Please sign in to comment.