Added recursive file looking for folders retrieving images, tap to zoom images library, and updated visuals of the folder card with blur
This commit is contained in:
1 parent
c9990c6dce
commit
5eb55575b4
10 files changed
+328
-97
No files matched your search
+41
-7
@@ -1,7 +1,12 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -21,10 +26,13 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.Ad
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.HomeScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen.WallpaperViewScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavScreens
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
@@ -57,14 +65,17 @@ fun PaperizeApp(
|
||||
enterTransition = {
|
||||
slideIntoContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Down,
|
||||
animationSpec = tween(500)
|
||||
animationSpec = tween(300)
|
||||
)
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutOfContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Up,
|
||||
animationSpec = tween(500)
|
||||
)
|
||||
fadeOut(animationSpec = tween(300, easing = LinearEasing))
|
||||
},
|
||||
popEnterTransition = {
|
||||
fadeIn(animationSpec = tween(300, easing = LinearEasing))
|
||||
},
|
||||
popExitTransition = {
|
||||
fadeOut(animationSpec = tween(300, easing = LinearEasing))
|
||||
}
|
||||
) {backStackEntry ->
|
||||
backStackEntry.arguments?.getString("initialAlbumName").let {
|
||||
@@ -77,23 +88,46 @@ fun PaperizeApp(
|
||||
},
|
||||
onConfirmation = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum)
|
||||
},
|
||||
onShowWallpaperView = { wallpaper ->
|
||||
val encodedWallpaper = URLEncoder.encode(wallpaper, StandardCharsets.UTF_8.toString())
|
||||
navController.navigate("${NavScreens.WallpaperView.route}/$encodedWallpaper")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = NavScreens.WallpaperView.route.plus("/{wallpaperUri}"),
|
||||
arguments = listOf(navArgument("wallpaperUri") { type = NavType.StringType }),
|
||||
enterTransition = {
|
||||
fadeIn(animationSpec = tween(300, easing = LinearEasing))
|
||||
},
|
||||
exitTransition = {
|
||||
fadeOut(animationSpec = tween(300, easing = LinearEasing))
|
||||
}
|
||||
) { backStackEntry ->
|
||||
backStackEntry.arguments?.getString("wallpaperUri").let {
|
||||
if (it != null) {
|
||||
WallpaperViewScreen(
|
||||
wallpaperUri = it,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = NavScreens.Settings.route,
|
||||
enterTransition = {
|
||||
slideIntoContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Down,
|
||||
animationSpec = tween(500)
|
||||
animationSpec = tween(300)
|
||||
)
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutOfContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Up,
|
||||
animationSpec = tween(500)
|
||||
animationSpec = tween(300)
|
||||
)
|
||||
}
|
||||
) {
|
||||
|
||||
+40
-49
@@ -3,6 +3,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -44,14 +45,16 @@ fun AddAlbumScreen(
|
||||
viewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
onBackClick: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit
|
||||
) {
|
||||
viewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
|
||||
val context = LocalContext.current
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val state = viewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
if (state.value.initialAlbumName.isEmpty())
|
||||
viewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
@@ -147,57 +150,45 @@ fun AddAlbumScreen(
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
if (state.value.folders.isNotEmpty()) {
|
||||
items (items = state.value.folders, key = { folder -> folder.folderUri}
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = state.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
if (!state.value.selectedFolders.contains(folder.folderUri)) {
|
||||
viewModel.onEvent(AddAlbumEvent.SelectFolder(folder.folderUri))
|
||||
} else {
|
||||
viewModel.onEvent(AddAlbumEvent.RemoveFolderFromSelection(folder.folderUri))
|
||||
} },
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
items (items = state.value.folders, key = { folder -> folder.folderUri}
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = state.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
if (!state.value.selectedFolders.contains(folder.folderUri)) {
|
||||
viewModel.onEvent(AddAlbumEvent.SelectFolder(folder.folderUri))
|
||||
} else {
|
||||
viewModel.onEvent(AddAlbumEvent.RemoveFolderFromSelection(folder.folderUri))
|
||||
} },
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
if (state.value.wallpapers.isNotEmpty()) {
|
||||
items (items = state.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri}
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = state.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
viewModel.onEvent(
|
||||
if (!state.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
)
|
||||
},
|
||||
onImageViewClick = {
|
||||
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
items (items = state.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri}
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = state.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
viewModel.onEvent(
|
||||
if (!state.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
)
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return folderDocumentFile?.listFiles()?.map { it.uri.toString() } ?: emptyList()
|
||||
}
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
+44
-13
@@ -3,7 +3,10 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -93,20 +96,22 @@ class AddAlbumViewModel @Inject constructor(
|
||||
is AddAlbumEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.folders.any { it.folderUri == event.directoryUri }) {
|
||||
val wallpapers = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
_state.update { it.copy(
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.random(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
if (wallpapers.isNotEmpty()) {
|
||||
_state.update { it.copy(
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.random(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,6 +210,7 @@ class AddAlbumViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateIsEmpty() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
@@ -220,5 +226,30 @@ class AddAlbumViewModel @Inject constructor(
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
private fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
private fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -149,8 +149,8 @@ fun AddAlbumSmallTopBar(
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
if (!isEmpty) {
|
||||
if (!isEmpty) {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
|
||||
+16
-5
@@ -19,6 +19,9 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CardElevation
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedCard
|
||||
@@ -29,6 +32,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.BlurredEdgeTreatment
|
||||
import androidx.compose.ui.draw.blur
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
@@ -64,15 +69,20 @@ fun FolderItem(
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
OutlinedCard(
|
||||
Card(
|
||||
elevation = CardDefaults.cardElevation(5.dp),
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selectionMode) { onItemSelection() }
|
||||
else { /*go to photo screen*/ }
|
||||
if (selectionMode) {
|
||||
onItemSelection()
|
||||
}
|
||||
else {
|
||||
/*go to photo screen*/
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
@@ -87,7 +97,7 @@ fun FolderItem(
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
tonalElevation = 5.dp,
|
||||
tonalElevation = 10.dp,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -98,7 +108,8 @@ fun FolderItem(
|
||||
AsyncImage(
|
||||
modifier = Modifier
|
||||
.height(configuration.screenHeightDp.dp / 4.0f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition)),
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.blur(radius = 3.dp),
|
||||
model = folder.coverUri,
|
||||
contentDescription = folder.folderName,
|
||||
alignment = Alignment.Center,
|
||||
|
||||
+91
-21
@@ -1,5 +1,9 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -7,9 +11,8 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -25,12 +28,20 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import coil.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.security.AccessController.getContext
|
||||
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -40,7 +51,7 @@ fun WallpaperItem(
|
||||
selectionMode: Boolean,
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
onImageViewClick: () -> Unit,
|
||||
onWallpaperViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
@@ -52,32 +63,52 @@ fun WallpaperItem(
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeStream(
|
||||
LocalContext.current.contentResolver.openInputStream(wallpaperUri.toUri()),
|
||||
null,
|
||||
options
|
||||
)
|
||||
val imageHeight = options.outHeight
|
||||
val imageWidth = options.outWidth
|
||||
val aspectRatio = (imageWidth.toFloat()/imageHeight.toFloat())
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selectionMode) { onItemSelection() }
|
||||
else { onImageViewClick() }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
AsyncImage(
|
||||
AsyncImage (
|
||||
model = wallpaperUri.toUri(),
|
||||
contentDescription = null,
|
||||
contentDescription = wallpaperUri,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
)
|
||||
.aspectRatio(aspectRatio)
|
||||
.combinedClickable(
|
||||
/*
|
||||
If in selection mode, a click will select the item.
|
||||
If not, a click will show an image view.
|
||||
*/
|
||||
onClick = {
|
||||
if (!selectionMode) { onWallpaperViewClick() }
|
||||
else { onItemSelection() }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
/*
|
||||
If in selection mode and item is selected, show a checkmark circle.
|
||||
If not selected, show an empty circle.
|
||||
*/
|
||||
if (selectionMode) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (itemSelected) {
|
||||
@@ -100,4 +131,43 @@ fun WallpaperItem(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fileFromContentUri(context: Context, contentUri: Uri): File {
|
||||
// Preparing Temp file name
|
||||
val fileExtension = getFileExtension(context, contentUri)
|
||||
val fileName = "temp_file" + if (fileExtension != null) ".$fileExtension" else ""
|
||||
|
||||
// Creating Temp file
|
||||
val tempFile = File(context.cacheDir, fileName)
|
||||
tempFile.createNewFile()
|
||||
|
||||
try {
|
||||
val oStream = FileOutputStream(tempFile)
|
||||
val inputStream = context.contentResolver.openInputStream(contentUri)
|
||||
|
||||
inputStream?.let {
|
||||
copy(inputStream, oStream)
|
||||
}
|
||||
|
||||
oStream.flush()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return tempFile
|
||||
}
|
||||
|
||||
private fun getFileExtension(context: Context, uri: Uri): String? {
|
||||
val fileType: String? = context.contentResolver.getType(uri)
|
||||
return MimeTypeMap.getSingleton().getExtensionFromMimeType(fileType)
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun copy(source: InputStream, target: OutputStream) {
|
||||
val buf = ByteArray(8192)
|
||||
var length: Int
|
||||
while (source.read(buf).also { length = it } > 0) {
|
||||
target.write(buf, 0, length)
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.BottomAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
import net.engawapg.lib.zoomable.rememberZoomState
|
||||
import net.engawapg.lib.zoomable.zoomable
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun WallpaperViewScreen(
|
||||
wallpaperUri: String,
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val zoomState = rememberZoomState()
|
||||
BackHandler { onBackClick() }
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.requiredSize(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
BottomAppBar(
|
||||
containerColor = Color.Transparent,
|
||||
actions = {}
|
||||
)
|
||||
},
|
||||
content = { padding ->
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = Color.Black
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.zoomable(zoomState)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = wallpaperUri,
|
||||
contentDescription = "hi",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+6
@@ -3,17 +3,23 @@ package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.BrowseGallery
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.filled.Wallpaper
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.BrowseGallery
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.material.icons.outlined.Wallpaper
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
|
||||
sealed class NavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
|
||||
object Home : NavScreens("home_screen", R.string.home_screen, Icons.Outlined.Image, Icons.Filled.Image)
|
||||
object Wallpaper : NavScreens("wallpaper_screen", R.string.wallpaper_screen, Icons.Outlined.Wallpaper, Icons.Filled.Wallpaper)
|
||||
object Settings : NavScreens("settings_screen", R.string.settings_screen, Icons.Outlined.Settings, Icons.Filled.Settings)
|
||||
object AddEdit : NavScreens("add_edit_screen", R.string.add_wallpaper_screen, Icons.Outlined.Add, Icons.Filled.Add)
|
||||
object WallpaperView : NavScreens("wallpaper_view_screen", R.string.wallpaper_view, Icons.Outlined.BrowseGallery, Icons.Filled.BrowseGallery)
|
||||
}
|
||||
@@ -26,4 +26,5 @@
|
||||
<string name="album_name">Album Name</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="wallpaper_view">Wallpaper View</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user