Skip to content

Commit

Permalink
feat: add dataBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
kimseongyu committed Jul 29, 2024
1 parent 737a32f commit 78e0aa0
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import campus.tech.kakao.map.BuildConfig
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.ActivityKakaoMapBinding
Expand Down Expand Up @@ -40,8 +41,7 @@ class KakaoMapActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityKakaoMapBinding.inflate(layoutInflater)
setContentView(binding.root)
binding = DataBindingUtil.setContentView(this, R.layout.activity_kakao_map)

setUpKakaoMap()
getSearchResult()
Expand Down Expand Up @@ -77,7 +77,7 @@ class KakaoMapActivity : AppCompatActivity() {
}

override fun onMapError(error: Exception?) {
binding.kakaomapErrDescription.text = error?.message.toString()
binding.errMsg = error?.message.toString()
showView(binding.kakaomapErr, true)
}
}, object : KakaoMapReadyCallback() {
Expand Down Expand Up @@ -146,8 +146,7 @@ class KakaoMapActivity : AppCompatActivity() {

fun displayPlaceInfoBottomSheet(place: Place) {
val bottomSheet = binding.placeInfoBottomSheet
bottomSheet.placeName.text = place.place_name
bottomSheet.addressName.text = place.address_name
bottomSheet.place = place

val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet.root)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package campus.tech.kakao.map.view.search

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.SavedSearchKeywordItemBinding
import campus.tech.kakao.map.model.search.SearchKeyword

Expand All @@ -16,19 +18,24 @@ class SavedSearchKeywordsAdapter(
inner class ViewHolder(private val binding: SavedSearchKeywordItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(item: SearchKeyword) {
binding.SavedSearchKeyword.text = item.searchKeyword
binding.searchKeyword = item

binding.SavedSearchKeyword.setOnClickListener {
itemClickListener?.onClickSavedSearchKeyword(item)
itemClickListener.onClickSavedSearchKeyword(item)
}
binding.delSavedSearchKeyword.setOnClickListener {
itemClickListener?.onClickDelSavedSearchKeyword(item)
itemClickListener.onClickDelSavedSearchKeyword(item)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = SavedSearchKeywordItemBinding.inflate(layoutInflater, parent, false)
val view: SavedSearchKeywordItemBinding = DataBindingUtil.inflate(
layoutInflater,
R.layout.saved_search_keyword_item,
parent,
false
)
return ViewHolder(view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package campus.tech.kakao.map.view.search

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.SearchResultItemBinding
import campus.tech.kakao.map.model.search.Place

Expand All @@ -16,18 +18,21 @@ class SearchResultsAdapter(
inner class ViewHolder(private val binding: SearchResultItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(item: Place) {
binding.placeName.text = item.place_name
binding.addressName.text = item.address_name
binding.categoryName.text = item.category_name

binding.place = item
binding.root.setOnClickListener {
itemClickListener?.onClick(item)
itemClickListener.onClick(item)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = SearchResultItemBinding.inflate(layoutInflater, parent, false)
val view: SearchResultItemBinding =
DataBindingUtil.inflate(
layoutInflater,
R.layout.search_result_item,
parent,
false
)
return ViewHolder(view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.BindingAdapter
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import campus.tech.kakao.map.R
import campus.tech.kakao.map.model.search.SearchKeyword
import campus.tech.kakao.map.databinding.ActivitySearchWindowBinding
import campus.tech.kakao.map.model.search.Place
Expand All @@ -26,8 +30,7 @@ class SearchWindowActivity : AppCompatActivity() {
private val viewModel: SearchViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySearchWindowBinding.inflate(layoutInflater)
setContentView(binding.root)
binding = DataBindingUtil.setContentView(this, R.layout.activity_search_window)

delSearchKeywordListener()
detectSearchWindowChangedListener()
Expand All @@ -37,7 +40,7 @@ class SearchWindowActivity : AppCompatActivity() {

private fun delSearchKeywordListener() {
binding.delSearchKeyword.setOnClickListener {
binding.searchWindow.text = null
binding.searchKeyword = SearchKeyword("")
}
}

Expand Down Expand Up @@ -101,7 +104,7 @@ class SearchWindowActivity : AppCompatActivity() {
adapter.setItemClickListener(object :
SavedSearchKeywordsAdapter.OnItemClickListener {
override fun onClickSavedSearchKeyword(item: SearchKeyword) {
binding.searchWindow.setText(item.searchKeyword)
binding.searchKeyword = item
}

override fun onClickDelSavedSearchKeyword(item: SearchKeyword) {
Expand Down
166 changes: 89 additions & 77 deletions app/src/main/res/layout/activity_kakao_map.xml
Original file line number Diff line number Diff line change
@@ -1,95 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.MainActivity">

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

<data>

<variable
name="errMsg"
type="String" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/goto_search_window"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:background="@color/white"
android:elevation="10dp"
android:padding="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/goto_search_window_text"
android:layout_width="0dp"
android:layout_height="35dp"
android:gravity="center|left"
android:text="@string/searchWindowHint"
android:layout_height="match_parent"
tools:context=".view.MainActivity">

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

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/goto_search_window"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:background="@color/white"
android:elevation="10dp"
android:padding="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/goto_search_window_img"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="spread" />

<ImageView
android:id="@+id/goto_search_window_img"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/ic_custom_magnifying_glass"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/goto_search_window_text"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent">

</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/goto_search_window_text"
android:layout_width="0dp"
android:layout_height="35dp"
android:gravity="center|left"
android:text="@string/searchWindowHint"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/goto_search_window_img"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="spread" />

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="@+id/goto_search_window_img"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/ic_custom_magnifying_glass"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/goto_search_window_text"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<include
android:id="@+id/place_info_bottom_sheet"
layout="@layout/activity_place_info_bottom_sheet" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<LinearLayout
android:id="@+id/kakaomap_err"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical"
android:elevation="10dp"
android:visibility="gone">

<TextView
android:id="@+id/kakaomap_err_msg"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kakaoMapErrMsg"
android:textSize="20sp" />
app:layout_constraintBottom_toBottomOf="parent">

<include
android:id="@+id/place_info_bottom_sheet"
layout="@layout/activity_place_info_bottom_sheet" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

<TextView
android:id="@+id/kakaomap_err_description"
<LinearLayout
android:id="@+id/kakaomap_err"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="20sp" />
android:layout_height="match_parent"
android:background="@color/white"
android:elevation="10dp"
android:gravity="center"
android:orientation="vertical"
android:padding="30dp"
android:visibility="gone">

<TextView
android:id="@+id/kakaomap_err_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kakaoMapErrMsg"
android:textSize="20sp" />

<TextView
android:id="@+id/kakaomap_err_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="@{errMsg}"
android:textSize="20sp" />

<ImageView
android:id="@+id/reload"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="30dp"
android:src="@drawable/ic_custom_reload" />
<ImageView
android:id="@+id/reload"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="30dp"
android:src="@drawable/ic_custom_reload" />

</LinearLayout>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading

0 comments on commit 78e0aa0

Please sign in to comment.