Skip to content

Commit

Permalink
Add share support for news article
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyansh Lodha <[email protected]>
  • Loading branch information
static-var committed Feb 10, 2024
1 parent 335c01b commit 47ce896
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 23 deletions.
33 changes: 22 additions & 11 deletions app/src/main/java/dev/staticvar/vlr/ui/helper/VlrNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ fun VlrNavHost(navController: NavHostController, onNavigation: (String) -> Unit)
exitTransition = { fadeOut },
popExitTransition = { fadeOut },
deepLinks =
listOf(
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_BASEURL}${Destination.Match.Args.ID}={${Destination.Match.Args.ID}}"
},
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_2_BASEURL}${Destination.Match.Args.ID}={${Destination.Match.Args.ID}}"
}
)
listOf(
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_BASEURL}${Destination.Match.Args.ID}={${Destination.Match.Args.ID}}"
},
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_2_BASEURL}${Destination.Match.Args.ID}={${Destination.Match.Args.ID}}"
}
)
) {
val id = it.arguments?.getString(Destination.Match.Args.ID) ?: ""
onNavigation(Destination.Match.route.replace(Destination.Match.Args.ID, id))
Expand Down Expand Up @@ -229,7 +229,18 @@ fun VlrNavHost(navController: NavHostController, onNavigation: (String) -> Unit)
enterTransition = { fadeIn },
popEnterTransition = { fadeIn },
exitTransition = { fadeOut },
popExitTransition = { fadeOut }
popExitTransition = { fadeOut },
deepLinks =
listOf(
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_BASEURL}news={${Destination.News.Args.ID}}"
},
navDeepLink {
uriPattern =
"${Constants.DEEP_LINK_2_BASEURL}news={${Destination.News.Args.ID}}"
}
)
) {
onNavigation(Destination.News.route)
val id = it.arguments?.getString(Destination.News.Args.ID) ?: ""
Expand Down
71 changes: 59 additions & 12 deletions app/src/main/java/dev/staticvar/vlr/ui/news/NewsDetailsScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.staticvar.vlr.ui.news

import android.content.Context
import android.content.Intent
import android.os.Build
import android.webkit.WebResourceRequest
import android.webkit.WebView
Expand All @@ -8,8 +10,10 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -27,6 +31,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.KeyboardArrowUp
import androidx.compose.material.icons.outlined.Share
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
Expand Down Expand Up @@ -63,13 +68,15 @@ import dev.staticvar.vlr.data.Subtext
import dev.staticvar.vlr.data.Tweet
import dev.staticvar.vlr.data.Unknown
import dev.staticvar.vlr.data.Video
import dev.staticvar.vlr.ui.Local4DPPadding
import dev.staticvar.vlr.ui.Local8DPPadding
import dev.staticvar.vlr.ui.VlrViewModel
import dev.staticvar.vlr.ui.scrim.NavigationBarSpacer
import dev.staticvar.vlr.ui.scrim.NavigationBarType
import dev.staticvar.vlr.ui.scrim.StatusBarSpacer
import dev.staticvar.vlr.ui.scrim.StatusBarType
import dev.staticvar.vlr.ui.theme.VLRTheme
import dev.staticvar.vlr.utils.Constants
import dev.staticvar.vlr.utils.openAsCustomTab
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -103,19 +110,35 @@ fun NewsDetailsScreen(viewModel: VlrViewModel, id: String) {
color = VLRTheme.colorScheme.primary
)
}

item { Spacer(modifier = modifier.padding(Local4DPPadding.current)) }

item {
Text(
text = news.authorName,
style = VLRTheme.typography.labelLarge,
color = VLRTheme.colorScheme.primary
)
}
item {
Text(
text = news.time,
style = VLRTheme.typography.labelLarge,
color = VLRTheme.colorScheme.primary
)
Row(modifier = modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
Column(modifier = modifier.weight(1f), verticalArrangement = Arrangement.Center) {
Text(
text = news.authorName,
style = VLRTheme.typography.labelLarge,
color = VLRTheme.colorScheme.primary
)
Text(
text = news.time,
style = VLRTheme.typography.labelLarge,
color = VLRTheme.colorScheme.primary
)
}
Icon(
imageVector = Icons.Outlined.Share,
contentDescription = "Share",
modifier = modifier
.clip(shape = VLRTheme.shapes.medium)
.clickable {
fireShareIntent(context, news.title, id)
},
tint = VLRTheme.colorScheme.primary
)
}

}
item { Spacer(modifier = modifier.padding(Local8DPPadding.current)) }

Expand Down Expand Up @@ -298,3 +321,27 @@ fun BoxScope.ScrollToTopButton(
}

}


fun fireShareIntent(context: Context, title: String, id: String) {
val shareString = buildString {
appendLine(title)
appendLine(
"Check out the complete article here : ${internalDeepLinkForNews(id)} | ${
websiteUrlForNews(
id
)
}"
)
}
val intent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_TEXT, shareString)
type = "text/plain"
}

val shareIntent = Intent.createChooser(intent, "Share Valorant News")
context.startActivity(shareIntent)
}

private fun internalDeepLinkForNews(id: String) = "${Constants.DEEP_LINK_BASEURL}news=$id"
private fun websiteUrlForNews(id: String) = "${Constants.VLR_BASE}$id"

0 comments on commit 47ce896

Please sign in to comment.