Skip to content

Commit

Permalink
Add key learnings to summary details (#124)
Browse files Browse the repository at this point in the history
* feat: Add key learnings to summary details

* fixed detekt issues

* Refactor: Update PreviewData and codecov config

- Update `codecov.yml` to exclude `*View.kt` and `*PreviewData.kt` files
- Update `PreviewData` with key learning data

* Refactor: Remove unused indicators

- Removed `hasVideo` and `hasGraphic` properties from `SummaryUi`.
- Removed `hasVideo` and `hasGraphic` parameters from `SummaryItem` and `SummaryIndicators` composables.
- Removed unused indicators from library screen.
- Removed unused indicators from preview data.
- Updated UI to no longer display video and graphic indicators.

* - Added `@Suppress("DuplicatedCode")` to the `PreviewData` class to suppress the "DuplicatedCode" warning.

* Refactor: Improve preview data generation

- Replaced the manual creation of lists with helper functions.
- Created helper functions `createCategory` and `createSummary`.
- Simplified the creation of `allCategories` and `allSummaries`.

* Refactor: Improve landing screen

- Replaced the background image on the landing screen with a new one, `landing_image`.
- Changed the status bar color on the landing screen to `LandingStatusBar`.
- Changed the moto text on the landing screen to "The simplest, most focused way to experience life-changing book summaries".
  • Loading branch information
rygelouv authored Jan 4, 2025
1 parent 70b269d commit c105647
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 184 deletions.
230 changes: 93 additions & 137 deletions app/src/main/java/app/books/tanga/data/PreviewData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,156 +8,112 @@ import java.util.UUID

private const val FAKE_COVER_URL = "https://i.ibb.co/VSbtQ6d/02-Deep-Work-01-1-min.jpg"

private fun createCategory(id: String, name: String, icon: Int) = CategoryUi(
id = id,
name = name,
icon = icon
)

private fun createSummary(
title: String,
author: String,
duration: String,
keyLearnings: List<String> = emptyList()
) = SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = title,
author = author,
duration = duration,
keyLearnings = keyLearnings
)

/**
* Used for Compose Previews
*/
@Suppress("DuplicatedCode")
object PreviewData {
fun allCategories() =
buildList {
add(
CategoryUi(
id = "1",
name = "Business",
icon = R.drawable.ic_business
)
)
add(
CategoryUi(
id = "2",
name = "Personal Development",
icon = app.books.tanga.coreui.R.drawable.ic_self_development
)
)
add(
CategoryUi(
id = "3",
name = "Psychology",
icon = app.books.tanga.coreui.R.drawable.ic_productivity
)
)
add(
CategoryUi(
id = "4",
name = "Financial Education",
icon = app.books.tanga.coreui.R.drawable.ic_financial_education
)
)
}
listOf(
createCategory("1", "Business", R.drawable.ic_business),
createCategory("2", "Personal Development", R.drawable.ic_self_development),
createCategory("3", "Psychology", R.drawable.ic_productivity),
createCategory("4", "Financial Education", R.drawable.ic_financial_education)
)

@Suppress("LongMethod")
fun allSummaries() =
buildList<SummaryUi> {
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "It doesn't have to be crazy at work",
author = "Jason Fried and David Heinemeir Hannson",
duration = "10",
hasGraphic = true
)
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Atomic Habits",
author = "James Clear",
duration = "15",
hasVideo = true
)
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Deep Work",
author = "Cal Newport",
duration = "9",
hasGraphic = true
)
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Ego is the Enemy",
author = "Ryan Holiday",
duration = "13",
hasVideo = true
)
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "So Good They Can't Ignore You",
author = "Cal Newport",
duration = "11"
)
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Good To Great",
author = "Jim Collins",
duration = "8"
)
fun allSummaries() = listOf(
createSummary(
title = "It doesn't have to be crazy at work",
author = "Jason Fried and David Heinemeir Hannson",
duration = "10",
keyLearnings = listOf(
"Create uncontested market space to thrive",
"Make competition largely irrelevant through innovation",
"Create and capture new market demand",
"Break value-cost trade-off traditional markets",
"Align innovation with utility and cost"
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Never Split The Difference",
author = "Chris Voss",
duration = "10"
)
),
createSummary(
title = "Atomic Habits",
author = "James Clear",
duration = "15",
keyLearnings = listOf(
"Make tiny changes for remarkable results",
"Create environment that supports good habits",
"Use habit stacking to build routines",
"Break bad habits through system design",
"Focus on identity over outcome goals"
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "The Obstacle Is the Way",
author = "Ryan Holiday",
duration = "10",
hasGraphic = true,
hasVideo = true
)
),
createSummary(
title = "Deep Work",
author = "Cal Newport",
duration = "9",
keyLearnings = listOf(
"Create uncontested market space to thrive",
"Make competition largely irrelevant through innovation",
"Create and capture new market demand",
"Break value-cost trade-off traditional markets",
"Align innovation with utility and cost"
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Psychology Of Money",
author = "Morgan Housel",
duration = "10",
hasGraphic = true
)
),
createSummary(
title = "Ego is the Enemy",
author = "Ryan Holiday",
duration = "13",
keyLearnings = listOf(
"Master money basics in your twenties",
"Negotiate financial relationships with romantic partners",
"Create sustainable long-term financial plans",
"Tackle student debt with strategic approach",
"Invest early with limited financial means"
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "Rework",
author = "Jason Fried and David Heinemeir Hannson",
duration = "11",
hasGraphic = true,
hasVideo = true
)
),
createSummary(
title = "So Good They Can't Ignore You",
author = "Cal Newport",
duration = "11",
keyLearnings = listOf(
"Build sustainable business without constant growth",
"Maximize profit through intentional smallness",
"Create systems for autonomous operation",
"Focus on quality over quantity",
"Design lifestyle-centered business model"
)
add(
SummaryUi(
id = SummaryId(UUID.randomUUID().toString()),
coverUrl = FAKE_COVER_URL,
title = "The Subtle Art Of Not Giving A Fuck",
author = "Mark Manson",
duration = "9",
hasGraphic = true,
hasVideo = true
)
),
createSummary(
title = "Good To Great",
author = "Jim Collins",
duration = "8",
keyLearnings = listOf(
"Embrace vulnerability as source of strength",
"Build shame resilience through practice",
"Develop authentic leadership through openness",
)
}
),
)

const val SUMMARY_TEXT = "## Summary of Atomic Habits\n" +
"\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ fun FirestoreData.toSummary(): Summary = Summary(
categories = this[FirestoreDatabase.Summaries.Fields.CATEGORIES].toCategoryIds(),
coverImageUrl = this[FirestoreDatabase.Summaries.Fields.COVER_IMAGE_URL].toString(),
playingLength = this[FirestoreDatabase.Summaries.Fields.PLAYING_LENGTH].toString(),
purchaseBookUrl = this[FirestoreDatabase.Summaries.Fields.PURCHASE_BOOK_URL].toString()
purchaseBookUrl = this[FirestoreDatabase.Summaries.Fields.PURCHASE_BOOK_URL].toString(),
keyLearnings = this[FirestoreDatabase.Summaries.Fields.KEY_LEARNINGS].toKeyLearnings()
)

private fun Any?.toKeyLearnings(): List<String> = (this as? List<*>)?.map { it.toString() } ?: run { emptyList() }
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class SummaryRepositoryImpl @Inject constructor(
.document(summaryId.value)
.get()
.await()

summary.data?.toSummary() ?: throw Exception("Summary not found")
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/app/books/tanga/entity/Summary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ value class SummaryId(val value: String)
* @param author: the author of the book the summary is about
* @param coverImageUrl: the link to the summary cover image
* @param playingLength: the length of the summary audio
* @param slug: the slug of the summary
* @param synopsis: the book synopsis
* @param title: the title of the book the summary is about
* @param keyLearnings the list of key learnings from the summary
* @param categories: the list of categories the summary belongs to
*/
data class Summary(
Expand All @@ -21,5 +21,6 @@ data class Summary(
val coverImageUrl: String,
val playingLength: String,
val purchaseBookUrl: String,
val categories: List<CategoryId>
val categories: List<CategoryId>,
val keyLearnings: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ fun FavoriteGrid(
title = favorite.title,
author = favorite.author,
duration = favorite.playingLength,
// TODO: Add video indicator support
hasVideo = false,
// TODO: Add graphic indicator support
hasGraphic = false,
width = 134.dp,
titleSize = 18.sp,
onSummaryClick = { onFavoriteClick(SummaryId(favorite.summaryId)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun LandingScreen(
modifier = modifier.fillMaxSize()
) {
Image(
painter = painterResource(id = R.drawable.reading_background_image),
painter = painterResource(id = R.drawable.landing_image),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app.books.tanga.feature.onboarding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import app.books.tanga.coreui.theme.Crayola
import app.books.tanga.coreui.theme.Cultured
import app.books.tanga.coreui.theme.LandingStatusBar
import app.books.tanga.coreui.theme.Navy
import app.books.tanga.coreui.theme.YaleBlue
import com.google.accompanist.systemuicontroller.rememberSystemUiController
Expand Down Expand Up @@ -40,7 +40,7 @@ sealed class OnboardingTransitionElement(
val navigationBarColor: Color
) {
data object Landing : OnboardingTransitionElement(
statusBarColor = Crayola,
statusBarColor = LandingStatusBar,
navigationBarColor = Navy
)
data object Onboarding : OnboardingTransitionElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ data class SummaryUi(
val title: String,
val author: String,
val duration: String,
val keyLearnings: List<String>,
// TODO: 2023-09-21 make this non-nullable after FakeData is removed
val synopsis: String? = "",
val purchaseBookUrl: String? = null,
// TODO: 2023-09-21 Remove this after FakeData is removed
val hasGraphic: Boolean = false,
// TODO: 2023-09-21 Remove this after FakeData is removed
val hasVideo: Boolean = false
)

fun Summary.toSummaryUi(): SummaryUi =
Expand All @@ -28,7 +25,8 @@ fun Summary.toSummaryUi(): SummaryUi =
author = author,
duration = playingLength,
synopsis = synopsis,
purchaseBookUrl = purchaseBookUrl
purchaseBookUrl = purchaseBookUrl,
keyLearnings = keyLearnings
)

data class SummaryContentState(
Expand Down
Loading

0 comments on commit c105647

Please sign in to comment.