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

전남대 Android_오진우_5주차 과제_Step2 #84

Open
wants to merge 21 commits into
base: fivejinw
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
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
35 changes: 10 additions & 25 deletions app/src/main/java/campus/tech/kakao/map/adapter/PlaceViewAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.VisibleForTesting
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import campus.tech.kakao.map.view.OnClickPlaceListener
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.PlaceItemBinding
import campus.tech.kakao.map.model.Place

class PlaceViewAdapter(
Expand All @@ -20,15 +22,13 @@ class PlaceViewAdapter(

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlaceViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.place_item, parent, false)
Log.d("testt", "검색 결과 뷰 생성")
return PlaceViewHolder(view, listener)
val binding = DataBindingUtil.inflate<PlaceItemBinding>(inflater, R.layout.place_item, parent, false)
return PlaceViewHolder(binding)
}

override fun onBindViewHolder(holder: PlaceViewHolder, position: Int) {
// Log.d("testt", "${placeList?.get(position)?.name}, ${placeList?.get(position)?.location}, ${placeList?.get(position)?.category}")
val currentPlace = getItem(position)
holder.bind(currentPlace)
holder.bind(currentPlace, listener)
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Expand All @@ -47,26 +47,11 @@ class PlaceDiffCallBack : DiffUtil.ItemCallback<Place>() {
}
}

class PlaceViewHolder(itemView: View, val listener: OnClickPlaceListener) :
RecyclerView.ViewHolder(itemView) {
val name = itemView.findViewById<TextView>(R.id.place_name)
val location = itemView.findViewById<TextView>(R.id.place_location)
val category = itemView.findViewById<TextView>(R.id.place_category)
var currentPlace : Place? = null
class PlaceViewHolder(private val binding : PlaceItemBinding) :
RecyclerView.ViewHolder(binding.root) {

init {
itemView.setOnClickListener {
val position = absoluteAdapterPosition
Log.d("testt", "콜백함수 호출")
currentPlace?.let { listener.savePlace(it) }
}
}

fun bind(place : Place){
currentPlace = place
name.text = place.name
location.text = place.location ?: ""
Log.d("testt", "입력값 : " + location.text.toString())
category.text = place.category ?: ""
fun bind(place : Place, listener : OnClickPlaceListener){
binding.place = place
binding.listener = listener

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listener 는 init 시점으로 옮겨주세요!

}
}
6 changes: 4 additions & 2 deletions app/src/main/java/campus/tech/kakao/map/view/MapActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
Expand Down Expand Up @@ -96,8 +97,8 @@ class MapActivity : AppCompatActivity() {


private fun initBottomSheet(){
bottomSheetBinding = DataBindingUtil.inflate(layoutInflater, R.layout.bottom_sheet, null, false)
bottomSheetBehavior = BottomSheetBehavior.from(findViewById<ConstraintLayout>(R.id.bottom_sheet))
bottomSheetBinding = binding.bottomSheetInclude
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetBinding.bottomSheet)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
}

Expand Down Expand Up @@ -148,6 +149,7 @@ class MapActivity : AppCompatActivity() {
isInitState = false
moveMapCamera(pos)
bottomSheetBinding.place = place
Log.d("placeTest", "Place : ${place}, Binding : ${bottomSheetBinding.place}")
viewModel.setRecentPos(latitude, longitude)
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<include layout="@layout/bottom_sheet" />
<include layout="@layout/bottom_sheet"
android:id="@+id/bottom_sheet_include"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
148 changes: 72 additions & 76 deletions app/src/main/res/layout/activity_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,90 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="viewModel"
type="campus.tech.kakao.map.viewmodel.SearchActivityViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".view.SearchActivity">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/input_search_field"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:transitionName="inputFieldTransition"
android:hint="@string/search_hint"
android:layout_marginHorizontal="5dp"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_marginTop="5dp"
android:padding="10dp"
android:paddingHorizontal="20dp"
/>
<ImageView
android:id="@+id/button_X"
android:layout_width="30dp"
android:layout_height="30dp"
app:layout_constraintTop_toTopOf="@id/input_search_field"
app:layout_constraintBottom_toBottomOf="@+id/input_search_field"
app:layout_constraintEnd_toEndOf="@id/input_search_field"
android:layout_marginEnd="10dp"
android:src="@android:drawable/ic_menu_close_clear_cancel"/>
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".view.SearchActivity">

<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:transitionName="inputFieldTransition"
app:layout_constraintTop_toTopOf="@id/search_result_recyclerView"
app:layout_constraintBottom_toBottomOf="@id/search_result_recyclerView"
app:layout_constraintStart_toStartOf="@id/search_result_recyclerView"
app:layout_constraintEnd_toEndOf="@id/search_result_recyclerView"
android:background="@color/white"
/>
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/input_search_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:layout_marginTop="5dp"
android:background="@color/white"
android:hint="@string/search_hint"
android:padding="10dp"
android:paddingHorizontal="20dp"
android:transitionName="inputFieldTransition"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/saved_search_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_constraintTop_toBottomOf="@+id/input_search_field"
app:layout_constraintBottom_toTopOf="@id/search_result_recyclerView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="10dp"
/>
<ImageView
android:id="@+id/button_X"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="10dp"
android:src="@android:drawable/ic_menu_close_clear_cancel"
app:layout_constraintBottom_toBottomOf="@+id/input_search_field"
app:layout_constraintEnd_toEndOf="@id/input_search_field"
app:layout_constraintTop_toTopOf="@id/input_search_field" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_result_recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:background="@color/white"
app:layout_constraintTop_toBottomOf="@+id/saved_search_recyclerView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/white"
android:transitionName="inputFieldTransition"
app:layout_constraintBottom_toBottomOf="@id/search_result_recyclerView"
app:layout_constraintEnd_toEndOf="@id/search_result_recyclerView"
app:layout_constraintStart_toStartOf="@id/search_result_recyclerView"
app:layout_constraintTop_toTopOf="@id/search_result_recyclerView" />

<TextView
android:id="@+id/no_search_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/no_search_result"
android:textSize="18sp"
android:textColor="#737373"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/saved_search_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/white"
app:layout_constraintBottom_toTopOf="@id/search_result_recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/input_search_field" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_result_recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/saved_search_recyclerView" />

<TextView
android:id="@+id/no_search_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_search_result"
android:textColor="#737373"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<variable
name="place"
type="campus.tech.kakao.map.model.Place" />
type="campus.tech.kakao.map.model.Place"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/res/layout/place_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="place"
type="campus.tech.kakao.map.model.Place" />
type="campus.tech.kakao.map.model.Place"/>

<variable
name="listener"
type="campus.tech.kakao.map.view.OnClickPlaceListener"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:onClick="@{() -> }">
android:onClick="@{() -> listener.savePlace(place)}">

<ImageView
android:id="@+id/place_image"
Expand All @@ -29,7 +34,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="장소1"
android:text="@{place.name}"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@id/place_image"
Expand All @@ -41,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="서울 농기구 고길동1"
android:text="@{place.location}"
android:textColor="@color/text_location"
android:textSize="14sp"
android:textStyle="bold"
Expand All @@ -54,7 +59,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:text="장소"
android:text="@{place.category}"
android:textColor="@color/text_location"
android:textSize="20sp"
android:textStyle="bold"
Expand Down