mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Enabled StrictMode, removed several deprecations
This commit is contained in:
1 parent
dca3f2c773
commit
1aefb04eb5
9 files changed
+45
-29
No files matched your search
@@ -18,6 +18,9 @@
|
||||
package com.rtbishop.look4sat
|
||||
|
||||
import android.app.Application
|
||||
import android.os.StrictMode
|
||||
import android.os.StrictMode.ThreadPolicy
|
||||
import android.os.StrictMode.VmPolicy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
@@ -28,6 +31,7 @@ class MainApplication : Application() {
|
||||
lateinit var container: MainContainer
|
||||
|
||||
override fun onCreate() {
|
||||
if (BuildConfig.DEBUG) enableStrictMode()
|
||||
super.onCreate()
|
||||
container = MainContainer(this)
|
||||
container.mainScope.launch { checkAutoUpdate() }
|
||||
@@ -37,11 +41,21 @@ class MainApplication : Application() {
|
||||
val settingsRepo = container.settingsRepo
|
||||
if (settingsRepo.otherSettings.value.updateState) {
|
||||
val timeDelta = System.currentTimeMillis() - settingsRepo.databaseState.value.timestamp
|
||||
if (timeDelta > 172800000) { // 48 hours in ms
|
||||
if (timeDelta > AUTO_UPDATE_DELTA_MS) {
|
||||
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
|
||||
println("Started periodic data update on ${sdf.format(Date())}")
|
||||
container.databaseRepo.updateFromRemote()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableStrictMode() {
|
||||
StrictMode.setThreadPolicy(ThreadPolicy.Builder().detectAll().penaltyLog().build())
|
||||
StrictMode.setVmPolicy(VmPolicy.Builder().detectAll().penaltyLog().build())
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val AUTO_UPDATE_DELTA_MS = 172_800_000L // 48 hours in ms
|
||||
const val MAX_OKHTTP_CACHE_SIZE = 10_000_000L // 10 Megabytes
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class MainContainer(private val context: Context) {
|
||||
}
|
||||
|
||||
private fun provideRemoteSource(): IRemoteSource {
|
||||
val cache = Cache(context.cacheDir, 1000 * 1000 * 10L)
|
||||
val cache = Cache(context.cacheDir, MainApplication.MAX_OKHTTP_CACHE_SIZE)
|
||||
val httpClient = OkHttpClient.Builder().cache(cache).build()
|
||||
return RemoteSource(httpClient, Dispatchers.IO)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.mutableDoubleStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -43,35 +44,35 @@ private fun FilterDialogPreview() {
|
||||
|
||||
@Composable
|
||||
fun FilterDialog(hours: Int, elevation: Double, toggle: () -> Unit, save: (Int, Double) -> Unit) {
|
||||
val hoursValue = rememberSaveable { mutableStateOf(hours) }
|
||||
val elevValue = rememberSaveable { mutableStateOf(elevation) }
|
||||
val hoursValue = rememberSaveable { mutableIntStateOf(hours) }
|
||||
val elevValue = rememberSaveable { mutableDoubleStateOf(elevation) }
|
||||
Dialog(onDismissRequest = { toggle() }) {
|
||||
ElevatedCard {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxWidth(1f)) {
|
||||
Text(text = "Filter passes", color = MaterialTheme.colorScheme.primary)
|
||||
Text(text = "Show passes that occur within X hours")
|
||||
OutlinedTextField(value = hoursValue.value.toString(), onValueChange = { newValue ->
|
||||
OutlinedTextField(value = hoursValue.intValue.toString(), onValueChange = { newValue ->
|
||||
val hoursAhead = try {
|
||||
newValue.toInt()
|
||||
} catch (exception: Exception) {
|
||||
12
|
||||
}
|
||||
hoursValue.value = hoursAhead
|
||||
hoursValue.intValue = hoursAhead
|
||||
})
|
||||
Text(text = "Show passes with max elevation above")
|
||||
OutlinedTextField(value = elevValue.value.toString(), onValueChange = { newValue ->
|
||||
OutlinedTextField(value = elevValue.doubleValue.toString(), onValueChange = { newValue ->
|
||||
val maxElevation = try {
|
||||
newValue.toDouble()
|
||||
} catch (exception: Exception) {
|
||||
16.0
|
||||
}
|
||||
elevValue.value = maxElevation
|
||||
elevValue.doubleValue = maxElevation
|
||||
})
|
||||
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
|
||||
CardButton(onClick = { toggle() }, text = "Cancel")
|
||||
CardButton(
|
||||
onClick = {
|
||||
save(hoursValue.value, elevValue.value)
|
||||
save(hoursValue.intValue, elevValue.doubleValue)
|
||||
toggle()
|
||||
}, text = "Accept"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ class PassesViewModel(
|
||||
val millisBeforeStart = nextPass.aosTime.minus(timeNow)
|
||||
val timerString = millisBeforeStart.toTimerString()
|
||||
_timerText.emit(Triple("Next - Id:$catNum", name, timerString))
|
||||
} catch (e: NoSuchElementException) {
|
||||
} catch (exception: NoSuchElementException) {
|
||||
val lastPass = newPasses.last()
|
||||
val catNum = lastPass.catNum
|
||||
val name = lastPass.name
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package com.rtbishop.look4sat.presentation.pullRefresh
|
||||
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -48,7 +48,7 @@ fun Modifier.pullRefreshIndicatorTransform(
|
||||
properties["state"] = state
|
||||
properties["scale"] = scale
|
||||
}) {
|
||||
var height by remember { mutableStateOf(0) }
|
||||
var height by remember { mutableIntStateOf(0) }
|
||||
Modifier
|
||||
.onSizeChanged { height = it.height }
|
||||
.graphicsLayer {
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
@@ -103,8 +104,8 @@ class PullRefreshState internal constructor(
|
||||
private val adjustedDistancePulled by derivedStateOf { distancePulled * DRAG_MULTIPLIER }
|
||||
|
||||
private var _refreshing by mutableStateOf(false)
|
||||
private var _position by mutableStateOf(0f)
|
||||
private var distancePulled by mutableStateOf(0f)
|
||||
private var _position by mutableFloatStateOf(0f)
|
||||
private var distancePulled by mutableFloatStateOf(0f)
|
||||
|
||||
internal fun onPull(pullDelta: Float): Float {
|
||||
if (this._refreshing) return 0f // Already refreshing, do nothing.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
@file:OptIn(ExperimentalTextApi::class)
|
||||
|
||||
package com.rtbishop.look4sat.presentation.radar
|
||||
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
@@ -9,6 +7,7 @@ import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -25,7 +24,6 @@ import androidx.compose.ui.graphics.drawscope.Fill
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.text.ExperimentalTextApi
|
||||
import androidx.compose.ui.text.TextMeasurer
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.drawText
|
||||
@@ -47,7 +45,7 @@ fun RadarViewCompose(item: SatPos, items: List<SatPos>, azimElev: Pair<Float, Fl
|
||||
val animSpec = infiniteRepeatable<Float>(tween(1000))
|
||||
val animScale = animTransition.animateFloat(16f, 64f, animSpec, label = "animScale")
|
||||
val measurer = rememberTextMeasurer()
|
||||
val sweepDegrees = remember { mutableStateOf(0f) }
|
||||
val sweepDegrees = remember { mutableFloatStateOf(0f) }
|
||||
val trackCreated = remember { mutableStateOf(false) }
|
||||
val trackPath = remember { mutableStateOf(Path()) }
|
||||
val trackEffect = remember { mutableStateOf(PathEffect.cornerPathEffect(0f)) }
|
||||
@@ -59,7 +57,7 @@ fun RadarViewCompose(item: SatPos, items: List<SatPos>, azimElev: Pair<Float, Fl
|
||||
trackCreated.value = true
|
||||
}
|
||||
rotate(-azimElev.first) {
|
||||
drawSweep(center, sweepDegrees.value, radius, primaryColor)
|
||||
drawSweep(center, sweepDegrees.floatValue, radius, primaryColor)
|
||||
drawRadar(radius, radarColor, strokeWidth, 3)
|
||||
drawInfo(radius, primaryColor, measurer, 3)
|
||||
translate(center.x, center.y) {
|
||||
@@ -67,7 +65,7 @@ fun RadarViewCompose(item: SatPos, items: List<SatPos>, azimElev: Pair<Float, Fl
|
||||
if (item.elevation > 0) drawPosition(item, radius, animScale.value, primaryColor)
|
||||
drawAim(azimElev.first, azimElev.second, radius, strokeWidth, secondaryColor)
|
||||
}
|
||||
sweepDegrees.value = (sweepDegrees.value + 360 / 12.0f / 60) % 360
|
||||
sweepDegrees.floatValue = (sweepDegrees.floatValue + 360 / 12.0f / 60) % 360
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +111,7 @@ private fun DrawScope.drawAim(azim: Float, elev: Float, radius: Float, width: Fl
|
||||
drawLine(color, center.copy(aimX, -aimY - size), center.copy(aimX, -aimY + size), width)
|
||||
drawCircle(color, size / 2, center.copy(aimX, -aimY), style = Stroke(width))
|
||||
} catch (exception: Exception) {
|
||||
// Timber.d(exception)
|
||||
println(exception)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ class SettingsViewModel(
|
||||
databaseRepo.updateFromRemote()
|
||||
} catch (exception: Exception) {
|
||||
_dataSettings.value = _dataSettings.value.copy(isUpdating = false)
|
||||
println(exception.printStackTrace())
|
||||
println(exception)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ class SettingsViewModel(
|
||||
databaseRepo.updateFromFile(uri)
|
||||
} catch (exception: Exception) {
|
||||
_dataSettings.value = _dataSettings.value.copy(isUpdating = false)
|
||||
println(exception.printStackTrace())
|
||||
println(exception)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user