Skip to content

Commit 848b74b

Browse files
Add more infos to share template feature (#299)
1 parent 948d89b commit 848b74b

File tree

8 files changed

+40
-39
lines changed

8 files changed

+40
-39
lines changed

app/src/main/java/com/readrops/app/item/ItemScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class ItemScreen(
133133
context.openInCustomTab(url, state.theme, accentColor)
134134
}
135135
},
136-
onShareItem = { screenModel.shareItem(item, context) },
136+
onShareItem = { screenModel.shareItem(itemWithFeed, context) },
137137
onSetReadState = { screenModel.setItemReadState(item) },
138138
onSetStarState = { screenModel.setItemStarState(item) },
139139
onOpenImageDialog = { screenModel.openImageDialog(it) },

app/src/main/java/com/readrops/app/item/ItemScreenModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ class ItemScreenModel(
356356
return FileProvider.getUriForFile(context, context.packageName, image)
357357
}
358358

359-
fun shareItem(item: Item, context: Context) = Utils.shareItem(
360-
item, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
359+
fun shareItem(itemWithFeed: ItemWithFeed, context: Context) = Utils.shareItem(
360+
itemWithFeed, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
361361
)
362362

363363
override fun onDispose() {

app/src/main/java/com/readrops/app/more/preferences/PreferencesScreenModel.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.readrops.app.more.preferences
22

3+
import android.content.ClipData
34
import android.content.Context
5+
import androidx.room.ColumnInfo
6+
import androidx.room.Embedded
47
import cafe.adriel.voyager.core.model.StateScreenModel
58
import cafe.adriel.voyager.core.model.screenModelScope
69
import com.readrops.app.R
710
import com.readrops.app.util.Preference
811
import com.readrops.app.util.Preferences
912
import com.readrops.db.Database
1013
import com.readrops.db.entities.Item
14+
import com.readrops.db.pojo.ItemWithFeed
15+
import com.readrops.db.queries.ItemSelectionQueryBuilder
1116
import kotlinx.coroutines.CoroutineDispatcher
1217
import kotlinx.coroutines.Dispatchers
1318
import kotlinx.coroutines.flow.combine
@@ -37,7 +42,7 @@ class PreferencesScreenModel(
3742
useCustomShareIntentTpl.flow,
3843
customShareIntentTpl.flow,
3944
swipeToLeft.flow,
40-
swipeToRight.flow
45+
swipeToRight.flow,
4146
)
4247

4348
combine(
@@ -56,16 +61,21 @@ class PreferencesScreenModel(
5661
customShareIntentTpl = (list[9] as String) to customShareIntentTpl,
5762
swipeToLeft = (list[10] as String) to swipeToLeft,
5863
swipeToRight = (list[11] as String) to swipeToRight,
59-
exampleItem = if (database.itemDao().count() > 0) {
60-
database.itemDao().selectFirst()
61-
} else {
62-
Item(
64+
exampleItem = ItemWithFeed(
65+
item = Item(
6366
title = context.getString(R.string.example_item_title),
6467
author = context.getString(R.string.example_item_author),
6568
content = context.getString(R.string.example_item_content),
66-
link = "https://example.org"
67-
)
68-
}
69+
link = "https://example.org/feed1"
70+
),
71+
feedName = "Example feed",
72+
feedId = -1,
73+
color = 0,
74+
feedIconUrl = "https://example.org/icon.webp",
75+
websiteUrl = "https://example.org",
76+
folder = null,
77+
openIn = null,
78+
)
6979
)
7080
}.collect { theme ->
7181
mutableState.update { previous ->
@@ -106,7 +116,7 @@ sealed class PreferencesScreenState {
106116
val customShareIntentTpl: PreferenceState<String>,
107117
val swipeToLeft: PreferenceState<String>,
108118
val swipeToRight: PreferenceState<String>,
109-
val exampleItem: Item,
119+
val exampleItem: ItemWithFeed,
110120
val showDialog: Boolean = false
111121
) : PreferencesScreenState()
112122

app/src/main/java/com/readrops/app/more/preferences/components/CustomShareIntentTextWidget.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ package com.readrops.app.more.preferences.components
33
import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.foundation.layout.Column
55
import androidx.compose.foundation.layout.Row
6-
import androidx.compose.material.icons.Icons
7-
import androidx.compose.material.icons.filled.KeyboardArrowDown
8-
import androidx.compose.material.icons.filled.KeyboardArrowUp
96
import androidx.compose.material3.AlertDialogDefaults
10-
import androidx.compose.material3.Icon
11-
import androidx.compose.material3.IconButton
127
import androidx.compose.material3.MaterialTheme
138
import androidx.compose.material3.Text
149
import androidx.compose.material3.TextButton
@@ -25,7 +20,6 @@ import androidx.compose.ui.Modifier
2520
import androidx.compose.ui.focus.FocusRequester
2621
import androidx.compose.ui.focus.focusRequester
2722
import androidx.compose.ui.graphics.Color
28-
import androidx.compose.ui.platform.LocalContext
2923
import androidx.compose.ui.res.stringResource
3024
import androidx.compose.ui.text.AnnotatedString
3125
import androidx.compose.ui.text.SpanStyle
@@ -38,14 +32,14 @@ import com.readrops.app.util.Preference
3832
import com.readrops.app.util.ShareIntentTextRenderer
3933
import com.readrops.app.util.theme.MediumSpacer
4034
import com.readrops.app.util.theme.ShortSpacer
41-
import com.readrops.db.entities.Item
35+
import com.readrops.db.pojo.ItemWithFeed
4236
import kotlinx.coroutines.launch
4337

4438
@Composable
4539
fun CustomShareIntentTextWidget(
4640
preference: Preference<String>,
4741
template: String,
48-
exampleItem: Item,
42+
exampleItem: ItemWithFeed,
4943
onDismiss: () -> Unit,
5044
) {
5145
var localTemplate by remember { mutableStateOf(template) }
@@ -100,7 +94,7 @@ fun CustomShareIntentTextWidget(
10094
modifier = Modifier.weight(1f),
10195
onClick = {
10296
localTemplate = """
103-
{{ title|remove_author|capitalize }} — {{ author }}
97+
{{ title|remove_author|capitalize }} — {{ feedName }}
10498
10599
{{ url }}
106100
""".trimIndent()

app/src/main/java/com/readrops/app/timelime/TimelineScreenModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ class TimelineScreenModel(
482482
}
483483
}
484484

485-
fun shareItem(item: Item, context: Context) = Utils.shareItem(
486-
item, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
485+
fun shareItem(itemWithFeed: ItemWithFeed, context: Context) = Utils.shareItem(
486+
itemWithFeed, context, useCustomShareIntentTpl.value, customShareIntentTpl.value
487487
)
488488
}
489489

app/src/main/java/com/readrops/app/timelime/TimelineTab.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,7 @@ object TimelineTab : Tab {
348348
screenModel.updateStarState(itemWithFeed.item)
349349
},
350350
onShare = {
351-
screenModel.shareItem(
352-
itemWithFeed.item,
353-
context
354-
)
351+
screenModel.shareItem(itemWithFeed, context)
355352
},
356353
onSetReadState = {
357354
screenModel.updateItemReadState(itemWithFeed.item)

app/src/main/java/com/readrops/app/util/ShareIntentTextRenderer.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.readrops.app.util
22

33
import android.content.Context
44
import androidx.annotation.VisibleForTesting
5-
import androidx.compose.ui.util.fastJoinToString
6-
import com.readrops.db.entities.Item
75
import io.pebbletemplates.pebble.PebbleEngine
86
import io.pebbletemplates.pebble.extension.AbstractExtension
97
import io.pebbletemplates.pebble.extension.Filter
@@ -13,6 +11,7 @@ import io.pebbletemplates.pebble.template.PebbleTemplate
1311
import org.koin.core.component.KoinComponent
1412
import java.io.StringWriter
1513
import com.readrops.app.R
14+
import com.readrops.db.pojo.ItemWithFeed
1615
import org.koin.core.component.get
1716

1817

@@ -84,7 +83,7 @@ class FrenchTypography : DocumentedFilter() {
8483
}
8584
}
8685

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

9998
val context
10099
get() = mapOf(
101-
"title" to item.title,
102-
"author" to item.author,
103-
"url" to item.link,
104-
"content" to item.content
100+
"title" to itemWithFeed.item.title,
101+
"author" to itemWithFeed.item.author,
102+
"url" to itemWithFeed.item.link,
103+
"content" to itemWithFeed.item.content,
104+
"feedName" to itemWithFeed.feedName,
105105
)
106106

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

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

116116
companion object {
117117
private val filters: Map<String, DocumentedFilter> = mapOf(

app/src/main/java/com/readrops/app/util/Utils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import android.content.Context
44
import android.content.Intent
55
import android.graphics.Color
66
import androidx.annotation.ColorInt
7-
import com.readrops.db.entities.Item
7+
import com.readrops.db.pojo.ItemWithFeed
88
import java.util.Locale
99

1010
object Utils {
@@ -41,14 +41,14 @@ object Utils {
4141
}
4242

4343
fun shareItem(
44-
item: Item,
44+
itemWithFeed: ItemWithFeed,
4545
context: Context,
4646
useCustomShareIntentTpl: Boolean,
4747
customShareIntentTpl: String
4848
) {
4949
val intentContent =
50-
if(!useCustomShareIntentTpl || customShareIntentTpl.isBlank()) item.link
51-
else ShareIntentTextRenderer(item).render(customShareIntentTpl)
50+
if(!useCustomShareIntentTpl || customShareIntentTpl.isBlank()) itemWithFeed.item.link
51+
else ShareIntentTextRenderer(itemWithFeed).render(customShareIntentTpl)
5252
Intent().apply {
5353
action = Intent.ACTION_SEND
5454
type = "text/plain"

0 commit comments

Comments
 (0)