Skip to content

Commit

Permalink
Added Favorite Options when grouping disabled by #1238
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Aug 1, 2024
1 parent a1faf79 commit 38dd84c
Show file tree
Hide file tree
Showing 14 changed files with 517 additions and 46 deletions.
2 changes: 2 additions & 0 deletions core/resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1295,4 +1295,6 @@
<string name="clustered_4x4_dithering">Clustered 4x4 Dithering</string>
<string name="clustered_8x8_dithering">Clustered 8x8 Dithering</string>
<string name="yililoma_dithering">Yililoma Dithering</string>
<string name="no_favorite_options_selected">No favorite options selected, add them in tools page</string>
<string name="add_favorites">Add Favorites</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ interface SettingsInteractor : SimpleSettingInteractor {

suspend fun setColorBlindType(value: Int?)

suspend fun toggleFavoriteScreen(screenId: Int)

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ data class SettingsState(
val openEditInsteadOfPreview: Boolean,
val canEnterPresetsByTextField: Boolean,
val donateDialogOpenCount: Int,
val colorBlindType: Int?
val colorBlindType: Int?,
val favoriteScreenList: List<Int>
) {

companion object {
Expand Down Expand Up @@ -167,7 +168,8 @@ data class SettingsState(
openEditInsteadOfPreview = false,
canEnterPresetsByTextField = false,
donateDialogOpenCount = 0,
colorBlindType = null
colorBlindType = null,
favoriteScreenList = emptyList()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ data class UiSettingsState(
val openEditInsteadOfPreview: Boolean,
val canEnterPresetsByTextField: Boolean,
val donateDialogOpenCount: Int?,
val colorBlindType: ColorBlindType?
val colorBlindType: ColorBlindType?,
val favoriteScreenList: List<Int>
)

fun UiSettingsState.isFirstLaunch(
Expand Down Expand Up @@ -280,6 +281,7 @@ fun SettingsState.toUiState(
}
}
}.value,
favoriteScreenList = favoriteScreenList
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fun MainContent(
onNavigateToScreenWithPopUpTo: (Screen) -> Unit,
onNavigateToEasterEgg: () -> Unit,
updateAvailable: Boolean,
updateUris: (List<Uri>) -> Unit
updateUris: (List<Uri>) -> Unit,
onToggleFavorite: (Screen) -> Unit
) {
fun tryGetUpdate(
newRequest: Boolean,
Expand Down Expand Up @@ -203,7 +204,8 @@ fun MainContent(
},
updateAvailable = updateAvailable,
onNavigateToSettings = { onNavigateToSettings() },
onNavigateToScreenWithPopUpTo = onNavigateToScreenWithPopUpTo
onNavigateToScreenWithPopUpTo = onNavigateToScreenWithPopUpTo,
onToggleFavorite = onToggleFavorite
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ internal fun filteredScreenListFor(

return remember(
settingsState.groupOptionsByTypes,
settingsState.favoriteScreenList,
screenSearchKeyword,
screenList,
selectedNavigationItem
) {
derivedStateOf {
if (settingsState.groupOptionsByTypes && (screenSearchKeyword.isEmpty() && !showScreenSearch)) {
Screen.typedEntries[selectedNavigationItem].first
} else if (!settingsState.groupOptionsByTypes && (screenSearchKeyword.isEmpty() && !showScreenSearch)) {
if (selectedNavigationItem == 0) {
settingsState.favoriteScreenList.mapNotNull {
Screen.entries.find { s -> s.id == it }
}
} else screenList
} else {
screenList
}.let { screens ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ internal fun MainContentImpl(
onGetClipList: (List<Uri>) -> Unit,
onNavigateToSettings: () -> Unit,
onNavigateToScreenWithPopUpTo: (Screen) -> Unit,
onToggleFavorite: (Screen) -> Unit,
onShowSnowfall: () -> Unit,
onTryGetUpdate: () -> Unit,
updateAvailable: Boolean
Expand Down Expand Up @@ -91,19 +92,28 @@ internal fun MainContentImpl(
modifier = Modifier.weight(1f)
) {
val showNavRail =
isGrid && settingsState.groupOptionsByTypes && screenSearchKeyword.isEmpty() && !sheetExpanded
isGrid && screenSearchKeyword.isEmpty() && !sheetExpanded

AnimatedVisibility(
visible = showNavRail,
enter = fadeIn() + expandHorizontally(),
exit = fadeOut() + shrinkHorizontally()
) {
MainNavigationRail(
selectedIndex = selectedNavigationItem,
onValueChange = {
selectedNavigationItem = it
}
)
if (settingsState.groupOptionsByTypes) {
MainNavigationRail(
selectedIndex = selectedNavigationItem,
onValueChange = {
selectedNavigationItem = it
}
)
} else {
MainNavigationRailForFavorites(
selectedIndex = selectedNavigationItem,
onValueChange = {
selectedNavigationItem = it
}
)
}
}

ScreenPreferenceSelection(
Expand All @@ -117,7 +127,9 @@ internal fun MainContentImpl(
showScreenSearch = it
},
onGetClipList = onGetClipList,
onNavigateToScreenWithPopUpTo = onNavigateToScreenWithPopUpTo
onNavigateToScreenWithPopUpTo = onNavigateToScreenWithPopUpTo,
onNavigationBarItemChange = { selectedNavigationItem = it },
onToggleFavorite = onToggleFavorite
)
}

Expand All @@ -135,6 +147,11 @@ internal fun MainContentImpl(
selectedIndex = selectedNavigationItem,
onValueChange = { selectedNavigationItem = it }
)
} else if (!searching) {
MainNavigationBarForFavorites(
selectedIndex = selectedNavigationItem,
onValueChange = { selectedNavigationItem = it }
)
} else {
SearchableBottomBar(
searching = searching,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* ImageToolbox is an image editor for android
* Copyright (c) 2024 T8RIN (Malik Mukhametzyanov)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* 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.
*
* You should have received a copy of the Apache License
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/

package ru.tech.imageresizershrinker.feature.main.presentation.components

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Bookmark
import androidx.compose.material.icons.rounded.BookmarkBorder
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import ru.tech.imageresizershrinker.core.resources.R
import ru.tech.imageresizershrinker.core.resources.icons.Toolbox
import ru.tech.imageresizershrinker.core.ui.widget.modifier.drawHorizontalStroke
import ru.tech.imageresizershrinker.core.ui.widget.text.marquee

@Composable
internal fun MainNavigationBarForFavorites(
selectedIndex: Int,
onValueChange: (Int) -> Unit
) {
NavigationBar(
modifier = Modifier
.drawHorizontalStroke(top = true)
.height(
80.dp + WindowInsets.systemBars
.asPaddingValues()
.calculateBottomPadding()
),
) {
val haptics = LocalHapticFeedback.current

NavigationBarItem(
modifier = Modifier.weight(1f),
selected = selectedIndex == 0,
onClick = {
onValueChange(0)
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
)
},
icon = {
AnimatedContent(
targetState = selectedIndex == 0,
transitionSpec = {
fadeIn() togetherWith fadeOut()
}
) { selected ->
Icon(
imageVector = if (selected) Icons.Rounded.Bookmark else Icons.Rounded.BookmarkBorder,
contentDescription = null
)
}
},
label = {
Text(
text = stringResource(R.string.favorite),
modifier = Modifier.marquee()
)
}
)

NavigationBarItem(
modifier = Modifier.weight(1f),
selected = selectedIndex == 1,
onClick = {
onValueChange(1)
haptics.performHapticFeedback(
HapticFeedbackType.LongPress
)
},
icon = {
AnimatedContent(
targetState = selectedIndex == 1,
transitionSpec = {
fadeIn() togetherWith fadeOut()
}
) { selected ->
Icon(
imageVector = if (selected) Icons.Rounded.Toolbox else Icons.Outlined.Toolbox,
contentDescription = null
)
}
},
label = {
Text(
text = stringResource(R.string.tools),
modifier = Modifier.marquee()
)
}
)
}
}
Loading

0 comments on commit 38dd84c

Please sign in to comment.