Skip to content

Commit

Permalink
[FEAT] Introduced a new Folder shape in the foundation module, al…
Browse files Browse the repository at this point in the history
…lowing customization of `corner radius`.

[FEAT] Added a new 'Shortcuts' section within folders for better organization and quick access.
[REFACTOR] Renamed 'showAndroidToast' to 'showPlatformToast' in `KoinViewModel` for platform-agnostic naming consistency.
[REFACTOR] Cleaned up `MainViewModel` by removing unnecessary messages; it now only displays toasts when required.
[FEAT] Implemented a proper `wallpaper` `intent` in `ViewerViewModel` for improved user experience.
  • Loading branch information
iZakirSheikh committed Sep 14, 2024
1 parent 9ed29c9 commit bc1ec7c
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId = "com.googol.android.apps.photos"
minSdk = 24
targetSdk = 35
versionCode = 17
versionName = "0.1.0-dev17"
versionCode = 18
versionName = "0.1.0-dev18"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/zs/gallery/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ class MainActivity : ComponentActivity(), SystemFacade, NavController.OnDestinat
// if authentication is required move to lock screen
Gallery(toastHostState, navController)
DisposableEffect(Unit) {
Log.d(TAG, "onCreate - DisposableEffect: $timeAppWentToBackground")
navController.addOnDestinationChangedListener(this@MainActivity)
// since auth is required; we will cover the scrren with lock_screen
// only when user authenticate can remove this veil.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zs/gallery/common/lazy-ktx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private fun GroupHeader(

IconButton(
imageVector = when (state) {
GroupSelectionLevel.NONE -> Icons.Outlined.Circle
GroupSelectionLevel.NONE -> Icons.Outlined.CheckCircleOutline
GroupSelectionLevel.PARTIAL -> Icons.Outlined.RemoveCircle
GroupSelectionLevel.FULL -> Icons.Outlined.CheckCircleOutline
},
Expand Down Expand Up @@ -340,4 +340,4 @@ inline fun <T> LazyGridScope.items(
itemContent = itemContent
)
}
}
}
39 changes: 38 additions & 1 deletion app/src/main/java/com/zs/gallery/folders/Folders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.zs.gallery.folders

import android.os.Build
import androidx.annotation.StringRes
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.core.animateFloatAsState
Expand All @@ -28,11 +29,13 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.shape.CircleShape
Expand All @@ -43,7 +46,9 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Sort
import androidx.compose.material.icons.filled.FolderCopy
import androidx.compose.material.icons.outlined.DateRange
import androidx.compose.material.icons.outlined.HotelClass
import androidx.compose.material.icons.outlined.Memory
import androidx.compose.material.icons.outlined.Recycling
import androidx.compose.material.icons.outlined.TextFields
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -58,6 +63,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.primex.core.drawHorizontalDivider
import com.primex.core.plus
import com.primex.core.textResource
Expand All @@ -72,12 +78,15 @@ import com.zs.foundation.adaptive.TwoPane
import com.zs.foundation.adaptive.contentInsets
import com.zs.foundation.sharedElement
import com.zs.gallery.R
import com.zs.gallery.bin.RouteTrash
import com.zs.gallery.common.LocalNavController
import com.zs.gallery.common.emit
import com.zs.gallery.common.fullLineSpan
import com.zs.gallery.common.preference
import com.zs.gallery.files.RouteAlbum
import com.zs.gallery.files.RouteFolder
import com.zs.gallery.viewer.RouteViewer
import com.zs.gallery.settings.Settings
import com.zs.gallery.viewer.RouteViewer

private const val TAG = "Folders"

Expand Down Expand Up @@ -190,6 +199,25 @@ private val FolderContentPadding =
PaddingValues(vertical = AppTheme.padding.normal, horizontal = AppTheme.padding.medium)
private val GridItemsArrangement = Arrangement.spacedBy(6.dp)

private fun LazyGridScope.shortcuts(navController: NavHostController) =
items(2, contentType = { "shortcut" }) { index ->
when (index) {
0 -> Shortcut(
Icons.Outlined.HotelClass,
"Favourites",
onClick = { navController.navigate(RouteAlbum()) }
)

1 -> Shortcut(
Icons.Outlined.Recycling,
"Recycle Bin",
onClick = { navController.navigate(RouteTrash()) },
// Only enable if R and above
enabled = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
)
}
}

@Composable
fun Folders(viewState: FoldersViewState) {
val navInsets = WindowInsets.contentInsets
Expand All @@ -212,8 +240,17 @@ fun Folders(viewState: FoldersViewState) {
columns = GridCells.Adaptive((MIN_TILE_SIZE * multiplier.coerceAtLeast(1f))),
contentPadding = FolderContentPadding + WindowInsets.contentInsets + navInsets,
verticalArrangement = GridItemsArrangement,
horizontalArrangement = GridItemsArrangement,
content = {
val data = emit(values) ?: return@LazyVerticalGrid

// The standard shortcuts.
shortcuts(navController)

item(span = fullLineSpan) {
Spacer(Modifier.padding(vertical = ContentPadding.medium))
}

// else emit the items.
items(data, key = { it.artworkID }) {
Folder(
Expand Down
96 changes: 96 additions & 0 deletions app/src/main/java/com/zs/gallery/folders/Shortcut.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2024 Zakir Sheikh
*
* Created by 2024 on 14-09-2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.zs.gallery.folders

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.ripple
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.primex.material2.Label
import com.zs.foundation.AppTheme
import com.zs.foundation.shapes.Folder as FolderShape


private val Folder = FolderShape(radius = 16.dp)

/**
* Composable function to create a clickable shortcut with an icon and label.
*
* @param icon: The ImageVector representing the shortcut's icon.
* @param label: The CharSequence representing the shortcut's label.
* @param onAction: The action to perform when the shortcut is clicked.
* @param modifier: Optional modifier to apply to the shortcut's layout.
*/
@Composable
fun Shortcut(
icon: ImageVector,
label: CharSequence,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
) {
// Base container for the shortcut with styling and click handling
val colors = AppTheme.colors
val accent = colors.onBackground
Box(
modifier = modifier
.aspectRatio(16/11f)
.clip(Folder) // Shape the shortcut like a folder
.background(colors.background(1.5.dp), Folder)
// .border(1.dp, accent.copy(0.5f), Folder) // Light border
// .background(colors.backgroundColorAtElevation(0.4.dp), FolderShape)
.clickable(
null,
ripple(true, color = AppTheme.colors.accent), // Ripple effect on click
role = Role.Button, // Semantically indicate a button
onClick = onClick, // Trigger the action on click
enabled = enabled
)
.padding(horizontal = 12.dp, vertical = 8.dp) // Add internal padding
// then modifier // Apply additional modifiers
) {
// Icon at the top
Icon(
imageVector = icon,
contentDescription = null, // Ensure a content description is provided elsewhere
tint = accent,
modifier = Modifier.align(Alignment.TopStart)
)

// Label at the bottom
Label(
text = label,
style = AppTheme.typography.caption,
color = accent,
modifier = Modifier.align(Alignment.BottomStart)
)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/zs/gallery/impl/KoinViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ abstract class KoinViewModel: ScopeViewModel() {
val preferences: Preferences by inject()
private val context: Application by inject()

fun showAndroidToast(
fun showPlatformToast(
@StringRes message: Int
) = AndroidToast.makeText(context, message, AndroidToast.LENGTH_LONG).show()

fun showAndroidToast(
fun showPlatformToast(
message: String
) = AndroidToast.makeText(context, message, AndroidToast.LENGTH_LONG).show()

Expand Down
Loading

0 comments on commit bc1ec7c

Please sign in to comment.