Skip to content

Commit

Permalink
Merge pull request #29
Browse files Browse the repository at this point in the history
Update weekly report chart properties
  • Loading branch information
Jacob3075 authored Oct 4, 2022
2 parents 8d55321 + 0b33aeb commit 22a1231
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Android Lint
on: push

jobs:
build:
lint_checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
package com.jacob.wakatimeapp.core.models

data class Time(val hours: Int, val minutes: Int, val decimal: Float) {
@Suppress("MagicNumber")
fun toMinutes(): Int = (hours * 60) + minutes
data class Time(
val hours: Int,
val minutes: Int,
val decimal: Float,
val totalSeconds: Int = calculateTotalSeconds(hours, minutes),
) {
fun toMinutes(): Int = (hours * MINUTES_IN_HOURS) + minutes

fun formattedPrint() = "${hours}H, ${minutes}M"

fun longFormattedPrint() = "$hours Hours, $minutes Minutes"

companion object {
private fun calculateTotalSeconds(hours: Int, minutes: Int) =
(hours * MINUTES_IN_HOURS * MINUTES_IN_HOURS) + (minutes * MINUTES_IN_HOURS)

fun fromDecimal(decimal: Float): Time {
val hours = decimal.toInt()
val minutesDecimal = (decimal - hours) * MINUTES_IN_HOURS
val minutes = minutesDecimal.toInt()
val totalSeconds = calculateTotalSeconds(hours, minutes)
return Time(
decimal = decimal,
hours = hours,
minutes = minutes,
totalSeconds = totalSeconds
)
}

fun createFrom(timeString: String, decimal: String): Time {
val (hours, minutes) = timeString.split(":")
.map(String::toInt)
return Time(hours, minutes, decimal.toFloat())
}

private const val MINUTES_IN_HOURS = 60
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.jacob.wakatimeapp.home.ui.components
import android.content.res.Configuration
import android.graphics.Color
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.widget.LinearLayout
import android.widget.LinearLayout.LayoutParams
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -38,6 +38,7 @@ import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.formatter.ValueFormatter
import com.jacob.wakatimeapp.core.common.getDisplayNameForDay
import com.jacob.wakatimeapp.core.models.DailyStats
import com.jacob.wakatimeapp.core.models.Time
import com.jacob.wakatimeapp.core.ui.theme.WakaTimeAppTheme
import com.jacob.wakatimeapp.core.ui.theme.sectionSubtitle
import com.jacob.wakatimeapp.core.ui.theme.sectionTitle
Expand Down Expand Up @@ -94,12 +95,12 @@ private fun WeeklyReportChart(dailyStats: List<DailyStats>) {
modifier = Modifier.padding(spacing.small),
factory = {
RoundedBarChart(it).apply {
layoutParams = LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
data = barData

configureChartProperties()
configureAxis(labels)

data = barData
invalidate()
}
},
Expand Down Expand Up @@ -134,8 +135,10 @@ private fun getBarData(pairList: List<Pair<Int, DailyStats>>) =
)
}
val barDataSet = BarDataSet(entries, "Label").apply {
setDrawValues(false)
setDrawValues(true)
isHighlightEnabled = false
valueTextColor = Color.WHITE
valueFormatter = BarValueFormatter()
}
BarData(barDataSet).apply { barWidth = 0.3f }
}
Expand Down Expand Up @@ -209,3 +212,9 @@ private class YAxisHourFormatter : ValueFormatter() {
*/
override fun getAxisLabel(value: Float, axis: AxisBase) = "${value.toInt()}H"
}

private class BarValueFormatter : ValueFormatter() {
override fun getBarLabel(barEntry: BarEntry?): String =
Time.fromDecimal(barEntry?.y ?: 0f)
.formattedPrint()
}

0 comments on commit 22a1231

Please sign in to comment.