From 6af2f62b32d9005b8c74acee6ad76eb4b0a5501f Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Tue, 6 Aug 2024 18:05:06 +0200 Subject: [PATCH] Add New feed intent filter --- app/src/main/AndroidManifest.xml | 6 +++ .../java/com/readrops/app/MainActivity.kt | 21 ++++++---- .../com/readrops/app/feeds/FeedScreenModel.kt | 41 +++++++++++-------- .../java/com/readrops/app/feeds/FeedState.kt | 2 +- .../java/com/readrops/app/feeds/FeedTab.kt | 23 +++++++++-- .../java/com/readrops/app/home/HomeScreen.kt | 5 +++ app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 71 insertions(+), 29 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ace96e8a..47229776 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,6 +38,12 @@ + + + + + + ().accountDao() - .updateCurrentAccount(accountId) + when { + intent.hasExtra(SyncWorker.ACCOUNT_ID_KEY) -> { + val accountId = intent.getIntExtra(SyncWorker.ACCOUNT_ID_KEY, -1) + get().accountDao() + .updateCurrentAccount(accountId) - HomeScreen.openTab(TimelineTab) + HomeScreen.openTab(TimelineTab) - if (intent.hasExtra(SyncWorker.ITEM_ID_KEY)) { - val itemId = intent.getIntExtra(SyncWorker.ITEM_ID_KEY, -1) - HomeScreen.openItemScreen(itemId) + if (intent.hasExtra(SyncWorker.ITEM_ID_KEY)) { + val itemId = intent.getIntExtra(SyncWorker.ITEM_ID_KEY, -1) + HomeScreen.openItemScreen(itemId) + } + } + intent.action != null && intent.action == Intent.ACTION_SEND -> { + HomeScreen.openAddFeedDialog(intent.getStringExtra(Intent.EXTRA_TEXT).orEmpty()) } } } diff --git a/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt b/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt index bb2cf641..266c94ab 100644 --- a/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt +++ b/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt @@ -167,24 +167,31 @@ class FeedScreenModel( } fun openDialog(state: DialogState) { - if (state is DialogState.UpdateFeed) { - _updateFeedDialogState.update { - it.copy( - feedId = state.feed.id, - feedName = state.feed.name!!, - feedUrl = state.feed.url!!, - selectedFolder = state.folder ?: it.folders.find { folder -> folder.id == 0 }, - feedRemoteId = state.feed.remoteId - ) + when (state) { + is DialogState.UpdateFeed -> { + _updateFeedDialogState.update { + it.copy( + feedId = state.feed.id, + feedName = state.feed.name!!, + feedUrl = state.feed.url!!, + selectedFolder = state.folder ?: it.folders.find { folder -> folder.id == 0 }, + feedRemoteId = state.feed.remoteId + ) + } } - } - - if (state is DialogState.UpdateFolder) { - _folderState.update { - it.copy( - value = state.folder.name.orEmpty() - ) + is DialogState.UpdateFolder -> { + _folderState.update { + it.copy( + value = state.folder.name.orEmpty() + ) + } } + is DialogState.AddFeed -> { + _addFeedDialogState.update { + it.copy(url = state.url.orEmpty()) + } + } + else -> {} } _feedState.update { it.copy(dialog = state) } @@ -308,7 +315,7 @@ class FeedScreenModel( ) if (errors.isEmpty()) { - closeDialog(DialogState.AddFeed) + closeDialog(_feedState.value.dialog) } else { _addFeedDialogState.update { it.copy( diff --git a/app/src/main/java/com/readrops/app/feeds/FeedState.kt b/app/src/main/java/com/readrops/app/feeds/FeedState.kt index 74a2f4f7..9a38a8ed 100644 --- a/app/src/main/java/com/readrops/app/feeds/FeedState.kt +++ b/app/src/main/java/com/readrops/app/feeds/FeedState.kt @@ -14,7 +14,7 @@ data class FeedState( ) sealed interface DialogState { - data object AddFeed : DialogState + data class AddFeed(val url: String? = null) : DialogState data object AddFolder : DialogState class DeleteFeed(val feed: Feed) : DialogState class DeleteFolder(val folder: Folder) : DialogState diff --git a/app/src/main/java/com/readrops/app/feeds/FeedTab.kt b/app/src/main/java/com/readrops/app/feeds/FeedTab.kt index 86ba280e..71d34aee 100644 --- a/app/src/main/java/com/readrops/app/feeds/FeedTab.kt +++ b/app/src/main/java/com/readrops/app/feeds/FeedTab.kt @@ -1,5 +1,6 @@ package com.readrops.app.feeds +import android.util.Patterns import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -53,9 +54,13 @@ import com.readrops.app.util.components.dialog.TextFieldDialog import com.readrops.app.util.components.dialog.TwoChoicesDialog import com.readrops.app.util.theme.spacing import com.readrops.db.entities.Feed +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.receiveAsFlow object FeedTab : Tab { + private val addFeedDialogChannel = Channel() + override val options: TabOptions @Composable get() = TabOptions( @@ -84,6 +89,15 @@ object FeedTab : Tab { } } + LaunchedEffect(Unit) { + addFeedDialogChannel.receiveAsFlow() + .collect { url -> + if (Patterns.WEB_URL.matcher(url).matches()) { + screenModel.openDialog(DialogState.AddFeed(url)) + } + } + } + FeedDialogs( state = state, screenModel = screenModel @@ -131,7 +145,7 @@ object FeedTab : Tab { } FloatingActionButton( - onClick = { screenModel.openDialog(DialogState.AddFeed) } + onClick = { screenModel.openDialog(DialogState.AddFeed()) } ) { Icon( imageVector = Icons.Default.Add, @@ -239,10 +253,10 @@ object FeedTab : Tab { AddFeedDialog( state = addFeedDialogState, onValueChange = { screenModel.setAddFeedDialogURL(it) }, - onExpandChange = { screenModel.setAccountDropDownExpanded(it) }, + onExpandChange = { screenModel.setAccountDropDownExpanded(it) }, onAccountClick = { screenModel.setAddFeedDialogSelectedAccount(it) }, onValidate = { screenModel.addFeedDialogValidate() }, - onDismiss = { screenModel.closeDialog(DialogState.AddFeed) }, + onDismiss = { screenModel.closeDialog(DialogState.AddFeed()) }, ) } @@ -325,6 +339,9 @@ object FeedTab : Tab { null -> {} } + } + suspend fun openAddFeedDialog(url: String) { + addFeedDialogChannel.send(url) } } \ No newline at end of file diff --git a/app/src/main/java/com/readrops/app/home/HomeScreen.kt b/app/src/main/java/com/readrops/app/home/HomeScreen.kt index c5a1c4ee..df6cf2fd 100644 --- a/app/src/main/java/com/readrops/app/home/HomeScreen.kt +++ b/app/src/main/java/com/readrops/app/home/HomeScreen.kt @@ -145,4 +145,9 @@ object HomeScreen : AndroidScreen() { suspend fun openTab(tab: Tab) { tabChannel.send(tab) } + + suspend fun openAddFeedDialog(url: String) { + tabChannel.send(FeedTab) + FeedTab.openAddFeedDialog(url) + } } \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f1bbbda7..66c37cc6 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -216,4 +216,5 @@ Bitcoin (copier l\'adresse) Litecoin (copier l\'adresse) "Si vous considérez que mon travail vous est utile et si vous souhaitez me soutenir, vous pouvez me faire une donation. " + Ajouter un flux \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5cd46121..93f50cec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,4 +229,5 @@ Bitcoin (copy address) Litecoin (copy address) I you find my work useful and you would like to support me, you can consider making me a donation. + Add feed \ No newline at end of file