From a749e88ef9ebceff9dc2d07581585c3561623ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Wed, 17 Jul 2024 01:54:05 +0900 Subject: [PATCH 01/21] =?UTF-8?q?docs:=20README.md=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64c3bb5d..f1ea3cdf 100644 --- a/README.md +++ b/README.md @@ -1 +1,10 @@ -# android-map-location \ No newline at end of file +# android-map-location +## step1 기능 목록 +1. 저장된 검색어 목록에 기능 추가하기 + - 저장된 검색어 중 하나를 선택하면 해당 검색어의 검색 결과 목록이 표시된다. +2. 검색 결과 목록에 기능 추가하기 + - 검색 결과 목록 중 하나의 항목을 선택하면 해당 항목의 위치를 지도에 표시한다. +3. 마지막 위치 저장하기 + - 앱 종료 시 마지막 위치를 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다. +4. 에러 처리하기 + - 카카오지도 onMapError() 호출 시 에러 화면을 보여준다. "지도 인증을 실패했습니다. 다시 시도해주세요. '에러이름(에러코드): 에러메세지' \ No newline at end of file From 80c47d67641dce7a34ef6992afcbbdda78da22b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 00:20:46 +0900 Subject: [PATCH 02/21] =?UTF-8?q?refactor:=20SavedLocationHolder=EC=9D=98?= =?UTF-8?q?=20=EB=B7=B0=20=EB=B3=80=EC=88=98=EB=A5=BC=20by=20lazy=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/search/SavedLocationAdapter.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt index cd8f60d0..a11e5f44 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt @@ -27,8 +27,12 @@ class SavedLocationAdapter( itemView:View, itemSelectedListener: OnItemSelectedListener ) : RecyclerView.ViewHolder(itemView) { - val savedLocationXButton: ImageView = itemView.findViewById(R.id.savedLocationXButton) - val savedLocationTextView: TextView = itemView.findViewById(R.id.savedLocationTextView) + val savedLocationXButton: ImageView by lazy{ + itemView.findViewById(R.id.savedLocationXButton) + } + val savedLocationTextView: TextView by lazy { + itemView.findViewById(R.id.savedLocationTextView) + } init { savedLocationXButton.setOnClickListener { From 3abbc9bb548f4b59825cf9871e891f5718dfd0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 00:52:39 +0900 Subject: [PATCH 03/21] =?UTF-8?q?feat:=20=EC=A0=80=EC=9E=A5=EB=90=9C=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=EC=96=B4=EC=9D=98=20=EC=A0=9C=EB=AA=A9(title?= =?UTF-8?q?)=EC=9D=84=20=EC=A0=84=EB=8B=AC=ED=95=98=EB=8A=94=20=EC=BD=9C?= =?UTF-8?q?=EB=B0=B1=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/search/OnItemSelectedListener.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt index 432f2090..f8d97f92 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt @@ -3,6 +3,7 @@ package campus.tech.kakao.map.view.search import campus.tech.kakao.map.model.SavedLocation interface OnItemSelectedListener { - fun addSavedLocation(title: String) - fun deleteSavedLocation(item: SavedLocation) + fun onAddSavedLocation(title: String) + fun onDeleteSavedLocation(item: SavedLocation) + fun onUpdateLocationRecyclerView(title: String) } \ No newline at end of file From b0527b5fc2d3efeaaee8c68455a0529755b3856a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 00:57:48 +0900 Subject: [PATCH 04/21] =?UTF-8?q?feat:=20itemView=EC=97=90=20=EC=BD=9C?= =?UTF-8?q?=EB=B0=B1=20=ED=95=A8=EC=88=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/campus/tech/kakao/map/view/search/LocationAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt index 8472b3be..412b84c3 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt @@ -32,7 +32,7 @@ class LocationAdapter( init { itemView.setOnClickListener { - itemSelectedListener.addSavedLocation(getItem(bindingAdapterPosition).title) + itemSelectedListener.onAddSavedLocation(getItem(bindingAdapterPosition).title) } } } From adca16100da5dbe1056f8abd2956981064a074bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:00:12 +0900 Subject: [PATCH 05/21] =?UTF-8?q?feat:=20MainActivity=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=BD=9C=EB=B0=B1=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20LocationViewModel=EC=9D=98=20searchLocatio?= =?UTF-8?q?nsFromKakaoAPI=20=ED=95=A8=EC=88=98=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/search/MainActivity.kt | 17 +++++++++++++---- .../map/view/search/SavedLocationAdapter.kt | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index 56ab33f7..606d2fa3 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -12,7 +12,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import campus.tech.kakao.map.BuildConfig import campus.tech.kakao.map.model.datasource.LocationLocalDataSource import campus.tech.kakao.map.model.datasource.LocationRemoteDataSource import campus.tech.kakao.map.R @@ -82,7 +81,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { val query = s.toString() - locationViewModel.searchLocationsFromKakaoAPI(query) {searchLocationsSize -> + locationViewModel.searchLocationsFromKakaoAPI(query) { searchLocationsSize -> if (searchLocationsSize > 0) { noResultTextView.visibility = View.GONE } else { @@ -138,11 +137,21 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationRecyclerView.adapter = savedLocationAdapter } - override fun addSavedLocation(title: String) { + override fun onAddSavedLocation(title: String) { savedLocationViewModel.addSavedLocation(title) } - override fun deleteSavedLocation(item: SavedLocation) { + override fun onDeleteSavedLocation(item: SavedLocation) { savedLocationViewModel.deleteSavedLocation(item) } + + override fun onUpdateLocationRecyclerView(title: String) { + locationViewModel.searchLocationsFromKakaoAPI(title){ searchLocationsSize -> + if (searchLocationsSize > 0) { + noResultTextView.visibility = View.GONE + } else { + noResultTextView.visibility = View.VISIBLE + } + } + } } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt index a11e5f44..45c9b151 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt @@ -35,8 +35,11 @@ class SavedLocationAdapter( } init { + itemView.setOnClickListener { + itemSelectedListener.onUpdateLocationRecyclerView(getItem(bindingAdapterPosition).title) + } savedLocationXButton.setOnClickListener { - itemSelectedListener.deleteSavedLocation(getItem(bindingAdapterPosition) as SavedLocation) + itemSelectedListener.onDeleteSavedLocation(getItem(bindingAdapterPosition) as SavedLocation) } } } From 6d7449baba14cbb7bf7393cf42bdaa0892ad90ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:10:45 +0900 Subject: [PATCH 06/21] =?UTF-8?q?refactor:=20handleNoResultMessage()=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=EC=A4=91=EB=B3=B5=20=EC=BD=94=EB=93=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kakao/map/view/search/MainActivity.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index 606d2fa3..fdba10b8 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -82,11 +82,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { val query = s.toString() locationViewModel.searchLocationsFromKakaoAPI(query) { searchLocationsSize -> - if (searchLocationsSize > 0) { - noResultTextView.visibility = View.GONE - } else { - noResultTextView.visibility = View.VISIBLE - } + handleNoResultMessage(searchLocationsSize) } } @@ -147,11 +143,15 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { override fun onUpdateLocationRecyclerView(title: String) { locationViewModel.searchLocationsFromKakaoAPI(title){ searchLocationsSize -> - if (searchLocationsSize > 0) { - noResultTextView.visibility = View.GONE - } else { - noResultTextView.visibility = View.VISIBLE - } + handleNoResultMessage(searchLocationsSize) + } + } + + private fun handleNoResultMessage(searchLocationsSize: Int) { + if (searchLocationsSize > 0) { + noResultTextView.visibility = View.GONE + } else { + noResultTextView.visibility = View.VISIBLE } } } From e533b253b628324b780228739a4f60352cd7a71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:14:16 +0900 Subject: [PATCH 07/21] =?UTF-8?q?feat:=20searchEditText=EC=9D=98=20text?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=80=EC=9E=A5=EB=90=9C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=96=B4=EC=9D=98=20=EC=A0=9C=EB=AA=A9(title)=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/campus/tech/kakao/map/view/search/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index fdba10b8..3a3fb5b2 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -142,6 +142,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { } override fun onUpdateLocationRecyclerView(title: String) { + searchEditText.setText(title) // 커서도 옮기고 싶다. locationViewModel.searchLocationsFromKakaoAPI(title){ searchLocationsSize -> handleNoResultMessage(searchLocationsSize) } From 2eb7b23e4217adba7ef7bc01da53af761f0d9cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:15:30 +0900 Subject: [PATCH 08/21] =?UTF-8?q?feat:=20searchEditText=EC=9D=98=20?= =?UTF-8?q?=EC=BB=A4=EC=84=9C=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/campus/tech/kakao/map/view/search/MainActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index 3a3fb5b2..f2aa1bed 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -142,7 +142,8 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { } override fun onUpdateLocationRecyclerView(title: String) { - searchEditText.setText(title) // 커서도 옮기고 싶다. + searchEditText.setText(title) + searchEditText.setSelection(searchEditText.text.length) locationViewModel.searchLocationsFromKakaoAPI(title){ searchLocationsSize -> handleNoResultMessage(searchLocationsSize) } From 0b3db8116853fc8a464cc5768d146d50302ce0e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:25:09 +0900 Subject: [PATCH 09/21] =?UTF-8?q?refactor:=20=EC=BD=9C=EB=B0=B1=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=BB=A8=EB=B2=A4=EC=85=98=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/search/LocationAdapter.kt | 2 +- .../tech/kakao/map/view/search/MainActivity.kt | 14 +++++++++----- .../map/view/search/OnItemSelectedListener.kt | 6 +++--- .../kakao/map/view/search/SavedLocationAdapter.kt | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt index 412b84c3..192f308f 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt @@ -32,7 +32,7 @@ class LocationAdapter( init { itemView.setOnClickListener { - itemSelectedListener.onAddSavedLocation(getItem(bindingAdapterPosition).title) + itemSelectedListener.onLocationViewClicked(getItem(bindingAdapterPosition).title) } } } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index f2aa1bed..a4dc5fe9 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -133,22 +133,26 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationRecyclerView.adapter = savedLocationAdapter } - override fun onAddSavedLocation(title: String) { + override fun onLocationViewClicked(title: String) { savedLocationViewModel.addSavedLocation(title) } - override fun onDeleteSavedLocation(item: SavedLocation) { + override fun onSavedLocationXButtonClicked(item: SavedLocation) { savedLocationViewModel.deleteSavedLocation(item) } - override fun onUpdateLocationRecyclerView(title: String) { - searchEditText.setText(title) - searchEditText.setSelection(searchEditText.text.length) + override fun onSavedLocationViewClicked(title: String) { + updateEditText(title) locationViewModel.searchLocationsFromKakaoAPI(title){ searchLocationsSize -> handleNoResultMessage(searchLocationsSize) } } + private fun updateEditText(title: String) { + searchEditText.setText(title) + searchEditText.setSelection(searchEditText.text.length) + } + private fun handleNoResultMessage(searchLocationsSize: Int) { if (searchLocationsSize > 0) { noResultTextView.visibility = View.GONE diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt index f8d97f92..f27a6fd6 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt @@ -3,7 +3,7 @@ package campus.tech.kakao.map.view.search import campus.tech.kakao.map.model.SavedLocation interface OnItemSelectedListener { - fun onAddSavedLocation(title: String) - fun onDeleteSavedLocation(item: SavedLocation) - fun onUpdateLocationRecyclerView(title: String) + fun onLocationViewClicked(title: String) + fun onSavedLocationXButtonClicked(item: SavedLocation) + fun onSavedLocationViewClicked(title: String) } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt index 45c9b151..97335afb 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/SavedLocationAdapter.kt @@ -36,10 +36,10 @@ class SavedLocationAdapter( init { itemView.setOnClickListener { - itemSelectedListener.onUpdateLocationRecyclerView(getItem(bindingAdapterPosition).title) + itemSelectedListener.onSavedLocationViewClicked(getItem(bindingAdapterPosition).title) } savedLocationXButton.setOnClickListener { - itemSelectedListener.onDeleteSavedLocation(getItem(bindingAdapterPosition) as SavedLocation) + itemSelectedListener.onSavedLocationXButtonClicked(getItem(bindingAdapterPosition) as SavedLocation) } } } From 193fa3c4385192a323b7fdfe2abb676a33af02c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:52:53 +0900 Subject: [PATCH 10/21] =?UTF-8?q?refactor:=20LocationLocalDataSource?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A4=91=EB=B3=B5=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=ED=95=A8=EC=88=98=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/LocationLocalDataSource.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/model/datasource/LocationLocalDataSource.kt b/app/src/main/java/campus/tech/kakao/map/model/datasource/LocationLocalDataSource.kt index e55559a1..81312fa6 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/datasource/LocationLocalDataSource.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/datasource/LocationLocalDataSource.kt @@ -1,6 +1,7 @@ package campus.tech.kakao.map.model.datasource import android.content.ContentValues +import android.database.Cursor import android.util.Log import campus.tech.kakao.map.model.Contract.LocationEntry import campus.tech.kakao.map.model.Contract.SavedLocationEntry @@ -46,16 +47,21 @@ class LocationLocalDataSource(private val dbHelper : LocationDbHelper) { val results = mutableListOf() with(cursor) { while (moveToNext()) { - val title = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_TITLE)) - val address = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_ADDRESS)) - val category = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_CATEGORY)) - results.add(Location(title, address, category)) + val location = getLocation() + results.add(location) } } cursor.close() return results } + private fun Cursor.getLocation(): Location { + val title = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_TITLE)) + val address = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_ADDRESS)) + val category = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_CATEGORY)) + return Location(title, address, category, "", "") + } + fun addSavedLocation(title: String): Long { val db = dbHelper.writableDatabase val values = ContentValues().apply { @@ -129,10 +135,8 @@ class LocationLocalDataSource(private val dbHelper : LocationDbHelper) { val results = mutableListOf() with(cursor) { while (moveToNext()) { - val title = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_TITLE)) - val address = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_ADDRESS)) - val category = getString(getColumnIndexOrThrow(LocationEntry.COLUMN_NAME_CATEGORY)) - results.add(Location(title, address, category)) + val location = getLocation() + results.add(location) } } cursor.close() From 681b9455762767fb524816d1d8f848dd1b6e6c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 01:55:36 +0900 Subject: [PATCH 11/21] =?UTF-8?q?feat:=20=ED=82=A4=EC=9B=8C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=A5=EC=86=8C=20=EA=B2=80=EC=83=89=ED=95=98?= =?UTF-8?q?=EB=8A=94=20api=EC=97=90=EC=84=9C=20x,=20y=20=EA=B0=92=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/campus/tech/kakao/map/model/Location.kt | 6 ++++-- .../tech/kakao/map/model/SearchFromKeywordResponse.kt | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/model/Location.kt b/app/src/main/java/campus/tech/kakao/map/model/Location.kt index 760ddd46..20da8de9 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/Location.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/Location.kt @@ -3,11 +3,13 @@ package campus.tech.kakao.map.model data class Location( val title: String, val address: String, - val category: String + val category: String, + val x: String, + val y: String ){ companion object { fun LocationDto.toLocation(): Location { - return Location(title, address, category) + return Location(title, address, category, x, y) } } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/model/SearchFromKeywordResponse.kt b/app/src/main/java/campus/tech/kakao/map/model/SearchFromKeywordResponse.kt index 1ea4b0c5..248ecf2b 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/SearchFromKeywordResponse.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/SearchFromKeywordResponse.kt @@ -13,5 +13,9 @@ data class LocationDto( @SerializedName("category_group_name") val category: String, @SerializedName("address_name") - val address: String + val address: String, + @SerializedName("x") + val x: String, + @SerializedName("y") + val y: String ) From 88faf63921056532635b21909ef3a5b38b9b4e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 02:15:11 +0900 Subject: [PATCH 12/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EB=AA=A9=EB=A1=9D=20=EC=A4=91=20=ED=95=98=EB=82=98?= =?UTF-8?q?=EC=9D=98=20=ED=95=AD=EB=AA=A9=EC=9D=84=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=ED=95=98=EB=A9=B4=20MapActivity=EB=A1=9C=20=EC=A0=84=ED=99=98?= =?UTF-8?q?=EB=90=98=EA=B2=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/campus/tech/kakao/map/view/map/MapActivity.kt | 5 +++++ .../campus/tech/kakao/map/view/search/LocationAdapter.kt | 3 ++- .../campus/tech/kakao/map/view/search/MainActivity.kt | 9 ++++++++- .../tech/kakao/map/view/search/OnItemSelectedListener.kt | 2 +- .../campus/tech/kakao/map/viewmodel/LocationViewModel.kt | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index e959b368..9406eddc 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -27,6 +27,11 @@ class MapActivity : AppCompatActivity() { setupMapView() } + override fun onStart() { + super.onStart() + Log.d("jieun", "map: onStart") + } + private fun initViews() { searchEditText = findViewById(R.id.SearchEditTextInMap) mapView = findViewById(R.id.map_view) diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt index 192f308f..8e7cdbdf 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt @@ -32,7 +32,8 @@ class LocationAdapter( init { itemView.setOnClickListener { - itemSelectedListener.onLocationViewClicked(getItem(bindingAdapterPosition).title) + val location = getItem(bindingAdapterPosition) + itemSelectedListener.onLocationViewClicked(location.title, location.x, location.y) } } } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index a4dc5fe9..f2739628 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -1,5 +1,6 @@ package campus.tech.kakao.map.view.search +import android.content.Intent import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -19,6 +20,7 @@ import campus.tech.kakao.map.model.SavedLocation import campus.tech.kakao.map.model.LocationDbHelper import campus.tech.kakao.map.model.repository.LocationRepository import campus.tech.kakao.map.model.repository.SavedLocationRepository +import campus.tech.kakao.map.view.map.MapActivity import campus.tech.kakao.map.viewmodel.ViewModelFactory.LocationViewModelFactory import campus.tech.kakao.map.viewmodel.ViewModelFactory.SavedLocationViewModelFactory import campus.tech.kakao.map.viewmodel.LocationViewModel @@ -133,8 +135,13 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationRecyclerView.adapter = savedLocationAdapter } - override fun onLocationViewClicked(title: String) { + override fun onLocationViewClicked(title: String, x: String, y: String) { savedLocationViewModel.addSavedLocation(title) + + val intent = Intent(this@MainActivity, MapActivity::class.java) + intent.putExtra("x", x) + intent.putExtra("y", y) + startActivity(intent) } override fun onSavedLocationXButtonClicked(item: SavedLocation) { diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt index f27a6fd6..3c5a9945 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt @@ -3,7 +3,7 @@ package campus.tech.kakao.map.view.search import campus.tech.kakao.map.model.SavedLocation interface OnItemSelectedListener { - fun onLocationViewClicked(title: String) + fun onLocationViewClicked(title: String, x: String, y: String) fun onSavedLocationXButtonClicked(item: SavedLocation) fun onSavedLocationViewClicked(title: String) } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/viewmodel/LocationViewModel.kt b/app/src/main/java/campus/tech/kakao/map/viewmodel/LocationViewModel.kt index f3e4b0a9..b3f95a69 100644 --- a/app/src/main/java/campus/tech/kakao/map/viewmodel/LocationViewModel.kt +++ b/app/src/main/java/campus/tech/kakao/map/viewmodel/LocationViewModel.kt @@ -39,10 +39,10 @@ class LocationViewModel( _searchedLocations.value = emptyList() } - fun searchLocationsFromKakaoAPI(query: String, deleteNoResultMessageCallback: (Int) -> Unit) { + fun searchLocationsFromKakaoAPI(query: String, handleNoResultMessage: (Int) -> Unit) { viewModelScope.launch { _searchedLocations.value = locationRepository.getLocationRemote(query) - deleteNoResultMessageCallback(getSearchedLocationsSize()) + handleNoResultMessage(getSearchedLocationsSize()) } } } \ No newline at end of file From 66c2ece8ecd4bae9c2132627ba4df0bedb06878d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 03:09:18 +0900 Subject: [PATCH 13/21] =?UTF-8?q?feat:=20mapView=EC=9D=98=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=EB=A5=BC=20=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A4=91=20=EC=84=A0=ED=83=9D=EB=90=9C=20?= =?UTF-8?q?=ED=95=AD=EB=AA=A9=EC=9D=98=20=EC=A2=8C=ED=91=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../campus/tech/kakao/map/model/Location.kt | 4 +- .../tech/kakao/map/view/map/Coordinates.kt | 3 ++ .../tech/kakao/map/view/map/MapActivity.kt | 38 ++++++++++++++++++- .../kakao/map/view/search/LocationAdapter.kt | 2 +- .../kakao/map/view/search/MainActivity.kt | 6 +-- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt diff --git a/app/src/main/java/campus/tech/kakao/map/model/Location.kt b/app/src/main/java/campus/tech/kakao/map/model/Location.kt index 20da8de9..34bbe807 100644 --- a/app/src/main/java/campus/tech/kakao/map/model/Location.kt +++ b/app/src/main/java/campus/tech/kakao/map/model/Location.kt @@ -4,8 +4,8 @@ data class Location( val title: String, val address: String, val category: String, - val x: String, - val y: String + val longitude: String, + val latitude: String ){ companion object { fun LocationDto.toLocation(): Location { diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt new file mode 100644 index 00000000..6e67f47a --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt @@ -0,0 +1,3 @@ +package campus.tech.kakao.map.view.map + +data class Coordinates(var longitude: Double, var latitude: Double) \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index 9406eddc..0aad2d9e 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -11,6 +11,7 @@ import campus.tech.kakao.map.view.search.MainActivity import com.kakao.vectormap.KakaoMap import com.kakao.vectormap.KakaoMapReadyCallback import com.kakao.vectormap.KakaoMapSdk +import com.kakao.vectormap.LatLng import com.kakao.vectormap.MapLifeCycleCallback import com.kakao.vectormap.MapView @@ -29,7 +30,7 @@ class MapActivity : AppCompatActivity() { override fun onStart() { super.onStart() - Log.d("jieun", "map: onStart") + Log.d("jieun", "onStart") } private fun initViews() { @@ -60,7 +61,42 @@ class MapActivity : AppCompatActivity() { override fun onMapReady(kakaoMap: KakaoMap) { // 인증 후 API 가 정상적으로 실행될 때 호출됨 Log.d("jieun", "onMapReady") + + } + + override fun getPosition(): LatLng { + Log.d("jieun", "getPosition") + val coordinates = getXY() + if (coordinates != null) { + return LatLng.from(coordinates.latitude, coordinates.longitude) + } + return LatLng.from(37.406960, 127.115587); } }) } + private fun getXY(): Coordinates? { + if(intent == null) + return null + val longitudeString = intent.getStringExtra("longitude") + val latitudeString = intent.getStringExtra("latitude") + if (longitudeString != null && latitudeString != null) { + val longitude = longitudeString.toDouble() + val latitude = latitudeString.toDouble() + Log.d("jieun", "longitude: " + longitude + " latitude:" + latitude) + return Coordinates(longitude, latitude) + } + return null + } + + override fun onResume() { + super.onResume() + mapView.resume() // MapView 의 resume 호출 + } + + override fun onPause() { + super.onPause() + Log.d("jieun", "onPause") + mapView.pause() // MapView 의 pause 호출 + } + } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt index 8e7cdbdf..6a5a190f 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt @@ -33,7 +33,7 @@ class LocationAdapter( init { itemView.setOnClickListener { val location = getItem(bindingAdapterPosition) - itemSelectedListener.onLocationViewClicked(location.title, location.x, location.y) + itemSelectedListener.onLocationViewClicked(location.title, location.longitude, location.latitude) } } } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index f2739628..9db62ba8 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -135,12 +135,12 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationRecyclerView.adapter = savedLocationAdapter } - override fun onLocationViewClicked(title: String, x: String, y: String) { + override fun onLocationViewClicked(title: String, longitude: String, latitude: String) { savedLocationViewModel.addSavedLocation(title) val intent = Intent(this@MainActivity, MapActivity::class.java) - intent.putExtra("x", x) - intent.putExtra("y", y) + intent.putExtra("longitude", longitude) + intent.putExtra("latitude", latitude) startActivity(intent) } From 4f44f65fd7d189cd592fa6d61fb00bd37325b3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Thu, 18 Jul 2024 23:33:46 +0900 Subject: [PATCH 14/21] =?UTF-8?q?feat:=20=EA=B2=80=EC=83=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EB=AA=A9=EB=A1=9D=20=EC=A4=91=20=EC=84=A0=ED=83=9D?= =?UTF-8?q?=EB=90=9C=20=ED=95=AD=EB=AA=A9=EC=9D=98=20=EC=A2=8C=ED=91=9C?= =?UTF-8?q?=EC=97=90=20KakaoMap=20label=EC=9D=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/Coordinates.kt | 2 +- .../tech/kakao/map/view/map/MapActivity.kt | 49 ++++++++++++++---- .../kakao/map/view/search/MainActivity.kt | 1 + .../drawable/location_red_icon_resized.png | Bin 0 -> 6110 bytes 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/location_red_icon_resized.png diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt index 6e67f47a..975fe2d6 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt @@ -1,3 +1,3 @@ package campus.tech.kakao.map.view.map -data class Coordinates(var longitude: Double, var latitude: Double) \ No newline at end of file +data class Coordinates(val title: String, val longitude: Double, val latitude: Double) \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index 0aad2d9e..d13f5cc4 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -1,6 +1,7 @@ package campus.tech.kakao.map.view.map import android.content.Intent +import android.graphics.Color import android.os.Bundle import android.util.Log import android.widget.EditText @@ -14,11 +15,20 @@ import com.kakao.vectormap.KakaoMapSdk import com.kakao.vectormap.LatLng import com.kakao.vectormap.MapLifeCycleCallback import com.kakao.vectormap.MapView +import com.kakao.vectormap.label.LabelManager +import com.kakao.vectormap.label.LabelOptions +import com.kakao.vectormap.label.LabelStyle +import com.kakao.vectormap.label.LabelStyles class MapActivity : AppCompatActivity() { private lateinit var searchEditText: EditText private lateinit var mapView: MapView + companion object{ + private val DEFAULT_LONGITUDE = 127.115587 + private val DEFAULT_LATITUDE = 37.406960 + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map) @@ -26,6 +36,8 @@ class MapActivity : AppCompatActivity() { initViews() setupEditText() setupMapView() + Log.d("jieun", "MapActivity onCreate"+Thread.currentThread()) + } override fun onStart() { @@ -60,30 +72,45 @@ class MapActivity : AppCompatActivity() { }, object : KakaoMapReadyCallback() { override fun onMapReady(kakaoMap: KakaoMap) { // 인증 후 API 가 정상적으로 실행될 때 호출됨 - Log.d("jieun", "onMapReady") - + val coordinates = getCoordinates() + Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) + if (coordinates != null) { + val labelStyles: LabelStyles = LabelStyles.from( + LabelStyle.from(R.drawable.location_red_icon_resized).setZoomLevel(8), + LabelStyle.from(R.drawable.location_red_icon_resized).setTextStyles(32, Color.BLACK, 1, Color.GRAY).setZoomLevel(15) + ) + val position = LatLng.from(coordinates.latitude, coordinates.longitude) + kakaoMap.labelManager?.getLayer()?.addLabel( + LabelOptions.from(position) + .setStyles(labelStyles) + .setTexts(coordinates.title) + ) + } } override fun getPosition(): LatLng { - Log.d("jieun", "getPosition") - val coordinates = getXY() + val coordinates = getCoordinates() + Log.d("jieun", "getPosition coordinates: " + coordinates.toString()) + if (coordinates != null) { return LatLng.from(coordinates.latitude, coordinates.longitude) } - return LatLng.from(37.406960, 127.115587); + return LatLng.from(DEFAULT_LATITUDE, DEFAULT_LONGITUDE); } + }) } - private fun getXY(): Coordinates? { - if(intent == null) - return null + private fun getCoordinates(): Coordinates? { + if(intent == null) return null + val title = intent.getStringExtra("title") val longitudeString = intent.getStringExtra("longitude") val latitudeString = intent.getStringExtra("latitude") - if (longitudeString != null && latitudeString != null) { + + if (title!=null && longitudeString != null && latitudeString != null) { val longitude = longitudeString.toDouble() val latitude = latitudeString.toDouble() - Log.d("jieun", "longitude: " + longitude + " latitude:" + latitude) - return Coordinates(longitude, latitude) + val coordinates = Coordinates(title, longitude, latitude) + return coordinates } return null } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index 9db62ba8..2eac581f 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -139,6 +139,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationViewModel.addSavedLocation(title) val intent = Intent(this@MainActivity, MapActivity::class.java) + intent.putExtra("title", title) intent.putExtra("longitude", longitude) intent.putExtra("latitude", latitude) startActivity(intent) diff --git a/app/src/main/res/drawable/location_red_icon_resized.png b/app/src/main/res/drawable/location_red_icon_resized.png new file mode 100644 index 0000000000000000000000000000000000000000..1f2b57bd58661b8c87e7bcfe0f84d3be5b4475e6 GIT binary patch literal 6110 zcmZ{I2T)T_^ls=?q(cM|>4YAtfOH5TAT2a$p?3p>rhxQFZ_(z~E^2)#%XqzHuG zdyyXW*_!rkUk;>000j()K&Dc((b=bOo$!f zYiWj9!D_3nuMGga;Q|0cA^?C}tSV#&0Pqn80QRf_0O?EsfB~M{q9==eKxp#A2DA~0>}_jw}XZW~$)8%Un#4Wmh+QA{lt`yP3iRGczV z9<+e10363&JzNkT6UkN-I!XHCi*9y$gGSDuWXJOt!N;@h=L0uIlN(Ez;Lf`{&axlD zvn_n4&m^yo>aU(V9@k&V-4TxkH-$b!QLiXjiwHl=B*4dcXg!Y3A+$jWPmm#S??Qu` zKcbs2>*;M;NQ4yuCWMuQOGNy*dr95A=?;(I;{~B`tQl%){AqZbyoE!*O*e-5Ia-rw2$Yaf*2PfLr?jpxmWuW?8-!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fN*xV_eQ|n;r|l@mKOQH zPQLbVPGB*>|1bux9T0vnFMEKWpP!(!hpV?O3~n#@+RHKLNcIud2%w>=qf)J89rk|! DMf`W+ literal 0 HcmV?d00001 From 97a4556d1a96a95235b9145285f41a2bd2cdf7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 00:46:22 +0900 Subject: [PATCH 15/21] =?UTF-8?q?feat:=20SharedPreferences=EC=97=90=20?= =?UTF-8?q?=EB=A7=88=EC=A7=80=EB=A7=89=20=EC=A2=8C=ED=91=9C=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=B0=8F=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/MapActivity.kt | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index d13f5cc4..8829b20c 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -1,6 +1,8 @@ package campus.tech.kakao.map.view.map +import android.app.Activity import android.content.Intent +import android.content.SharedPreferences import android.graphics.Color import android.os.Bundle import android.util.Log @@ -15,7 +17,6 @@ import com.kakao.vectormap.KakaoMapSdk import com.kakao.vectormap.LatLng import com.kakao.vectormap.MapLifeCycleCallback import com.kakao.vectormap.MapView -import com.kakao.vectormap.label.LabelManager import com.kakao.vectormap.label.LabelOptions import com.kakao.vectormap.label.LabelStyle import com.kakao.vectormap.label.LabelStyles @@ -36,15 +37,9 @@ class MapActivity : AppCompatActivity() { initViews() setupEditText() setupMapView() - Log.d("jieun", "MapActivity onCreate"+Thread.currentThread()) } - override fun onStart() { - super.onStart() - Log.d("jieun", "onStart") - } - private fun initViews() { searchEditText = findViewById(R.id.SearchEditTextInMap) mapView = findViewById(R.id.map_view) @@ -70,10 +65,10 @@ class MapActivity : AppCompatActivity() { Log.d("jieun", "onMapError" + error) } }, object : KakaoMapReadyCallback() { + val coordinates = getCoordinates() override fun onMapReady(kakaoMap: KakaoMap) { // 인증 후 API 가 정상적으로 실행될 때 호출됨 - val coordinates = getCoordinates() - Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) +// Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) if (coordinates != null) { val labelStyles: LabelStyles = LabelStyles.from( LabelStyle.from(R.drawable.location_red_icon_resized).setZoomLevel(8), @@ -85,13 +80,14 @@ class MapActivity : AppCompatActivity() { .setStyles(labelStyles) .setTexts(coordinates.title) ) + + setSharedData("pref", coordinates) +// Log.d("jieun", "onMapReady setSharedData: " + getSharedData("pref")) } } override fun getPosition(): LatLng { - val coordinates = getCoordinates() - Log.d("jieun", "getPosition coordinates: " + coordinates.toString()) - +// Log.d("jieun", "getPosition coordinates: " + coordinates.toString()) if (coordinates != null) { return LatLng.from(coordinates.latitude, coordinates.longitude) } @@ -101,18 +97,31 @@ class MapActivity : AppCompatActivity() { }) } private fun getCoordinates(): Coordinates? { - if(intent == null) return null - val title = intent.getStringExtra("title") - val longitudeString = intent.getStringExtra("longitude") - val latitudeString = intent.getStringExtra("latitude") - - if (title!=null && longitudeString != null && latitudeString != null) { - val longitude = longitudeString.toDouble() - val latitude = latitudeString.toDouble() - val coordinates = Coordinates(title, longitude, latitude) - return coordinates + var coordinates = getCoordinatesByIntent() + if(coordinates == null) { + coordinates = getCoordinatedBySharedPreference() } - return null + return coordinates + + } + + private fun getCoordinatedBySharedPreference(): Coordinates { + val coordinates = getSharedData("pref") + Log.d("jieun", "getSharedIntData " + coordinates) + return coordinates + } + + private fun getCoordinatesByIntent(): Coordinates? { + if (intent.hasExtra("title") && intent.hasExtra("longitude") && intent.hasExtra("latitude")) { + val title = intent.getStringExtra("title").toString() + val longitudeString = intent.getStringExtra("longitude") + val latitudeString = intent.getStringExtra("latitude") + if (longitudeString != null && latitudeString != null) { + val longitude = longitudeString.toDouble() + val latitude = latitudeString.toDouble() + return Coordinates(title, longitude, latitude) + } else return null + } else return null } override fun onResume() { @@ -122,8 +131,25 @@ class MapActivity : AppCompatActivity() { override fun onPause() { super.onPause() - Log.d("jieun", "onPause") mapView.pause() // MapView 의 pause 호출 } + fun setSharedData(name: String, coordinates: Coordinates?) { + if (coordinates != null) { + var pref: SharedPreferences = getSharedPreferences(name, Activity.MODE_PRIVATE) + var editor: SharedPreferences.Editor = pref.edit() + editor.putString("longitude", coordinates.longitude.toString()) + editor.putString("latitude", coordinates.latitude.toString()) + editor.putString("title", coordinates.title.toString()) + editor.apply() + } + } + + fun getSharedData(name: String): Coordinates { + var pref: SharedPreferences = getSharedPreferences(name, Activity.MODE_PRIVATE) + val title = pref.getString("title", "").toString() + val longitude = pref.getString("longitude", "").toString().toDouble() + val latitude = pref.getString("latitude", "").toString().toDouble() + return Coordinates(title, longitude, latitude) + } } \ No newline at end of file From e1786ed459149e72b4fd6d39c9f7d65231ef5c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 01:02:44 +0900 Subject: [PATCH 16/21] =?UTF-8?q?feat:=20onMapError()=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=20=EC=8B=9C=20=EC=97=90=EB=9F=AC=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EB=85=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- .../tech/kakao/map/view/map/MapActivity.kt | 7 ++++++- app/src/main/res/layout/error_map.xml | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/layout/error_map.xml diff --git a/README.md b/README.md index f1ea3cdf..d61e4360 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,6 @@ 2. 검색 결과 목록에 기능 추가하기 - 검색 결과 목록 중 하나의 항목을 선택하면 해당 항목의 위치를 지도에 표시한다. 3. 마지막 위치 저장하기 - - 앱 종료 시 마지막 위치를 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다. + - 앱 종료 시 마지막 위치를 SharedPreference 저장하여 다시 앱 실행 시 해당 위치로 포커스 한다. 4. 에러 처리하기 - 카카오지도 onMapError() 호출 시 에러 화면을 보여준다. "지도 인증을 실패했습니다. 다시 시도해주세요. '에러이름(에러코드): 에러메세지' \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index 8829b20c..5386e4ff 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -7,6 +7,7 @@ import android.graphics.Color import android.os.Bundle import android.util.Log import android.widget.EditText +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import campus.tech.kakao.map.BuildConfig import campus.tech.kakao.map.R @@ -53,7 +54,8 @@ class MapActivity : AppCompatActivity() { } private fun setupMapView() { - KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY); +// KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY); + KakaoMapSdk.init(this, BuildConfig.KAKAO_REST_API_KEY); mapView.start(object : MapLifeCycleCallback() { override fun onMapDestroy() { // 지도 API 가 정상적으로 종료될 때 호출됨 @@ -63,6 +65,9 @@ class MapActivity : AppCompatActivity() { override fun onMapError(error: Exception) { // 인증 실패 및 지도 사용 중 에러가 발생할 때 호출됨 Log.d("jieun", "onMapError" + error) + setContentView(R.layout.error_map) + val errorMessageTextView: TextView = findViewById(R.id.errorMessageTextView) + errorMessageTextView.text = "지도 인증을 실패했습니다.\n다시 시도해주세요.\n\n"+error.message } }, object : KakaoMapReadyCallback() { val coordinates = getCoordinates() diff --git a/app/src/main/res/layout/error_map.xml b/app/src/main/res/layout/error_map.xml new file mode 100644 index 00000000..d392d7bb --- /dev/null +++ b/app/src/main/res/layout/error_map.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file From c3d8a4a8d35ddc094d81bd509b1f977eda2a1b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 02:07:40 +0900 Subject: [PATCH 17/21] =?UTF-8?q?feat:=20MapActivity=EC=97=90=EC=84=9C=20B?= =?UTF-8?q?ottomSheet=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=A0=95=EB=B3=B4=20=EB=85=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/Coordinates.kt | 2 +- .../tech/kakao/map/view/map/MapActivity.kt | 35 +++++++++--- .../kakao/map/view/search/LocationAdapter.kt | 2 +- .../kakao/map/view/search/MainActivity.kt | 3 +- .../map/view/search/OnItemSelectedListener.kt | 2 +- .../drawable/map_background_bottom_sheet.xml | 17 ++++++ app/src/main/res/layout/activity_map.xml | 12 +++++ app/src/main/res/layout/map_bottom_sheet.xml | 54 +++++++++++++++++++ 8 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/map_background_bottom_sheet.xml create mode 100644 app/src/main/res/layout/map_bottom_sheet.xml diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt index 975fe2d6..e8c8dad9 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/Coordinates.kt @@ -1,3 +1,3 @@ package campus.tech.kakao.map.view.map -data class Coordinates(val title: String, val longitude: Double, val latitude: Double) \ No newline at end of file +data class Coordinates(val title: String, val longitude: Double, val latitude: Double, val address: String) \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index 5386e4ff..efbdaad6 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -6,12 +6,15 @@ import android.content.SharedPreferences import android.graphics.Color import android.os.Bundle import android.util.Log +import android.view.View import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout import campus.tech.kakao.map.BuildConfig import campus.tech.kakao.map.R import campus.tech.kakao.map.view.search.MainActivity +import com.google.android.material.bottomsheet.BottomSheetBehavior import com.kakao.vectormap.KakaoMap import com.kakao.vectormap.KakaoMapReadyCallback import com.kakao.vectormap.KakaoMapSdk @@ -26,6 +29,10 @@ import com.kakao.vectormap.label.LabelStyles class MapActivity : AppCompatActivity() { private lateinit var searchEditText: EditText private lateinit var mapView: MapView + private val bottomSheetLayout by lazy { findViewById(R.id.bottom_sheet_layout) } + private val bottom_sheet_title by lazy { findViewById(R.id.bottom_sheet_title) } + private val bottom_sheet_address by lazy { findViewById(R.id.bottom_sheet_address) } + private lateinit var bottomSheetBehavior: BottomSheetBehavior companion object{ private val DEFAULT_LONGITUDE = 127.115587 private val DEFAULT_LATITUDE = 37.406960 @@ -36,6 +43,7 @@ class MapActivity : AppCompatActivity() { setContentView(R.layout.activity_map) initViews() + initBottomSheet() setupEditText() setupMapView() @@ -53,9 +61,15 @@ class MapActivity : AppCompatActivity() { } } + // Persistent BottomSheet 초기화 + private fun initBottomSheet() { + // BottomSheetBehavior에 layout 설정 + bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout) + } + private fun setupMapView() { -// KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY); - KakaoMapSdk.init(this, BuildConfig.KAKAO_REST_API_KEY); + KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY); +// KakaoMapSdk.init(this, BuildConfig.KAKAO_REST_API_KEY); mapView.start(object : MapLifeCycleCallback() { override fun onMapDestroy() { // 지도 API 가 정상적으로 종료될 때 호출됨 @@ -73,7 +87,7 @@ class MapActivity : AppCompatActivity() { val coordinates = getCoordinates() override fun onMapReady(kakaoMap: KakaoMap) { // 인증 후 API 가 정상적으로 실행될 때 호출됨 -// Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) + Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) if (coordinates != null) { val labelStyles: LabelStyles = LabelStyles.from( LabelStyle.from(R.drawable.location_red_icon_resized).setZoomLevel(8), @@ -85,6 +99,11 @@ class MapActivity : AppCompatActivity() { .setStyles(labelStyles) .setTexts(coordinates.title) ) + runOnUiThread { + bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + bottom_sheet_title.text = coordinates.title + bottom_sheet_address.text = coordinates.address + } setSharedData("pref", coordinates) // Log.d("jieun", "onMapReady setSharedData: " + getSharedData("pref")) @@ -117,14 +136,16 @@ class MapActivity : AppCompatActivity() { } private fun getCoordinatesByIntent(): Coordinates? { - if (intent.hasExtra("title") && intent.hasExtra("longitude") && intent.hasExtra("latitude")) { + if (intent.hasExtra("title") && intent.hasExtra("longitude") + && intent.hasExtra("latitude") && intent.hasExtra("address")) { val title = intent.getStringExtra("title").toString() val longitudeString = intent.getStringExtra("longitude") val latitudeString = intent.getStringExtra("latitude") + val address = intent.getStringExtra("address").toString() if (longitudeString != null && latitudeString != null) { val longitude = longitudeString.toDouble() val latitude = latitudeString.toDouble() - return Coordinates(title, longitude, latitude) + return Coordinates(title, longitude, latitude, address) } else return null } else return null } @@ -146,6 +167,7 @@ class MapActivity : AppCompatActivity() { editor.putString("longitude", coordinates.longitude.toString()) editor.putString("latitude", coordinates.latitude.toString()) editor.putString("title", coordinates.title.toString()) + editor.putString("address", coordinates.address.toString()) editor.apply() } } @@ -155,6 +177,7 @@ class MapActivity : AppCompatActivity() { val title = pref.getString("title", "").toString() val longitude = pref.getString("longitude", "").toString().toDouble() val latitude = pref.getString("latitude", "").toString().toDouble() - return Coordinates(title, longitude, latitude) + val address = pref.getString("address", "").toString() + return Coordinates(title, longitude, latitude, address) } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt index 6a5a190f..0c494b82 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/LocationAdapter.kt @@ -33,7 +33,7 @@ class LocationAdapter( init { itemView.setOnClickListener { val location = getItem(bindingAdapterPosition) - itemSelectedListener.onLocationViewClicked(location.title, location.longitude, location.latitude) + itemSelectedListener.onLocationViewClicked(location.title, location.longitude, location.latitude, location.address) } } } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index 2eac581f..ab9946c9 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -135,13 +135,14 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { savedLocationRecyclerView.adapter = savedLocationAdapter } - override fun onLocationViewClicked(title: String, longitude: String, latitude: String) { + override fun onLocationViewClicked(title: String, longitude: String, latitude: String, address:String) { savedLocationViewModel.addSavedLocation(title) val intent = Intent(this@MainActivity, MapActivity::class.java) intent.putExtra("title", title) intent.putExtra("longitude", longitude) intent.putExtra("latitude", latitude) + intent.putExtra("address", address) startActivity(intent) } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt index 3c5a9945..811c067d 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/OnItemSelectedListener.kt @@ -3,7 +3,7 @@ package campus.tech.kakao.map.view.search import campus.tech.kakao.map.model.SavedLocation interface OnItemSelectedListener { - fun onLocationViewClicked(title: String, x: String, y: String) + fun onLocationViewClicked(title: String, longitude: String, latitude: String, address:String) fun onSavedLocationXButtonClicked(item: SavedLocation) fun onSavedLocationViewClicked(title: String) } \ No newline at end of file diff --git a/app/src/main/res/drawable/map_background_bottom_sheet.xml b/app/src/main/res/drawable/map_background_bottom_sheet.xml new file mode 100644 index 00000000..798be23e --- /dev/null +++ b/app/src/main/res/drawable/map_background_bottom_sheet.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 39747345..940e1691 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -40,4 +40,16 @@ android:layout_marginRight="10dp" android:elevation="4dp"/> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/map_bottom_sheet.xml b/app/src/main/res/layout/map_bottom_sheet.xml new file mode 100644 index 00000000..aabaa4b7 --- /dev/null +++ b/app/src/main/res/layout/map_bottom_sheet.xml @@ -0,0 +1,54 @@ + + + + + + + + + + \ No newline at end of file From 038d548b930fb2ea89a98490e674f7e539724d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 02:19:37 +0900 Subject: [PATCH 18/21] =?UTF-8?q?refactor:=20=EB=B7=B0=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=93=A4=EC=9D=84=20by=20lazy=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/MapActivity.kt | 16 ++--- .../kakao/map/view/search/MainActivity.kt | 59 +++++++------------ 2 files changed, 26 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index efbdaad6..fd9eb9c5 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -6,7 +6,6 @@ import android.content.SharedPreferences import android.graphics.Color import android.os.Bundle import android.util.Log -import android.view.View import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -27,8 +26,8 @@ import com.kakao.vectormap.label.LabelStyles class MapActivity : AppCompatActivity() { - private lateinit var searchEditText: EditText - private lateinit var mapView: MapView + private val searchEditText by lazy { findViewById(R.id.SearchEditTextInMap) } + private val mapView by lazy { findViewById(R.id.map_view) } private val bottomSheetLayout by lazy { findViewById(R.id.bottom_sheet_layout) } private val bottom_sheet_title by lazy { findViewById(R.id.bottom_sheet_title) } private val bottom_sheet_address by lazy { findViewById(R.id.bottom_sheet_address) } @@ -42,16 +41,9 @@ class MapActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map) - initViews() - initBottomSheet() + setupBottomSheet() setupEditText() setupMapView() - - } - - private fun initViews() { - searchEditText = findViewById(R.id.SearchEditTextInMap) - mapView = findViewById(R.id.map_view) } private fun setupEditText() { @@ -62,7 +54,7 @@ class MapActivity : AppCompatActivity() { } // Persistent BottomSheet 초기화 - private fun initBottomSheet() { + private fun setupBottomSheet() { // BottomSheetBehavior에 layout 설정 bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout) } diff --git a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt index ab9946c9..1cf41966 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/search/MainActivity.kt @@ -27,56 +27,43 @@ import campus.tech.kakao.map.viewmodel.LocationViewModel import campus.tech.kakao.map.viewmodel.SavedLocationViewModel class MainActivity : AppCompatActivity(), OnItemSelectedListener { + private val locationViewModel: LocationViewModel by lazy { + ViewModelProvider(this, LocationViewModelFactory(locationRepository)) + .get(LocationViewModel::class.java) + } + private val locationAdapter: LocationAdapter by lazy { LocationAdapter(this) } + private val locationRecyclerView: RecyclerView by lazy { findViewById(R.id.locationRecyclerView) } - private lateinit var locationViewModel: LocationViewModel - private lateinit var locationAdapter: LocationAdapter - private lateinit var locationRecyclerView: RecyclerView + private val savedLocationViewModel: SavedLocationViewModel by lazy { + ViewModelProvider(this, SavedLocationViewModelFactory(savedLocationRepository)) + .get(SavedLocationViewModel::class.java) + } - private lateinit var savedLocationViewModel: SavedLocationViewModel - private lateinit var savedLocationAdapter: SavedLocationAdapter - private lateinit var savedLocationRecyclerView: RecyclerView + private val savedLocationAdapter: SavedLocationAdapter by lazy { SavedLocationAdapter(this) } + private val savedLocationRecyclerView: RecyclerView by lazy { + findViewById(R.id.savedLocationRecyclerView) + } - private lateinit var locationDbHelper: LocationDbHelper - private lateinit var locationLocalDataSource: LocationLocalDataSource - private lateinit var locationRemoteDataSource: LocationRemoteDataSource - private lateinit var locationRepository: LocationRepository - private lateinit var savedLocationRepository: SavedLocationRepository + private val locationDbHelper: LocationDbHelper by lazy { LocationDbHelper(this) } + private val locationLocalDataSource: LocationLocalDataSource by lazy { LocationLocalDataSource(locationDbHelper) } + private val locationRemoteDataSource: LocationRemoteDataSource by lazy { LocationRemoteDataSource() } + private val locationRepository: LocationRepository by lazy { LocationRepository(locationLocalDataSource, locationRemoteDataSource) } + private val savedLocationRepository: SavedLocationRepository by lazy { SavedLocationRepository(locationLocalDataSource) } - private lateinit var clearButton: ImageView - private lateinit var searchEditText: EditText - private lateinit var noResultTextView: TextView + private val clearButton: ImageView by lazy { findViewById(R.id.clearButton) } + private val searchEditText: EditText by lazy { findViewById(R.id.SearchEditTextInMain) } + private val noResultTextView: TextView by lazy { findViewById(R.id.NoResultTextView) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - initViews() setupSearchEditText() setupClearButton() setupViewModels() setupRecyclerViews() } - private fun initViews() { - locationDbHelper = LocationDbHelper(this) - locationLocalDataSource = LocationLocalDataSource(locationDbHelper) - locationRemoteDataSource = LocationRemoteDataSource() - locationRepository = LocationRepository(locationLocalDataSource, locationRemoteDataSource) - savedLocationRepository = SavedLocationRepository(locationLocalDataSource) - - locationViewModel = ViewModelProvider(this, LocationViewModelFactory(locationRepository)) - .get(LocationViewModel::class.java) - locationRecyclerView = findViewById(R.id.locationRecyclerView) - - savedLocationViewModel = ViewModelProvider(this, SavedLocationViewModelFactory(savedLocationRepository)) - .get(SavedLocationViewModel::class.java) - savedLocationRecyclerView = findViewById(R.id.savedLocationRecyclerView) - - clearButton = findViewById(R.id.clearButton) - searchEditText = findViewById(R.id.SearchEditTextInMain) - noResultTextView = findViewById(R.id.NoResultTextView) - } - private fun setupSearchEditText() { searchEditText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} @@ -125,11 +112,9 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener { } private fun setupRecyclerViews() { - locationAdapter = LocationAdapter(this) locationRecyclerView.layoutManager = LinearLayoutManager(this) locationRecyclerView.adapter = locationAdapter - savedLocationAdapter = SavedLocationAdapter(this) savedLocationRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false) savedLocationRecyclerView.adapter = savedLocationAdapter From 116e601e023aceaf3b94631d042e41bc0adac532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 02:26:13 +0900 Subject: [PATCH 19/21] =?UTF-8?q?refactor:=20onMapError()=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20=EB=9D=84=EC=9A=B8=20=EB=95=8C=20=EC=8A=A4=EB=A0=88?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20runOnUiThread=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/MapActivity.kt | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index fd9eb9c5..15285c6d 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -31,7 +31,9 @@ class MapActivity : AppCompatActivity() { private val bottomSheetLayout by lazy { findViewById(R.id.bottom_sheet_layout) } private val bottom_sheet_title by lazy { findViewById(R.id.bottom_sheet_title) } private val bottom_sheet_address by lazy { findViewById(R.id.bottom_sheet_address) } - private lateinit var bottomSheetBehavior: BottomSheetBehavior + private val errorMessageTextView by lazy { findViewById(R.id.errorMessageTextView) } + private val bottomSheetBehavior: BottomSheetBehavior by lazy { BottomSheetBehavior.from(bottomSheetLayout) } + companion object{ private val DEFAULT_LONGITUDE = 127.115587 private val DEFAULT_LATITUDE = 37.406960 @@ -41,11 +43,20 @@ class MapActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map) - setupBottomSheet() setupEditText() setupMapView() } + override fun onResume() { + super.onResume() + mapView.resume() // MapView 의 resume 호출 + } + + override fun onPause() { + super.onPause() + mapView.pause() // MapView 의 pause 호출 + } + private fun setupEditText() { searchEditText.setOnClickListener { val intent: Intent = Intent(this@MapActivity, MainActivity::class.java) @@ -53,27 +64,20 @@ class MapActivity : AppCompatActivity() { } } - // Persistent BottomSheet 초기화 - private fun setupBottomSheet() { - // BottomSheetBehavior에 layout 설정 - bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout) - } - private fun setupMapView() { KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY); -// KakaoMapSdk.init(this, BuildConfig.KAKAO_REST_API_KEY); mapView.start(object : MapLifeCycleCallback() { override fun onMapDestroy() { - // 지도 API 가 정상적으로 종료될 때 호출됨 Log.d("jieun", "onMapDestroy") } override fun onMapError(error: Exception) { // 인증 실패 및 지도 사용 중 에러가 발생할 때 호출됨 Log.d("jieun", "onMapError" + error) - setContentView(R.layout.error_map) - val errorMessageTextView: TextView = findViewById(R.id.errorMessageTextView) - errorMessageTextView.text = "지도 인증을 실패했습니다.\n다시 시도해주세요.\n\n"+error.message + runOnUiThread { + setContentView(R.layout.error_map) + errorMessageTextView.text = "지도 인증을 실패했습니다.\n다시 시도해주세요.\n\n"+error.message + } } }, object : KakaoMapReadyCallback() { val coordinates = getCoordinates() @@ -112,7 +116,7 @@ class MapActivity : AppCompatActivity() { }) } - private fun getCoordinates(): Coordinates? { + private fun getCoordinates(): Coordinates { var coordinates = getCoordinatesByIntent() if(coordinates == null) { coordinates = getCoordinatedBySharedPreference() @@ -142,16 +146,6 @@ class MapActivity : AppCompatActivity() { } else return null } - override fun onResume() { - super.onResume() - mapView.resume() // MapView 의 resume 호출 - } - - override fun onPause() { - super.onPause() - mapView.pause() // MapView 의 pause 호출 - } - fun setSharedData(name: String, coordinates: Coordinates?) { if (coordinates != null) { var pref: SharedPreferences = getSharedPreferences(name, Activity.MODE_PRIVATE) From 8b2cd64d38f6e713b49ff687c70d7c8ff831b878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 02:35:56 +0900 Subject: [PATCH 20/21] =?UTF-8?q?refactor:=20=EC=A0=80=EC=9E=A5=EB=90=9C?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EA=B0=80=20=EC=97=86=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20null=20=EC=B2=98=EB=A6=AC=EB=A1=9C=20BottomSheet?= =?UTF-8?q?=EA=B0=80=20=EB=9C=A8=EC=A7=80=20=EC=95=8A=EA=B2=8C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/MapActivity.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index 15285c6d..fe222f78 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -6,6 +6,7 @@ import android.content.SharedPreferences import android.graphics.Color import android.os.Bundle import android.util.Log +import android.view.View import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -96,6 +97,7 @@ class MapActivity : AppCompatActivity() { .setTexts(coordinates.title) ) runOnUiThread { + bottomSheetLayout.visibility = View.VISIBLE bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED bottom_sheet_title.text = coordinates.title bottom_sheet_address.text = coordinates.address @@ -103,6 +105,8 @@ class MapActivity : AppCompatActivity() { setSharedData("pref", coordinates) // Log.d("jieun", "onMapReady setSharedData: " + getSharedData("pref")) + } else{ + runOnUiThread { bottomSheetLayout.visibility = View.GONE } } } @@ -110,27 +114,23 @@ class MapActivity : AppCompatActivity() { // Log.d("jieun", "getPosition coordinates: " + coordinates.toString()) if (coordinates != null) { return LatLng.from(coordinates.latitude, coordinates.longitude) + } else{ + return LatLng.from(DEFAULT_LATITUDE, DEFAULT_LONGITUDE) } - return LatLng.from(DEFAULT_LATITUDE, DEFAULT_LONGITUDE); + } }) } - private fun getCoordinates(): Coordinates { + private fun getCoordinates(): Coordinates? { var coordinates = getCoordinatesByIntent() if(coordinates == null) { - coordinates = getCoordinatedBySharedPreference() + coordinates = getCoordinatedBySharedPreference("pref") } return coordinates } - private fun getCoordinatedBySharedPreference(): Coordinates { - val coordinates = getSharedData("pref") - Log.d("jieun", "getSharedIntData " + coordinates) - return coordinates - } - private fun getCoordinatesByIntent(): Coordinates? { if (intent.hasExtra("title") && intent.hasExtra("longitude") && intent.hasExtra("latitude") && intent.hasExtra("address")) { @@ -158,8 +158,11 @@ class MapActivity : AppCompatActivity() { } } - fun getSharedData(name: String): Coordinates { + fun getCoordinatedBySharedPreference(name: String): Coordinates? { var pref: SharedPreferences = getSharedPreferences(name, Activity.MODE_PRIVATE) + if(pref.getString("title", "") == ""){ + return null + } val title = pref.getString("title", "").toString() val longitude = pref.getString("longitude", "").toString().toDouble() val latitude = pref.getString("latitude", "").toString().toDouble() From b99401c489a66b0c95b8ef6fd77bc791657dfdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=9D=80?= Date: Fri, 19 Jul 2024 02:40:31 +0900 Subject: [PATCH 21/21] =?UTF-8?q?refactor:=20onMapReady=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=ED=95=A8=EC=88=98=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tech/kakao/map/view/map/MapActivity.kt | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt index fe222f78..0fcfae3b 100644 --- a/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt +++ b/app/src/main/java/campus/tech/kakao/map/view/map/MapActivity.kt @@ -72,41 +72,21 @@ class MapActivity : AppCompatActivity() { Log.d("jieun", "onMapDestroy") } - override fun onMapError(error: Exception) { - // 인증 실패 및 지도 사용 중 에러가 발생할 때 호출됨 + override fun onMapError(error: Exception) { // 인증 실패 및 지도 사용 중 에러가 발생할 때 호출됨 Log.d("jieun", "onMapError" + error) - runOnUiThread { - setContentView(R.layout.error_map) - errorMessageTextView.text = "지도 인증을 실패했습니다.\n다시 시도해주세요.\n\n"+error.message - } + showErrorMessage(error) } }, object : KakaoMapReadyCallback() { val coordinates = getCoordinates() - override fun onMapReady(kakaoMap: KakaoMap) { - // 인증 후 API 가 정상적으로 실행될 때 호출됨 + override fun onMapReady(kakaoMap: KakaoMap) { // 인증 후 API 가 정상적으로 실행될 때 호출됨 Log.d("jieun", "onMapReady coordinates: " + coordinates.toString()) if (coordinates != null) { - val labelStyles: LabelStyles = LabelStyles.from( - LabelStyle.from(R.drawable.location_red_icon_resized).setZoomLevel(8), - LabelStyle.from(R.drawable.location_red_icon_resized).setTextStyles(32, Color.BLACK, 1, Color.GRAY).setZoomLevel(15) - ) - val position = LatLng.from(coordinates.latitude, coordinates.longitude) - kakaoMap.labelManager?.getLayer()?.addLabel( - LabelOptions.from(position) - .setStyles(labelStyles) - .setTexts(coordinates.title) - ) - runOnUiThread { - bottomSheetLayout.visibility = View.VISIBLE - bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED - bottom_sheet_title.text = coordinates.title - bottom_sheet_address.text = coordinates.address - } - + showLabel(coordinates, kakaoMap) + showBottomSheet(coordinates) setSharedData("pref", coordinates) // Log.d("jieun", "onMapReady setSharedData: " + getSharedData("pref")) } else{ - runOnUiThread { bottomSheetLayout.visibility = View.GONE } + hideBottomSheet() } } @@ -122,6 +102,44 @@ class MapActivity : AppCompatActivity() { }) } + + private fun showErrorMessage(error: Exception) { + runOnUiThread { + setContentView(R.layout.error_map) + errorMessageTextView.text = "지도 인증을 실패했습니다.\n다시 시도해주세요.\n\n" + error.message + } + } + + private fun showLabel( + coordinates: Coordinates, + kakaoMap: KakaoMap + ) { + val labelStyles: LabelStyles = LabelStyles.from( + LabelStyle.from(R.drawable.location_red_icon_resized).setZoomLevel(8), + LabelStyle.from(R.drawable.location_red_icon_resized) + .setTextStyles(32, Color.BLACK, 1, Color.GRAY).setZoomLevel(15) + ) + val position = LatLng.from(coordinates.latitude, coordinates.longitude) + kakaoMap.labelManager?.getLayer()?.addLabel( + LabelOptions.from(position) + .setStyles(labelStyles) + .setTexts(coordinates.title) + ) + } + + private fun hideBottomSheet() { + runOnUiThread { bottomSheetLayout.visibility = View.GONE } + } + + private fun showBottomSheet(coordinates: Coordinates) { + runOnUiThread { + bottomSheetLayout.visibility = View.VISIBLE + bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + bottom_sheet_title.text = coordinates.title + bottom_sheet_address.text = coordinates.address + } + } + private fun getCoordinates(): Coordinates? { var coordinates = getCoordinatesByIntent() if(coordinates == null) {