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

Add date started and completed to BookDetailScreen #2

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 2 additions & 7 deletions app/src/main/java/com/enoch02/literarylinc/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.enoch02.literarylinc.navigation.NavigationGraph
import com.enoch02.literarylinc.navigation.LiteraryLincNavHost
import com.enoch02.literarylinc.ui.theme.LiteraryLincTheme
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.components.SingletonComponent
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
Expand All @@ -27,7 +22,7 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
NavigationGraph()
LiteraryLincNavHost()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.enoch02.more.navigation.MoreScreenDestination
import com.enoch02.more.settings.SettingsScreen

@Composable
fun NavigationGraph(navController: NavHostController = rememberNavController()) {
fun LiteraryLincNavHost(navController: NavHostController = rememberNavController()) {
NavHost(
navController = navController,
startDestination = Screen.LiteraryLincApp.route,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/enoch02/literarylinc/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.enoch02.literarylinc.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
Expand Down Expand Up @@ -73,4 +75,4 @@ fun LiteraryLincTheme(
typography = Typography,
content = content
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.enoch02.bookdetail

import android.icu.text.SimpleDateFormat
import android.os.Build
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -30,9 +32,15 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.enoch02.composables.BookDetailHeader
import com.enoch02.composables.BookInfoText
import com.enoch02.components.BookDetailHeader
import com.enoch02.components.BookInfoText
import com.enoch02.database.model.Book
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Date
import java.util.Locale

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -159,11 +167,16 @@ fun BookDetailScreen(
value = "${book.pageCount}"
)
}
item { BookInfoText(header = "Date Started", value = "Demo value") }
item {
BookInfoText(
header = "Date Started",
value = formatEpochDate(book.dateStarted)
)
}
item {
BookInfoText(
header = "Date Completed",
value = "Demo value"
value = formatEpochDate(book.dateCompleted)
)
}
item {
Expand All @@ -175,7 +188,7 @@ fun BookDetailScreen(
item {
BookInfoText(
header = "Personal Rating",
value = "${book.personalRating}"
value = "${book.personalRating}/10"
)
}
item { BookInfoText(header = "ISBN", value = book.isbn) }
Expand All @@ -188,3 +201,26 @@ fun BookDetailScreen(
}
)
}

//TODO: move to some module or package...
fun formatEpochDate(date: Long?): String {
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && date != null -> {
val formatter = DateTimeFormatter.ofPattern("dd MMM yyyy")
val dateObj = LocalDateTime.ofInstant(
Instant.ofEpochMilli(date),
ZoneId.systemDefault()
)
formatter.format(dateObj)
}

Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && date != null -> {
val formatter = SimpleDateFormat("dd MMM yyyy", Locale.ROOT)
formatter.format(Date(date))
}

else -> {
""
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.enoch02.composables
package com.enoch02.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.enoch02.composables
package com.enoch02.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -7,7 +7,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.enoch02.composables
package com.enoch02.components

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
Expand Down
Loading