diff --git a/README.md b/README.md index 91dbd079..dc23030f 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ # android-map-location + +## 1단계 - 카카오맵 API 심화 +### 기능 요구 사항 +- 저장된 검색어를 선택하면 해당 검색어의 검색 결과가 표시된다. +- 검색 결과 목록 중 하나의 항목을 선택하면 해당 항목의 위치를 지도에 표시한다. +- 앱 종료 시 마지막 위치를 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다. +- 카카오지도 onMapError() 호출 시 에러 화면을 보여준다. +### 프로그래밍 요구 사항 +- BottomSheet를 사용한다. +- 카카오 API 사용을 위한 앱 키를 외부에 노출하지 않는다. +- 가능한 MVVM 아키텍처 패턴을 적용하도록 한다. +- 코드 컨벤션을 준수하며 프로그래밍한다. \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9b4327c9..7240e4b1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -48,10 +48,13 @@ android { viewBinding = true buildConfig = true } + testOptions { + animationsDisabled = true + } } dependencies { - val lifecycle_version = "2.8.3" + val lifecycle_version = "2.8.3" implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") implementation("androidx.core:core-ktx:1.12.0") @@ -75,5 +78,6 @@ dependencies { androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("androidx.test:rules:1.5.0") androidTestImplementation("androidx.test.espresso:espresso-intents:3.5.1") + androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1") } fun getApiKey(key: String): String = gradleLocalProperties(rootDir, providers).getProperty(key) \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/Document.kt b/app/src/main/java/campus/tech/kakao/map/DTO/Document.kt deleted file mode 100644 index 1b33c093..00000000 --- a/app/src/main/java/campus/tech/kakao/map/DTO/Document.kt +++ /dev/null @@ -1,22 +0,0 @@ -package campus.tech.kakao.map.DTO - -import com.google.gson.annotations.SerializedName - -//필요 없는 데이터 주석화 -data class Document( - //val id: String, - @SerializedName("place_name") - val placeName: String, - //val category_name: String, - //val category_group_code: String, - @SerializedName("category_group_name") - val categoryGroupName: String, - //val phone: String, - @SerializedName("address_name") - val addressName: String, - //val road_address_name: String, - //val x: String, - //val y: String, - //val place_url: String, - //val distance: String, -) diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/SameName.kt b/app/src/main/java/campus/tech/kakao/map/DTO/SameName.kt deleted file mode 100644 index b3b9f3bc..00000000 --- a/app/src/main/java/campus/tech/kakao/map/DTO/SameName.kt +++ /dev/null @@ -1,7 +0,0 @@ -package campus.tech.kakao.map.DTO - -data class SameName( - val region: List, - val keyword: String, - val selected_region: String -) diff --git a/app/src/main/java/campus/tech/kakao/map/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/MainActivity.kt deleted file mode 100644 index 95b43803..00000000 --- a/app/src/main/java/campus/tech/kakao/map/MainActivity.kt +++ /dev/null @@ -1,11 +0,0 @@ -package campus.tech.kakao.map - -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - } -} diff --git a/app/src/main/java/campus/tech/kakao/map/MainViewModel.kt b/app/src/main/java/campus/tech/kakao/map/MainViewModel.kt index d5344630..b1658c30 100644 --- a/app/src/main/java/campus/tech/kakao/map/MainViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/MainViewModel.kt @@ -3,10 +3,13 @@ package campus.tech.kakao.map import android.app.Application import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData -import campus.tech.kakao.map.DBHelper.SearchWordDbHelper -import campus.tech.kakao.map.DTO.Document -import campus.tech.kakao.map.DTO.SearchWord -import campus.tech.kakao.map.RetrofitData.Companion.getInstance +import androidx.lifecycle.MutableLiveData +import campus.tech.kakao.map.adapter.AdapterCallback +import campus.tech.kakao.map.dto.MapPosition.getMapPosition +import campus.tech.kakao.map.url.RetrofitData.Companion.getInstance +import campus.tech.kakao.map.dto.Document +import campus.tech.kakao.map.dto.SearchWord +import campus.tech.kakao.map.dto.SearchWordDbHelper class MainViewModel(application: Application): AndroidViewModel(application) { @@ -16,6 +19,12 @@ class MainViewModel(application: Application): AndroidViewModel(application) { private val retrofitData = getInstance() val documentList: LiveData> get() = retrofitData.getDocuments() + private val _documentClicked = MutableLiveData() + val documentClicked: LiveData get() = _documentClicked + + + + fun addWord(document: Document){ wordDbHelper.addWord(wordfromDocument(document)) } @@ -39,4 +48,35 @@ class MainViewModel(application: Application): AndroidViewModel(application) { super.onCleared() wordDbHelper.close() } + + fun setMapInfo(document: Document){ + getMapPosition(getApplication()).setMapInfo(document) + } + + fun getMapInfo():List{ + val latitude = getMapPosition(getApplication()).getPreferences(LATITUDE,INIT_LATITUDE) + val longitude = getMapPosition(getApplication()).getPreferences(LONGITUDE,INIT_LONGITUDE) + val placeName = getMapPosition(getApplication()).getPreferences(PLACE_NAME,"") + val addressName = getMapPosition(getApplication()).getPreferences(ADDRESS_NAME,"") + return listOf(latitude, longitude, placeName, addressName) + } + + fun placeClicked(document: Document, callback:AdapterCallback){ + callback.onWordAdded(document) + callback.onDocumentInfoSet(document) + _documentClicked.value = true + } + + fun documentClickedDone(){ + _documentClicked.value = false + } + + companion object{ + const val INIT_LATITUDE = "37.402005" + const val INIT_LONGITUDE = "127.108621" + const val LATITUDE = "latitude" + const val LONGITUDE = "longitude" + const val PLACE_NAME = "placeName" + const val ADDRESS_NAME = "addressName" + } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/MapActivity.kt index f71c0cb5..a90b0a99 100644 --- a/app/src/main/java/campus/tech/kakao/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/MapActivity.kt @@ -1,31 +1,65 @@ package campus.tech.kakao.map import android.content.Intent +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Color import android.os.Bundle import android.util.Log +import android.view.View import android.widget.LinearLayout +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.ViewModelProvider +import com.google.android.material.bottomsheet.BottomSheetBehavior 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.CameraUpdate +import com.kakao.vectormap.camera.CameraUpdateFactory +import com.kakao.vectormap.label.LabelOptions +import com.kakao.vectormap.label.LabelStyle +import com.kakao.vectormap.label.LabelStyles import java.lang.Exception + class MapActivity : AppCompatActivity() { private lateinit var mapView: MapView private var map: KakaoMap? = null private lateinit var searchBar: LinearLayout + private lateinit var model: MainViewModel + private lateinit var placeName:String + private lateinit var addressName:String + private lateinit var bottomSheetBehavior: BottomSheetBehavior + private lateinit var bottomSheet :LinearLayout + private lateinit var bottomSheetName:TextView + private lateinit var bottomSheetAddress :TextView + private var longitude:Double = 0.0 + private var latitude:Double = 0.0 + companion object{ + const val MARKER_WIDTH = 100 + const val MARKER_HEIGHT = 100 + const val MARKER_TEXT_SIZE = 40 + const val ZOOM_LEVEL = 17 + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map) mapView = findViewById(R.id.map_view) + model = ViewModelProvider(this)[MainViewModel::class.java] + getMapInfo() mapView.start(object : MapLifeCycleCallback() { override fun onMapDestroy() { } override fun onMapError(p0: Exception?) { - Log.e("MapActivity", "onMapError: ${p0?.message}", p0) + setContentView(R.layout.map_error) + val errorText = findViewById(R.id.map_error_text) + errorText.text = p0?.message } }, object: KakaoMapReadyCallback() { @@ -33,17 +67,40 @@ class MapActivity : AppCompatActivity() { map = kakaoMap } + override fun getPosition(): LatLng { + return LatLng.from(latitude, longitude) + } + + override fun getZoomLevel(): Int { + return ZOOM_LEVEL + } }) searchBar = findViewById(R.id.search_bar) searchBar.setOnClickListener { val intent = Intent(this@MapActivity, SearchActivity::class.java) startActivity(intent) } + initBottomSheet() } override fun onResume() { super.onResume() + getMapInfo() mapView.resume() + model.documentClicked.observe(this){documentClicked-> + if(documentClicked){ + makeMarker() + setBottomSheet() + model.documentClickedDone() + } + else{ + map?.labelManager?.layer?.removeAll() + bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + } + } + + val cameraUpdate: CameraUpdate = CameraUpdateFactory.newCenterPosition(LatLng.from(latitude, longitude)) + map?.moveCamera(cameraUpdate) } override fun onPause() { @@ -51,4 +108,49 @@ class MapActivity : AppCompatActivity() { mapView.pause() } + private fun getMapInfo(){ + val mapInfoList = model.getMapInfo() + latitude = mapInfoList[0].toDouble() + longitude = mapInfoList[1].toDouble() + placeName = mapInfoList[2] + addressName = mapInfoList[3] + model.documentClickedDone() + } + + private fun makeMarker(){ + val bitmapImage = BitmapFactory.decodeResource(resources, R.drawable.marker) + val markerImage = Bitmap.createScaledBitmap(bitmapImage, MARKER_WIDTH, MARKER_HEIGHT, true) + val styles = map?.labelManager?.addLabelStyles(LabelStyles.from(LabelStyle.from(markerImage).setTextStyles( + MARKER_TEXT_SIZE, Color.BLACK))) + if(styles != null){ + val options = LabelOptions.from(LatLng.from(latitude, longitude)).setStyles(styles).setTexts(placeName) + map?.labelManager?.layer?.removeAll() + map?.labelManager?.layer?.addLabel(options) + } + else{ + Log.e("MapActivity", "makeMarker: styles is null") + } + } + + private fun initBottomSheet(){ + bottomSheet = findViewById(R.id.bottom_sheet) + bottomSheetName = findViewById(R.id.name) + bottomSheetAddress = findViewById(R.id.address) + bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) + bottomSheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback(){ + override fun onStateChanged(bottomSheet: View, newState: Int) { + } + + override fun onSlide(bottomSheet: View, slideOffset: Float) { + } + + }) + bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + } + + private fun setBottomSheet(){ + bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + bottomSheetName.text = placeName + bottomSheetAddress.text = addressName + } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/MyApplication.kt b/app/src/main/java/campus/tech/kakao/map/MyApplication.kt index 2d2aa825..54201a5b 100644 --- a/app/src/main/java/campus/tech/kakao/map/MyApplication.kt +++ b/app/src/main/java/campus/tech/kakao/map/MyApplication.kt @@ -1,11 +1,14 @@ package campus.tech.kakao.map import android.app.Application +import campus.tech.kakao.map.dto.MapPosition import com.kakao.vectormap.KakaoMapSdk class MyApplication : Application() { override fun onCreate() { super.onCreate() + MapPosition.getMapPosition(this) KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY) } + } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/SearchActivity.kt b/app/src/main/java/campus/tech/kakao/map/SearchActivity.kt index 3a10cb0b..609e9c82 100644 --- a/app/src/main/java/campus/tech/kakao/map/SearchActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/SearchActivity.kt @@ -10,10 +10,13 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import campus.tech.kakao.map.Adapter.DocumentAdapter -import campus.tech.kakao.map.Adapter.WordAdapter +import campus.tech.kakao.map.adapter.AdapterCallback +import campus.tech.kakao.map.adapter.DocumentAdapter +import campus.tech.kakao.map.adapter.WordAdapter +import campus.tech.kakao.map.dto.Document +import campus.tech.kakao.map.dto.SearchWord -class SearchActivity : AppCompatActivity() { +class SearchActivity : AppCompatActivity(), AdapterCallback { private lateinit var model: MainViewModel private lateinit var search:EditText @@ -29,13 +32,9 @@ class SearchActivity : AppCompatActivity() { setupUI() searchResult.layoutManager = LinearLayoutManager(this) searchWordResult.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) - documentAdapter = DocumentAdapter(){ Document -> - model.addWord(Document) - } - wordAdapter = WordAdapter() { SearchWord -> - model.deleteWord(SearchWord) - } - search.doOnTextChanged { text, start, before, count -> + documentAdapter = DocumentAdapter(this) + wordAdapter = WordAdapter(this) + search.doOnTextChanged { text, _, _, _ -> val query = text.toString() if (query.isEmpty()){ noResult.visibility = View.VISIBLE @@ -71,7 +70,7 @@ class SearchActivity : AppCompatActivity() { }) } - fun setupUI(){ + private fun setupUI(){ search = findViewById(R.id.search) clear = findViewById(R.id.search_clear) noResult = findViewById(R.id.no_search_result) @@ -82,5 +81,22 @@ class SearchActivity : AppCompatActivity() { } } + override fun onWordAdded(document: Document) { + model.addWord(document) + } + + override fun onDocumentInfoSet(document: Document) { + model.setMapInfo(document) + finish() + } + + override fun onWordDeleted(searchWord: SearchWord) { + model.deleteWord(searchWord) + } + + override fun onWordSearched(searchWord: SearchWord) { + model.searchLocalAPI(searchWord.name) + } + } diff --git a/app/src/main/java/campus/tech/kakao/map/adapter/AdapterCallback.kt b/app/src/main/java/campus/tech/kakao/map/adapter/AdapterCallback.kt new file mode 100644 index 00000000..18088d1a --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/adapter/AdapterCallback.kt @@ -0,0 +1,11 @@ +package campus.tech.kakao.map.adapter + +import campus.tech.kakao.map.dto.Document +import campus.tech.kakao.map.dto.SearchWord + +interface AdapterCallback { + fun onWordAdded(document: Document) + fun onDocumentInfoSet(document: Document) + fun onWordDeleted(searchWord: SearchWord) + fun onWordSearched(searchWord: SearchWord) +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/Adapter/DocumentAdapter.kt b/app/src/main/java/campus/tech/kakao/map/adapter/DocumentAdapter.kt similarity index 81% rename from app/src/main/java/campus/tech/kakao/map/Adapter/DocumentAdapter.kt rename to app/src/main/java/campus/tech/kakao/map/adapter/DocumentAdapter.kt index 74492c58..a165cabb 100644 --- a/app/src/main/java/campus/tech/kakao/map/Adapter/DocumentAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/adapter/DocumentAdapter.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.Adapter +package campus.tech.kakao.map.adapter import android.view.LayoutInflater import android.view.View @@ -7,11 +7,13 @@ import android.widget.TextView import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import campus.tech.kakao.map.DTO.Document +import campus.tech.kakao.map.MainViewModel +import campus.tech.kakao.map.dto.Document +import campus.tech.kakao.map.MyApplication import campus.tech.kakao.map.R class DocumentAdapter( - val addWord: (Document) -> Unit + private val callback: AdapterCallback ): ListAdapter( object : DiffUtil.ItemCallback(){ override fun areItemsTheSame(oldItem: Document, newItem: Document): Boolean { @@ -24,9 +26,10 @@ class DocumentAdapter( } ) { - private var placeClicked = { position:Int -> + private fun placeClicked(position:Int){ val document: Document = getItem(position) - addWord(document) + val viewModel = MainViewModel(MyApplication()) + viewModel.placeClicked(document, callback) } inner class ViewHolder( itemView: View diff --git a/app/src/main/java/campus/tech/kakao/map/Adapter/WordAdapter.kt b/app/src/main/java/campus/tech/kakao/map/adapter/WordAdapter.kt similarity index 78% rename from app/src/main/java/campus/tech/kakao/map/Adapter/WordAdapter.kt rename to app/src/main/java/campus/tech/kakao/map/adapter/WordAdapter.kt index 9b051e3d..1584dd17 100644 --- a/app/src/main/java/campus/tech/kakao/map/Adapter/WordAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/adapter/WordAdapter.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.Adapter +package campus.tech.kakao.map.adapter import android.view.LayoutInflater import android.view.View @@ -9,10 +9,10 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import campus.tech.kakao.map.R -import campus.tech.kakao.map.DTO.SearchWord +import campus.tech.kakao.map.dto.SearchWord class WordAdapter( - val deleteWord: (SearchWord) -> Unit + private val callback: AdapterCallback ): ListAdapter( object : DiffUtil.ItemCallback(){ override fun areItemsTheSame(oldItem: SearchWord, newItem: SearchWord): Boolean { @@ -34,6 +34,9 @@ class WordAdapter( delete.setOnClickListener { deletedWords(bindingAdapterPosition) } + searchWord.setOnClickListener { + clickedWord(bindingAdapterPosition) + } } } @@ -46,8 +49,14 @@ class WordAdapter( holder.searchWord.text = word.name } - private val deletedWords = { position:Int -> + private fun deletedWords(position:Int){ val word = getItem(position) - deleteWord(word) + callback.onWordDeleted(word) } + + private fun clickedWord(position:Int){ + val word = getItem(position) + callback.onWordSearched(word) + } + } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/dto/Document.kt b/app/src/main/java/campus/tech/kakao/map/dto/Document.kt new file mode 100644 index 00000000..7873ce81 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/dto/Document.kt @@ -0,0 +1,16 @@ +package campus.tech.kakao.map.dto + +import com.google.gson.annotations.SerializedName + +data class Document( + @SerializedName("place_name") + val placeName: String, + @SerializedName("category_group_name") + val categoryGroupName: String, + @SerializedName("address_name") + val addressName: String, + @SerializedName("x") + val longitude : String, + @SerializedName("y") + val latitude: String +) diff --git a/app/src/main/java/campus/tech/kakao/map/dto/MapPosition.kt b/app/src/main/java/campus/tech/kakao/map/dto/MapPosition.kt new file mode 100644 index 00000000..1d63e21a --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/dto/MapPosition.kt @@ -0,0 +1,14 @@ +package campus.tech.kakao.map.dto + +import android.content.Context + +object MapPosition { + private var mapPosition: MapPositionPreferences? = null + + fun getMapPosition(context: Context): MapPositionPreferences { + if (mapPosition == null) { + mapPosition = MapPositionPreferences(context) + } + return mapPosition!! + } +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/dto/MapPositionContract.kt b/app/src/main/java/campus/tech/kakao/map/dto/MapPositionContract.kt new file mode 100644 index 00000000..b0af0619 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/dto/MapPositionContract.kt @@ -0,0 +1,9 @@ +package campus.tech.kakao.map.dto + +object MapPositionContract { + const val PREFERENCE_NAME = "MapPosition" + const val PREFERENCE_KEY_LATITUDE = "latitude" + const val PREFERENCE_KEY_LONGITUDE = "longitude" + const val PREFERENCE_KEY_PLACENAME = "placeName" + const val PREFERENCE_KEY_ADDRESSNAME = "addressName" +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/dto/MapPositionPreferences.kt b/app/src/main/java/campus/tech/kakao/map/dto/MapPositionPreferences.kt new file mode 100644 index 00000000..487ded95 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/dto/MapPositionPreferences.kt @@ -0,0 +1,24 @@ +package campus.tech.kakao.map.dto + +import android.content.Context + +class MapPositionPreferences(context: Context) { + + private val mapPosition = context.getSharedPreferences(MapPositionContract.PREFERENCE_NAME, Context.MODE_PRIVATE) + + fun setPreferences(key: String, value: String) { + mapPosition.edit().putString(key, value).apply() + } + + fun getPreferences(key: String, defaultValue: String): String { + return mapPosition.getString(key, defaultValue).toString() + } + + fun setMapInfo(document: Document){ + setPreferences(MapPositionContract.PREFERENCE_KEY_LATITUDE, document.latitude) + setPreferences(MapPositionContract.PREFERENCE_KEY_LONGITUDE, document.longitude) + setPreferences(MapPositionContract.PREFERENCE_KEY_PLACENAME, document.placeName) + setPreferences(MapPositionContract.PREFERENCE_KEY_ADDRESSNAME, document.addressName) + } + +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/Meta.kt b/app/src/main/java/campus/tech/kakao/map/dto/Meta.kt similarity index 89% rename from app/src/main/java/campus/tech/kakao/map/DTO/Meta.kt rename to app/src/main/java/campus/tech/kakao/map/dto/Meta.kt index e34d3048..60b41d75 100644 --- a/app/src/main/java/campus/tech/kakao/map/DTO/Meta.kt +++ b/app/src/main/java/campus/tech/kakao/map/dto/Meta.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.DTO +package campus.tech.kakao.map.dto import com.google.gson.annotations.SerializedName diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/PlaceResponse.kt b/app/src/main/java/campus/tech/kakao/map/dto/PlaceResponse.kt similarity index 69% rename from app/src/main/java/campus/tech/kakao/map/DTO/PlaceResponse.kt rename to app/src/main/java/campus/tech/kakao/map/dto/PlaceResponse.kt index 9ab49a5d..3abf2475 100644 --- a/app/src/main/java/campus/tech/kakao/map/DTO/PlaceResponse.kt +++ b/app/src/main/java/campus/tech/kakao/map/dto/PlaceResponse.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.DTO +package campus.tech.kakao.map.dto data class PlaceResponse( val meta: Meta, diff --git a/app/src/main/java/campus/tech/kakao/map/dto/SameName.kt b/app/src/main/java/campus/tech/kakao/map/dto/SameName.kt new file mode 100644 index 00000000..457cb4fe --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/dto/SameName.kt @@ -0,0 +1,10 @@ +package campus.tech.kakao.map.dto + +import com.google.gson.annotations.SerializedName + +data class SameName( + val region: List, + val keyword: String, + @SerializedName("selected_region") + val selectedRegion: String +) diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/SearchWord.kt b/app/src/main/java/campus/tech/kakao/map/dto/SearchWord.kt similarity index 70% rename from app/src/main/java/campus/tech/kakao/map/DTO/SearchWord.kt rename to app/src/main/java/campus/tech/kakao/map/dto/SearchWord.kt index 2823ba00..8ee333ed 100644 --- a/app/src/main/java/campus/tech/kakao/map/DTO/SearchWord.kt +++ b/app/src/main/java/campus/tech/kakao/map/dto/SearchWord.kt @@ -1,3 +1,3 @@ -package campus.tech.kakao.map.DTO +package campus.tech.kakao.map.dto data class SearchWord(val name: String, val address: String, val type: String) diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/SearchWordContract.kt b/app/src/main/java/campus/tech/kakao/map/dto/SearchWordContract.kt similarity index 87% rename from app/src/main/java/campus/tech/kakao/map/DTO/SearchWordContract.kt rename to app/src/main/java/campus/tech/kakao/map/dto/SearchWordContract.kt index 5c97b8cd..2acdb952 100644 --- a/app/src/main/java/campus/tech/kakao/map/DTO/SearchWordContract.kt +++ b/app/src/main/java/campus/tech/kakao/map/dto/SearchWordContract.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.DTO +package campus.tech.kakao.map.dto object SearchWordContract { const val DB_NAME = "search_word.db" diff --git a/app/src/main/java/campus/tech/kakao/map/DBHelper/SearchWordDbHelper.kt b/app/src/main/java/campus/tech/kakao/map/dto/SearchWordDbHelper.kt similarity index 93% rename from app/src/main/java/campus/tech/kakao/map/DBHelper/SearchWordDbHelper.kt rename to app/src/main/java/campus/tech/kakao/map/dto/SearchWordDbHelper.kt index a736d865..a92efb21 100644 --- a/app/src/main/java/campus/tech/kakao/map/DBHelper/SearchWordDbHelper.kt +++ b/app/src/main/java/campus/tech/kakao/map/dto/SearchWordDbHelper.kt @@ -1,15 +1,12 @@ -package campus.tech.kakao.map.DBHelper +package campus.tech.kakao.map.dto import android.content.ContentValues import android.content.Context import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper -import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData -import campus.tech.kakao.map.DTO.SearchWord -import campus.tech.kakao.map.DTO.SearchWordContract -import campus.tech.kakao.map.DTO.SearchWordContract.DB_VERSION +import campus.tech.kakao.map.dto.SearchWordContract.DB_VERSION class SearchWordDbHelper(context: Context): SQLiteOpenHelper( context, SearchWordContract.DB_NAME, null, DB_VERSION) { diff --git a/app/src/main/java/campus/tech/kakao/map/RetrofitData.kt b/app/src/main/java/campus/tech/kakao/map/url/RetrofitData.kt similarity index 74% rename from app/src/main/java/campus/tech/kakao/map/RetrofitData.kt rename to app/src/main/java/campus/tech/kakao/map/url/RetrofitData.kt index de3f13a0..3eddd6f5 100644 --- a/app/src/main/java/campus/tech/kakao/map/RetrofitData.kt +++ b/app/src/main/java/campus/tech/kakao/map/url/RetrofitData.kt @@ -1,10 +1,9 @@ -package campus.tech.kakao.map +package campus.tech.kakao.map.url import androidx.lifecycle.MutableLiveData -import campus.tech.kakao.map.DTO.Document -import campus.tech.kakao.map.DTO.PlaceResponse -import campus.tech.kakao.map.DTO.UrlContract -import campus.tech.kakao.map.DTO.UrlContract.AUTHORIZATION +import campus.tech.kakao.map.dto.Document +import campus.tech.kakao.map.dto.PlaceResponse +import campus.tech.kakao.map.url.UrlContract.AUTHORIZATION import retrofit2.Call import retrofit2.Callback import retrofit2.Response @@ -28,8 +27,15 @@ class RetrofitData private constructor() { if (response.isSuccessful) { val documentList = mutableListOf() val body = response.body() - body?.documents?.forEach { - documentList.add(Document(it.placeName, it.categoryGroupName, it.addressName)) + body?.documents?.forEach {document -> + documentList.add( + Document( + document.placeName, + document.categoryGroupName, + document.addressName, + document.longitude, + document.latitude) + ) } _documents.value = documentList } diff --git a/app/src/main/java/campus/tech/kakao/map/RetrofitService.kt b/app/src/main/java/campus/tech/kakao/map/url/RetrofitService.kt similarity index 77% rename from app/src/main/java/campus/tech/kakao/map/RetrofitService.kt rename to app/src/main/java/campus/tech/kakao/map/url/RetrofitService.kt index 7f4e7be9..c6a1765b 100644 --- a/app/src/main/java/campus/tech/kakao/map/RetrofitService.kt +++ b/app/src/main/java/campus/tech/kakao/map/url/RetrofitService.kt @@ -1,6 +1,6 @@ -package campus.tech.kakao.map +package campus.tech.kakao.map.url -import campus.tech.kakao.map.DTO.PlaceResponse +import campus.tech.kakao.map.dto.PlaceResponse import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Header diff --git a/app/src/main/java/campus/tech/kakao/map/DTO/UrlContract.kt b/app/src/main/java/campus/tech/kakao/map/url/UrlContract.kt similarity index 85% rename from app/src/main/java/campus/tech/kakao/map/DTO/UrlContract.kt rename to app/src/main/java/campus/tech/kakao/map/url/UrlContract.kt index 88d057c7..ca34affa 100644 --- a/app/src/main/java/campus/tech/kakao/map/DTO/UrlContract.kt +++ b/app/src/main/java/campus/tech/kakao/map/url/UrlContract.kt @@ -1,4 +1,4 @@ -package campus.tech.kakao.map.DTO +package campus.tech.kakao.map.url import campus.tech.kakao.map.BuildConfig diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 24d17df2..00000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 4c302a6f..700f4819 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -1,36 +1,40 @@ - - + - - - - - - \ No newline at end of file + android:layout_height="match_parent" + tools:context=".MapActivity"> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet.xml b/app/src/main/res/layout/bottom_sheet.xml new file mode 100644 index 00000000..a020f694 --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet.xml @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/map_error.xml b/app/src/main/res/layout/map_error.xml new file mode 100644 index 00000000..4d0a94b9 --- /dev/null +++ b/app/src/main/res/layout/map_error.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfa0bb3e..9175c622 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,7 @@ 검색어를 입력해 주세요. 검색 결과가 없습니다. word + 카카오 + 경기 성남시 분당구 백현동 532 + 오류가 발생했습니다.\n다시 시도해 주세요. \ No newline at end of file