Skip to content

Commit

Permalink
Fix frequency formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Dec 17, 2023
1 parent 7afe283 commit 9b4d349
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
19 changes: 13 additions & 6 deletions app/src/main/java/dev/zwander/cellreader/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.WindowCompat
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import dev.zwander.cellreader.data.CellReaderTheme
import dev.zwander.cellreader.data.data.CellModel
import dev.zwander.cellreader.data.data.ProvideCellModel
import dev.zwander.cellreader.data.util.preferences
import dev.zwander.cellreader.data.util.toColorInt
import dev.zwander.cellreader.ui.components.BottomBarScrimContainer
import dev.zwander.cellreader.ui.components.MainContent
import dev.zwander.cellreader.ui.view.PermissionRationaleBottomSheetDialog
Expand Down Expand Up @@ -168,12 +168,19 @@ class MainActivity : ComponentActivity(), CoroutineScope by MainScope() {
false
)

WindowCompat.setDecorFitsSystemWindows(window, false)
val controller = WindowCompat.getInsetsController(window, window.decorView)

setContent {
val sysUiController = rememberSystemUiController()
sysUiController.setStatusBarColor(Color.Transparent)
sysUiController.setNavigationBarColor(Color.Transparent)
sysUiController.statusBarDarkContentEnabled = !isSystemInDarkTheme()
sysUiController.navigationBarDarkContentEnabled = !isSystemInDarkTheme()
controller.isAppearanceLightStatusBars = !isSystemInDarkTheme()
controller.isAppearanceLightNavigationBars = !isSystemInDarkTheme()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isStatusBarContrastEnforced = false
window.isNavigationBarContrastEnforced = false
}
window.statusBarColor = Color.Transparent.toColorInt()
window.navigationBarColor = Color.Transparent.toColorInt()

Content()
}
Expand Down
21 changes: 16 additions & 5 deletions data/src/main/java/dev/zwander/cellreader/data/ARFCNTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.zwander.cellreader.data


import android.os.Parcelable
import dev.zwander.cellreader.data.util.roundTo
import dev.zwander.cellreader.data.wrappers.CellType
import kotlinx.parcelize.Parcelize
import java.util.*
Expand Down Expand Up @@ -153,14 +154,14 @@ object ARFCNTools {
val fdl = if (firstDl != -1) {
refContainer.fRefOff.toDouble() + refContainer.dfGlobal.toDouble() * (nrarfcn - refContainer.nRefOff.toDouble())
} else {
-1
-1.0
}
val ful = if (firstUl != -1) {
val realDl = if (firstDl == -1) firstUl else firstDl

refContainer.fRefOff.toDouble() + refContainer.dfGlobal.toDouble() * ((realDl - firstUl).absoluteValue + nrarfcn - refContainer.nRefOff.toDouble())
} else {
-1
-1.0
}

ARFCNInfo(
Expand All @@ -183,11 +184,21 @@ object ARFCNTools {
}

@Parcelize
data class ARFCNInfo(
data class ARFCNInfo private constructor(
val band: String,
val dlFreq: Number,
val ulFreq: Number
) : Parcelable
val ulFreq: Number,
) : Parcelable {
companion object {
operator fun invoke(band: String, dlFreq: Number, ulFreq: Number): ARFCNInfo {
return ARFCNInfo(
band = band,
dlFreq = dlFreq.roundTo(2),
ulFreq = ulFreq.roundTo(2),
)
}
}
}

data class ARFCNContainer(
val dlLow: Number = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.zwander.cellreader.data.util

import kotlin.math.pow
import kotlin.math.roundToInt

fun Number.roundTo(numFractionDigits: Int): Number {
val factor = 10.0.pow(numFractionDigits.toDouble())
return (this.toDouble() * factor).roundToInt() / factor
}

0 comments on commit 9b4d349

Please sign in to comment.