Skip to content

Commit

Permalink
[feat] #76 지도 및 기프티콘 상세에 표시되는 지도로 인한 공통 코드 및 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
ows3090 committed May 18, 2024
1 parent 61f6951 commit 13b8dba
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 250 deletions.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.yapp.buddycon",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package com.yapp.buddycon.designsystem.component.modal

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -32,7 +24,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -56,9 +47,12 @@ private val PlaceModalSheetButtonRadius = 12.dp
fun PlaceModalSheet(
sheetState: SheetState = rememberModalBottomSheetState(),
searchPlaceModel: SearchPlaceModel,
onNavigateToNaverMap: (String, String, String) -> Unit = { _, _, _ -> },
onNavigateToKakaoMap: (String, String) -> Unit = { _, _ -> },
onNavigateToGoogleMap: (String, String, String) -> Unit = { _, _, _ -> },
onCopy: (String) -> Unit = {},
onDismiss: () -> Unit = {}
) {
val context = LocalContext.current
var isClicked by remember { mutableStateOf(false) }
ModalBottomSheet(
onDismissRequest = onDismiss,
Expand All @@ -77,23 +71,13 @@ fun PlaceModalSheet(
.fillMaxWidth()
.weight(1f)
.clickable {
val naverMapUri = Uri
.Builder()
.scheme("nmap")
.authority("route")
.appendPath("public")
.appendQueryParameter("appname", "com.yapp.buddycon")
.appendQueryParameter("dlat", searchPlaceModel.y.toString())
.appendQueryParameter("dlng", searchPlaceModel.x.toString())
.appendQueryParameter("dname", searchPlaceModel.place_name)
.build()

runDeepLink(
context = context,
uri = naverMapUri,
marketLink = "market://details?id=com.nhn.android.nmap"
onNavigateToNaverMap(
searchPlaceModel.y.toString(),
searchPlaceModel.x.toString(),
searchPlaceModel.place_name
)
}.padding(horizontal = Paddings.xlarge),
}
.padding(horizontal = Paddings.xlarge),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
Expand All @@ -114,18 +98,9 @@ fun PlaceModalSheet(
.fillMaxWidth()
.weight(1f)
.clickable {
val kakaoMapUri = Uri
.Builder()
.scheme("kakaomap")
.authority("route")
.appendQueryParameter("ep", "${searchPlaceModel.y},${searchPlaceModel.x}")
.appendQueryParameter("by", "PUBLICTRANSIT")
.build()

runDeepLink(
context = context,
uri = kakaoMapUri,
marketLink = "market://details?id=net.daum.android.map"
onNavigateToKakaoMap(
searchPlaceModel.y.toString(),
searchPlaceModel.x.toString()
)
}
.padding(horizontal = Paddings.xlarge),
Expand All @@ -149,18 +124,10 @@ fun PlaceModalSheet(
.fillMaxWidth()
.weight(1f)
.clickable {
val googleMapUri = Uri
.Builder()
.scheme("geo")
.appendPath("${searchPlaceModel.y},${searchPlaceModel.x}")
.appendQueryParameter("q", "${searchPlaceModel.place_name}")
.build()

runDeepLink(
context = context,
uri = googleMapUri,
marketLink = "market://details?id=com.google.android.apps.maps",
packageName = "com.google.android.apps.maps"
onNavigateToGoogleMap(
searchPlaceModel.y.toString(),
searchPlaceModel.x.toString(),
searchPlaceModel.place_name
)
}
.padding(horizontal = Paddings.xlarge),
Expand Down Expand Up @@ -240,12 +207,7 @@ fun PlaceModalSheet(
)
}
Button(
onClick = {
copyInClipBoard(
context = context,
text = searchPlaceModel.address_name
)
},
onClick = { onCopy(searchPlaceModel.address_name) },
modifier = Modifier
.padding(start = Paddings.medium)
.weight(1f)
Expand All @@ -267,42 +229,3 @@ fun PlaceModalSheet(
}
}
}

private fun copyInClipBoard(
context: Context,
text: String
) {
val manager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Address", text)
manager.setPrimaryClip(clip)

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(context, context.getString(R.string.copy_complete), Toast.LENGTH_SHORT).show()
}
}

private fun runDeepLink(
context: Context,
uri: Uri,
marketLink: String,
packageName: String? = null
) {
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.addCategory(Intent.CATEGORY_BROWSABLE)

packageName?.let { name ->
intent.setPackage(name)
}

val list = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.packageManager.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
} else {
context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
}

if (list.isEmpty()) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(marketLink)))
} else {
context.startActivity(intent)
}
}
21 changes: 21 additions & 0 deletions core/utility/src/main/java/com/yapp/buddycon/utility/Clipboard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.yapp.buddycon.utility

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.widget.Toast
import com.yapp.buddycon.designsystem.R

fun copyInClipBoard(
context: Context,
text: String
) {
val manager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("Address", text)
manager.setPrimaryClip(clip)

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
Toast.makeText(context, context.getString(R.string.copy_complete), Toast.LENGTH_SHORT).show()
}
}
6 changes: 4 additions & 2 deletions core/utility/src/main/java/com/yapp/buddycon/utility/Date.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

fun String.isDeadLine(): Boolean {
fun String.isDeadLine(
endDay: Int = 14
): Boolean {
val today = Date()
val date = SimpleDateFormat("yyyy-MM-dd", Locale.KOREA).parse(this) ?: Date()
val diff = (date.time - today.time) / (1000 * 60 * 60 * 24)
return diff in 0..14
return diff in 0..endDay
}
111 changes: 111 additions & 0 deletions core/utility/src/main/java/com/yapp/buddycon/utility/DeepLink.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.yapp.buddycon.utility

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.provider.Settings

fun navigateToSetting(
context: Context,
packageName: String
) {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:$packageName")
context.startActivity(intent)
}

fun navigateToNaverMap(
context: Context,
dlat: String,
dlng: String,
dname: String
) {
val uri = Uri
.Builder()
.scheme("nmap")
.authority("route")
.appendPath("public")
.appendQueryParameter("appname", "com.yapp.buddycon")
.appendQueryParameter("dlat", dlat)
.appendQueryParameter("dlng", dlng)
.appendQueryParameter("dname", dname)
.build()

val marketUrl = "market://details?id=com.nhn.android.nmap"
runDeepLink(
context = context,
uri = uri,
marketUrl = marketUrl
)
}

fun navigateToKakaoMap(
context: Context,
dlat: String,
dlng: String
) {
val uri = Uri
.Builder()
.scheme("kakaomap")
.authority("route")
.appendQueryParameter("ep", "$dlat,$dlng")
.appendQueryParameter("by", "PUBLICTRANSIT")
.build()

val marketUrl = "market://details?id=net.daum.android.map"
runDeepLink(
context = context,
uri = uri,
marketUrl = marketUrl
)
}

fun navigateToGoogleMap(
context: Context,
dlat: String,
dlng: String,
dname: String
) {
val uri = Uri
.Builder()
.scheme("geo")
.appendPath("$dlat,$dlng")
.appendQueryParameter("q", "$dname")
.build()

val marketUrl = "market://details?id=com.google.android.apps.maps"
runDeepLink(
context = context,
uri = uri,
marketUrl = marketUrl,
packageName = "com.google.android.apps.maps"
)
}

private fun runDeepLink(
context: Context,
uri: Uri,
marketUrl: String,
packageName: String? = null
) {
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.addCategory(Intent.CATEGORY_BROWSABLE)

packageName?.let { name ->
intent.setPackage(name)
}

val list = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.packageManager.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_DEFAULT_ONLY.toLong()))
} else {
context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
}

if (list.isEmpty()) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(marketUrl)))
} else {
context.startActivity(intent)
}
}
10 changes: 6 additions & 4 deletions core/utility/src/main/java/com/yapp/buddycon/utility/Location.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun getCurrentLocation(
}
}

// 지도 위 마커 추가 및 반환
// 지도 위 마커 추가 및 리턴
fun getLocationLabels(
labelManager: LabelManager,
searchPlaceModels: List<SearchPlaceModel>
Expand All @@ -49,6 +49,7 @@ fun getLocationLabels(
}.toMap()
}

// TODO 마커 변경되면 추후 수정 예정
fun scaleToLabel(
label: Label,
scale: Float
Expand Down Expand Up @@ -76,6 +77,7 @@ fun GifticonStore?.getDrawableRes() = when (this) {
}
}

// TODO 마커 변경 시 변경 예정
fun GifticonStore?.getExpandedDrawableRes() = when (this) {
GifticonStore.STARBUCKS,
GifticonStore.TWOSOME_PLACE,
Expand All @@ -84,14 +86,14 @@ fun GifticonStore?.getExpandedDrawableRes() = when (this) {
GifticonStore.COFFEE_BEAN,
GifticonStore.GONG_CHA,
GifticonStore.BASKIN_ROBBINS -> {
R.drawable.ic_location
R.drawable.ic_coffee
}

GifticonStore.MACDONALD -> {
R.drawable.ic_location
R.drawable.ic_fastfood
}

else -> {
R.drawable.ic_location
R.drawable.ic_store
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat

// 현재 위치 권한 확인
fun checkLocationPermission(
context: Context
): Boolean {
Expand All @@ -20,6 +21,7 @@ fun checkLocationPermission(
return permissions.all { ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED }
}

// 시스템 위치 권한 요청
@Composable
fun RequestLocationPermission(
onGranted: () -> Unit = {},
Expand Down
Loading

0 comments on commit 13b8dba

Please sign in to comment.