Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[강원대 안드로이드 주민철] 4주차 과제 스텝2 #82

Open
wants to merge 21 commits into
base: joominchul
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8ae483b
Rename[]: 이동 3주차 과제 내용
joominchul Jul 15, 2024
7c76c97
Refactor[]: 변경 warning 부분
joominchul Jul 15, 2024
ba17eaf
Docs[README.md]: 추가 요구 사항 정리
joominchul Jul 15, 2024
4c2c111
Feat[]: 추가 선택 항목 위치, 정보를 지도에 표시
joominchul Jul 16, 2024
c69b181
Refactor[]: 변경 warning 요소
joominchul Jul 16, 2024
2613a7d
Design[bottom_sheet]: 변경 패딩
joominchul Jul 16, 2024
daefd35
Feat[]: 추가 저장된 검색어 선택 시 해당 검색어 검색 결과 표시
joominchul Jul 16, 2024
4bc4784
Feat[]: 추가 카카오지도 onMapError() 호출 시 에러 화면 표시
joominchul Jul 17, 2024
47c2fca
Docs[README.md]: 2단계 요구 사항 작성
joominchul Jul 18, 2024
3c24b64
Test[FunTest]: 추가 검색어를_입력하면_검색_결과_표시 함수
joominchul Jul 18, 2024
2c5abdf
Test[SearchActivityUITest]: 추가 입력한_검색어_X_눌러_삭제 함수
joominchul Jul 19, 2024
504a272
Test[SearchActivityUITest]: 추가 검색_결과_클릭시 함수
joominchul Jul 19, 2024
e3da3c0
Test[SearchActivityUITest]: 변경 검색_결과_클릭시 함수 이름
joominchul Jul 19, 2024
a6c8a27
Test[SearchActivityUITest]: 추가 검색창_표시_확인
joominchul Jul 19, 2024
5bb33ef
Test[SearchActivityUITest]: 추가 X_버튼_확인
joominchul Jul 19, 2024
bacca26
Test[MapActivityUITest]: 추가 검색창_보이는지_확인 함수
joominchul Jul 19, 2024
3c189cb
Merge branch 'joominchul' into feat-joominchul-step2
joominchul Jul 19, 2024
236eb18
Fix[MainViewModel]: 수정 wordfromDocument
joominchul Jul 19, 2024
42b46d9
Feat[FunTest]: 추가 검색어_저장_되는지_확인
joominchul Jul 19, 2024
ef22501
Merge remote-tracking branch 'origin/feat-joominchul-step2' into feat…
joominchul Jul 19, 2024
a88c1a7
Feat[FunTest]: 추가 검색어_저장_되는지_확인 함수에 삭제 확인 기능
joominchul Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feat[]: 추가 선택 항목 위치, 정보를 지도에 표시
라벨과 바텀시트 사용
  • Loading branch information
joominchul committed Jul 16, 2024
commit 4c2c1117176391c9b3fa11674c34279854746414
11 changes: 0 additions & 11 deletions app/src/main/java/campus/tech/kakao/map/MainActivity.kt

This file was deleted.

15 changes: 12 additions & 3 deletions app/src/main/java/campus/tech/kakao/map/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ 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.dbHelper.SearchWordDbHelper
import campus.tech.kakao.map.dto.Document
import campus.tech.kakao.map.dto.MapPositionContract
import campus.tech.kakao.map.dto.SearchWord
import campus.tech.kakao.map.MyApplication.Companion.mapPosition
import campus.tech.kakao.map.RetrofitData.Companion.getInstance

class MainViewModel(application: Application): AndroidViewModel(application) {
Expand Down Expand Up @@ -39,4 +41,11 @@ class MainViewModel(application: Application): AndroidViewModel(application) {
super.onCleared()
wordDbHelper.close()
}

fun getMapInfo(document: Document){
mapPosition.setPreferences(MapPositionContract.PREFERENCE_KEY_LATITUDE, document.latitude)
mapPosition.setPreferences(MapPositionContract.PREFERENCE_KEY_LONGITUDE, document.longitude)
mapPosition.setPreferences(MapPositionContract.PREFERENCE_KEY_PLACENAME, document.placeName)
mapPosition.setPreferences(MapPositionContract.PREFERENCE_KEY_ADDRESSNAME, document.addressName)
}
}
96 changes: 96 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/MapActivity.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
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 campus.tech.kakao.map.MyApplication.Companion.mapPosition
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.Label
import com.kakao.vectormap.label.LabelLayer
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 var latitude = 37.402005
private var longitude = 127.108621
private lateinit var placeName:String
private lateinit var addressName:String
private var styles: LabelStyles? = null
private lateinit var options:LabelOptions
private var layer: LabelLayer? = null
private var label: Label? = null
private lateinit var bitmapImage: Bitmap
private lateinit var markerImage: Bitmap
private lateinit var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>
private val bottomSheet by lazy { findViewById<LinearLayout>(R.id.bottom_sheet) }
private val bottomSheetName by lazy { findViewById<TextView>(R.id.name) }
private val bottomSheetAddress by lazy { findViewById<TextView>(R.id.address) }
companion object{
var documentClicked = false
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map)
mapView = findViewById(R.id.map_view)
setMapInfo()
mapView.start(object : MapLifeCycleCallback() {
override fun onMapDestroy() {

Expand All @@ -33,22 +67,84 @@ class MapActivity : AppCompatActivity() {
map = kakaoMap
}

override fun getPosition(): LatLng {
return LatLng.from(latitude, longitude)
}

override fun getZoomLevel(): Int {
return 17
}
})
searchBar = findViewById(R.id.search_bar)
searchBar.setOnClickListener {
val intent = Intent(this@MapActivity, SearchActivity::class.java)
startActivity(intent)
}
initBottomSheet()
}

override fun onResume() {
super.onResume()
setMapInfo()
mapView.resume()
if(documentClicked){
makeMarker()
setBottomSheet()
documentClicked = false
}
else{
layer?.remove(label)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
}
val cameraUpdate: CameraUpdate = CameraUpdateFactory.newCenterPosition(LatLng.from(latitude, longitude))
map?.moveCamera(cameraUpdate)
}

override fun onPause() {
super.onPause()
mapView.pause()
}

private fun setMapInfo(){
latitude = mapPosition.getPreferences("latitude","37.406960").toDouble()
longitude = mapPosition.getPreferences("longitude","127.110030").toDouble()
placeName = mapPosition.getPreferences("placeName","")
addressName = mapPosition.getPreferences("addressName","")
}

private fun makeMarker(){
bitmapImage = BitmapFactory.decodeResource(resources, R.drawable.marker)
markerImage = Bitmap.createScaledBitmap(bitmapImage, 100, 100, true)
styles = map?.labelManager?.addLabelStyles(LabelStyles.from(LabelStyle.from(markerImage).setTextStyles(40, Color.BLACK)))
if(styles != null){
options = LabelOptions.from(LatLng.from(latitude, longitude)).setStyles(styles).setTexts(placeName)
layer = map?.labelManager?.layer
if(label != null){
layer?.remove(label)
}
label = layer?.addLabel(options)
}
else{
Log.e("MapActivity", "makeMarker: styles is null")
}
}

private fun initBottomSheet(){
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
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package campus.tech.kakao.map

import android.app.Application
import campus.tech.kakao.map.dto.MapPositionPreferences
import com.kakao.vectormap.KakaoMapSdk

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
mapPosition = MapPositionPreferences(this)
KakaoMapSdk.init(this, BuildConfig.KAKAO_API_KEY)
}

companion object{
lateinit var mapPosition : MapPositionPreferences
}
}
17 changes: 11 additions & 6 deletions app/src/main/java/campus/tech/kakao/map/RetrofitData.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package campus.tech.kakao.map

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.dto.UrlContract
import campus.tech.kakao.map.dto.UrlContract.AUTHORIZATION
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -28,8 +28,13 @@ class RetrofitData private constructor() {
if (response.isSuccessful) {
val documentList = mutableListOf<Document>()
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
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/campus/tech/kakao/map/RetrofitService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package campus.tech.kakao.map

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
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/campus/tech/kakao/map/SearchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ 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.DocumentAdapter
import campus.tech.kakao.map.adapter.WordAdapter

class SearchActivity : AppCompatActivity() {

Expand All @@ -29,9 +29,12 @@ class SearchActivity : AppCompatActivity() {
setupUI()
searchResult.layoutManager = LinearLayoutManager(this)
searchWordResult.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
documentAdapter = DocumentAdapter(){ Document ->
documentAdapter = DocumentAdapter({ Document ->
model.addWord(Document)
}
},{Document ->
model.getMapInfo(Document)
finish()
})
wordAdapter = WordAdapter() { SearchWord ->
model.deleteWord(SearchWord)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.Adapter
package campus.tech.kakao.map.adapter

import android.view.LayoutInflater
import android.view.View
Expand All @@ -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.dto.Document
import campus.tech.kakao.map.MapActivity.Companion.documentClicked
import campus.tech.kakao.map.R

class DocumentAdapter(
val addWord: (Document) -> Unit
val addWord: (Document) -> Unit,
val sendDocumentInfo: (Document) -> Unit
): ListAdapter<Document, DocumentAdapter.ViewHolder>(
object : DiffUtil.ItemCallback<Document>(){
override fun areItemsTheSame(oldItem: Document, newItem: Document): Boolean {
Expand All @@ -27,6 +29,8 @@ class DocumentAdapter(
private var placeClicked = { position:Int ->
val document: Document = getItem(position)
addWord(document)
sendDocumentInfo(document)
documentClicked = true
}
inner class ViewHolder(
itemView: View
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.Adapter
package campus.tech.kakao.map.adapter

import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,7 +9,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package campus.tech.kakao.map.DBHelper
package campus.tech.kakao.map.dbHelper

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.SearchWord
import campus.tech.kakao.map.dto.SearchWordContract
import campus.tech.kakao.map.dto.SearchWordContract.DB_VERSION

class SearchWordDbHelper(context: Context): SQLiteOpenHelper(
context, SearchWordContract.DB_NAME, null, DB_VERSION) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.DTO
package campus.tech.kakao.map.dto

import com.google.gson.annotations.SerializedName

Expand All @@ -15,8 +15,10 @@ data class Document(
@SerializedName("address_name")
val addressName: String,
//val road_address_name: String,
//val x: String,
//val y: String,
@SerializedName("x")
val longitude : String,
@SerializedName("y")
val latitude: String,
//val place_url: String,
//val distance: String,
)
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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()
}

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

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package campus.tech.kakao.map.DTO
package campus.tech.kakao.map.dto

data class PlaceResponse(
val meta: Meta,
Expand Down
Loading