Skip to content

Commit

Permalink
refactor: Apply DataBinding in MapActivity and PlaceActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
jooiss committed Jul 22, 2024
1 parent 80757f5 commit 88aa1f9
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 171 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {

buildFeatures {
viewBinding = true
dataBinding = true
buildConfig = true
}
}
Expand Down
24 changes: 11 additions & 13 deletions app/src/main/java/campus/tech/kakao/map/ui/MapActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import android.content.Intent
import android.content.SharedPreferences
import android.content.SharedPreferences.Editor
import android.os.Bundle
import android.widget.EditText
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.ErrorLayoutBinding
import campus.tech.kakao.map.databinding.MapLayoutBinding
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.CameraAnimation
import com.kakao.vectormap.camera.CameraUpdateFactory
import com.kakao.vectormap.label.LabelManager
Expand All @@ -23,9 +24,8 @@ import com.kakao.vectormap.label.LabelStyle
import com.kakao.vectormap.label.LabelStyles

class MapActivity : AppCompatActivity() {

lateinit var mapView: MapView
lateinit var etSearch: EditText
lateinit var mapBinding: MapLayoutBinding
lateinit var errorBinding: ErrorLayoutBinding
private lateinit var labelManager: LabelManager
private val startZoomLevel = 15
var latitude: String? = "35.234"
Expand Down Expand Up @@ -140,27 +140,25 @@ class MapActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.map_layout)
mapView = findViewById(R.id.mapView)
etSearch = findViewById(R.id.etSearch)
mapView.start(lifeCycleCallback, readyCallback)
etSearch.setOnClickListener {
mapBinding = DataBindingUtil.setContentView(this, R.layout.map_layout)
mapBinding.mapView.start(lifeCycleCallback, readyCallback)
mapBinding.etSearch.setOnClickListener {
val searchIntent = Intent(this, PlaceActivity::class.java)
startActivity(searchIntent)
}
}

override fun onResume() {
super.onResume()
mapView.resume()
mapBinding.mapView.resume()
}

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

private fun initializeMap() {
mapView.start(lifeCycleCallback, readyCallback)
mapBinding.mapView.start(lifeCycleCallback, readyCallback)
}
}
49 changes: 19 additions & 30 deletions app/src/main/java/campus/tech/kakao/map/ui/PlaceActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import android.widget.EditText
import android.widget.ImageButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.domain.PlaceDataModel
import campus.tech.kakao.map.data.PlaceDatabaseAccess
import campus.tech.kakao.map.data.PlaceRepository
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.SearchLayoutBinding

class PlaceActivity : AppCompatActivity() {
lateinit var etSearch: EditText
lateinit var btnErase: ImageButton
lateinit var tvNoData: TextView
lateinit var rvPlaceList: RecyclerView
lateinit var rvSearchList: RecyclerView
lateinit var binding: SearchLayoutBinding
lateinit var placeAdapter: PlaceRecyclerViewAdapter
private lateinit var searchAdapter: SearchRecyclerViewAdapter
var searchDatabaseAccess = PlaceDatabaseAccess(this, "Search.db")
Expand All @@ -31,12 +25,7 @@ class PlaceActivity : AppCompatActivity() {

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.search_layout)
etSearch = findViewById<EditText>(R.id.etSearch)
btnErase = findViewById<ImageButton>(R.id.btnErase)
tvNoData = findViewById<TextView>(R.id.tvNoData)
rvPlaceList = findViewById<RecyclerView>(R.id.rvPlaceList)
rvSearchList = findViewById<RecyclerView>(R.id.rvSearchList)
binding = DataBindingUtil.setContentView(this, R.layout.search_layout)

val searchList: MutableList<PlaceDataModel> = searchDatabaseAccess.getAllPlace()
val keywordList: MutableList<PlaceDataModel> = mutableListOf()
Expand All @@ -45,23 +34,23 @@ class PlaceActivity : AppCompatActivity() {

// Search 어댑터
searchAdapter = searchRecyclerViewAdapter(searchList)
rvSearchList.adapter = searchAdapter
rvSearchList.layoutManager =
binding.rvSearchList.adapter = searchAdapter
binding.rvSearchList.layoutManager =
LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)

// Place 어댑터
placeAdapter = placeRecyclerViewAdapter(keywordList, searchList)
rvPlaceList.adapter = placeAdapter
rvPlaceList.layoutManager = LinearLayoutManager(this)
binding.rvPlaceList.adapter = placeAdapter
binding.rvPlaceList.layoutManager = LinearLayoutManager(this)

controlPlaceVisibility(keywordList)
controlSearchVisibility(searchList)

btnErase.setOnClickListener {
etSearch.setText("")
binding.btnErase.setOnClickListener {
binding.etSearch.setText("")
}

etSearch.addTextChangedListener(object : TextWatcher {
binding.etSearch.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}

Expand Down Expand Up @@ -118,8 +107,8 @@ class PlaceActivity : AppCompatActivity() {
searchList,
// 저장 목록 선택 시, 검색칸에 장소명 표시
onItemClick = { place ->
etSearch.setText(place.name)
etSearch.setSelection(place.name.length)
binding.etSearch.setText(place.name)
binding.etSearch.setSelection(place.name.length)
},
// X 선택 시, 저장 목록에서 삭제
onCloseButtonClick = { place ->
Expand All @@ -145,21 +134,21 @@ class PlaceActivity : AppCompatActivity() {
// visibility 조작
fun controlPlaceVisibility(placeList: List<PlaceDataModel>) {
if (placeList.isEmpty()) {
rvPlaceList.visibility = View.INVISIBLE
tvNoData.visibility = View.VISIBLE
binding.rvPlaceList.visibility = View.INVISIBLE
binding.tvNoData.visibility = View.VISIBLE
}
else {
rvPlaceList.visibility = View.VISIBLE
tvNoData.visibility = View.GONE
binding.rvPlaceList.visibility = View.VISIBLE
binding.tvNoData.visibility = View.GONE
}
}

fun controlSearchVisibility(searchList: List<PlaceDataModel>) {
if (searchList.isEmpty()) {
rvSearchList.visibility = View.GONE
binding.rvSearchList.visibility = View.GONE
}
else {
rvSearchList.visibility = View.VISIBLE
binding.rvSearchList.visibility = View.VISIBLE
}
}
}
113 changes: 58 additions & 55 deletions app/src/main/res/layout/map_layout.xml
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.MapActivity">


<com.kakao.vectormap.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.cardview.widget.CardView
<layout>
<androidx.constraintlayout.widget.ConstraintLayout 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="50dp"
android:layout_margin="30dp"
app:cardElevation="10dp"
app:layout_constraintTop_toTopOf="parent">
android:layout_height="match_parent"
tools:context=".ui.MapActivity">

<androidx.constraintlayout.widget.ConstraintLayout

<com.kakao.vectormap.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/etSearch"
android:layout_width="300dp"
android:layout_height="match_parent"
android:padding="12dp"
android:hint="@string/search_placeholder"
android:background="@color/white"
android:focusable="false"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ibSearch"
app:layout_constraintStart_toStartOf="parent"/>

<ImageButton
android:id="@+id/ibSearch"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:scaleType="centerInside"
android:src="@drawable/search"
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/etSearch"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>


</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="50dp"
android:layout_margin="30dp"
app:cardElevation="10dp"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/etSearch"
android:layout_width="300dp"
android:layout_height="match_parent"
android:padding="12dp"
android:hint="@string/search_placeholder"
android:background="@color/white"
android:focusable="false"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ibSearch"
app:layout_constraintStart_toStartOf="parent"/>

<ImageButton
android:id="@+id/ibSearch"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:scaleType="centerInside"
android:src="@drawable/search"
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/etSearch"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
Loading

0 comments on commit 88aa1f9

Please sign in to comment.