mirror of https://github.com/readrops/Readrops.git
Add New feed intent filter
This commit is contained in:
parent
22913aa129
commit
6af2f62b32
|
@ -38,6 +38,12 @@
|
|||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter android:label="@string/add_feed">
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
|
|
|
@ -101,16 +101,21 @@ class MainActivity : ComponentActivity(), KoinComponent {
|
|||
}
|
||||
|
||||
private suspend fun handleIntent(intent: Intent) {
|
||||
if (intent.hasExtra(SyncWorker.ACCOUNT_ID_KEY)) {
|
||||
val accountId = intent.getIntExtra(SyncWorker.ACCOUNT_ID_KEY, -1)
|
||||
get<Database>().accountDao()
|
||||
.updateCurrentAccount(accountId)
|
||||
when {
|
||||
intent.hasExtra(SyncWorker.ACCOUNT_ID_KEY) -> {
|
||||
val accountId = intent.getIntExtra(SyncWorker.ACCOUNT_ID_KEY, -1)
|
||||
get<Database>().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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String>()
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -216,4 +216,5 @@
|
|||
<string name="bitcoin_copy_address">Bitcoin (copier l\'adresse)</string>
|
||||
<string name="litecoin_copy_address">Litecoin (copier l\'adresse)</string>
|
||||
<string name="donation_text">"Si vous considérez que mon travail vous est utile et si vous souhaitez me soutenir, vous pouvez me faire une donation. "</string>
|
||||
<string name="add_feed">Ajouter un flux</string>
|
||||
</resources>
|
|
@ -229,4 +229,5 @@
|
|||
<string name="bitcoin_copy_address">Bitcoin (copy address)</string>
|
||||
<string name="litecoin_copy_address">Litecoin (copy address)</string>
|
||||
<string name="donation_text">I you find my work useful and you would like to support me, you can consider making me a donation.</string>
|
||||
<string name="add_feed">Add feed</string>
|
||||
</resources>
|
Loading…
Reference in New Issue