Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

전남대_Android 이가현 3주차 step2 과제 #101

Open
wants to merge 18 commits into
base: leeghy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
- 코드 복사
- API 받아오기

1단계
1단계 ✅

: 이전 단계와 기능은 비슷하나 카카오로컬 API를 사용한다.
- 검색어를 입력하면 검색 결과가 15개 이상 표시된다.
- 검색 결과 목록은 세로 스크롤이 된다.
Expand Down
16 changes: 16 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import java.util.Properties

fun getApiKey(key: String): String {
return gradleLocalProperties(rootDir, providers).getProperty(key) ?: ""
}

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())

android {
namespace = "campus.tech.kakao.map"
compileSdk = 34
Expand All @@ -15,6 +25,8 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField("String", "API_KEY", "\"${getApiKey("API_KEY")}\"")
leeghy marked this conversation as resolved.
Show resolved Hide resolved
}

buildTypes {
Expand All @@ -36,6 +48,7 @@ android {

buildFeatures {
viewBinding = true
buildConfig = true
}
}

Expand All @@ -51,6 +64,9 @@ dependencies {
implementation("com.google.code.gson:gson:2.9.0")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("com.squareup.retrofit2:converter-gson:2.11.0")
implementation("com.kakao.maps.open:android:2.9.5")
implementation("com.kakao.sdk:v2-all:2.20.3")
implementation("androidx.activity:activity:1.9.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,16 +15,24 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
android:name=".Model.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".view.MainActivity"
android:exported="false" />
<activity
android:name=".view.MapActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="com.kakao.sdk.APP_KEY"
android:value="b6f4b70a2090ca9cfca380ec1ebc9c5f"/>
leeghy marked this conversation as resolved.
Show resolved Hide resolved
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Model

import retrofit2.Call
import retrofit2.http.GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Model

data class LocationData (
val name: String,
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/Model/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package campus.tech.kakao.map.Model

import android.app.Application
import android.util.Log
import com.kakao.vectormap.KakaoMapSdk

class MyApplication: Application() {
override fun onCreate() {
super.onCreate()

try {
KakaoMapSdk.init(this, "b6f4b70a2090ca9cfca380ec1ebc9c5f")
leeghy marked this conversation as resolved.
Show resolved Hide resolved
Log.d("KakaoMapSDK", "SDK initialized successfully")
} catch (e: Exception) {
Log.e("KakaoMapSDK", "error", e)
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Model

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Model

import android.util.Log
import campus.tech.kakao.map.view.MainActivity
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.Model

data class SearchResult(
val documents: List<Place>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.view

import android.content.Context
import android.os.Bundle
Expand All @@ -12,13 +12,21 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.BuildConfig
import campus.tech.kakao.map.viewmodel.DataDbHelper
import campus.tech.kakao.map.viewmodel.LocationAdapter
import campus.tech.kakao.map.Model.LocationData
import campus.tech.kakao.map.Model.RetrofitClient
import campus.tech.kakao.map.Model.Place
import campus.tech.kakao.map.R
import campus.tech.kakao.map.Model.SearchCallback
import campus.tech.kakao.map.Model.SearchResult
import campus.tech.kakao.map.viewmodel.SearchViewAdapter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import retrofit2.Call
import campus.tech.kakao.map.SearchResult

class MainActivity : AppCompatActivity() {
private val API_KEY = "KakaoAK 276613de22bf074fb398b9eed102f89b"

private lateinit var db: DataDbHelper
private lateinit var recyclerView: RecyclerView
Expand Down Expand Up @@ -138,11 +146,10 @@ class MainActivity : AppCompatActivity() {
saveSearchList()
Log.d("MainActivity", "Item clicked: ${locationData.name}")
}

private fun searchLocations(key: String) {
val apiService = RetrofitClient.instance
val call: Call<campus.tech.kakao.map.SearchResult> = apiService.searchPlaces(API_KEY, key)
call.enqueue(campus.tech.kakao.map.SearchCallback(this))
val call: Call<SearchResult> = apiService.searchPlaces(BuildConfig.API_KEY, key)
call.enqueue(SearchCallback(this))
leeghy marked this conversation as resolved.
Show resolved Hide resolved
}

fun updateSearchResults(results: List<Place>) {
Expand Down
71 changes: 71 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/view/MapActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package campus.tech.kakao.map.view

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import campus.tech.kakao.map.R
import com.kakao.vectormap.KakaoMap
import com.kakao.vectormap.KakaoMapReadyCallback
import com.kakao.vectormap.LatLng
import com.kakao.vectormap.MapLifeCycleCallback
import com.kakao.vectormap.MapView
import com.kakao.vectormap.camera.CameraUpdateFactory

class MapActivity : AppCompatActivity() {

private lateinit var mapView: MapView
private lateinit var inputText: EditText

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map)

mapView = findViewById(R.id.map_view)
inputText = findViewById(R.id.MapinputText)

mapView.start(
object : MapLifeCycleCallback() {
override fun onMapDestroy() {}
override fun onMapError(error: Exception) {
Log.e("MapError", "${error.message}", error)
}
},
object : KakaoMapReadyCallback() {
override fun onMapReady(kakaoMap: KakaoMap) {
// 맵 초기화 코드
val mapCenter = LatLng.from(37.566, 126.978) // 서울시청 좌표
kakaoMap.moveCamera(CameraUpdateFactory.newCenterPosition(mapCenter))
kakaoMap.moveCamera(CameraUpdateFactory.zoomTo(15))


}
}
)

inputText.setOnClickListener {
val intent = Intent(this@MapActivity, MainActivity::class.java)
startActivity(intent)
}
}

override fun onResume() {
super.onResume()
if (::mapView.isInitialized && mapView != null) {
try {
mapView.resume()
} catch (e: Exception) {
Log.e("MapError", "Error resuming map: ${e.message}", e)
}
}
}

override fun onPause() {
super.onPause()
if (::mapView.isInitialized) {
mapView.pause()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.viewmodel

import android.content.Context
import android.database.sqlite.SQLiteDatabase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.viewmodel

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.Model.LocationData
import campus.tech.kakao.map.R

class LocationAdapter(
private val locationList: List<LocationData>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package campus.tech.kakao.map
package campus.tech.kakao.map.viewmodel

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.Model.LocationData
import campus.tech.kakao.map.R

class SearchViewAdapter(
private val searchList: ArrayList<LocationData>,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".view.MainActivity">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/searchView"
Expand Down Expand Up @@ -57,4 +57,5 @@
app:layout_constraintBottom_toBottomOf="parent"
/>


</androidx.constraintlayout.widget.ConstraintLayout>
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.kakao.vectormap.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<EditText
android:id="@+id/MapinputText"
android:layout_width="390dp"
android:layout_height="wrap_content"
android:hint="검색어를 입력해주세요."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="10dp"/>

<Button
android:id="@+id/MapcancelBtn"
android:layout_width="30dp"
android:layout_height="30dp"
app:layout_constraintEnd_toEndOf="@id/MapinputText"
app:layout_constraintBottom_toBottomOf="@id/MapinputText"
android:background="@drawable/baseline_close_24"
android:layout_marginBottom="8dp"
android:layout_marginEnd="5dp"
android:backgroundTint="@color/black"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">Map</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
15 changes: 10 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.3.1" apply false
id("com.android.application") version "8.4.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("org.jlleitschuh.gradle.ktlint") version "12.1.0" apply false
}

allprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
}
//
//allprojects {
// apply(plugin = "org.jlleitschuh.gradle.ktlint")
// repositories {
// google()
// mavenCentral()
// maven(url = "https://devrepo.kakao.com/nexus/repository/kakaomap-releases/")
// }
//}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading