Skip to content

Commit

Permalink
Fixed clearing content URIs on first launch would always remove due t…
Browse files Browse the repository at this point in the history
…o syncing issue
  • Loading branch information
Anthonyy232 committed May 4, 2024
1 parent 2c33307 commit 48aefd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.activity.ComponentActivity
Expand Down Expand Up @@ -41,6 +42,13 @@ class MainActivity : ComponentActivity() {
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent {
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
if (isFirstLaunch) {
val contentResolver = context.contentResolver
val persistedUris = contentResolver.persistedUriPermissions
for (permission in persistedUris) {
contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
}
}
PaperizeTheme(settingsViewModel.state) {
Surface(tonalElevation = 5.dp) {
PaperizeApp(isFirstLaunch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ fun PaperizeApp(
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val context = LocalContext.current

if (settingsState.value.firstLaunch) {
val contentResolver = context.contentResolver
val persistedUris = contentResolver.persistedUriPermissions
for (permission in persistedUris) {
contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
}
}

// React to albumState changes and change selectedAlbum's details to keep it from being stale
LaunchedEffect(albumState.value.albumsWithWallpapers) {
albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers ->
Expand Down

0 comments on commit 48aefd2

Please sign in to comment.