Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed May 15, 2022
1 parent dff0063 commit d53c53a
Show file tree
Hide file tree
Showing 43 changed files with 56 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ data class LunarEclipse(
val magnitude: Float
){
val isTotal: Boolean = magnitude >= 1f
val duration = Duration.between(start, end)
val duration: Duration = Duration.between(start, end)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.view.isVisible
import com.kylecorry.andromeda.battery.Battery
import com.kylecorry.andromeda.battery.BatteryHealth
import com.kylecorry.andromeda.core.sensors.Quality
Expand Down Expand Up @@ -89,18 +88,18 @@ class SensorDetailsFragment : BoundFragment<FragmentSensorDetailsBinding>() {

sensorListView.addLineSeparator()

cachedGPS.asLiveData().observe(viewLifecycleOwner, { updateGPSCache() })
gps.asLiveData().observe(viewLifecycleOwner, { updateGPS() })
compass.asLiveData().observe(viewLifecycleOwner, { updateCompass() })
barometer.asLiveData().observe(viewLifecycleOwner, { updateBarometer() })
altimeter.asLiveData().observe(viewLifecycleOwner, { updateAltimeter() })
thermometer.asLiveData().observe(viewLifecycleOwner, { updateThermometer() })
hygrometer.asLiveData().observe(viewLifecycleOwner, { updateHygrometer() })
gravity.asLiveData().observe(viewLifecycleOwner, { updateGravity() })
cellSignal.asLiveData().observe(viewLifecycleOwner, { updateCellSignal() })
magnetometer.asLiveData().observe(viewLifecycleOwner, { updateMagnetometer() })
battery.asLiveData().observe(viewLifecycleOwner, { updateBattery() })
gyroscope.asLiveData().observe(viewLifecycleOwner, { updateGyro() })
cachedGPS.asLiveData().observe(viewLifecycleOwner) { updateGPSCache() }
gps.asLiveData().observe(viewLifecycleOwner) { updateGPS() }
compass.asLiveData().observe(viewLifecycleOwner) { updateCompass() }
barometer.asLiveData().observe(viewLifecycleOwner) { updateBarometer() }
altimeter.asLiveData().observe(viewLifecycleOwner) { updateAltimeter() }
thermometer.asLiveData().observe(viewLifecycleOwner) { updateThermometer() }
hygrometer.asLiveData().observe(viewLifecycleOwner) { updateHygrometer() }
gravity.asLiveData().observe(viewLifecycleOwner) { updateGravity() }
cellSignal.asLiveData().observe(viewLifecycleOwner) { updateCellSignal() }
magnetometer.asLiveData().observe(viewLifecycleOwner) { updateMagnetometer() }
battery.asLiveData().observe(viewLifecycleOwner) { updateBattery() }
gyroscope.asLiveData().observe(viewLifecycleOwner) { updateGyro() }

if (!Sensors.hasCompass(requireContext())) {
sensorDetailsMap["compass"] = SensorDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class BeaconDetailsFragment : BoundFragment<FragmentBeaconDetailsBinding>() {
if (beaconId != null) {
loadBeacon(beaconId!!)
}
gps.asLiveData().observe(viewLifecycleOwner, {
gps.asLiveData().observe(viewLifecycleOwner) {
val beacon = beacon
if (isBound && beacon != null) {
val distance = Distance.meters(beacon.coordinate.distanceTo(gps.location))
Expand All @@ -136,7 +136,7 @@ class BeaconDetailsFragment : BoundFragment<FragmentBeaconDetailsBinding>() {
false
)
}
})
}
}

override fun generateBinding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ object LocationMath {
return unitPerSecond * 60 * 60
}

fun convertToBaseUnit(meters: Float, units: UserPreferences.DistanceUnits): Float {
return if (units == UserPreferences.DistanceUnits.Feet) {
Distance(meters, DistanceUnits.Meters).convertTo(DistanceUnits.Feet).distance
} else {
meters
}
}

fun convertToBaseSpeed(metersPerSecond: Float, units: UserPreferences.DistanceUnits): Float {
return if (units == UserPreferences.DistanceUnits.Feet) {
convertUnitPerSecondsToUnitPerHours(
Expand All @@ -42,11 +34,4 @@ object LocationMath {
}
}

fun convertToMeters(distance: Float, units: UserPreferences.DistanceUnits): Float {
return if (units == UserPreferences.DistanceUnits.Meters) {
distance
} else {
Distance(distance, DistanceUnits.Feet).meters().distance
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ class NavigationService {
return Duration.ofSeconds(time.toLong())
}

fun pathDuration(path: List<PathPoint>, speed: Float = 0f): Duration {
val realSpeed = if (speed < 3) clamp(speed, 0.89408f, 1.78816f) else speed
var distance = 0f
for (i in 1..path.lastIndex) {
distance += scarfsDistance(
path[i - 1].coordinate,
path[i].coordinate,
path[i - 1].elevation,
path[i].elevation
)
}
return Duration.ofSeconds((distance / realSpeed).toLong())
}

private fun scarfsDistance(
from: Coordinate,
to: Coordinate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,10 @@ class NavigationPreferences(private val context: Context) : ICompassStylePrefere
var pathSort: PathSortMethod by IntEnumPreference(
cache,
context.getString(R.string.pref_path_sort),
PathSortMethod.values().map { it.id.toInt() to it }.toMap(),
PathSortMethod.values().associateBy { it.id.toInt() },
PathSortMethod.MostRecent
)

val factorInNonLinearDistance: Boolean
get() = cache.getBoolean(context.getString(R.string.pref_non_linear_distances)) ?: true

val leftQuickAction: QuickActionType
get() {
val id = cache.getString(context.getString(R.string.pref_navigation_quick_action_left))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.kylecorry.trail_sense.shared.scales.IColorScale
import com.kylecorry.trail_sense.navigation.paths.domain.waypointcolors.DefaultPointColoringStrategy
import com.kylecorry.trail_sense.navigation.paths.domain.waypointcolors.IPointColoringStrategy

class NonePointDisplayFactory(private val context: Context) : IPointDisplayFactory {
class NonePointDisplayFactory : IPointDisplayFactory {
override fun createColoringStrategy(path: List<PathPoint>): IPointColoringStrategy {
return DefaultPointColoringStrategy(Color.TRANSPARENT)
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private fun getPointFactory(
pointColoringStyle: PathPointColoringStyle
): IPointDisplayFactory {
return when (pointColoringStyle) {
PathPointColoringStyle.None -> NonePointDisplayFactory(context)
PathPointColoringStyle.None -> NonePointDisplayFactory()
PathPointColoringStyle.CellSignal -> CellSignalPointDisplayFactory(context)
PathPointColoringStyle.Altitude -> AltitudePointDisplayFactory(context)
PathPointColoringStyle.Time -> TimePointDisplayFactory(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ class PathOverviewFragment : BoundFragment<FragmentPathOverviewBinding>() {
PathPointColoringStyle.CellSignal -> CellSignalPointDisplayFactory(requireContext())
PathPointColoringStyle.Altitude -> AltitudePointDisplayFactory(requireContext())
PathPointColoringStyle.Time -> TimePointDisplayFactory(requireContext())
else -> NonePointDisplayFactory(requireContext())
else -> NonePointDisplayFactory()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.lifecycle.LifecycleCoroutineScope
import com.kylecorry.andromeda.pickers.Pickers
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.navigation.paths.domain.IPathService
import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService
import com.kylecorry.trail_sense.navigation.paths.domain.Path
import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -28,7 +28,7 @@ class RenamePathCommand(
if (it != null) {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
pathService.addPath(path.copy(name = if (it.isBlank()) null else it))
pathService.addPath(path.copy(name = it.ifBlank { null }))
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {

navController = findNavController()

compass.asLiveData().observe(viewLifecycleOwner,
{ updateUI() })
orientation.asLiveData().observe(viewLifecycleOwner,
{ onOrientationUpdate() })
altimeter.asLiveData().observe(viewLifecycleOwner,
{ updateUI() })
gps.asLiveData().observe(viewLifecycleOwner,
{ onLocationUpdate() })
speedometer.asLiveData().observe(viewLifecycleOwner,
{ updateUI() })
compass.asLiveData().observe(viewLifecycleOwner
) { updateUI() }
orientation.asLiveData().observe(viewLifecycleOwner
) { onOrientationUpdate() }
altimeter.asLiveData().observe(viewLifecycleOwner
) { updateUI() }
gps.asLiveData().observe(viewLifecycleOwner
) { onLocationUpdate() }
speedometer.asLiveData().observe(viewLifecycleOwner
) { updateUI() }

binding.navigationTitle.subtitle.setOnLongClickListener {
// TODO: Show custom share sheet instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.kylecorry.trail_sense.quickactions

import android.widget.ImageButton
import androidx.fragment.app.Fragment
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.shared.CustomUiUtils
import com.kylecorry.trail_sense.shared.LowPowerMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.view.MotionEvent
import android.widget.ImageButton
import androidx.fragment.app.Fragment
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.kylecorry.andromeda.sound.ISoundPlayer
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.shared.CustomUiUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ class ThermometerSettingsFragment : AndromedaPreferenceFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
thermometer.asLiveData().observe(viewLifecycleOwner, {
thermometer.asLiveData().observe(viewLifecycleOwner) {
temperatureTxt?.summary =
formatService.formatTemperature(
Temperature(
thermometer.temperature,
TemperatureUnits.C
).convertTo(prefs.temperatureUnits)
)
})
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.kylecorry.andromeda.core.units.CoordinateExtensions.toUTM
import com.kylecorry.andromeda.core.units.CoordinateFormat
import com.kylecorry.andromeda.signal.CellNetwork
import com.kylecorry.sol.science.astronomy.moon.MoonTruePhase
import com.kylecorry.sol.science.geology.Region
import com.kylecorry.sol.science.meteorology.Precipitation
import com.kylecorry.sol.science.meteorology.Weather
import com.kylecorry.sol.science.shared.Season
Expand Down Expand Up @@ -421,16 +420,6 @@ class FormatService(private val context: Context) {
}
}

fun formatRegion(region: Region): String {
val regionStr = when (region) {
Region.Polar -> context.getString(R.string.climate_polar)
Region.Temperate -> context.getString(R.string.climate_temperate)
Region.Tropical -> context.getString(R.string.climate_tropical)
}

return context.getString(R.string.climate_zone, regionStr)
}

fun formatShortTermWeather(weather: Weather): String {
return when (weather) {
Weather.ImprovingFast -> context.getString(R.string.weather_improving_fast)
Expand All @@ -442,14 +431,6 @@ class FormatService(private val context: Context) {
}
}

fun formatLongTermWeather(weather: Weather): String {
return when (weather) {
Weather.ImprovingFast, Weather.ImprovingSlow -> context.getString(R.string.forecast_improving)
Weather.WorseningSlow, Weather.WorseningFast, Weather.Storm -> context.getString(R.string.forecast_worsening)
else -> ""
}
}

fun sortDistanceUnits(
units: List<DistanceUnits>,
metric: Boolean = prefs.baseDistanceUnits == DistanceUnits.Meters
Expand Down Expand Up @@ -500,13 +481,13 @@ class FormatService(private val context: Context) {
}

fun getTemperatureUnitName(unit: TemperatureUnits, short: Boolean = false): String {
if (short) {
return when (unit) {
return if (short) {
when (unit) {
TemperatureUnits.F -> context.getString(R.string.temp_f_short)
TemperatureUnits.C -> context.getString(R.string.temp_c_short)
}
} else {
return when (unit) {
when (unit) {
TemperatureUnits.F -> context.getString(R.string.fahrenheit)
TemperatureUnits.C -> context.getString(R.string.celsius)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d53c53a

Please sign in to comment.