Skip to content

Commit de375ed

Browse files
committed
feat : 최근 검색 기록 화면 구현
1 parent b8dac13 commit de375ed

File tree

5 files changed

+101
-11
lines changed

5 files changed

+101
-11
lines changed

presentation/src/main/java/com/stop/ui/placesearch/PlaceSearchFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PlaceSearchFragment : Fragment() {
6060

6161
nearPlaceAdapter.onItemClick = {
6262
placeSearchViewModel.setClickPlace(it)
63-
placeSearchViewModel.setNearPlaceListEmpty()
63+
placeSearchViewModel.setNearPlacesEmpty()
6464

6565
binding.root.findNavController().navigate(R.id.action_placeSearchFragment_to_mapFragment)
6666
}
@@ -129,7 +129,7 @@ class PlaceSearchFragment : Fragment() {
129129
placeSearchViewModel.searchKeyword.debounce(100)
130130
.onEach {
131131
if(it.isBlank()){
132-
placeSearchViewModel.setNearPlaceListEmpty()
132+
placeSearchViewModel.setNearPlacesEmpty()
133133
}else{
134134
placeSearchViewModel.getNearPlaces(it)
135135
}

presentation/src/main/java/com/stop/ui/placesearch/PlaceSearchViewModel.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ class PlaceSearchViewModel @Inject constructor(
3232

3333
var panelInfo: com.stop.model.route.Place? = null
3434

35-
private val _nearPlaceList = MutableStateFlow<List<Place>>(emptyList())
36-
val nearPlaceList: StateFlow<List<Place>> = _nearPlaceList
35+
private val _nearPlaces = MutableStateFlow<List<Place>>(emptyList())
36+
val nearPlaces: StateFlow<List<Place>> = _nearPlaces
37+
38+
private val _isNearPlacesNotEmpty = MutableStateFlow(false)
39+
val isNearPlacesNotEmpty: StateFlow<Boolean> = _isNearPlacesNotEmpty
3740

3841
var bookmarks = mutableListOf(EXAMPLE_BOOKMARK_1, EXAMPLE_BOOKMARK_2, EXAMPLE_BOOKMARK_3)
3942

@@ -47,7 +50,7 @@ class PlaceSearchViewModel @Inject constructor(
4750
val clickCurrentLocation = clickCurrentLocationChannel.receiveAsFlow()
4851

4952
private val _searchKeyword = MutableStateFlow("")
50-
val searchKeyword : StateFlow<String> = _searchKeyword
53+
val searchKeyword: StateFlow<String> = _searchKeyword
5154

5255
private val _geoLocation = MutableLiveData<GeoLocationInfo>()
5356
val geoLocation: LiveData<GeoLocationInfo> = _geoLocation
@@ -67,22 +70,25 @@ class PlaceSearchViewModel @Inject constructor(
6770
) {
6871
viewModelScope.launch {
6972
try {
70-
_nearPlaceList.emit(
73+
_nearPlaces.emit(
7174
getNearPlacesUseCase.getNearPlaces(
7275
searchKeyword,
7376
currentLocation.longitude,
7477
currentLocation.latitude
7578
)
7679
)
80+
81+
_isNearPlacesNotEmpty.value = true
7782
} catch (e: Exception) {
78-
setNearPlaceListEmpty()
83+
setNearPlacesEmpty()
7984
errorMessageChannel.send(e.message ?: "something is wrong")
8085
}
8186
}
8287
}
8388

84-
fun setNearPlaceListEmpty() {
85-
_nearPlaceList.value = emptyList()
89+
fun setNearPlacesEmpty() {
90+
_nearPlaces.value = emptyList()
91+
_isNearPlacesNotEmpty.value = false
8692
}
8793

8894
fun setClickPlace(place: Place) {

presentation/src/main/res/layout/fragment_place_search.xml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<layout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:bind="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools">
56

67
<data>
78

9+
<import type="android.view.View" />
10+
811
<variable
912
name="viewModel"
1013
type="com.stop.ui.placesearch.PlaceSearchViewModel" />
@@ -92,18 +95,41 @@
9295
app:layout_constraintStart_toEndOf="@id/text_view_current_location"
9396
app:layout_constraintTop_toTopOf="@id/text_view_current_location" />
9497

98+
<com.google.android.material.divider.MaterialDivider
99+
android:id="@+id/divider"
100+
android:layout_width="0dp"
101+
android:layout_height="3dp"
102+
android:layout_marginTop="12dp"
103+
app:dividerColor="@color/light_grey"
104+
app:layout_constraintEnd_toEndOf="parent"
105+
app:layout_constraintStart_toStartOf="parent"
106+
app:layout_constraintTop_toBottomOf="@id/text_view_current_location" />
107+
95108
<androidx.recyclerview.widget.RecyclerView
96109
android:id="@+id/recycler_view_place"
97110
android:layout_width="0dp"
98111
android:layout_height="0dp"
99112
android:layout_marginTop="16dp"
113+
android:visibility="@{viewModel.isNearPlacesNotEmpty ? View.VISIBLE : View.GONE}"
114+
app:items="@{viewModel.nearPlaces}"
100115
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
101116
app:layout_constraintBottom_toBottomOf="parent"
102117
app:layout_constraintEnd_toEndOf="@id/guide_line_end"
103118
app:layout_constraintStart_toStartOf="@id/guide_line_start"
104-
app:layout_constraintTop_toBottomOf="@id/text_view_current_location"
105-
app:items="@{viewModel.nearPlaceList}" />
119+
app:layout_constraintTop_toBottomOf="@id/divider"
120+
tools:visibility="gone" />
106121

122+
<include
123+
android:id="@+id/layout_recent_search"
124+
layout="@layout/layout_recent_search"
125+
android:layout_width="0dp"
126+
android:layout_height="0dp"
127+
android:visibility="@{viewModel.isNearPlacesNotEmpty ? View.GONE : View.VISIBLE}"
128+
app:layout_constraintBottom_toBottomOf="parent"
129+
app:layout_constraintEnd_toEndOf="@id/guide_line_end"
130+
app:layout_constraintStart_toStartOf="@id/guide_line_start"
131+
app:layout_constraintTop_toBottomOf="@id/divider"
132+
bind:viewModel="@{viewModel}" />
107133

108134
</androidx.constraintlayout.widget.ConstraintLayout>
109135

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools">
5+
6+
<data>
7+
8+
<variable
9+
name="viewModel"
10+
type="com.stop.ui.placesearch.PlaceSearchViewModel" />
11+
</data>
12+
13+
<androidx.constraintlayout.widget.ConstraintLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
tools:theme="@style/Theme.Material3.Light.NoActionBar">
17+
18+
<TextView
19+
android:id="@+id/text_view_recent_search"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="16dp"
23+
android:text="@string/recent_search_text"
24+
android:textColor="@color/black"
25+
android:textSize="24sp"
26+
android:textStyle="bold"
27+
app:layout_constraintStart_toStartOf="parent"
28+
app:layout_constraintTop_toTopOf="parent" />
29+
30+
<androidx.recyclerview.widget.RecyclerView
31+
android:id="@+id/recycler_view_recent_search"
32+
android:layout_width="0dp"
33+
android:layout_height="0dp"
34+
android:layout_marginVertical="12dp"
35+
app:layout_constraintBottom_toTopOf="@id/button_delete_recent_search"
36+
app:layout_constraintEnd_toEndOf="parent"
37+
app:layout_constraintStart_toStartOf="parent"
38+
app:layout_constraintTop_toBottomOf="@id/text_view_recent_search" />
39+
40+
<com.google.android.material.button.MaterialButton
41+
android:id="@+id/button_delete_recent_search"
42+
style="@style/Widget.Material3.Button.OutlinedButton"
43+
android:layout_width="0dp"
44+
android:layout_height="wrap_content"
45+
android:layout_marginBottom="12dp"
46+
android:text="@string/delete_recent_search_text"
47+
android:textColor="@color/black"
48+
android:textSize="24sp"
49+
android:textStyle="bold"
50+
app:layout_constraintBottom_toBottomOf="parent"
51+
app:layout_constraintEnd_toEndOf="parent"
52+
app:layout_constraintStart_toStartOf="parent" />
53+
54+
</androidx.constraintlayout.widget.ConstraintLayout>
55+
56+
</layout>

presentation/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
<string name="walk_time_text">도보시간 : %1$d분</string>
4343
<string name="alarm_turn_off_text">알람 해제</string>
4444
<string name="alarm_delete_text">알람 삭제</string>
45+
<string name="recent_search_text">최근기록</string>
46+
<string name="delete_recent_search_text">최근기록 삭제</string>
4547
</resources>

0 commit comments

Comments
 (0)