Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create navigation module #202

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ kotlin {
dependencies {
implementation(projects.api.anilist)
implementation(projects.core)
implementation(projects.navigation)
implementation(projects.profile)
implementation(projects.rslash)
implementation(projects.social)
implementation(projects.materialColorUtilities)

// AndroidX
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/imashnake/animite/features/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navDeepLink
import com.imashnake.animite.api.anilist.sanitize.media.MediaList
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.features.home.Home
import com.imashnake.animite.features.home.HomeScreen
import com.imashnake.animite.features.media.MediaPage
import com.imashnake.animite.features.navigationbar.NavigationBar
import com.imashnake.animite.features.navigationbar.NavigationBarPaths
import com.imashnake.animite.features.searchbar.SearchFrontDrop
import com.imashnake.animite.features.theme.AnimiteTheme
import com.imashnake.animite.profile.Profile
import com.imashnake.animite.navigation.HomeRoute
import com.imashnake.animite.navigation.NavigationBar
import com.imashnake.animite.navigation.NavigationBarPaths
import com.imashnake.animite.navigation.ProfileRoute
import com.imashnake.animite.navigation.SocialRoute
import com.imashnake.animite.profile.ProfileScreen
import com.imashnake.animite.profile.dev.internal.ANILIST_AUTH_DEEPLINK
import com.imashnake.animite.social.Social
import com.imashnake.animite.social.SocialScreen
import dagger.hilt.android.AndroidEntryPoint

Expand Down Expand Up @@ -89,8 +89,8 @@ fun MainScreen(modifier: Modifier = Modifier) {
LocalContentColor provides MaterialTheme.colorScheme.onBackground
) {
SharedTransitionLayout {
NavHost(navController = navController, startDestination = Home) {
composable<Home> {
NavHost(navController = navController, startDestination = HomeRoute) {
composable<HomeRoute> {
HomeScreen(
onNavigateToMediaItem = { navController.navigate(it) },
sharedTransitionScope = this@SharedTransitionLayout,
Expand All @@ -103,14 +103,14 @@ fun MainScreen(modifier: Modifier = Modifier) {
animatedVisibilityScope = this,
)
}
composable<Profile>(
composable<ProfileRoute>(
deepLinks = listOf(
navDeepLink { uriPattern = ANILIST_AUTH_DEEPLINK }
)
) {
ProfileScreen()
}
composable<Social> {
composable<SocialRoute> {
SocialScreen()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import com.imashnake.animite.dev.SharedContentKey.Component.Image
import com.imashnake.animite.dev.SharedContentKey.Component.Page
import com.imashnake.animite.dev.SharedContentKey.Component.Text
import com.imashnake.animite.features.media.MediaPage
import kotlinx.serialization.Serializable
import com.imashnake.animite.core.R as coreR

@OptIn(ExperimentalSharedTransitionApi::class)
Expand Down Expand Up @@ -194,7 +193,7 @@ fun HomeScreen(
},
contentModifier = Modifier.padding(
top = LocalPaddings.current.large,
bottom = dimensionResource(coreR.dimen.navigation_bar_height) + LocalPaddings.current.large
bottom = dimensionResource(com.imashnake.animite.navigation.R.dimen.navigation_bar_height) + LocalPaddings.current.large
imashnake0 marked this conversation as resolved.
Show resolved Hide resolved
),
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.large)
)
Expand Down Expand Up @@ -342,6 +341,3 @@ private fun MediaTypeSelector(
}
}
}

@Serializable
data object Home
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imeNestedScroll
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -49,9 +47,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.imashnake.animite.R
import com.imashnake.animite.api.anilist.sanitize.search.Search
import com.imashnake.animite.api.anilist.type.MediaType
import com.imashnake.animite.core.Constants
import com.imashnake.animite.core.extensions.landscapeCutoutPadding
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.Constants
import com.imashnake.animite.core.ui.MediaSmall
import com.imashnake.animite.core.R as coreR

Expand Down Expand Up @@ -79,7 +77,7 @@ fun SearchFrontDrop(
var isExpanded by rememberSaveable { mutableStateOf(false) }
val searchBarBottomPadding: Dp by animateDpAsState(
targetValue = if (hasExtraPadding) {
dimensionResource(coreR.dimen.navigation_bar_height)
dimensionResource(com.imashnake.animite.navigation.R.dimen.navigation_bar_height)
} else 0.dp,
label = "translate_search_bar"
)
Expand Down Expand Up @@ -144,7 +142,7 @@ fun SearchList(
bottom = dimensionResource(R.dimen.search_bar_height)
+ LocalPaddings.current.large
+ LocalPaddings.current.large
+ dimensionResource(coreR.dimen.navigation_bar_height)
+ dimensionResource(com.imashnake.animite.navigation.R.dimen.navigation_bar_height)
+ WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
),
verticalArrangement = Arrangement.spacedBy(LocalPaddings.current.small)
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<resources>
<string name="app_name">Animite</string>
<string name="home">Home</string>
<string name="profile">Profile</string>
<string name="social">Social</string>

<!-- Home -->
<string name="okaeri" translatable="false">おかえり</string>
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

<dimen name="markdown_block_corner_radius">3dp</dimen>

<dimen name="navigation_bar_height">65dp</dimen>

<dimen name="progress_indicator_width">100dp</dimen>
<dimen name="progress_indicator_height">3dp</dimen>

Expand Down
36 changes: 36 additions & 0 deletions navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.detekt)
}

android {
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

buildFeatures {
compose = true
}
composeCompiler.enableStrongSkippingMode = true

namespace = "com.imashnake.animite.navigation"
}

kotlin {
jvmToolchain(17)
}

dependencies {
api(libs.androidx.navigationCompose)
implementation(libs.bundles.compose)
implementation(libs.compose.material)
debugImplementation(libs.compose.ui.tooling)
implementation(libs.compose.ui.toolingPreview)
implementation(libs.kotlinx.serialization.core)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imashnake.animite.features.navigationbar
package com.imashnake.animite.navigation

import android.content.res.Configuration
import androidx.annotation.StringRes
Expand Down Expand Up @@ -27,8 +27,6 @@ import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.currentBackStackEntryAsState
import com.imashnake.animite.R
import com.imashnake.animite.core.R as coreR

@Composable
fun NavigationBar(
Expand All @@ -39,7 +37,7 @@ fun NavigationBar(
// TODO: Can we use `navigationBarsPadding()` instead?
NavigationBar(
Modifier.height(
dimensionResource(coreR.dimen.navigation_bar_height) + WindowInsets
dimensionResource(R.dimen.navigation_bar_height) + WindowInsets
.navigationBars
.asPaddingValues()
.calculateBottomPadding()
Expand Down Expand Up @@ -73,15 +71,15 @@ enum class NavigationBarPaths(
) {
Social(
navigateTo = {
it.navigate(com.imashnake.animite.social.Social) {
it.navigate(SocialRoute) {
popUpTo(id = it.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
}
},
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(com.imashnake.animite.social.Social::class) }
it.destination.hierarchy.any { it.hasRoute(SocialRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.social), contentDescription = stringResource(R.string.social))
Expand All @@ -90,7 +88,7 @@ enum class NavigationBarPaths(
),
Home(
navigateTo = {
it.navigate(com.imashnake.animite.features.home.Home) {
it.navigate(HomeRoute) {
popUpTo(id = it.graph.findStartDestination().id) {
saveState = true
inclusive = true
Expand All @@ -99,7 +97,7 @@ enum class NavigationBarPaths(
}
},
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(com.imashnake.animite.features.home.Home::class) }
it.destination.hierarchy.any { it.hasRoute(HomeRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.home), contentDescription = stringResource(R.string.home))
Expand All @@ -109,15 +107,15 @@ enum class NavigationBarPaths(

Profile(
navigateTo = {
it.navigate(com.imashnake.animite.profile.Profile()) {
it.navigate(ProfileRoute()) {
popUpTo(id = it.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
}
},
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(com.imashnake.animite.profile.Profile::class) }
it.destination.hierarchy.any { it.hasRoute(ProfileRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.profile), contentDescription = stringResource(R.string.profile))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.imashnake.animite.navigation

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ProfileRoute(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm a fan of this, but it suddenly becomes a bigger refactor to not have it here

@SerialName("accessToken")
val accessToken: String? = null,
@SerialName("tokenType")
val tokenType: String? = null,
@SerialName("expiresIn")
val expiresIn: Int = -1
)

@Serializable
data object SocialRoute

@Serializable
data object HomeRoute
4 changes: 4 additions & 0 deletions navigation/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="navigation_bar_height">65dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions navigation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="home">Home</string>
<string name="profile">Profile</string>
<string name="social">Social</string>
</resources>
1 change: 1 addition & 0 deletions profile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kotlin {
}

dependencies {
implementation(projects.navigation)
implementation(projects.core)
implementation(projects.api.anilist)
implementation(projects.api.preferences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import com.imashnake.animite.profile.tabs.AboutTab
import com.imashnake.animite.profile.tabs.AnimeTab
import com.imashnake.animite.profile.tabs.ProfileTabs
import kotlinx.coroutines.launch
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import com.imashnake.animite.core.R as coreR

@Suppress("LongMethod")
Expand Down Expand Up @@ -117,7 +115,7 @@ fun ProfileScreen(
contentModifier = Modifier
.padding(
top = LocalPaddings.current.large,
bottom = dimensionResource(coreR.dimen.navigation_bar_height)
bottom = dimensionResource(com.imashnake.animite.navigation.R.dimen.navigation_bar_height)
)
)
}
Expand Down Expand Up @@ -221,13 +219,3 @@ private fun UserTabs(
}
}
}

@Serializable
data class Profile(
@SerialName("accessToken")
val accessToken: String? = null,
@SerialName("tokenType")
val tokenType: String? = null,
@SerialName("expiresIn")
val expiresIn: Int = -1
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.imashnake.animite.api.anilist.AnilistUserRepository
import com.imashnake.animite.api.preferences.PreferencesRepository
import com.imashnake.animite.core.data.Resource
import com.imashnake.animite.core.data.Resource.Companion.asResource
import com.imashnake.animite.navigation.ProfileRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -27,7 +28,7 @@ class ProfileViewModel @Inject constructor(
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val navArgs = savedStateHandle.toRoute<Profile>()
private val navArgs = savedStateHandle.toRoute<ProfileRoute>()

val isLoggedIn = preferencesRepository
.accessToken
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ include(
":api:preferences",
":material-color-utilities",
":core",
":navigation",
":profile",
":rslash",
":social",
":app"
)

Expand Down
2 changes: 1 addition & 1 deletion rslash/build.gradle.kts → social/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}

kotlin {
jvmToolchain(17)
jvmToolchain(21)
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,3 @@ fun SocialScreen() {
}
}
}

@Serializable
data object Social