Skip to content

Commit

Permalink
Merge pull request #21 from dmzz-yyhyy/detail_ui
Browse files Browse the repository at this point in the history
完成书本信息页ui
  • Loading branch information
dmzz-yyhyy authored Jul 18, 2024
2 parents 8183773 + c7c889b commit 68d5ec9
Show file tree
Hide file tree
Showing 21 changed files with 684 additions and 276 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetSelector.xml

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

Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package indi.dmzz_yyhyy.lightnovelreader

import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.RequiresApi
import androidx.compose.material3.MaterialTheme
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import dagger.hilt.android.AndroidEntryPoint
import indi.dmzz_yyhyy.lightnovelreader.ui.LightNovelReaderApp

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class BookInformation(
val publishingHouse: String,
val wordCount: Int,
val lastUpdated: LocalDateTime,
val isComplete: Boolean,
)
val isComplete: Boolean
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package indi.dmzz_yyhyy.lightnovelreader.data.book

data class ChapterInformation(
val id: Int
val id: Int,
val title: String
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package indi.dmzz_yyhyy.lightnovelreader.ui

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import indi.dmzz_yyhyy.lightnovelreader.ui.book.BookScreen
import indi.dmzz_yyhyy.lightnovelreader.ui.home.HomeScreen

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun LightNovelReaderApp() {
val navController = rememberNavController()
LightNovelReaderNavHost(navController)
}

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun LightNovelReaderNavHost(
navController: NavHostController
Expand All @@ -21,9 +26,19 @@ fun LightNovelReaderNavHost(
composable(route = Screen.Home.route) {
HomeScreen(
onOpenBook = {
navController.navigate(Screen.Book.Detail.createRoute(it))
navController.navigate(Screen.Book.createRoute(it))
}
)
}
composable(
route = Screen.Book.route,
arguments = Screen.Book.navArguments
) {
it.arguments?.let { it1 ->
BookScreen(
onClickBackButton = { navController.popBackStack() },
id = it1.getInt("bookId")
) }
}
}
}
22 changes: 11 additions & 11 deletions app/src/main/java/indi/dmzz_yyhyy/lightnovelreader/ui/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ sealed class Screen(
data object Bookshelf : Screen("home_bookshelf")
data object Settings : Screen("home_settings")
}
data object Book {
data object Detail : Screen(
route = "detail/{bookId}",
navArguments = listOf(navArgument("bookId") {
type = NavType.IntType
})
) {
fun createRoute(bookId: Int) = "detail/${bookId}"
}
data object Book : Screen(
route = "book/{bookId}",
navArguments = listOf(navArgument("bookId") {
type = NavType.IntType
})
) {
fun createRoute(bookId: Int) = "book/${bookId}"

data object Detail: Screen("detail")
data object Content : Screen(
route = "content/content/{chapterId}",
route = "book_content/{chapterId}",
navArguments = listOf(navArgument("chapterId") {
type = NavType.IntType
})
) {
fun createRoute(chapterId: Int) = "content/${chapterId}"
fun createRoute(chapterId: Int) = "book_content/${chapterId}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package indi.dmzz_yyhyy.lightnovelreader.ui.book

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import indi.dmzz_yyhyy.lightnovelreader.ui.Screen
import indi.dmzz_yyhyy.lightnovelreader.ui.book.detail.DetailScreen

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun BookScreen(
onClickBackButton: () -> Unit,
id: Int) {
val navController = rememberNavController()
var topBar : @Composable () -> Unit by remember { mutableStateOf(@Composable {}) }
var dialog : @Composable () -> Unit by remember { mutableStateOf(@Composable {}) }
Scaffold(
topBar = topBar
) { it ->
NavHost(
modifier = Modifier.padding(it),
navController = navController,
startDestination = Screen.Book.Detail.route
) {
composable(
route = Screen.Book.Detail.route,
arguments = Screen.Book.Detail.navArguments
) {
DetailScreen(
onClickBackButton = onClickBackButton,
topBar = {newTopBar ->
topBar = newTopBar
},
dialog = {newdialog ->
dialog = newdialog
}
)
}
}
dialog()
}
}
Loading

0 comments on commit 68d5ec9

Please sign in to comment.