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

✨ Session sharing functionality was implemented. #1029

Merged
merged 11 commits into from
Sep 1, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import io.github.droidkaigi.confsched2023.sessions.nestedSessionScreens
import io.github.droidkaigi.confsched2023.sessions.searchScreen
import io.github.droidkaigi.confsched2023.sessions.sessionScreens
import io.github.droidkaigi.confsched2023.sessions.timetableScreenRoute
import io.github.droidkaigi.confsched2023.share.ShareNavigator
import io.github.droidkaigi.confsched2023.sponsors.navigateSponsorsScreen
import io.github.droidkaigi.confsched2023.sponsors.sponsorsScreen
import io.github.droidkaigi.confsched2023.staff.navigateStaffScreen
Expand Down Expand Up @@ -109,9 +110,10 @@ private fun KaigiNavHost(
sessionScreens(
onNavigationIconClick = navController::popBackStack,
onTimetableItemClick = navController::navigateToTimetableItemDetailScreen,
onNavigateToBookmarkScreenRequested = navController::navigateToBookmarkScreen,
onLinkClick = externalNavController::navigate,
onCalendarRegistrationClick = externalNavController::navigateToCalendarRegistration,
onNavigateToBookmarkScreenRequested = navController::navigateToBookmarkScreen,
onShareClick = externalNavController::onShareClick,
)
searchScreen(
onNavigationIconClick = navController::popBackStack,
Expand Down Expand Up @@ -242,13 +244,19 @@ class KaigiAppMainNestedGraphStateHolder : MainNestedGraphStateHolder {
@Composable
private fun rememberExternalNavController(): ExternalNavController {
val context = LocalContext.current
val shareNavigator = ShareNavigator(context)

return remember(context) {
ExternalNavController(context = context)
ExternalNavController(
context = context,
shareNavigator = shareNavigator,
)
}
}

private class ExternalNavController(
private val context: Context,
private val shareNavigator: ShareNavigator,
) {

fun navigate(url: String) {
Expand Down Expand Up @@ -292,6 +300,14 @@ private class ExternalNavController(
context.startActivity(Intent(context, OssLicensesMenuActivity::class.java))
}

fun onShareClick(timeTableItem: TimetableItem) {
shareNavigator.share(
"[${timeTableItem.room.name.currentLangTitle}] ${timeTableItem.startsTimeString} - ${timeTableItem.endsTimeString}\n" +
Copy link
Contributor

@tkhs0604 tkhs0604 Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding date info too? 👀
Perhaps, we are referring the formatted datetime property on the detail screen, so we may reuse it.

Copy link
Contributor

@tkhs0604 tkhs0604 Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Corvus400
Ah, sorry. My intention was to use timetableItem.formattedDateTimeString 🙇‍♂️
I think it is not suitable to use getDropDownText here since it is literally prepared for the drop down menu.

On the other hand, the value of timetableItem.formattedDateTimeString was much longer than I originally expected. This is just an optional, so please revert it if it is difficult to add date info in a simple way 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkhs0604
It seems that we can add a method to get only month and date by adding it to TimetableItem.kt.
However, I felt it was a bit redundant to add a method that is only used for the share function, so I decided to revert to the original method. 🙇

"${timeTableItem.title.currentLangTitle}\n" +
"https://2023.droidkaigi.jp/timetable/${timeTableItem.id.value}",
)
}

@Suppress("SwallowedException")
@RequiresApi(Build.VERSION_CODES.R)
private fun navigateToNativeAppApi30(context: Context, uri: Uri): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.droidkaigi.confsched2023.share

import android.content.ActivityNotFoundException
import android.content.Context
import androidx.core.app.ShareCompat
import co.touchlab.kermit.Logger

class ShareNavigator(private val context: Context) {
fun share(text: String) {
try {
ShareCompat.IntentBuilder(context)
.setText(text)
.setType("text/plain")
.startChooser()
} catch (e: ActivityNotFoundException) {
Logger.e("ActivityNotFoundException Fail startActivity: $e")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TimetableItemDetailScreenRobot @Inject constructor(
onNavigationIconClick = { },
onLinkClick = { },
onCalendarRegistrationClick = { },
onShareClick = { },
onNavigateToBookmarkScreenRequested = { },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ const val timetableItemDetailScreenRoute =
fun NavGraphBuilder.sessionScreens(
onNavigationIconClick: () -> Unit,
onTimetableItemClick: (TimetableItem) -> Unit,
onNavigateToBookmarkScreenRequested: () -> Unit,
onLinkClick: (url: String) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onNavigateToBookmarkScreenRequested: () -> Unit,
onShareClick: (TimetableItem) -> Unit,
) {
composable(timetableItemDetailScreenRoute) {
TimetableItemDetailScreen(
onNavigationIconClick = onNavigationIconClick,
onLinkClick = onLinkClick,
onCalendarRegistrationClick = onCalendarRegistrationClick,
onNavigateToBookmarkScreenRequested = onNavigateToBookmarkScreenRequested,
onShareClick = onShareClick,
)
}
composable(bookmarkScreenRoute) {
Expand Down Expand Up @@ -84,6 +86,7 @@ fun TimetableItemDetailScreen(
onLinkClick: (url: String) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onNavigateToBookmarkScreenRequested: () -> Unit,
onShareClick: (TimetableItem) -> Unit,
viewModel: TimetableItemDetailViewModel = hiltViewModel(),
) {
val uiState by viewModel.uiState.collectAsState()
Expand All @@ -107,6 +110,7 @@ fun TimetableItemDetailScreen(
onBookmarkClick = viewModel::onBookmarkClick,
onLinkClick = onLinkClick,
onCalendarRegistrationClick = onCalendarRegistrationClick,
onShareClick = onShareClick,
onSelectedLanguage = viewModel::onSelectDescriptionLanguage,
snackbarHostState = snackbarHostState,
)
Expand Down Expand Up @@ -139,6 +143,7 @@ private fun TimetableItemDetailScreen(
onBookmarkClick: (TimetableItem) -> Unit,
onLinkClick: (url: String) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onShareClick: (TimetableItem) -> Unit,
onSelectedLanguage: (Lang) -> Unit,
snackbarHostState: SnackbarHostState,
) {
Expand All @@ -162,6 +167,7 @@ private fun TimetableItemDetailScreen(
isBookmarked = uiState.isBookmarked,
onBookmarkClick = onBookmarkClick,
onCalendarRegistrationClick = onCalendarRegistrationClick,
onShareClick = onShareClick,
)
}
},
Expand Down Expand Up @@ -217,6 +223,7 @@ fun TimetableItemDetailScreenPreview() {
},
onLinkClick = {},
onCalendarRegistrationClick = {},
onShareClick = {},
onSelectedLanguage = {},
snackbarHostState = SnackbarHostState(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ fun TimetableItemDetailBottomAppBar(
isBookmarked: Boolean,
onBookmarkClick: (TimetableItem) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onShareClick: (TimetableItem) -> Unit,
modifier: Modifier = Modifier,
) {
BottomAppBar(
modifier = modifier,
actions = {
IconButton(onClick = { /*TODO*/ }) {
IconButton(onClick = { onShareClick(timetableItem) }) {
Icon(
imageVector = Icons.Filled.Share,
contentDescription = SessionsStrings.Share.asString(),
Expand Down Expand Up @@ -84,6 +85,7 @@ fun TimetableItemDetailBottomAppBarPreview() {
isBookmarked = true,
onBookmarkClick = {},
onCalendarRegistrationClick = {},
onShareClick = {},
)
}
}
Expand Down
Loading