-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract cell signal list item mappers
Signed-off-by: Kyle Corry <kylecorry31@gmail.com>
- Loading branch information
1 parent
2a90cbe
commit fd0f38f
Showing
5 changed files
with
146 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...rc/main/java/com/kylecorry/trail_sense/tools/signal_finder/ui/CellSignalListItemMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.kylecorry.trail_sense.tools.signal_finder.ui | ||
|
||
import android.content.Context | ||
import com.kylecorry.andromeda.signal.CellSignal | ||
import com.kylecorry.andromeda.views.list.ListItem | ||
import com.kylecorry.andromeda.views.list.ListItemMapper | ||
import com.kylecorry.andromeda.views.list.ResourceListIcon | ||
import com.kylecorry.trail_sense.R | ||
import com.kylecorry.trail_sense.shared.CustomUiUtils | ||
import com.kylecorry.trail_sense.shared.FormatService | ||
import com.kylecorry.trail_sense.shared.extensions.AppServiceRegistry | ||
import com.kylecorry.trail_sense.shared.sensors.CellSignalUtils | ||
|
||
class CellSignalListItemMapper(private val context: Context) : ListItemMapper<CellSignal> { | ||
|
||
private val formatter = AppServiceRegistry.get<FormatService>() | ||
|
||
override fun map(value: CellSignal): ListItem { | ||
return ListItem( | ||
value.id.hashCode().toLong(), | ||
formatter.formatCellNetwork(value.network), | ||
formatter.join( | ||
formatter.formatPercentage(value.strength), | ||
formatter.formatTime(value.time), | ||
if (value.isRegistered) { | ||
context.getString(R.string.full_service) | ||
} else { | ||
context.getString(R.string.emergency_calls_only) | ||
}, | ||
separator = FormatService.Separator.Dot | ||
), | ||
icon = ResourceListIcon( | ||
CellSignalUtils.getCellQualityImage(value.quality), | ||
CustomUiUtils.getQualityColor(value.quality) | ||
) | ||
) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...src/main/java/com/kylecorry/trail_sense/tools/signal_finder/ui/CellTowerListItemMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.kylecorry.trail_sense.tools.signal_finder.ui | ||
|
||
import android.content.Context | ||
import com.kylecorry.andromeda.core.system.Resources | ||
import com.kylecorry.andromeda.signal.CellNetwork | ||
import com.kylecorry.andromeda.views.list.ListItem | ||
import com.kylecorry.andromeda.views.list.ListItemMapper | ||
import com.kylecorry.andromeda.views.list.ListMenuItem | ||
import com.kylecorry.andromeda.views.list.ResourceListIcon | ||
import com.kylecorry.sol.units.Coordinate | ||
import com.kylecorry.sol.units.Distance | ||
import com.kylecorry.trail_sense.R | ||
import com.kylecorry.trail_sense.shared.FormatService | ||
import com.kylecorry.trail_sense.shared.Units | ||
import com.kylecorry.trail_sense.shared.UserPreferences | ||
import com.kylecorry.trail_sense.shared.extensions.AppServiceRegistry | ||
import com.kylecorry.trail_sense.shared.toRelativeDistance | ||
|
||
enum class CellTowerListItemAction { | ||
Navigate, | ||
CreateBeacon | ||
} | ||
|
||
class CellTowerListItemMapper( | ||
private val context: Context, | ||
private val location: Coordinate, | ||
private val onAction: (Pair<Coordinate, CellNetwork>, CellTowerListItemAction) -> Unit | ||
) : | ||
ListItemMapper<Pair<Coordinate, CellNetwork>> { | ||
|
||
private val formatter = AppServiceRegistry.get<FormatService>() | ||
private val prefs = AppServiceRegistry.get<UserPreferences>() | ||
|
||
override fun map(value: Pair<Coordinate, CellNetwork>): ListItem { | ||
val towerLocation = value.first | ||
val network = value.second | ||
val distance = | ||
Distance.meters(location.distanceTo(towerLocation)) | ||
.convertTo(prefs.baseDistanceUnits).toRelativeDistance() | ||
val direction = location.bearingTo(towerLocation) | ||
val formattedDistance = | ||
formatter.formatDistance(distance, Units.getDecimalPlaces(distance.units)) | ||
val formattedBearing = formatter.formatDegrees(direction.value, replace360 = true) | ||
val formattedDirection = formatter.formatDirection(direction.direction) | ||
return ListItem( | ||
value.hashCode().toLong(), | ||
formatter.formatCellNetwork(network), | ||
formatter.join( | ||
context.getString(R.string.cell_tower), | ||
formattedDistance, | ||
"$formattedBearing $formattedDirection", | ||
separator = FormatService.Separator.Dot | ||
), | ||
icon = ResourceListIcon( | ||
R.drawable.cell_tower, | ||
Resources.androidTextColorSecondary(context) | ||
), | ||
menu = listOf( | ||
ListMenuItem(context.getString(R.string.navigate)) { | ||
onAction(value, CellTowerListItemAction.Navigate) | ||
}, | ||
ListMenuItem(context.getString(R.string.create_beacon)) { | ||
onAction(value, CellTowerListItemAction.CreateBeacon) | ||
} | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters