-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from GuoXiCheng/dev
add NotificationDialog
- Loading branch information
Showing
6 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/android/skip/ui/components/notification/NotificationDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.android.skip.ui.components.notification | ||
|
||
import android.content.Intent | ||
import android.provider.Settings | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import com.android.skip.MyApp | ||
import com.android.skip.R | ||
|
||
@Composable | ||
fun NotificationDialog( | ||
notificationDialogViewModel: NotificationDialogViewModel, | ||
onDismiss: () -> Unit | ||
) { | ||
val showDialog = notificationDialogViewModel.showDialog.observeAsState() | ||
val context = LocalContext.current | ||
if (showDialog.value == true) { | ||
AlertDialog( | ||
containerColor = MaterialTheme.colorScheme.background, | ||
title = { | ||
Text(text = stringResource(id = R.string.dialog_notification_title)) | ||
}, | ||
text = { | ||
Text(text = stringResource(id = R.string.dialog_notification_content)) | ||
}, | ||
onDismissRequest = onDismiss, | ||
confirmButton = { | ||
TextButton( | ||
onClick = { | ||
val intent = Intent().apply { | ||
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS | ||
putExtra(Settings.EXTRA_APP_PACKAGE, MyApp.context.packageName) | ||
} | ||
context.startActivity(intent) | ||
notificationDialogViewModel.changeDialogState(false) | ||
} | ||
) { | ||
Text(stringResource(id = R.string.dialog_confirm)) | ||
} | ||
}, | ||
dismissButton = { | ||
TextButton( | ||
onClick = onDismiss | ||
) { | ||
Text(stringResource(id = R.string.dialog_dismiss)) | ||
} | ||
} | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/android/skip/ui/components/notification/NotificationDialogViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.android.skip.ui.components.notification | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class NotificationDialogViewModel @Inject constructor(): ViewModel() { | ||
private val _showDialog = MutableLiveData(false) | ||
val showDialog: LiveData<Boolean> = _showDialog | ||
|
||
fun changeDialogState(isShow: Boolean) { | ||
_showDialog.postValue(isShow) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters