Skip to content

Commit

Permalink
add notification permission to WelcomeScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mr committed Oct 2, 2024
1 parent 71496f9 commit c0d228b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fun SettingsScreen(
}

item {
TextContent(modifier = Modifier
TextContent(modifier = Modifier.fillMaxWidth()
.clickable {
onReWelcomeClick()
}
Expand Down
31 changes: 28 additions & 3 deletions app/src/main/java/top/maary/oblivionis/ui/screen/WelcomeScreen.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package top.maary.oblivionis.ui.screen

import android.Manifest
import android.content.Intent
import android.os.Build
import android.provider.MediaStore
import android.provider.Settings
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
Expand Down Expand Up @@ -38,7 +42,9 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import com.google.accompanist.permissions.rememberPermissionState
import top.maary.oblivionis.R
import top.maary.oblivionis.ui.PermissionBlock

Expand All @@ -54,16 +60,19 @@ fun WelcomeScreen(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
rememberMultiplePermissionsState(
permissions = listOf(
android.Manifest.permission.READ_MEDIA_IMAGES,
android.Manifest.permission.READ_MEDIA_VIDEO
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO
)
)
} else {
rememberMultiplePermissionsState(permissions = listOf(android.Manifest.permission.READ_EXTERNAL_STORAGE))
rememberMultiplePermissionsState(permissions = listOf(Manifest.permission.READ_EXTERNAL_STORAGE))
}

val manageMediaPermissionState = rememberCanManageMediaState()

val notificationPermissionState =
rememberPermissionState(permission = Manifest.permission.POST_NOTIFICATIONS)

Scaffold(
topBar = {
LargeTopAppBar(
Expand Down Expand Up @@ -128,6 +137,22 @@ fun WelcomeScreen(
granted = manageMediaPermissionState.value
)
}
item {
PermissionBlock(
title = stringResource(R.string.notification),
onClick = {
notificationPermissionState.launchPermissionRequest()
},
details = stringResource(R.string.notification_perission_description),
isOptional = true,
granted = notificationPermissionState.status.isGranted
)
}
item {
Spacer(modifier = Modifier.windowInsetsBottomHeight(
WindowInsets.systemBars
))
}

}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
<string name="select_all">全部选择</string>
<string name="restore_selected_confirmation">被选中的媒体将会被恢复。</string>
<string name="d1">1 天</string>
<string name="notification_perission_description">允许应用推送通知。相关的功能仍需在设置中启用。</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
<string name="select_all">Select All</string>
<string name="restore_selected_confirmation">Selected media will be restored.</string>
<string name="d1">1 Day</string>
<string name="notification_perission_description">Allow Oblivionis push notifications. Related feature still needs to be enabled in the settings.</string>
</resources>

0 comments on commit c0d228b

Please sign in to comment.