Skip to content

Commit

Permalink
- Refactor: Reorganize General Settings and Bottom Navigation Bar
Browse files Browse the repository at this point in the history
This commit refactors the general settings screen and bottom navigation bar:

- Reorganizes the general settings screen for better readability and consistency.
- Adds the option to configure the middle navigation action for multiple actions.
- Refactors the navigation bar to be bottom or rail-style depending on screen size.
- Adds support for a middle action button for navigation with multiple actions.
- Improves handling of screen transition animations for the bottom navigation bar.
  • Loading branch information
jacobrein committed Oct 18, 2024
1 parent 4e35671 commit 720cc9d
Show file tree
Hide file tree
Showing 7 changed files with 747 additions and 307 deletions.
347 changes: 259 additions & 88 deletions UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fun NotificationsScreen(
.filter { it == 0 }
.collect {
cancelNotificationById(42)
navController.popBackStack()
//navController.popBackStack()
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.programmersbox.uiviews.NotificationSortBy
import com.programmersbox.uiviews.Settings
import com.programmersbox.uiviews.SystemThemeMode
import com.programmersbox.uiviews.ThemeColor
import com.programmersbox.uiviews.middleMultipleActions
import com.programmersbox.uiviews.settings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -73,6 +74,10 @@ object SettingsSerializer : GenericSerializer<Settings, Settings.Builder> {
amoledMode = false
usePalette = true
showBlur = true
multipleActions = middleMultipleActions {
startAction = MiddleNavigationAction.All
endAction = MiddleNavigationAction.Notifications
}
}
override val parseFrom: (input: InputStream) -> Settings get() = Settings::parseFrom
}
Expand Down Expand Up @@ -181,6 +186,16 @@ class SettingsHandling(context: Context) {
update = { setMiddleNavigationAction(it) },
defaultValue = MiddleNavigationAction.All,
)

@Composable
fun rememberMiddleMultipleActions() = preferences.rememberPreference(
key = { it.multipleActions },
update = { setMultipleActions(it) },
defaultValue = middleMultipleActions {
startAction = MiddleNavigationAction.All
endAction = MiddleNavigationAction.Notifications
},
)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import androidx.compose.material.icons.filled.BrowseGallery
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.UnfoldMore
import androidx.compose.material.icons.outlined.BrowseGallery
import androidx.compose.material.icons.outlined.Notifications
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemColors
import androidx.compose.material3.NavigationBarItemDefaults
Expand Down Expand Up @@ -69,7 +71,13 @@ val MiddleNavigationAction.item: MiddleNavigationItem?
screen = Screen.GlobalSearchScreen.Home(),
)

MiddleNavigationAction.UNRECOGNIZED -> null
MiddleNavigationAction.Multiple -> MiddleNavigationItem(
icon = { Icons.Default.UnfoldMore },
label = R.string.more,
screen = Screen.MoreSettings,
)

else -> null
}

@Composable
Expand Down Expand Up @@ -98,6 +106,50 @@ fun MiddleNavigationItem.ScreenBottomItem(
}
}

@Composable
fun MiddleNavigationItem.ScreenBottomItem(
currentDestination: NavDestination?,
navController: NavHostController,
additionalOnClick: () -> Unit,
modifier: Modifier = Modifier,
) {
IconButton(
onClick = {
additionalOnClick()
navController.navigate(screen) {
popUpTo(navController.graph.findStartDestination().id) { saveState = true }
launchSingleTop = true
restoreState = true
}
},
modifier = modifier
) { Icon(icon(currentDestination.isTopLevelDestinationInHierarchy(screen)), null) }
}

@Composable
fun MiddleNavigationAction.ScreenBottomItem(
rowScope: RowScope,
currentDestination: NavDestination?,
navController: NavHostController,
modifier: Modifier = Modifier,
colors: NavigationBarItemColors = NavigationBarItemDefaults.colors(),
multipleClick: () -> Unit,
) {
if (this == MiddleNavigationAction.Multiple) {
with(rowScope) {
NavigationBarItem(
icon = { Icon(Icons.Default.UnfoldMore, null) },
label = { Text("More") },
selected = false,
colors = colors,
onClick = multipleClick
)
}
} else {
item?.ScreenBottomItem(rowScope, currentDestination, navController, modifier, colors)
}
}

private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: Screen) = isTopLevelDestinationInHierarchy(destination.route)

private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: String) = this?.hierarchy?.any {
Expand Down
7 changes: 7 additions & 0 deletions UIViews/src/main/proto/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ message Settings {
GridChoice gridChoice = 15;
ThemeColor themeColor = 16;
MiddleNavigationAction middleNavigationAction = 17;
MiddleMultipleActions multipleActions = 18;
}

enum SystemThemeMode {
Expand Down Expand Up @@ -56,4 +57,10 @@ enum MiddleNavigationAction {
Lists = 2;
Favorites = 3;
Search = 4;
Multiple = 5;
}

message MiddleMultipleActions {
MiddleNavigationAction startAction = 1;
MiddleNavigationAction endAction = 2;
}
3 changes: 3 additions & 0 deletions UIViews/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<string name="add_a_favorite">Add a Favorite</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="global_search">Global Search</string>
<string name="more">More</string>
<string name="search">Search</string>
<string name="global_search_by_name">Global Search by Name</string>
<string name="are_you_sure_delete_notifications">Are you sure you want to delete all notifications?</string>
Expand Down Expand Up @@ -211,4 +212,6 @@
<string name="more_settings">More Settings</string>
<string name="for_later">For Later</string>
<string name="add_to_for_later_list">Add to For Later list</string>
<string name="show_download_button">Show Download Button</string>
<string name="show_list_detail_pane_for_lists">Show List Detail Pane for Lists</string>
</resources>

0 comments on commit 720cc9d

Please sign in to comment.