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

Change the Notification permission flow #1099

Closed
wants to merge 4 commits into from

Conversation

arvindri2005
Copy link

Fixes #1095
Now Notification permission will be asked after knowing the interests of the user

WhatsApp.Video.2023-12-18.at.20.35.41_0476bb29.mp4

Now Notification permission will be ask after knowing the interests of the user
Copy link

google-cla bot commented Dec 18, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Text(text = "Grant Notification Permission")
},
text = {
Text("Would you like to be informed when new content is published on these topics, content is typically published every few days?")
Copy link
Contributor

Choose a reason for hiding this comment

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

String resources should be placed in strings.xml

Copy link
Collaborator

Choose a reason for hiding this comment

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

@arvindri2005 Please do not resolve comments before they have actually been resolved.

Copy link
Author

Choose a reason for hiding this comment

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

I have fixed this in the latest commit cfa1d51

Comment on lines 119 to 121
viewModelScope.launch {
_dialogState.emit(!_dialogState.value)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

_dialogState.update {} is simpler

Copy link
Author

@arvindri2005 arvindri2005 Dec 19, 2023

Choose a reason for hiding this comment

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

val showNotificationPermission = savedStateHandle.getStateFlow(SHOW_NOTIFICATION_PERMISSION, false)
val dialogState = savedStateHandle.getStateFlow(DIALOG_STATE, false)
fun toggleDialog() {
    savedStateHandle[DIALOG_STATE] = !dialogState.value
}
fun showNotificationPermission() {
    savedStateHandle[SHOW_NOTIFICATION_PERMISSION] = !showNotificationPermission.value
}

you want something Like this

Comment on lines 124 to 126
viewModelScope.launch {
_showNotificationPermission.emit(!_showNotificationPermission.value)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above 🙏

},
dismissButton = {
NiaButton(onClick = onDismissRequest ) {
Text(text ="Cancel")

Choose a reason for hiding this comment

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

To maintain consistency and ease of localization, the "Ok" and the "Cancel" strings also should be included in the string file.

@@ -444,6 +473,38 @@ fun TopicIcon(
)
}

@Composable
private fun ShowDialog(

Choose a reason for hiding this comment

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

I suggest renaming this function to ShowNotificationPermissionDialog for better clarity.

Comment on lines 155 to 156
showNotificationPermissionDialog: () -> Unit,
showNotificationPermission: () -> Unit,

Choose a reason for hiding this comment

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

I suggest renaming these to onNotificationPermissionDismiss and onNotificationPermissionConfirm alternatively

_dialogState.update {!_dialogState.value}
}
}
fun showNotificationPermission() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this function is showNotificationPermission, but it looks like it will toggle whether we are asking for a notification permission. Can the the name of this function be updated, or have two different functions?

private val _showNotificationPermission = MutableStateFlow(false)
val showNotificationPermission: StateFlow<Boolean> = _showNotificationPermission
private val _dialogState = MutableStateFlow(false)
val dialogState: StateFlow<Boolean> = _dialogState
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be named more descriptively? It's not clear which dialog this state is for.

@@ -244,7 +269,7 @@ internal fun ForYouScreen(
)
}
TrackScreenViewEvent(screenName = "ForYou")
NotificationPermissionEffect()
// NotificationPermissionEffect()
Copy link
Contributor

Choose a reason for hiding this comment

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

Before merging, commented out code should be removed entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like all of the changes here are to make existing tests pass, could we add a new test for the updated flow?

onTopicCheckedChanged = viewModel::updateTopicSelection,
onDeepLinkOpened = viewModel::onDeepLinkOpened,
onTopicClick = onTopicClick,
saveFollowedTopics = viewModel::dismissOnboarding,
onNotificationPermissionDismiss = viewModel::toggleNotificationPermissionDialog,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the comment in the viewmodel, this parameter is named dismiss, but it is used as a toggle (and called that way later). Could we change this to be two different functions to make the behavior more clear?


if(askNotificationPermission){
NotificationPermissionEffect()
onNotificationPermissionConfirm()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a side-effect causing function called directly in composition - this should likely be wrapped in a SideEffect or something similar.

@keyboardsurfer
Copy link
Member

Thank you for submitting this pull request. We have decided not to accept it at this time.
Feel free to comment or open an issue for further discussion if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR]: Notification permission dialog should not be shown immediately on first run
7 participants