Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/com/readrops/app/item/ItemScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ItemScreen(
context.openInCustomTab(url, state.theme, accentColor)
}
},
onShareItem = { screenModel.shareItem(item, context) },
onShareItem = { screenModel.shareItem(itemWithFeed, context) },
onSetReadState = { screenModel.setItemReadState(item) },
onSetStarState = { screenModel.setItemStarState(item) },
onOpenImageDialog = { screenModel.openImageDialog(it) },
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/readrops/app/item/ItemScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ class ItemScreenModel(
return FileProvider.getUriForFile(context, context.packageName, image)
}

fun shareItem(item: Item, context: Context) = Utils.shareItem(
item, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
fun shareItem(itemWithFeed: ItemWithFeed, context: Context) = Utils.shareItem(
itemWithFeed, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
)

override fun onDispose() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.readrops.app.more.preferences

import android.content.ClipData
import android.content.Context
import androidx.room.ColumnInfo
import androidx.room.Embedded
import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import com.readrops.app.R
import com.readrops.app.util.Preference
import com.readrops.app.util.Preferences
import com.readrops.db.Database
import com.readrops.db.entities.Item
import com.readrops.db.pojo.ItemWithFeed
import com.readrops.db.queries.ItemSelectionQueryBuilder
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
Expand Down Expand Up @@ -37,7 +42,7 @@ class PreferencesScreenModel(
useCustomShareIntentTpl.flow,
customShareIntentTpl.flow,
swipeToLeft.flow,
swipeToRight.flow
swipeToRight.flow,
)

combine(
Expand All @@ -56,16 +61,21 @@ class PreferencesScreenModel(
customShareIntentTpl = (list[9] as String) to customShareIntentTpl,
swipeToLeft = (list[10] as String) to swipeToLeft,
swipeToRight = (list[11] as String) to swipeToRight,
exampleItem = if (database.itemDao().count() > 0) {
database.itemDao().selectFirst()
} else {
Comment on lines -59 to -61
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just removing this. Event though using real data makes for a better UX generally speaking, querying an ItemWithFeed is just too difficult from here.

Item(
exampleItem = ItemWithFeed(
item = Item(
title = context.getString(R.string.example_item_title),
author = context.getString(R.string.example_item_author),
content = context.getString(R.string.example_item_content),
link = "https://example.org"
)
}
link = "https://example.org/feed1"
),
feedName = "Example feed",
feedId = -1,
color = 0,
feedIconUrl = "https://example.org/icon.webp",
websiteUrl = "https://example.org",
folder = null,
openIn = null,
)
)
}.collect { theme ->
mutableState.update { previous ->
Expand Down Expand Up @@ -106,7 +116,7 @@ sealed class PreferencesScreenState {
val customShareIntentTpl: PreferenceState<String>,
val swipeToLeft: PreferenceState<String>,
val swipeToRight: PreferenceState<String>,
val exampleItem: Item,
val exampleItem: ItemWithFeed,
val showDialog: Boolean = false
) : PreferencesScreenState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ package com.readrops.app.more.preferences.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.AlertDialogDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
Expand All @@ -25,7 +20,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
Expand All @@ -38,14 +32,14 @@ import com.readrops.app.util.Preference
import com.readrops.app.util.ShareIntentTextRenderer
import com.readrops.app.util.theme.MediumSpacer
import com.readrops.app.util.theme.ShortSpacer
import com.readrops.db.entities.Item
import com.readrops.db.pojo.ItemWithFeed
import kotlinx.coroutines.launch

@Composable
fun CustomShareIntentTextWidget(
preference: Preference<String>,
template: String,
exampleItem: Item,
exampleItem: ItemWithFeed,
onDismiss: () -> Unit,
) {
var localTemplate by remember { mutableStateOf(template) }
Expand Down Expand Up @@ -100,7 +94,7 @@ fun CustomShareIntentTextWidget(
modifier = Modifier.weight(1f),
onClick = {
localTemplate = """
{{ title|remove_author|capitalize }} — {{ author }}
{{ title|remove_author|capitalize }} — {{ feedName }}

{{ url }}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ class TimelineScreenModel(
}
}

fun shareItem(item: Item, context: Context) = Utils.shareItem(
item, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
fun shareItem(itemWithFeed: ItemWithFeed, context: Context) = Utils.shareItem(
itemWithFeed, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
)
}

Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/readrops/app/timelime/TimelineTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ object TimelineTab : Tab {
screenModel.updateStarState(itemWithFeed.item)
},
onShare = {
screenModel.shareItem(
itemWithFeed.item,
context
)
screenModel.shareItem(itemWithFeed, context)
},
onSetReadState = {
screenModel.updateItemReadState(itemWithFeed.item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.readrops.app.util

import android.content.Context
import androidx.annotation.VisibleForTesting
import androidx.compose.ui.util.fastJoinToString
import com.readrops.db.entities.Item
import io.pebbletemplates.pebble.PebbleEngine
import io.pebbletemplates.pebble.extension.AbstractExtension
import io.pebbletemplates.pebble.extension.Filter
Expand All @@ -13,6 +11,7 @@ import io.pebbletemplates.pebble.template.PebbleTemplate
import org.koin.core.component.KoinComponent
import java.io.StringWriter
import com.readrops.app.R
import com.readrops.db.pojo.ItemWithFeed
import org.koin.core.component.get


Expand Down Expand Up @@ -84,7 +83,7 @@ class FrenchTypography : DocumentedFilter() {
}
}

class ShareIntentTextRenderer(private val item: Item): KoinComponent {
class ShareIntentTextRenderer(private val itemWithFeed: ItemWithFeed): KoinComponent {
val documentation by lazy {
filters.entries.joinToString(prefix = "<br/>", separator = ",<br/>") { (key, filter) ->
val str = get<Context>().getString(
Expand All @@ -98,10 +97,11 @@ class ShareIntentTextRenderer(private val item: Item): KoinComponent {

val context
get() = mapOf(
"title" to item.title,
"author" to item.author,
"url" to item.link,
"content" to item.content
"title" to itemWithFeed.item.title,
"author" to itemWithFeed.item.author,
"url" to itemWithFeed.item.link,
"content" to itemWithFeed.item.content,
"feedName" to itemWithFeed.feedName,
)

private fun renderSafe(template: String) = runCatching {
Expand All @@ -111,7 +111,7 @@ class ShareIntentTextRenderer(private val item: Item): KoinComponent {
}

fun renderOrError(template: String) = renderSafe(template).getOrElse { it.toString() }
fun render(template: String) = renderSafe(template).getOrDefault(item.link)
fun render(template: String) = renderSafe(template).getOrDefault(itemWithFeed.item.link)

companion object {
private val filters: Map<String, DocumentedFilter> = mapOf(
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/readrops/app/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import androidx.annotation.ColorInt
import com.readrops.db.entities.Item
import com.readrops.db.pojo.ItemWithFeed
import java.util.Locale

object Utils {
Expand Down Expand Up @@ -41,14 +41,14 @@ object Utils {
}

fun shareItem(
item: Item,
itemWithFeed: ItemWithFeed,
context: Context,
useCustomShareIntentTpl: Boolean,
customShareIntentTpl: String
) {
val intentContent =
if(!useCustomShareIntentTpl || customShareIntentTpl.isBlank()) item.link
else ShareIntentTextRenderer(item).render(customShareIntentTpl)
if(!useCustomShareIntentTpl || customShareIntentTpl.isBlank()) itemWithFeed.item.link
else ShareIntentTextRenderer(itemWithFeed).render(customShareIntentTpl)
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
Expand Down