-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
34 changed files
with
559 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/teumteum/teumteum/presentation/group/search/KeywordAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.teumteum.teumteum.presentation.group.search | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.teumteum.teumteum.databinding.ItemKeywordListBinding | ||
|
||
class KeywordAdapter(private val itemClick: (String) -> (Unit)) : | ||
RecyclerView.Adapter<KeywordAdapter.KeywordAdapter>() { | ||
private val keywordList = mutableListOf<String>() | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KeywordAdapter { | ||
val binding = ItemKeywordListBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false, | ||
) | ||
return KeywordAdapter(binding, itemClick) | ||
} | ||
|
||
override fun onBindViewHolder(holder: KeywordAdapter, position: Int) { | ||
holder.onBind(keywordList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = keywordList.size | ||
|
||
fun setItems(newItems: List<String>) { | ||
keywordList.clear() | ||
keywordList.addAll(newItems) | ||
notifyDataSetChanged() | ||
} | ||
|
||
class KeywordAdapter( | ||
private val binding: ItemKeywordListBinding, | ||
private val itemClick: (String) -> (Unit) | ||
): RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(keyword: String) { | ||
binding.tvKeyword.text = keyword | ||
|
||
binding.root.setOnClickListener { | ||
itemClick(keyword) | ||
} | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
app/src/main/java/com/teumteum/teumteum/presentation/group/search/SearchActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.teumteum.teumteum.presentation.group.search | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.core.view.isGone | ||
import androidx.core.view.isVisible | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.teumteum.base.BindingActivity | ||
import com.teumteum.base.util.extension.hideKeyboard | ||
import com.teumteum.base.util.extension.toast | ||
import com.teumteum.teumteum.R | ||
import com.teumteum.teumteum.databinding.ActivitySearchBinding | ||
import com.teumteum.teumteum.presentation.group.GroupListAdapter | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@AndroidEntryPoint | ||
class SearchActivity : BindingActivity<ActivitySearchBinding>(R.layout.activity_search) { | ||
private val viewModel by viewModels<SearchViewModel>() | ||
private lateinit var keywordAdapter: KeywordAdapter | ||
private lateinit var groupListAdapter: GroupListAdapter | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding.viewModel = viewModel | ||
initView() | ||
initEvent() | ||
observe() | ||
} | ||
|
||
private fun initView() { | ||
initKeywordAdapter() | ||
initGroupListAdapter() | ||
} | ||
|
||
private fun initKeywordAdapter() { | ||
keywordAdapter = KeywordAdapter { | ||
binding.etSearch.setText(it) | ||
viewModel.initCurrentPage(it) | ||
hideKeyboard(binding.root) | ||
} | ||
binding.rvRecommendKeyword.adapter = keywordAdapter | ||
keywordAdapter.setItems(viewModel.keywordList) | ||
} | ||
|
||
private fun initGroupListAdapter() { | ||
groupListAdapter = GroupListAdapter { | ||
//TODO 그룹 상세보기로 이동하는 로직 들어가야 함 | ||
} | ||
binding.rvGroupList.adapter = groupListAdapter | ||
} | ||
|
||
private fun initEvent() { | ||
binding.ivSearch.setOnClickListener { | ||
if (viewModel.isInputBlank) { | ||
toast(getString(R.string.group_search_empty_keyword)) | ||
} else { | ||
viewModel.initCurrentPage() | ||
hideKeyboard(binding.root) | ||
} | ||
} | ||
|
||
binding.ivClear.setOnClickListener { | ||
binding.etSearch.text.clear() | ||
} | ||
|
||
binding.etSearch.setOnFocusChangeListener { _, hasFocus -> | ||
binding.ivClear.isVisible = (hasFocus) | ||
} | ||
} | ||
|
||
private fun observe() { | ||
viewModel.searchData.flowWithLifecycle(lifecycle) | ||
.onEach { | ||
binding.clRecommendKeyword.isVisible = it is SearchUiState.Init | ||
binding.rvGroupList.isGone = it is SearchUiState.Init || it is SearchUiState.Empty | ||
binding.clEmpty.isVisible = it is SearchUiState.Empty | ||
when (it) { | ||
is SearchUiState.Success -> { | ||
groupListAdapter.setItems(it.data) | ||
} | ||
|
||
is SearchUiState.Empty -> { | ||
binding.tvEmptyGroupTitle.text = | ||
getString(R.string.group_search_keyword, it.keyword) | ||
} | ||
|
||
else -> {} | ||
} | ||
}.launchIn(lifecycleScope) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/teumteum/teumteum/presentation/group/search/SearchViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.teumteum.teumteum.presentation.group.search | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.teumteum.domain.entity.Meeting | ||
import com.teumteum.domain.repository.GroupRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SearchViewModel @Inject constructor( | ||
private val repository: GroupRepository | ||
) : ViewModel() { | ||
val etSearch = MutableStateFlow("") | ||
|
||
val isInputBlank | ||
get() = etSearch.value.isBlank() | ||
|
||
private var currentPage = 0 | ||
|
||
val keywordList = | ||
listOf<String>("스터디", "독서", "외주", "모여서 각자 일하기", "커리어", "직무 고민", "사이드 프로젝트", "N잡") | ||
|
||
private val _searchData = MutableStateFlow<SearchUiState>(SearchUiState.Init) | ||
val searchData: StateFlow<SearchUiState> = _searchData | ||
|
||
fun initCurrentPage(keyword: String? = null) { | ||
currentPage = 0 | ||
getSearchGroup(keyword) | ||
} | ||
|
||
fun getSearchGroup(keyword: String? = null) { | ||
viewModelScope.launch { | ||
repository.getSearchGroup(currentPage++, keyword ?: etSearch.value) | ||
.onSuccess { | ||
if (it.isEmpty()) { | ||
_searchData.value = SearchUiState.Empty(keyword ?: etSearch.value) | ||
} else { | ||
_searchData.value = SearchUiState.Success(it) | ||
} | ||
}.onFailure { | ||
_searchData.value = SearchUiState.Failure("실패") | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed interface SearchUiState { | ||
object Init : SearchUiState | ||
data class Empty(val keyword: String) : SearchUiState | ||
data class Success(val data: List<Meeting>) : SearchUiState | ||
data class Failure(val msg: String) : SearchUiState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<stroke android:width="1dp" android:color="@color/outline_level03" /> | ||
<corners android:radius="200dp" /> | ||
</shape> |
Oops, something went wrong.