Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compose post with shared content #543

Merged
merged 4 commits into from
Nov 19, 2024
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
14 changes: 14 additions & 0 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<!-- alias with traditional icon -->
Expand Down Expand Up @@ -75,6 +82,13 @@

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="text/plain" />
</intent-filter>
</activity-alias>

<!-- Trigger Google Play services to install the backported photo picker module. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import com.livefast.eattrash.raccoonforfriendica.auth.DefaultAuthManager
import com.livefast.eattrash.raccoonforfriendica.core.navigation.BottomNavigationSection
import com.livefast.eattrash.raccoonforfriendica.core.navigation.di.getDetailOpener
import com.livefast.eattrash.raccoonforfriendica.core.navigation.di.getDrawerCoordinator
import com.livefast.eattrash.raccoonforfriendica.core.navigation.di.getNavigationCoordinator
import com.livefast.eattrash.raccoonforfriendica.domain.identity.repository.di.getAuthManager
Expand Down Expand Up @@ -86,15 +87,26 @@ class MainActivity : ComponentActivity() {
)
}

intent.data?.also {
handleIncomingUrl(it)
}
handleIntent(intent)
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intent.data?.also {
handleIncomingUrl(it)
handleIntent(intent)
}

private fun handleIntent(intent: Intent) {
when {
intent.action == Intent.ACTION_SEND ->
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { content ->
val detailOpener = getDetailOpener()
detailOpener.openComposer(initialText = content.trim('"'))
}

else ->
intent.data?.also {
handleIncomingUrl(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class DefaultDetailOpener(
editedPostId: String?,
urlToShare: String?,
inGroup: Boolean,
initialText: String?,
) {
if (!isLogged) {
return
Expand All @@ -226,6 +227,7 @@ class DefaultDetailOpener(
groupHandle = inReplyToUser?.handle.takeIf { isGroup },
editedPostId = editedPostId,
urlToShare = urlToShare,
initialText = initialText,
)
navigationCoordinator.push(screen)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface DetailOpener {
editedPostId: String? = null,
urlToShare: String? = null,
inGroup: Boolean = false,
initialText: String? = null,
)

fun openEditUnpublished(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
Expand Down Expand Up @@ -109,6 +110,7 @@ class ComposerScreen(
private val scheduledPostId: String? = null,
private val draftId: String? = null,
private val urlToShare: String? = null,
private val initialText: String? = null,
) : Screen {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -180,6 +182,14 @@ class ComposerScreen(
!urlToShare.isNullOrEmpty() ->
model.reduce(ComposerMviModel.Intent.AddShareUrl(urlToShare))

!initialText.isNullOrEmpty() ->
model.reduce(
ComposerMviModel.Intent.SetFieldValue(
value = TextFieldValue(text = initialText),
fieldType = ComposerFieldType.Body,
),
)

inReplyToId != null ->
model.reduce(
ComposerMviModel.Intent.AddInitialMentions(initialHandle = inReplyToHandle),
Expand Down