Skip to content

Commit

Permalink
Merge pull request #44 from Team-Notitime/feat/organization/42-manage…
Browse files Browse the repository at this point in the history
…ment-ui

Feat/organization/42 management UI
  • Loading branch information
easyhz authored Aug 7, 2024
2 parents 7922ec0 + 873efbb commit d84e38b
Show file tree
Hide file tree
Showing 66 changed files with 1,713 additions and 571 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation(projects.core.common)
implementation(projects.core.designSystem)
implementation(projects.core.network)
implementation(projects.core.model)

implementation(projects.domain.home)

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/easyhz/noffice/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import com.easyhz.noffice.core.design_system.theme.NofficeTheme
import com.easyhz.noffice.navigation.rememberNofficeNavController
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -12,8 +13,9 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
// WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
val nofficeNavController = rememberNofficeNavController()
NofficeTheme {
NofficeApp()
NofficeApp(nofficeNavController)
}
}
}
Expand Down
80 changes: 42 additions & 38 deletions app/src/main/java/com/easyhz/noffice/NofficeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,27 @@ import androidx.navigation.compose.NavHost
import com.easyhz.noffice.core.design_system.component.bottomBar.HomeBottomBar
import com.easyhz.noffice.core.design_system.component.button.HomeAddButton
import com.easyhz.noffice.core.design_system.component.scaffold.NofficeScaffold
import com.easyhz.noffice.navigation.announcement.announcementScreen
import com.easyhz.noffice.navigation.NofficeNavController
import com.easyhz.noffice.navigation.announcement.announcementGraph
import com.easyhz.noffice.navigation.announcement.navigateToAnnouncementDetail
import com.easyhz.noffice.navigation.announcement.navigateToAnnouncementNofficeSelection
import com.easyhz.noffice.navigation.home.homeScreen
import com.easyhz.noffice.navigation.home.homeGraph
import com.easyhz.noffice.navigation.home.navigateToHome
import com.easyhz.noffice.navigation.home.screen.Home
import com.easyhz.noffice.navigation.organization.navigateToOrganizationCreation
import com.easyhz.noffice.navigation.organization.navigateToOrganizationDetail
import com.easyhz.noffice.navigation.organization.navigateToOrganizationInvitation
import com.easyhz.noffice.navigation.organization.organizationScreen
import com.easyhz.noffice.navigation.rememberNofficeNavController
import com.easyhz.noffice.navigation.sign.signScreen
import com.easyhz.noffice.navigation.organization.organizationGraph
import com.easyhz.noffice.navigation.sign.signGraph
import com.easyhz.noffice.navigation.util.BOTTOM_BAR_DURATION
import com.easyhz.noffice.navigation.util.BottomMenuTabs
import com.easyhz.noffice.navigation.util.DURATION

@Composable
fun NofficeApp() {
val nofficeNavController = rememberNofficeNavController()
internal fun NofficeApp(
nofficeNavController: NofficeNavController
) {
val navController = nofficeNavController.navController
val isVisibleBottomBar = nofficeNavController.isInBottomTabs()

val currentTab = nofficeNavController.mapRouteToTab()

NofficeScaffold(
floatingActionButton = {
AnimatedVisibility(
Expand Down Expand Up @@ -81,40 +78,47 @@ fun NofficeApp() {
NavHost(
navController = navController,
startDestination = Home,
enterTransition = { slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Start, tween(
DURATION
)) },
exitTransition = { slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.Start, tween(
DURATION
)) },
popEnterTransition = { slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.End, tween(
DURATION
)) },
popExitTransition = { slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.End, tween(
DURATION
)) }
enterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Start, tween(
DURATION
)
)
},
exitTransition = {
slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.Start, tween(
DURATION
)
)
},
popEnterTransition = {
slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.End, tween(
DURATION
)
)
},
popExitTransition = {
slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.End, tween(
DURATION
)
)
}
) {
homeScreen(
homeGraph(
modifier = Modifier.padding(it),
navigateToAnnouncementDetail = navController::navigateToAnnouncementDetail
)
organizationScreen(
organizationGraph(
modifier = Modifier.padding(it),
navigateToOrganizationDetail = navController::navigateToOrganizationDetail,
navigateToAnnouncementDetail = navController::navigateToAnnouncementDetail,
navigateToCreation = navController::navigateToOrganizationCreation,
navigateToInvitation = navController::navigateToOrganizationInvitation,
navigateToHome = navController::navigateToHome,
navigateToUp = navController::navigateUp
navController = navController,
)
signScreen(
navigateToHome = navController::navigateToHome
signGraph(
navigateToHome = navController::navigateToHome
)
announcementScreen(
announcementGraph(
navController = navController,
)
}
Expand Down
36 changes: 20 additions & 16 deletions app/src/main/java/com/easyhz/noffice/navigation/NavController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.easyhz.noffice.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavBackStackEntry
import androidx.compose.ui.util.trace
import androidx.navigation.NavDestination
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
Expand All @@ -16,19 +18,20 @@ import com.easyhz.noffice.navigation.util.BottomMenuTabs

@Composable
internal fun rememberNofficeNavController(navController: NavHostController = rememberNavController()) =
remember { NofficeNavController(navController = navController) }
remember(navController) { NofficeNavController(navController = navController) }

internal class NofficeNavController(
val navController: NavHostController
) {
private val navBackStackEntry: NavBackStackEntry?
@Composable get() = navController.currentBackStackEntryAsState().value
private val currentDestination: NavDestination?
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination

private val routes: List<String>
@Composable get() = remember { BottomMenuTabs.entries.map { it.qualifierName } }

private val currentRoute: String?
@Composable get() = navBackStackEntry?.destination?.route
@Composable get() = currentDestination?.route

@Composable
fun isInBottomTabs(): Boolean = currentRoute in routes
Expand All @@ -44,18 +47,19 @@ internal class NofficeNavController(

fun navigate(route: BottomMenuTabs) {
if (route.qualifierName == navController.currentDestination?.route) return
val navOptions = navOptions {
popUpTo(navController.graph.id) {
saveState = true
inclusive = false
trace("Navigation: ${route.name}") {
val navOptions = navOptions {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
when (route) {
BottomMenuTabs.HOME -> navController.navigateToHome(navOptions)
BottomMenuTabs.ADD -> navController.navigateToAnnouncementNofficeSelection()
BottomMenuTabs.ORGANIZATION -> navController.navigateToOrganization(navOptions)
}
launchSingleTop = true
restoreState = true
}
when (route) {
BottomMenuTabs.HOME -> navController.navigateToHome(navOptions)
BottomMenuTabs.ADD -> navController.navigateToAnnouncementNofficeSelection()
BottomMenuTabs.ORGANIZATION -> navController.navigateToOrganization(navOptions)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.easyhz.noffice.navigation.announcement.screen.AnnouncementCreation
import com.easyhz.noffice.navigation.announcement.screen.AnnouncementDetail
import com.easyhz.noffice.navigation.util.sharedViewModel

internal fun NavGraphBuilder.announcementScreen(
internal fun NavGraphBuilder.announcementGraph(
navController: NavController,
) {
composable<AnnouncementDetail> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.navOptions
import com.easyhz.noffice.feature.home.screen.home.HomeScreen
import com.easyhz.noffice.navigation.home.screen.Home

internal fun NavGraphBuilder.homeScreen(
internal fun NavGraphBuilder.homeGraph(
modifier: Modifier,
navigateToAnnouncementDetail: (Int, String) -> Unit
) {
Expand All @@ -30,14 +29,8 @@ internal fun NavGraphBuilder.homeScreen(
}

internal fun NavController.navigateToHome(navOptions: NavOptions? = null) {
val mNavOptions = navOptions
?: navOptions {
popUpTo(this@navigateToHome.graph.id) {
inclusive = true
}
}
navigate(
route = Home,
navOptions = mNavOptions
navOptions = navOptions
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.navOptions
import androidx.navigation.toRoute
import com.easyhz.noffice.core.model.organization.OrganizationInformation
import com.easyhz.noffice.core.model.organization.member.MemberType
import com.easyhz.noffice.feature.organization.screen.creation.OrganizationCreationScreen
import com.easyhz.noffice.feature.organization.screen.detail.OrganizationDetailScreen
import com.easyhz.noffice.feature.organization.screen.invitation.OrganizationInvitationScreen
import com.easyhz.noffice.feature.organization.screen.management.OrganizationManagementScreen
import com.easyhz.noffice.feature.organization.screen.member.MemberScreen
import com.easyhz.noffice.feature.organization.screen.organization.OrganizationScreen
import com.easyhz.noffice.feature.organization.screen.standby.StandbyMemberScreen
import com.easyhz.noffice.navigation.announcement.navigateToAnnouncementDetail
import com.easyhz.noffice.navigation.home.navigateToHome
import com.easyhz.noffice.navigation.organization.screen.MemberManagement
import com.easyhz.noffice.navigation.organization.screen.Organization
import com.easyhz.noffice.navigation.organization.screen.OrganizationCreation
import com.easyhz.noffice.navigation.organization.screen.OrganizationDetail
import com.easyhz.noffice.navigation.organization.screen.OrganizationInvitation
import com.easyhz.noffice.navigation.organization.screen.OrganizationManagement
import com.easyhz.noffice.navigation.organization.screen.StandbyMember

internal fun NavGraphBuilder.organizationScreen(
internal fun NavGraphBuilder.organizationGraph(
modifier: Modifier,
navigateToOrganizationDetail: (Int, String) -> Unit,
navigateToAnnouncementDetail: (Int, String) -> Unit,
navigateToCreation: () -> Unit,
navigateToInvitation: (String, String)-> Unit,
navigateToHome: () -> Unit,
navigateToUp: () -> Unit,
navController: NavController,
) {
composable<Organization>(
enterTransition = { fadeIn(animationSpec = tween(700)) },
Expand All @@ -36,34 +41,65 @@ internal fun NavGraphBuilder.organizationScreen(
) {
OrganizationScreen(
modifier = modifier,
navigateToCreation = navigateToCreation,
navigateToDetail = navigateToOrganizationDetail
navigateToCreation = navController::navigateToOrganizationCreation,
navigateToDetail = navController::navigateToOrganizationDetail
)
}
composable<OrganizationDetail> {
val args = it.toRoute<OrganizationDetail>()
OrganizationDetailScreen(
organizationId = args.organizationId,
organizationName = args.organizationName,
navigateToUp = navigateToUp,
navigateToAnnouncementDetail = navigateToAnnouncementDetail
navigateToUp = navController::navigateUp,
navigateToAnnouncementDetail = navController::navigateToAnnouncementDetail,
navigateToStandbyMember = navController::navigateToStandbyMember,
navigateToOrganizationManagement = navController::navigateToOrganizationManagement
)
}
composable<OrganizationManagement>(
typeMap = OrganizationManagement.typeMap
) {
val args = it.toRoute<OrganizationManagement>()
OrganizationManagementScreen(
organizationInformation = args.organizationInformation,
numberOfMembers = args.numberOfMembers,
navigateToUp = navController::navigateUp,
navigateToMemberManagement = navController::navigateToMemberManagement,
)
}
composable<MemberManagement> {
val args = it.toRoute<MemberManagement>()
MemberScreen(
organizationId = args.organizationId,
navigateToUp = navController::navigateUp
)
}
composable<OrganizationCreation> {
OrganizationCreationScreen(
navigateToInvitation = navigateToInvitation,
navigateToUp = navigateToUp
navigateToInvitation = navController::navigateToOrganizationInvitation,
navigateToUp = navController::navigateUp,
)
}
composable<OrganizationInvitation> {
val args = it.toRoute<OrganizationInvitation>()
val navOptions = navOptions {
popUpTo(navController.graph.id) {
inclusive = true
}
}
OrganizationInvitationScreen(
invitationUrl = args.invitationUrl,
imageUrl = args.imageUrl,
navigateToHome = navigateToHome
navigateToHome = { navController.navigateToHome(navOptions) }
)
}
composable<StandbyMember> {
val args = it.toRoute<StandbyMember>()
StandbyMemberScreen(
organizationId = args.organizationId,
navigateToUp = navController::navigateUp
)
}

}

internal fun NavController.navigateToOrganization(navOptions: NavOptions) {
Expand All @@ -77,6 +113,17 @@ internal fun NavController.navigateToOrganizationDetail(id: Int, name: String) {
navigate(OrganizationDetail(organizationId = id, organizationName = name))
}

internal fun NavController.navigateToOrganizationManagement(
information: OrganizationInformation,
number: LinkedHashMap<MemberType, Int>
) {
navigate(OrganizationManagement(organizationInformation = information, numberOfMembers = number))
}

internal fun NavController.navigateToMemberManagement(id: Int) {
navigate(MemberManagement(id))
}

internal fun NavController.navigateToOrganizationCreation() {
navigate(OrganizationCreation)
}
Expand All @@ -86,4 +133,8 @@ internal fun NavController.navigateToOrganizationInvitation(invitationUrl: Strin
popUpTo(OrganizationCreation) { inclusive = true }
}
navigate(OrganizationInvitation(invitationUrl = invitationUrl, imageUrl = imageUrl), navOptions)
}

internal fun NavController.navigateToStandbyMember(id: Int) {
navigate(StandbyMember(id))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.easyhz.noffice.navigation.organization.screen

import kotlinx.serialization.Serializable

@Serializable
data class MemberManagement(
val organizationId: Int
)
Loading

0 comments on commit d84e38b

Please sign in to comment.