-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# Mały Poszukiwacz Skarbów | ||
|
||
GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html) | ||
|
||
|
||
TODO: | ||
- add screens titles | ||
-- on searching screen title show which treasure is being searched | ||
- |
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
59 changes: 59 additions & 0 deletions
59
app/src/main/java/pl/marianjureczko/poszukiwacz/activity/map/n/MapScreen.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,59 @@ | ||
package pl.marianjureczko.poszukiwacz.activity.map.n | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.res.Resources | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import com.mapbox.bindgen.Value | ||
import com.mapbox.maps.MapView | ||
import com.mapbox.maps.Style | ||
import pl.marianjureczko.poszukiwacz.App | ||
import pl.marianjureczko.poszukiwacz.model.Route | ||
import pl.marianjureczko.poszukiwacz.shared.MapHelper | ||
import pl.marianjureczko.poszukiwacz.ui.components.TopBar | ||
|
||
@SuppressLint("UnusedMaterialScaffoldPaddingParameter") | ||
@Composable | ||
fun MapScreen( | ||
navController: NavController?, | ||
resources: Resources, | ||
onClickOnGuide: () -> Unit | ||
) { | ||
Scaffold( | ||
topBar = { TopBar(navController, onClickOnGuide) }, | ||
content = { | ||
MapScreenBody(resources) | ||
} | ||
) | ||
} | ||
|
||
@Composable | ||
fun MapScreenBody(resources: Resources) { | ||
val viewModel: MapViewModel = hiltViewModel() | ||
val state = viewModel.state.value | ||
MapboxMap(state.route, resources) | ||
} | ||
|
||
@Composable | ||
fun MapboxMap(route: Route, resources: Resources) { | ||
val mapView = MapView(App.getAppContext()) | ||
|
||
MapHelper.renderTreasures(route, mapView, resources) | ||
mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) { style -> hideRoads(style) } | ||
|
||
AndroidView({ mapView }, Modifier.fillMaxSize()) | ||
MapHelper.positionMapOnTreasures(route, mapView, 400.0) | ||
} | ||
|
||
private fun hideRoads(style: Style) { | ||
style.styleLayers.asSequence() | ||
.filter { l -> l.id.startsWith("road") } | ||
.forEach { l -> | ||
style.setStyleLayerProperty(l.id, "visibility", Value("none")) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/pl/marianjureczko/poszukiwacz/activity/map/n/MapState.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,7 @@ | ||
package pl.marianjureczko.poszukiwacz.activity.map.n | ||
|
||
import pl.marianjureczko.poszukiwacz.model.Route | ||
|
||
data class MapState( | ||
val route: Route | ||
) |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/pl/marianjureczko/poszukiwacz/activity/map/n/MapViewModel.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,41 @@ | ||
package pl.marianjureczko.poszukiwacz.activity.map.n | ||
|
||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import pl.marianjureczko.poszukiwacz.model.Route | ||
import pl.marianjureczko.poszukiwacz.shared.StorageHelper | ||
import javax.inject.Inject | ||
|
||
const val PARAMETER_ROUTE_NAME_2 = "route_name" | ||
|
||
@HiltViewModel | ||
class MapViewModel @Inject constructor( | ||
private val storageHelper: StorageHelper, | ||
private val stateHandle: SavedStateHandle | ||
) : ViewModel() { | ||
|
||
private var _state: MutableState<MapState> = mutableStateOf(createState()) | ||
|
||
val state: State<MapState> | ||
get() = _state | ||
|
||
private fun createState(): MapState { | ||
val routeName = stateHandle.get<String>(PARAMETER_ROUTE_NAME_2)!! | ||
return MapState(loadRoute(routeName)) | ||
} | ||
|
||
private fun loadRoute(routeName: String): Route { | ||
// return Route( | ||
// "Kalinowice", mutableListOf( | ||
// TreasureDescription( | ||
// 1, 25.1, 26.1, "g01abc", null, null | ||
// ) | ||
// ) | ||
// ) | ||
return storageHelper.loadRoute(routeName) | ||
} | ||
} |
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