Skip to content

Commit

Permalink
Merge pull request #87 from adessoTurkey/fix/share
Browse files Browse the repository at this point in the history
Update share context
  • Loading branch information
senaaydin authored Nov 22, 2023
2 parents 75cdfd4 + aa2070c commit 86f3e1f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.example.moveeapp_compose_kmm.core

import android.content.Intent
import android.net.Uri
import androidx.compose.runtime.NoLiveLiterals
import com.example.moveeapp_compose_kmm.domain.location.DeviceLocation


@NoLiveLiterals
actual fun navigateToMap(
context: PlatformContext,
deviceLocation: DeviceLocation?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.example.moveeapp_compose_kmm.core

import android.content.Intent
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

@Composable
actual fun Share(text: String) {
val context = LocalContext.current
actual fun share(context: PlatformContext, text: String) {

val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
Expand All @@ -15,5 +11,5 @@ actual fun Share(text: String) {
}
val shareIntent = Intent.createChooser(sendIntent, null)

context.startActivity(shareIntent)
context.androidContext.startActivity(shareIntent)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package com.example.moveeapp_compose_kmm.core

import androidx.compose.runtime.Composable

@Composable
expect fun Share (text: String)
expect fun share (context: PlatformContext, text: String)
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.moveeapp_compose_kmm.MR
import com.example.moveeapp_compose_kmm.core.Share
import com.example.moveeapp_compose_kmm.core.getPlatformContext
import com.example.moveeapp_compose_kmm.core.ifNotNull
import com.example.moveeapp_compose_kmm.core.share
import com.example.moveeapp_compose_kmm.domain.MediaType
import com.example.moveeapp_compose_kmm.domain.artist.Credits
import com.example.moveeapp_compose_kmm.ui.components.BackPressedItem
Expand Down Expand Up @@ -160,6 +158,8 @@ fun MovieDetailContent(
ratingValue: State<Int?>,
onRateMovie: (rate: Int, movieId: Int) -> Unit,
) {
val platformContext = getPlatformContext()

Column(modifier = Modifier.padding(start = 16.dp, end = 16.dp)) {

TextItem(
Expand Down Expand Up @@ -195,18 +195,13 @@ fun MovieDetailContent(
ratingValue = ratingValue,
onRatingValueChange = { onRateMovie.invoke(it, uiState.movieDetailData.movieId) },
hidableContent = {
var shareText by remember { mutableStateOf("") }

FloatingActionButtonItem(
text = stringResource(MR.strings.share),
icon = Icons.Default.Share,
onClick = { shareText = uiState.movieDetailData.homepage }
onClick = {
share(platformContext, uiState.movieDetailData.homepage)
}
)

if (shareText.isNotEmpty()) {
Share(shareText)
shareText = ""
}
})

Divider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.moveeapp_compose_kmm.MR
import com.example.moveeapp_compose_kmm.core.Share
import com.example.moveeapp_compose_kmm.core.getPlatformContext
import com.example.moveeapp_compose_kmm.core.ifNotNull
import com.example.moveeapp_compose_kmm.core.share
import com.example.moveeapp_compose_kmm.domain.MediaType
import com.example.moveeapp_compose_kmm.domain.artist.Credits
import com.example.moveeapp_compose_kmm.ui.components.BackPressedItem
Expand Down Expand Up @@ -163,6 +161,8 @@ fun TvDetailContent(
ratingValue: State<Int?>,
onRateTvShow: (rate: Int, tvShowId: Int) -> Unit,
) {
val platformContext = getPlatformContext()

Column(modifier = Modifier.padding(horizontal = 16.dp)) {

TextItem(
Expand All @@ -185,21 +185,15 @@ fun TvDetailContent(
ratingValue = ratingValue,
onRatingValueChange = { onRateTvShow.invoke(it, uiState.tvDetailData.tvSeriesId) },
hidableContent = {
var shareText by remember { mutableStateOf("") }

FloatingActionButtonItem(
text = stringResource(MR.strings.share),
icon = Icons.Default.Share,
onClick = { shareText = uiState.tvDetailData.homepage }
onClick = {
share(platformContext, uiState.tvDetailData.homepage)
}
)

if (shareText.isNotEmpty()) {
Share(shareText)
shareText = ""
}
})


Divider(
modifier = Modifier.padding(vertical = 10.dp),
thickness = 1.dp,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.example.moveeapp_compose_kmm.core

import androidx.compose.runtime.Composable
import com.example.moveeapp_compose_kmm.Holder
import platform.UIKit.UIActivityViewController

@Composable
actual fun Share(text: String) {
val controller = UIActivityViewController(listOf(text), null)
actual fun share(context: PlatformContext, text: String) {
val controller = UIActivityViewController(listOf(context), null)

Holder.viewController?.presentViewController(controller, true, null)
}

0 comments on commit 86f3e1f

Please sign in to comment.