Skip to content

Commit

Permalink
Make IndoorSelection as pure kotlin class to prepare KMP (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid authored Nov 26, 2024
1 parent ed51ebe commit d5088ec
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
Expand All @@ -29,6 +30,7 @@ import com.naver.maps.map.compose.MapUiSettings
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
import com.naver.maps.map.compose.demo.common.DefaultTopAppBar
import com.naver.maps.map.compose.demo.common.showToast
import com.naver.maps.map.compose.rememberCameraPositionState

@OptIn(ExperimentalNaverMapApi::class)
Expand All @@ -46,10 +48,19 @@ fun IndoorMapScreen(upPress: () -> Unit) {
val cameraPositionState = rememberCameraPositionState {
this.position = CameraPosition(LatLng(37.5116620, 127.0594274), 16.0)
}
val context = LocalContext.current
NaverMap(
cameraPositionState = cameraPositionState,
properties = MapProperties(isIndoorEnabled = true),
uiSettings = MapUiSettings(isIndoorLevelPickerEnabled = true),
onIndoorSelectionChange = { selection ->
if (selection != null) {
context.showToast(
R.string.format_indoor_selection,
selection.level.name,
)
}
},
)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@

<string name="name_indoor_map">Indoor Map</string>
<string name="description_indoor_map">싀내지도 μ‚¬μš©</string>
<string name="format_indoor_selection">싀내지도: %1$s μΈ΅</string>

<string name="name_lite_mode">Lite Mode</string>
<string name="description_lite_mode">라이트 λͺ¨λ“œ μ‚¬μš©</string>
Expand Down
65 changes: 64 additions & 1 deletion naver-map-compose/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ package com.naver.maps.map.compose {
}

public final class NaverMapKt {
method @androidx.compose.runtime.Composable @com.naver.maps.map.compose.ExperimentalNaverMapApi public static void NaverMap(optional androidx.compose.ui.Modifier modifier, optional com.naver.maps.map.compose.CameraPositionState cameraPositionState, optional com.naver.maps.map.compose.MapProperties properties, optional com.naver.maps.map.compose.MapUiSettings uiSettings, optional com.naver.maps.map.LocationSource? locationSource, optional java.util.Locale? locale, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,kotlin.Unit> onMapClick, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,kotlin.Unit> onMapLongClick, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,java.lang.Boolean> onMapDoubleTab, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,java.lang.Boolean> onMapTwoFingerTap, optional kotlin.jvm.functions.Function0<kotlin.Unit> onMapLoaded, optional kotlin.jvm.functions.Function1<? super android.location.Location,kotlin.Unit> onLocationChange, optional kotlin.jvm.functions.Function0<kotlin.Unit> onOptionChange, optional kotlin.jvm.functions.Function1<? super com.naver.maps.map.compose.Symbol,java.lang.Boolean> onSymbolClick, optional kotlin.jvm.functions.Function1<? super com.naver.maps.map.indoor.IndoorSelection,kotlin.Unit> onIndoorSelectionChange, optional androidx.compose.foundation.layout.PaddingValues contentPadding, optional kotlin.jvm.functions.Function0<kotlin.Unit> content);
method @androidx.compose.runtime.Composable @com.naver.maps.map.compose.ExperimentalNaverMapApi public static void NaverMap(optional androidx.compose.ui.Modifier modifier, optional com.naver.maps.map.compose.CameraPositionState cameraPositionState, optional com.naver.maps.map.compose.MapProperties properties, optional com.naver.maps.map.compose.MapUiSettings uiSettings, optional com.naver.maps.map.LocationSource? locationSource, optional java.util.Locale? locale, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,kotlin.Unit> onMapClick, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,kotlin.Unit> onMapLongClick, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,java.lang.Boolean> onMapDoubleTab, optional kotlin.jvm.functions.Function2<? super android.graphics.PointF,? super com.naver.maps.geometry.LatLng,java.lang.Boolean> onMapTwoFingerTap, optional kotlin.jvm.functions.Function0<kotlin.Unit> onMapLoaded, optional kotlin.jvm.functions.Function1<? super android.location.Location,kotlin.Unit> onLocationChange, optional kotlin.jvm.functions.Function0<kotlin.Unit> onOptionChange, optional kotlin.jvm.functions.Function1<? super com.naver.maps.map.compose.Symbol,java.lang.Boolean> onSymbolClick, optional kotlin.jvm.functions.Function1<? super com.naver.maps.map.compose.indoor.IndoorSelection,kotlin.Unit> onIndoorSelectionChange, optional androidx.compose.foundation.layout.PaddingValues contentPadding, optional kotlin.jvm.functions.Function0<kotlin.Unit> content);
}

public final class PathOverlayDefaults {
Expand Down Expand Up @@ -503,3 +503,66 @@ package com.naver.maps.map.compose {

}

package com.naver.maps.map.compose.indoor {

public final class IndoorLevel {
ctor public IndoorLevel(String name, com.naver.maps.map.compose.indoor.IndoorView indoorView, java.util.List<com.naver.maps.map.compose.indoor.IndoorView> connections);
method public com.naver.maps.map.compose.indoor.IndoorView? getConnection(String zoneId);
method public int getConnectionIndex(String zoneId);
method public java.util.List<com.naver.maps.map.compose.indoor.IndoorView> getConnections();
method public com.naver.maps.map.compose.indoor.IndoorView getIndoorView();
method public String getName();
property public final java.util.List<com.naver.maps.map.compose.indoor.IndoorView> connections;
property public final com.naver.maps.map.compose.indoor.IndoorView indoorView;
property public final String name;
}

public final class IndoorRegion {
ctor public IndoorRegion(java.util.List<com.naver.maps.map.compose.indoor.IndoorZone> zones);
method public com.naver.maps.map.compose.indoor.IndoorZone? getZone(String zoneId);
method public int getZoneIndex(String zoneId);
method public java.util.List<com.naver.maps.map.compose.indoor.IndoorZone> getZones();
property public final java.util.List<com.naver.maps.map.compose.indoor.IndoorZone> zones;
}

public final class IndoorSelection {
ctor public IndoorSelection(com.naver.maps.map.compose.indoor.IndoorRegion region, int zoneIndex, int levelIndex);
method public com.naver.maps.map.compose.indoor.IndoorLevel getLevel();
method public int getLevelIndex();
method public com.naver.maps.map.compose.indoor.IndoorRegion getRegion();
method public com.naver.maps.map.compose.indoor.IndoorZone getZone();
method public int getZoneIndex();
property public final com.naver.maps.map.compose.indoor.IndoorLevel level;
property public final int levelIndex;
property public final com.naver.maps.map.compose.indoor.IndoorRegion region;
property public final com.naver.maps.map.compose.indoor.IndoorZone zone;
property public final int zoneIndex;
}

public final class IndoorView {
ctor public IndoorView(String zoneId, String levelId);
method public String component1();
method public String component2();
method public com.naver.maps.map.compose.indoor.IndoorView copy(String zoneId, String levelId);
method public String getLevelId();
method public String getZoneId();
property public final String levelId;
property public final String zoneId;
}

public final class IndoorZone {
ctor public IndoorZone(String zoneId, int defaultLevelIndex, java.util.List<com.naver.maps.map.compose.indoor.IndoorLevel> levels);
method public com.naver.maps.map.compose.indoor.IndoorLevel getDefaultLevel();
method public int getDefaultLevelIndex();
method public com.naver.maps.map.compose.indoor.IndoorLevel? getLevel(String levelId);
method public int getLevelIndex(String levelId);
method public java.util.List<com.naver.maps.map.compose.indoor.IndoorLevel> getLevels();
method public String getZoneId();
property public final com.naver.maps.map.compose.indoor.IndoorLevel defaultLevel;
property public final int defaultLevelIndex;
property public final java.util.List<com.naver.maps.map.compose.indoor.IndoorLevel> levels;
property public final String zoneId;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ import com.naver.maps.map.NaverMap.OnMapLongClickListener
import com.naver.maps.map.NaverMap.OnMapTwoFingerTapListener
import com.naver.maps.map.NaverMap.OnOptionChangeListener
import com.naver.maps.map.NaverMap.OnSymbolClickListener
import com.naver.maps.map.indoor.IndoorSelection
import com.naver.maps.map.compose.indoor.IndoorLevel
import com.naver.maps.map.compose.indoor.IndoorRegion
import com.naver.maps.map.compose.indoor.IndoorSelection
import com.naver.maps.map.compose.indoor.IndoorView
import com.naver.maps.map.compose.indoor.IndoorZone

internal class MapClickListeners {
var onMapClick: (PointF, LatLng) -> Unit by mutableStateOf({ _, _ -> })
Expand Down Expand Up @@ -164,7 +168,41 @@ internal fun MapClickListenerUpdater() {
callback,
NaverMap::addOnIndoorSelectionChangeListener,
NaverMap::removeOnIndoorSelectionChangeListener,
OnIndoorSelectionChangeListener { callback().invoke(it) },
OnIndoorSelectionChangeListener { it ->
callback().invoke(
it?.let { selection ->
IndoorSelection(
region = selection.region.let { region ->
IndoorRegion(
zones = region.zones.map { zone ->
IndoorZone(
zoneId = zone.zoneId,
defaultLevelIndex = zone.defultLevelIndex,
levels = zone.levels.map { level ->
IndoorLevel(
name = level.name,
indoorView = IndoorView(
zoneId = level.indoorView.zoneId,
levelId = level.indoorView.levelId,
),
connections = level.connections.map {
IndoorView(
zoneId = it.zoneId,
levelId = it.levelId,
)
},
)
},
)
},
)
},
zoneIndex = selection.zoneIndex,
levelIndex = selection.levelIndex,
)
},
)
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.naver.maps.map.LocationSource
import com.naver.maps.map.MapView
import com.naver.maps.map.NaverMap
import com.naver.maps.map.NaverMapOptions
import com.naver.maps.map.indoor.IndoorSelection
import com.naver.maps.map.compose.indoor.IndoorSelection
import kotlinx.coroutines.awaitCancellation
import java.util.Locale
import kotlin.coroutines.resume
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.naver.maps.map.compose.indoor

/**
*
* ν•˜λ‚˜μ˜ 싀내지도 측을 λ‚˜νƒ€λ‚΄λŠ” λΆˆλ³€ 클래슀.
* ν•˜λ‚˜μ˜ 싀내지도 측은 λ‹€λ₯Έ μΈ΅κ³Ό 연결될 수 μžˆμŠ΅λ‹ˆλ‹€.
* 이 클래슀의 μΈμŠ€ν„΄μŠ€λŠ” 직접 생성할 수 μ—†κ³  [IndoorZone]을 μ΄μš©ν•΄μ„œ κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€.
*
* @property name μΈ΅ λͺ…μΉ­.
* @property indoorView 측에 ν•΄λ‹Ήν•˜λŠ” 싀내지도 λ·°.
* @property connections μ—°κ²°λœ 싀내지도 λ·° λͺ©λ‘.
*/
public class IndoorLevel(
public val name: String,
public val indoorView: IndoorView,
public val connections: List<IndoorView>,
) {

/**
* μ—°κ²°λœ μΈ΅ 쀑 ꡬ역 IDκ°€ zoneId인 싀내지도 뷰의 인덱슀λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
*
* @param zoneId ꡬ역 ID.
* @return 싀내지도 뷰의 인덱슀. μ—°κ²°λœ μΈ΅ 쀑에 IDκ°€ zoneId인 측이 없을 경우 -1.
*/
public fun getConnectionIndex(zoneId: String): Int {
return connections.indexOfFirst { connection ->
connection.zoneId == zoneId
}
}

/**
* μ—°κ²°λœ μΈ΅ 쀑 ꡬ역 IDκ°€ zoneId인 싀내지도 λ·°λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
*
* @param zoneId ꡬ역 ID.
* @return 싀내지도 λ·°. μ—°κ²°λœ μΈ΅ 쀑에 IDκ°€ zoneId인 측이 없을 경우 null.
*/
public fun getConnection(zoneId: String): IndoorView? {
return connections.getOrNull(getConnectionIndex(zoneId))
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return indoorView == (other as IndoorLevel).indoorView
}

override fun hashCode(): Int {
return indoorView.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.naver.maps.map.compose.indoor

/**
* 싀내지도가 μ‘΄μž¬ν•˜λŠ” μ˜μ—­μ„ λ‚˜νƒ€λ‚΄λŠ” λΆˆλ³€ 클래슀.
* ν•˜λ‚˜μ˜ 싀내지도 μ˜μ—­μ€ μ„œλ‘œ 겹쳐진 ν•œ 개 μ΄μƒμ˜ κ΅¬μ—­μœΌλ‘œ μ΄λ£¨μ–΄μ§‘λ‹ˆλ‹€.
* 이 클래슀의 μΈμŠ€ν„΄μŠ€λŠ” 직접 생성할 수 μ—†μŠ΅λ‹ˆλ‹€.
*
* @property zones μ˜μ—­μ— 속해 μžˆλŠ” ꡬ역 λͺ©λ‘.
*/
public class IndoorRegion(
public val zones: List<IndoorZone>,
) {

/**
* μ˜μ—­μ— 속해 μžˆλŠ” ꡬ역 쀑 IDκ°€ zoneId인 κ΅¬μ—­μ˜ 인덱슀λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
*
* @param zoneId ꡬ역 ID.
* @return κ΅¬μ—­μ˜ 인덱슀. μ˜μ—­ 내에 IDκ°€ zoneId인 ꡬ역이 없을 경우 -1.
*/
public fun getZoneIndex(zoneId: String): Int {
return zones.indexOfFirst { zone ->
zone.zoneId == zoneId
}
}

/**
* μ˜μ—­μ— 속해 μžˆλŠ” ꡬ역 쀑 IDκ°€ zoneId인 ꡬ역을 λ°˜ν™˜ν•©λ‹ˆλ‹€.
*
* @param zoneId ꡬ역 ID.
* @return ꡬ역 객체. μ˜μ—­ 내에 IDκ°€ zoneId인 ꡬ역이 없을 경우 null.
*/
public fun getZone(zoneId: String): IndoorZone? {
return zones.getOrNull(getZoneIndex(zoneId))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.naver.maps.map.compose.indoor

/**
* ν•˜λ‚˜μ˜ 싀내지도 μ˜μ—­ λ‚΄μ—μ„œ μ„ νƒλœ ꡬ역 및 측을 λ‚˜νƒ€λ‚΄λŠ” λΆˆλ³€ 클래슀.
*
* @property region μ˜μ—­μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.
* @property zoneIndex μ„ νƒλœ κ΅¬μ—­μ˜ 인덱슀λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
* @property levelIndex μ„ νƒλœ 측의 인덱슀λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
*/
public class IndoorSelection(
public val region: IndoorRegion,
public val zoneIndex: Int,
public val levelIndex: Int,
) {

/**
* μ„ νƒλœ ꡬ역을 λ°˜ν™˜ν•©λ‹ˆλ‹€.
*/
public val zone: IndoorZone
get() = region.zones[zoneIndex]

/**
* μ„ νƒλœ 측을 λ°˜ν™˜ν•©λ‹ˆλ‹€.
*/
public val level: IndoorLevel
get() = zone.levels[levelIndex]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 SOUP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.naver.maps.map.compose.indoor

/**
* ν•˜λ‚˜μ˜ 싀내지도λ₯Ό λ‚˜νƒ€λ‚΄λŠ” λΆˆλ³€ 클래슀.
*
* @property zoneId ꡬ역 IDλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
* @property levelId μΈ΅ IDλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
*/
public data class IndoorView(
public val zoneId: String,
public val levelId: String,
)
Loading

0 comments on commit d5088ec

Please sign in to comment.