Skip to content

Commit

Permalink
WTA #90 updated charts to use vico charts and removed MpAndroidChart lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Dec 9, 2023
1 parent 704987f commit 2637026
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 360 deletions.
2 changes: 0 additions & 2 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ dependencies {

implementation(libs.lottie.compose)

implementation(libs.philJay.mpAndroidChart)

testImplementation(libs.test.junit4)
androidTestImplementation(libs.androidx.test.ext)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ val Typography = defaultTypography.let {
bodyMedium = it.bodyMedium.setDefaultFontFamily(),
bodySmall = it.bodySmall.setDefaultFontFamily(),
labelLarge = it.labelLarge.setDefaultFontFamily(),
labelMedium = it.labelMedium.setDefaultFontFamily(),
labelSmall = it.labelSmall.setDefaultFontFamily(),
labelMedium = it.labelMedium.setDefaultFontFamily().copy(fontSize = 10.sp),
labelSmall = it.labelSmall.setDefaultFontFamily().copy(fontSize = 8.sp),
)
}

Expand Down
2 changes: 0 additions & 2 deletions details/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ android {
dependencies {
implementation(libs.accompanist.pager)
implementation(libs.accompanist.pager.indicators)

implementation(libs.philJay.mpAndroidChart)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.data.EmptyGroup.data
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.github.mikephil.charting.animation.Easing
Expand All @@ -29,7 +30,6 @@ import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.formatter.ValueFormatter
import com.jacob.wakatimeapp.core.common.utils.getDisplayNameForDay
import com.jacob.wakatimeapp.core.models.Time
import com.jacob.wakatimeapp.core.ui.components.RoundedBarChart
import com.jacob.wakatimeapp.core.ui.theme.spacing
import kotlinx.collections.immutable.ImmutableCollection
import kotlinx.collections.immutable.ImmutableMap
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ timber = "5.0.1" # https://github.com/JakeWharton/timber
coil = "2.4.0" # https://github.com/coil-kt/coil
appAuth = "0.11.1" # https://github.com/openid/AppAuth-Android
lottieCompose = "6.1.0" # https://github.com/airbnb/lottie-android
detekt = "1.23.1" # https://detekt.dev
detekt = "1.23.3" # https://detekt.dev
gradleVersionsPlugin = "0.48.0" # https://github.com/ben-manes/gradle-versions-plugin
turbine = "0.13.0" # https://github.com/cashapp/turbine/
mockk = "1.13.7" # https://mockk.io
mannodermausAndroidJunit5 = "1.9.3.0" # https://github.com/mannodermaus/android-junit5
mpAndroidChart = "v3.1.0"
vico = "1.13.1"

detektVersion = "0.0.26"
detektFormatting = "1.22.0"
Expand Down Expand Up @@ -121,7 +121,7 @@ arrow-kt-core = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
lottie-compose = { module = "com.airbnb.android:lottie-compose", version.ref = "lottieCompose" }
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
appAuth = { module = "net.openid:appauth", version.ref = "appAuth" }
philJay-mpAndroidChart = { module = "com.github.PhilJay:MPAndroidChart", version.ref = "mpAndroidChart" }
vico-compose-m3 = { group = "com.patrykandpatrick.vico", name = "compose-m3", version.ref = "vico" }

detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
gradle-version-plugin = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "gradleVersionsPlugin" }
Expand Down
2 changes: 1 addition & 1 deletion home/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
dependencies {
// Image Loading, Charts, Lottie Animations
implementation(libs.coil.kt.compose)
implementation(libs.philJay.mpAndroidChart)
implementation(libs.vico.compose.m3)

implementation(libs.androidx.dataStore.preferences)
}
13 changes: 10 additions & 3 deletions home/src/main/java/com/jacob/wakatimeapp/home/ui/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand All @@ -33,6 +34,7 @@ import com.jacob.wakatimeapp.core.ui.theme.spacing
import com.jacob.wakatimeapp.home.domain.models.HomePageUserDetails
import com.jacob.wakatimeapp.home.domain.models.Last7DaysStats
import com.jacob.wakatimeapp.home.domain.models.Streak
import com.jacob.wakatimeapp.home.ui.HomePageViewState.Loaded
import com.jacob.wakatimeapp.home.ui.components.OtherDailyStatsSection
import com.jacob.wakatimeapp.home.ui.components.RecentProjects
import com.jacob.wakatimeapp.home.ui.components.UserDetailsSection
Expand Down Expand Up @@ -61,6 +63,7 @@ private fun HomePageScreen(
) {
val snackBarCoroutineScope = rememberCoroutineScope()
val viewState by viewModel.homePageState.collectAsState()
val todaysDate = remember { viewModel.getTodaysDate() }

LaunchedEffect(viewState) {
Timber.d("viewState: $viewState")
Expand All @@ -79,6 +82,7 @@ private fun HomePageScreen(
viewState = viewState,
toDetailsPage = navigator::toProjectDetailsPage,
toSearchPage = navigator::toSearchPage,
todaysDate = todaysDate,
modifier = modifier,
)
}
Expand All @@ -89,6 +93,7 @@ private fun HomePageContent(
toDetailsPage: (String) -> Unit,
toSearchPage: () -> Unit,
modifier: Modifier = Modifier,
todaysDate: LocalDate,
) {
Column(modifier = modifier.statusBarsPadding()) {
when (viewState) {
Expand All @@ -97,6 +102,7 @@ private fun HomePageContent(
homePageViewState = viewState,
toDetailsPage = toDetailsPage,
toSearchPage = toSearchPage,
todaysDate = todaysDate,
)

is HomePageViewState.Error -> HomePageError(viewState)
Expand All @@ -106,9 +112,10 @@ private fun HomePageContent(

@Composable
private fun HomePageLoaded(
homePageViewState: HomePageViewState.Loaded,
homePageViewState: Loaded,
toDetailsPage: (String) -> Unit,
toSearchPage: () -> Unit = {},
todaysDate: LocalDate,
) {
val scrollState = rememberScrollState()
val spacing = MaterialTheme.spacing
Expand Down Expand Up @@ -140,7 +147,7 @@ private fun HomePageLoaded(
)
Spacer(modifier = Modifier.height(spacing.extraSmall))

WeeklyReport(homePageViewState.last7DaysStats.weeklyTimeSpent)
WeeklyReport(homePageViewState.last7DaysStats.weeklyTimeSpent, today = todaysDate)
Spacer(modifier = Modifier.height(spacing.small))

OtherDailyStatsSection(
Expand Down Expand Up @@ -175,7 +182,7 @@ private fun HomePageLoading() = WtaAnimation(
private fun HomePagePreview(
@PreviewParameter(HomePagePreviewProvider::class) viewState: HomePageViewState,
) = WakaTimeAppTheme {
HomePageContent(viewState = viewState, toDetailsPage = { }, toSearchPage = { })
HomePageContent(viewState = viewState, toDetailsPage = { }, toSearchPage = { }, todaysDate = LocalDate(2023, 1, 1))
}

private class HomePagePreviewProvider : CollectionPreviewParameterProvider<HomePageViewState>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import arrow.core.Either
import arrow.core.raise.either
import com.jacob.wakatimeapp.core.common.utils.InstantProvider
import com.jacob.wakatimeapp.core.common.utils.log
import com.jacob.wakatimeapp.home.domain.usecases.CalculateCurrentStreakUC
import com.jacob.wakatimeapp.home.domain.usecases.CalculateLongestStreakUC
Expand All @@ -17,6 +18,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import kotlinx.datetime.LocalDate

@HiltViewModel
internal class HomePageViewModel @Inject constructor(
Expand All @@ -25,6 +27,7 @@ internal class HomePageViewModel @Inject constructor(
private val calculateCurrentStreakUC: CalculateCurrentStreakUC,
private val calculateLongestStreakUC: CalculateLongestStreakUC,
private val updateCachedHomePageUiData: UpdateCachedHomePageUiData,
private val instantProvider: InstantProvider,
ioDispatcher: CoroutineContext = Dispatchers.IO,
) : ViewModel() {

Expand Down Expand Up @@ -84,4 +87,6 @@ internal class HomePageViewModel @Inject constructor(
longestStreak = longestStreak,
)
}

fun getTodaysDate(): LocalDate = instantProvider.date()
}
Loading

0 comments on commit 2637026

Please sign in to comment.