Skip to content

Commit

Permalink
Hotfix for relative percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
francoiscampbell committed Mar 20, 2016
1 parent 3f262e0 commit cec9538
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.francoiscampbell.xposeddatausage.model.usage

import android.graphics.Color
import de.robv.android.xposed.XposedBridge
import io.github.francoiscampbell.xposeddatausage.BuildConfig

/**
* Created by francois on 16-03-11.
Expand All @@ -9,6 +11,11 @@ class DataUsageFormatter(var format: UnitFormat = DataUsageFormatter.UnitFormat.
var decimalPlaces: Int = 2,
var relativeToPace: Boolean = false) {
fun format(dataUsage: DataUsageFetcher.DataUsage) = formatForPace(dataUsage).run {
if (BuildConfig.DEBUG) {
XposedBridge.log("relativeToPace: ${relativeToPace}")
XposedBridge.log(toString())
}

val absBytes = Math.abs(bytes)
val displayFormat = when (format) {
UnitFormat.SMART_SI -> when {
Expand Down Expand Up @@ -37,19 +44,19 @@ class DataUsageFormatter(var format: UnitFormat = DataUsageFormatter.UnitFormat.

fun getColor(dataUsage: DataUsageFetcher.DataUsage) = formatForPace(dataUsage).run {
when {
bytes > warningBytes && warningBytes >= 0 -> Color.YELLOW
bytes > limitBytes && limitBytes >= 0 -> Color.RED
bytes > warningBytes && warningBytes >= 0 -> Color.YELLOW
else -> null
}
}

fun formatForPace(dataUsage: DataUsageFetcher.DataUsage) = dataUsage.run {
when (relativeToPace) {
true -> when (format) {
UnitFormat.PCT_WARNING, UnitFormat.PCT_LIMIT -> DataUsageFetcher.DataUsage(
bytes,
(warningBytes * progressThroughCycle).toLong(),
(limitBytes * progressThroughCycle).toLong(),
UnitFormat.PCT_WARNING -> DataUsageFetcher.DataUsage(
bytes - (warningBytes * progressThroughCycle).toLong(), //bytes over pace warning
(warningBytes * progressThroughCycle).toLong(), //warning scaled to current time
(limitBytes * progressThroughCycle).toLong(), //limit scaled to current time
progressThroughCycle)
else -> DataUsageFetcher.DataUsage(
bytes - (limitBytes * progressThroughCycle).toLong(), //bytes over pace limit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.francoiscampbell.xposeddatausage.widget

import android.graphics.Color
import de.robv.android.xposed.XposedBridge
import io.github.francoiscampbell.xposeddatausage.BuildConfig
import io.github.francoiscampbell.xposeddatausage.model.net.NetworkManagerImpl
import io.github.francoiscampbell.xposeddatausage.model.settings.OnSettingsChangedListener
import io.github.francoiscampbell.xposeddatausage.model.settings.SettingsImpl
Expand Down Expand Up @@ -40,10 +38,6 @@ class DataUsagePresenterImpl(private val view: DataUsageView, private val clockW
}

fetcher.getCurrentCycleBytes({ dataUsage ->
if (BuildConfig.DEBUG) {
XposedBridge.log("relativeToPace: ${settings.relativeToPace}")
XposedBridge.log(dataUsage.toString())
}
view.text = dataUsageFormatter.format(dataUsage)
clockWrapper.colorOverride = dataUsageFormatter.getColor(dataUsage)
}, { throwable ->
Expand Down

0 comments on commit cec9538

Please sign in to comment.