Skip to content

Commit

Permalink
feat: 버튼 클릭 시 검색어 요청으로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Mar 25, 2024
1 parent c6d596b commit d014ad4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.festago.festago.presentation.ui.search

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
Expand Down Expand Up @@ -152,9 +154,9 @@ class SearchFragment : Fragment() {
private fun handleSuccessSearch(uiState: SearchUiState.SearchSuccess) {
searchScreenAdapter.submitList(
listOf(
FestivalSearchScreen(uiState.searchedFestivals),
ArtistSearchScreen(uiState.searchedArtists),
SchoolSearchScreen(uiState.searchedSchools),
FestivalSearchScreen(uiState.searchedFestivals, ::requestAddSearchQuery),
ArtistSearchScreen(uiState.searchedArtists, ::requestAddSearchQuery),
SchoolSearchScreen(uiState.searchedSchools, ::requestAddSearchQuery),
),
)
initSearchTab()
Expand Down Expand Up @@ -206,6 +208,16 @@ class SearchFragment : Fragment() {
}
}

private fun requestAddSearchQuery() {
startBrowser("https://forms.gle/y17dmCFw1jAYLR9H7")
}

private fun startBrowser(url: String) {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
startActivity(intent)
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ class ArtistSearchScreenViewHolder(

fun bind(item: ItemSearchScreenUiState.ArtistSearchScreen) {
artistSearchAdapter.submitList(item.artistSearches)
binding.tvNoResult.visibility =
if (item.artistSearches.isEmpty()) View.VISIBLE else View.GONE
setNoResultVisibility(item)
binding.btnFestago.setOnClickListener {
item.onAddSearchQueryClick()
}
}

private fun setNoResultVisibility(item: ItemSearchScreenUiState.ArtistSearchScreen) {
val visibility = if (item.artistSearches.isEmpty()) View.VISIBLE else View.GONE
binding.tvNoResult.visibility = visibility
binding.tvNoResultGuide.visibility = visibility
binding.btnFestago.visibility = visibility
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class FestivalSearchScreenViewHolder(

fun bind(item: ItemSearchScreenUiState.FestivalSearchScreen) {
festivalSearchAdapter.submitList(item.festivalSearches)
setNoResultVisibility(item)
binding.btnFestago.setOnClickListener {
item.onAddSearchQueryClick()
}
}

private fun setNoResultVisibility(item: ItemSearchScreenUiState.FestivalSearchScreen) {
val visibility = if (item.festivalSearches.isEmpty()) View.VISIBLE else View.GONE
binding.tvNoResult.visibility = visibility
binding.tvNoResultGuide.visibility = visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import com.festago.festago.presentation.ui.search.uistate.ArtistSearchItemUiStat
import com.festago.festago.presentation.ui.search.uistate.FestivalSearchItemUiState
import com.festago.festago.presentation.ui.search.uistate.SchoolSearchItemUiState

sealed class ItemSearchScreenUiState(val screenPosition: Int) {
data class FestivalSearchScreen(val festivalSearches: List<FestivalSearchItemUiState>) :
ItemSearchScreenUiState(FESTIVAL_POSITION)
sealed class ItemSearchScreenUiState(
val screenPosition: Int,
) {
data class FestivalSearchScreen(
val festivalSearches: List<FestivalSearchItemUiState>,
val onAddSearchQueryClick: () -> Unit = {},
) : ItemSearchScreenUiState(FESTIVAL_POSITION)

data class ArtistSearchScreen(val artistSearches: List<ArtistSearchItemUiState>) :
ItemSearchScreenUiState(ARTIST_POSITION)
data class ArtistSearchScreen(
val artistSearches: List<ArtistSearchItemUiState>,
val onAddSearchQueryClick: () -> Unit = {},
) : ItemSearchScreenUiState(ARTIST_POSITION)

data class SchoolSearchScreen(val schoolSearches: List<SchoolSearchItemUiState>) :
ItemSearchScreenUiState(SCHOOL_POSITION)
data class SchoolSearchScreen(
val schoolSearches: List<SchoolSearchItemUiState>,
val onAddSearchQueryClick: () -> Unit = {},
) : ItemSearchScreenUiState(SCHOOL_POSITION)

companion object {
const val FESTIVAL_POSITION = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ class SchoolSearchScreenViewHolder(private val binding: ItemSchoolSearchScreenBi

fun bind(item: ItemSearchScreenUiState.SchoolSearchScreen) {
schoolSearchAdapter.submitList(item.schoolSearches)
binding.tvNoResult.visibility =
if (item.schoolSearches.isEmpty()) View.VISIBLE else View.GONE
setNoResultVisibility(item)
binding.btnFestago.setOnClickListener {
item.onAddSearchQueryClick()
}
}

private fun setNoResultVisibility(item: ItemSearchScreenUiState.SchoolSearchScreen) {
val visibility = if (item.schoolSearches.isEmpty()) View.VISIBLE else View.GONE
binding.tvNoResult.visibility = visibility
binding.tvNoResultGuide.visibility = visibility
binding.btnFestago.visibility = visibility
}

companion object {
Expand Down

0 comments on commit d014ad4

Please sign in to comment.