Skip to content

Commit

Permalink
Fixed some crashes related to article viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jun 6, 2024
1 parent 8ac5fa6 commit 57490d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nononsenseapps.feeder.model.html

import com.nononsenseapps.feeder.util.logDebug

class LinearTextBuilder : Appendable {
private data class MutableRange<T>(
val item: T,
Expand Down Expand Up @@ -125,12 +127,23 @@ class LinearTextBuilder : Appendable {
text = trimmed,
blockStyle = blockStyle,
annotations =
annotations.map {
LinearTextAnnotation(
data = it.item,
start = it.start.coerceAtMost(trimmed.lastIndex),
end = (it.end ?: text.lastIndex).coerceAtMost(trimmed.lastIndex),
)
annotations.mapNotNull {
val start = it.start.coerceAtMost(trimmed.lastIndex)
val end = (it.end ?: text.lastIndex).coerceAtMost(trimmed.lastIndex)

if (start < 0 || end < 0 || start > end) {
// This can happen if the link encloses an image for example
logDebug(LOG_TAG, "Ignoring ${it.item} start: $start, end: $end")
null
} else {
LinearTextAnnotation(
data = it.item,
start = start,
end = end,
).also {
logDebug(LOG_TAG, "$it")
}
}
},
)
}
Expand Down Expand Up @@ -159,6 +172,10 @@ class LinearTextBuilder : Appendable {
}
return null
}

companion object {
private const val LOG_TAG = "FEEDER_LINEARTB"
}
}

fun LinearTextBuilder.isEmpty() = lastTwoChars.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -109,7 +108,6 @@ import com.nononsenseapps.feeder.ui.compose.theme.hasImageAspectRatioInReader
import com.nononsenseapps.feeder.ui.compose.utils.ProvideScaledText
import com.nononsenseapps.feeder.ui.compose.utils.WithAllPreviewProviders
import com.nononsenseapps.feeder.ui.compose.utils.focusableInNonTouchMode
import com.nononsenseapps.feeder.util.logDebug
import kotlin.math.abs

fun LazyListScope.linearArticleContent(
Expand Down Expand Up @@ -464,10 +462,6 @@ fun LinearImageContent(
}
}

SideEffect {
logDebug("JONAS", "imgUri ${bestImage.imgUri}")
}

AsyncImage(
model =
ImageRequest.Builder(LocalContext.current)
Expand Down

0 comments on commit 57490d9

Please sign in to comment.