diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/domain/hiking/HikingService.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/domain/hiking/HikingService.kt index ebad5ada1..d6886cd51 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/domain/hiking/HikingService.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/domain/hiking/HikingService.kt @@ -15,6 +15,9 @@ import kotlin.math.sqrt class HikingService(private val geology: IGeologyService = GeologyService()) : IHikingService { override fun getDistances(points: List): List { + if (points.isEmpty()){ + return emptyList() + } var distance = 0f var last = points.first() @@ -26,6 +29,9 @@ class HikingService(private val geology: IGeologyService = GeologyService()) : I } override fun correctElevations(points: List): List { + if (points.isEmpty()){ + return emptyList() + } val distances = getDistances(points) val smoothed = DataUtils.smooth( points, diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathCommand.kt index 7732578d7..5500063de 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathCommand.kt @@ -1,6 +1,7 @@ package com.kylecorry.trail_sense.navigation.paths.ui.commands import android.content.Context +import com.kylecorry.andromeda.pickers.CoroutinePickers import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.navigation.paths.domain.IPathService import com.kylecorry.trail_sense.navigation.paths.domain.Path @@ -8,7 +9,6 @@ import com.kylecorry.trail_sense.navigation.paths.domain.PathMetadata import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.IPathPreferences import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService import com.kylecorry.trail_sense.shared.UserPreferences -import com.kylecorry.trail_sense.shared.alerts.CoroutineAlerts import com.kylecorry.trail_sense.shared.extensions.onIO import com.kylecorry.trail_sense.shared.extensions.onMain @@ -21,7 +21,7 @@ class CreatePathCommand( suspend fun execute(parentId: Long?): Long? { val name = onMain { - CoroutineAlerts.text( + CoroutinePickers.text( context, context.getString(R.string.path), hint = context.getString(R.string.name) diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathGroupCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathGroupCommand.kt index 66ce4e2a8..40ac1a12e 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathGroupCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreatePathGroupCommand.kt @@ -1,11 +1,11 @@ package com.kylecorry.trail_sense.navigation.paths.ui.commands import android.content.Context +import com.kylecorry.andromeda.pickers.CoroutinePickers import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.navigation.paths.domain.IPathService import com.kylecorry.trail_sense.navigation.paths.domain.PathGroup import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService -import com.kylecorry.trail_sense.shared.alerts.CoroutineAlerts import com.kylecorry.trail_sense.shared.extensions.onIO import com.kylecorry.trail_sense.shared.extensions.onMain @@ -17,7 +17,7 @@ class CreatePathGroupCommand( suspend fun execute(parentId: Long?) { val name = onMain { - CoroutineAlerts.text( + CoroutinePickers.text( context, context.getString(R.string.group), hint = context.getString(R.string.name) diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/DeletePathGroupGroupCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/DeletePathGroupGroupCommand.kt index dc7db8bae..e776854e6 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/DeletePathGroupGroupCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/DeletePathGroupGroupCommand.kt @@ -1,11 +1,11 @@ package com.kylecorry.trail_sense.navigation.paths.ui.commands import android.content.Context +import com.kylecorry.andromeda.alerts.CoroutineAlerts import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.navigation.paths.domain.IPathService import com.kylecorry.trail_sense.navigation.paths.domain.PathGroup import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService -import com.kylecorry.trail_sense.shared.alerts.CoroutineAlerts import com.kylecorry.trail_sense.shared.extensions.onIO import com.kylecorry.trail_sense.shared.extensions.onMain diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/RenamePathGroupGroupCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/RenamePathGroupGroupCommand.kt index 0b7d94824..714ca487e 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/RenamePathGroupGroupCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/RenamePathGroupGroupCommand.kt @@ -1,11 +1,11 @@ package com.kylecorry.trail_sense.navigation.paths.ui.commands import android.content.Context +import com.kylecorry.andromeda.pickers.CoroutinePickers import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.navigation.paths.domain.IPathService import com.kylecorry.trail_sense.navigation.paths.domain.PathGroup import com.kylecorry.trail_sense.navigation.paths.infrastructure.persistence.PathService -import com.kylecorry.trail_sense.shared.alerts.CoroutineAlerts import com.kylecorry.trail_sense.shared.extensions.onIO import com.kylecorry.trail_sense.shared.extensions.onMain @@ -17,7 +17,7 @@ class RenamePathGroupGroupCommand( override suspend fun execute(group: PathGroup) { val newName = onMain { - CoroutineAlerts.text( + CoroutinePickers.text( context, context.getString(R.string.rename), default = group.name, diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/alerts/CoroutineAlerts.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/alerts/CoroutineAlerts.kt deleted file mode 100644 index c3381b4eb..000000000 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/alerts/CoroutineAlerts.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.kylecorry.trail_sense.shared.alerts - -import android.content.Context -import android.view.View -import com.kylecorry.andromeda.alerts.Alerts -import com.kylecorry.andromeda.pickers.Pickers -import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine - -object CoroutineAlerts { - - suspend fun dialog( - context: Context, - title: CharSequence, - content: CharSequence? = null, - contentView: View? = null, - okText: CharSequence? = context.getString(android.R.string.ok), - cancelText: CharSequence? = context.getString(android.R.string.cancel), - allowLinks: Boolean = false - ) = suspendCoroutine { cont -> - Alerts.dialog( - context, - title, - content, - contentView, - okText, - cancelText, - allowLinks - ) { - cont.resume(it) - } - } - - suspend fun text( - context: Context, - title: CharSequence, - description: CharSequence? = null, - default: String? = null, - hint: CharSequence? = null, - okText: CharSequence? = context.getString(android.R.string.ok), - cancelText: CharSequence? = context.getString(android.R.string.cancel) - ) = suspendCoroutine { cont -> - Pickers.text( - context, - title, - description, - default, - hint, - okText, - cancelText - ) { - cont.resume(it) - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/tides/ui/TidesFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/tides/ui/TidesFragment.kt index 5b3abe67d..3c240a1ee 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/tides/ui/TidesFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/tides/ui/TidesFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.navigation.fragment.findNavController +import com.kylecorry.andromeda.alerts.CoroutineAlerts import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.andromeda.core.time.Timer import com.kylecorry.andromeda.fragments.BoundFragment @@ -19,7 +20,6 @@ import com.kylecorry.trail_sense.shared.CustomUiUtils import com.kylecorry.trail_sense.shared.CustomUiUtils.setCompoundDrawables import com.kylecorry.trail_sense.shared.FormatService import com.kylecorry.trail_sense.shared.UserPreferences -import com.kylecorry.trail_sense.shared.alerts.CoroutineAlerts import com.kylecorry.trail_sense.shared.extensions.onMain import com.kylecorry.trail_sense.tools.tides.domain.TideService import com.kylecorry.trail_sense.tools.tides.domain.TideTable