Skip to content

Commit

Permalink
Make MapType to pure class to prepare KMP (#118)
Browse files Browse the repository at this point in the history
* Make MapType to pure class to prepare KMP

* Add test codes to compare

* generate metalava
  • Loading branch information
fornewid authored Nov 19, 2024
1 parent 6f9a0b9 commit 64a3d35
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -63,8 +62,15 @@ fun LiteModeScreen(upPress: () -> Unit) {
}
) { contentPadding ->
Column(modifier = Modifier.padding(contentPadding)) {
val mapTypes = stringArrayResource(R.array.map_types_without_navi)
var selectedPosition by remember { mutableStateOf(0) }
val mapTypes = remember {
listOf(
MapType.Basic,
MapType.Satellite,
MapType.Hybrid,
MapType.Terrain,
)
}
var selectedMapType by remember { mutableStateOf<MapType>(MapType.Basic) }

Row(verticalAlignment = Alignment.CenterVertically) {
Text(
Expand All @@ -85,9 +91,11 @@ fun LiteModeScreen(upPress: () -> Unit) {
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = mapTypes[selectedPosition],
text = selectedMapType.toString(),
fontSize = 18.sp,
modifier = Modifier.padding(end = 8.dp).weight(1f)
modifier = Modifier
.padding(end = 8.dp)
.weight(1f)
)
Icon(
Icons.Filled.ArrowDropDown,
Expand All @@ -98,14 +106,14 @@ fun LiteModeScreen(upPress: () -> Unit) {
expanded = expanded,
onDismissRequest = { expanded = false }
) {
mapTypes.forEachIndexed { index, mapType ->
mapTypes.forEach { mapType ->
DropdownMenuItem(
onClick = {
expanded = false
selectedPosition = index
selectedMapType = mapType
}
) {
Text(text = mapType)
Text(text = mapType.toString())
}
}
}
Expand All @@ -124,7 +132,7 @@ fun LiteModeScreen(upPress: () -> Unit) {
cameraPositionState = cameraPositionState,
properties = MapProperties(
isLiteModeEnabled = true,
mapType = MapType.valueOf(mapTypes[selectedPosition])
mapType = selectedMapType,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -68,8 +67,18 @@ fun MapTypesAndLayerGroupsScreen(upPress: () -> Unit) {
}
) { contentPadding ->
Column(modifier = Modifier.padding(contentPadding)) {
val mapTypes = stringArrayResource(R.array.map_types)
var selectedMapTypePosition by remember { mutableStateOf(0) }
val mapTypes = remember {
listOf(
MapType.Basic,
MapType.Navi,
MapType.Satellite,
MapType.Hybrid,
MapType.NaviHybrid,
MapType.Terrain,
MapType.None,
)
}
var selectedMapType by remember { mutableStateOf<MapType>(MapType.Basic) }

var isBuildingLayerGroupEnabled by remember { mutableStateOf(true) }
var isTransitLayerGroupEnabled by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -97,7 +106,7 @@ fun MapTypesAndLayerGroupsScreen(upPress: () -> Unit) {
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = mapTypes[selectedMapTypePosition],
text = selectedMapType.toString(),
fontSize = 18.sp,
modifier = Modifier.padding(end = 8.dp).weight(1f)
)
Expand All @@ -114,10 +123,10 @@ fun MapTypesAndLayerGroupsScreen(upPress: () -> Unit) {
DropdownMenuItem(
onClick = {
mapTypeExpanded = false
selectedMapTypePosition = index
selectedMapType = mapType
}
) {
Text(text = mapType)
Text(text = mapType.toString())
}
}
}
Expand Down Expand Up @@ -235,7 +244,7 @@ fun MapTypesAndLayerGroupsScreen(upPress: () -> Unit) {
NaverMap(
cameraPositionState = cameraPositionState,
properties = MapProperties(
mapType = MapType.valueOf(mapTypes[selectedMapTypePosition]),
mapType = selectedMapType,
isBuildingLayerGroupEnabled = isBuildingLayerGroupEnabled,
isTransitLayerGroupEnabled = isTransitLayerGroupEnabled,
isBicycleLayerGroupEnabled = isBicycleLayerGroupEnabled,
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,23 +285,6 @@
<string name="name_tile_cover_helper">Tile Cover Helper</string>
<string name="description_tile_cover_helper">타일 컀버 헬퍼 μ‚¬μš©</string>

<string-array name="map_types">
<item>Basic</item>
<item>Navi</item>
<item>Satellite</item>
<item>Hybrid</item>
<item>NaviHybrid</item>
<item>Terrain</item>
<item>None</item>
</string-array>

<string-array name="map_types_without_navi">
<item>Basic</item>
<item>Satellite</item>
<item>Hybrid</item>
<item>Terrain</item>
</string-array>

<string-array name="locales">
<item>μ‹œμŠ€ν…œ μ„€μ • μ‚¬μš©</item>
<item>ν•œκ΅­μ–΄(ko-KR)</item>
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ google-play-services-location = { module = "com.google.android.gms:play-services

kotlin-pluginGradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }

dokka-pluginGradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }

Expand All @@ -60,6 +62,6 @@ androidx-profileinstaller = "androidx.profileinstaller:profileinstaller:1.2.0"

# Test

androidx-test-ext-junit = "androidx.test.ext:junit:1.1.3"
androidx-test-ext-junit = "androidx.test.ext:junit:1.2.1"
androidx-test-espresso-core = "androidx.test.espresso:espresso-core:3.4.0"
androidx-test-uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0"
41 changes: 29 additions & 12 deletions naver-map-compose/api/current.api
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,35 @@ package com.naver.maps.map.compose {
property public final float symbolScale;
}

@androidx.compose.runtime.Immutable public enum MapType {
method public final com.naver.maps.map.NaverMap.MapType! getValue();
method public static com.naver.maps.map.compose.MapType valueOf(String value) throws java.lang.IllegalArgumentException, java.lang.NullPointerException;
method public static com.naver.maps.map.compose.MapType[] values();
property public final com.naver.maps.map.NaverMap.MapType! value;
enum_constant public static final com.naver.maps.map.compose.MapType Basic;
enum_constant public static final com.naver.maps.map.compose.MapType Hybrid;
enum_constant public static final com.naver.maps.map.compose.MapType Navi;
enum_constant public static final com.naver.maps.map.compose.MapType NaviHybrid;
enum_constant public static final com.naver.maps.map.compose.MapType None;
enum_constant public static final com.naver.maps.map.compose.MapType Satellite;
enum_constant public static final com.naver.maps.map.compose.MapType Terrain;
@androidx.compose.runtime.Immutable public sealed interface MapType {
}

public static final class MapType.Basic implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.Basic INSTANCE;
}

public static final class MapType.Hybrid implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.Hybrid INSTANCE;
}

public static final class MapType.Navi implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.Navi INSTANCE;
}

public static final class MapType.NaviHybrid implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.NaviHybrid INSTANCE;
}

public static final class MapType.None implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.None INSTANCE;
}

public static final class MapType.Satellite implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.Satellite INSTANCE;
}

public static final class MapType.Terrain implements com.naver.maps.map.compose.MapType {
field public static final com.naver.maps.map.compose.MapType.Terrain INSTANCE;
}

public final class MapUiSettings {
Expand Down
2 changes: 2 additions & 0 deletions naver-map-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dependencies {
implementation libs.google.play.services.location
implementation libs.accompanist.permissions

androidTestImplementation libs.kotlin.test
androidTestImplementation libs.kotlin.reflect
androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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

/**
* The list of the immediate subclasses if this class is a sealed class, or an empty list otherwise.
*/
internal inline fun <reified T> sealedSubclasses(): List<T> {
return T::class.sealedSubclasses.mapNotNull { it.objectInstance }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 SOUP
* 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.
Expand All @@ -16,22 +16,23 @@
package com.naver.maps.map.compose

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals
import com.naver.maps.map.NaverMap.MapType as NaverMapType
import com.naver.maps.map.compose.MapType as ComposeMapType

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
internal class ExampleInstrumentedTest {
internal class MapTypeTest {

@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.naver.maps.map.compose.test", appContext.packageName)
fun equals() {
val naverMapTypes = NaverMapType.entries.map { it.name }.sorted()
val composeMapTypes = sealedSubclasses<ComposeMapType>().map { it.toString() }.sorted()
assertEquals(
expected = naverMapTypes,
actual = composeMapTypes,
message = "The MapType class of NaverMap SDK and naver-map-compose do not match exactly.",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,47 +120,6 @@ public data class MapProperties(
}
}

/**
* μ§€λ„μ˜ μœ ν˜•μ„ λ‚˜νƒ€λ‚΄λŠ” μ—΄κ±°ν˜•.
*/
@Immutable
public enum class MapType(public val value: com.naver.maps.map.NaverMap.MapType) {
/**
* 일반 지도.
*/
Basic(com.naver.maps.map.NaverMap.MapType.Basic),

/**
* λ‚΄λΉ„κ²Œμ΄μ…˜ 지도.
*/
Navi(com.naver.maps.map.NaverMap.MapType.Navi),

/**
* μœ„μ„± 지도.
*/
Satellite(com.naver.maps.map.NaverMap.MapType.Satellite),

/**
* μœ„μ„± 지도(겹쳐보기).
*/
Hybrid(com.naver.maps.map.NaverMap.MapType.Hybrid),

/**
* λ‚΄λΉ„κ²Œμ΄μ…˜μš© μœ„μ„± 지도(겹쳐보기).
*/
NaviHybrid(com.naver.maps.map.NaverMap.MapType.NaviHybrid),

/**
* μ§€ν˜•λ„.
*/
Terrain(com.naver.maps.map.NaverMap.MapType.Terrain),

/**
* μ—†μŒ. μ§€λ„λŠ” λ‚˜νƒ€λ‚˜μ§€ μ•Šκ³  μ˜€λ²„λ ˆμ΄λ§Œμ΄ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.
*/
None(com.naver.maps.map.NaverMap.MapType.None)
}

/**
* μœ„μΉ˜ 좔적 λͺ¨λ“œλ₯Ό λ‚˜νƒ€λ‚΄λŠ” μ—΄κ±°ν˜•.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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

import androidx.compose.runtime.Immutable

/**
* μ§€λ„μ˜ μœ ν˜•μ„ λ‚˜νƒ€λ‚΄λŠ” μ—΄κ±°ν˜•.
*/
@Immutable
public sealed interface MapType {
/**
* 일반 지도.
*/
public data object Basic : MapType

/**
* λ‚΄λΉ„κ²Œμ΄μ…˜ 지도.
*/
public data object Navi : MapType

/**
* μœ„μ„± 지도.
*/
public data object Satellite : MapType

/**
* μœ„μ„± 지도(겹쳐보기).
*/
public data object Hybrid : MapType

/**
* λ‚΄λΉ„κ²Œμ΄μ…˜μš© μœ„μ„± 지도(겹쳐보기).
*/
public data object NaviHybrid : MapType

/**
* μ§€ν˜•λ„.
*/
public data object Terrain : MapType

/**
* μ—†μŒ. μ§€λ„λŠ” λ‚˜νƒ€λ‚˜μ§€ μ•Šκ³  μ˜€λ²„λ ˆμ΄λ§Œμ΄ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.
*/
public data object None : MapType
}
Loading

0 comments on commit 64a3d35

Please sign in to comment.