Skip to content

Commit

Permalink
Merge pull request #101 from FakeDevelopers/feature/BDBD-531
Browse files Browse the repository at this point in the history
FEAT : BaseFragment에 initListener, initCollector 추가
  • Loading branch information
minseonglove authored Feb 16, 2023
2 parents de0796f + 8b0280d commit f0ab3c2
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ abstract class BaseFragment<VB : ViewDataBinding>(
}
}

fun sendSnackBar(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initListener()
initCollector()
}

protected open fun initListener() {
// 호출을 BaseFragment로 위임하기 위한 빈 메소드 입니다.
}

protected open fun initCollector() {
// 호출을 BaseFragment로 위임하기 위한 빈 메소드 입니다.
}

protected fun sendSnackBar(
message: String,
@IntRange(from = -2) length: Int = Snackbar.LENGTH_SHORT,
anchorView: View? = null
Expand All @@ -47,7 +61,7 @@ abstract class BaseFragment<VB : ViewDataBinding>(
}.show()
}

fun navigateActivity(activity: Class<*>) {
protected fun navigateActivity(activity: Class<*>) {
startActivity(Intent(requireContext(), activity))
requireActivity().finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class ChannelListFragment : BaseFragment<FragmentChannelListBinding>(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
initCollector()
initListener()
}

override fun onStart() {
Expand All @@ -49,7 +47,7 @@ class ChannelListFragment : BaseFragment<FragmentChannelListBinding>(
}
}

private fun initCollector() {
override fun initCollector() {
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.streamUserTokenEvent.collectLatest { result ->
Expand All @@ -65,7 +63,7 @@ class ChannelListFragment : BaseFragment<FragmentChannelListBinding>(
}
}

private fun initListener() {
override fun initListener() {
binding.channelListChat.setChannelItemClickListener { channel ->
findNavController().navigate(
ChannelListFragmentDirections.actionChannelListFragmentToChattingFragment(channel.cid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
initListener()
initCollector()
}

private fun initListener() {
override fun initListener() {
binding.textviewLoginRegistration.setOnClickListener {
findNavController().navigate(R.id.action_loginFragment_to_userRegistrationFragment)
}
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.loginEvent.collectLatest { result ->
if (result.isSuccess && result.getOrThrow() == LOGIN_SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ class LoginTypeFragment : BaseFragment<FragmentLoginTypeBinding>(
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
initListener()
initCollector()
}

private fun initListener() {
override fun initListener() {
binding.buttonLogintypeGoogle.setOnClickListener {
googleLogin()
}
Expand All @@ -77,7 +75,7 @@ class LoginTypeFragment : BaseFragment<FragmentLoginTypeBinding>(
}
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.loginWithGoogleEvent.collect { result ->
if (result.isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ class ProductDetailFragment : BaseFragment<FragmentProductDetailBinding>(
adapter = productDetailAdapter
registerOnPageChangeCallback(onPageChanged)
}
initCollector()
initListener()
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.eventFlow.collect { event ->
handleEvent(event)
}
}
}

private fun initListener() {
override fun initListener() {
binding.toolbarProductDetail.buttonToolbarBack.setOnClickListener {
findNavController().popBackStack()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.ArrayAdapter
import android.widget.EditText
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.CallSuper
import androidx.annotation.StringRes
import androidx.core.content.PermissionChecker
import androidx.core.content.PermissionChecker.checkCallingOrSelfPermission
Expand Down Expand Up @@ -79,8 +80,6 @@ abstract class ProductEditorFragment(
if (viewModel.category.isNotEmpty()) {
setCategory(viewModel.category)
}
initListener()
initCollector()
}

override fun onStart() {
Expand Down Expand Up @@ -111,7 +110,8 @@ abstract class ProductEditorFragment(

protected abstract fun initSelectedImages()

protected open fun initListener() {
@CallSuper
override fun initListener() {
// 가격 필터 등록
binding.edittextProductEditorHopePrice.setPriceFilter(MAX_PRICE_LENGTH)
binding.edittextProductEditorOpeningBid.setPriceFilter(MAX_PRICE_LENGTH)
Expand Down Expand Up @@ -170,7 +170,8 @@ abstract class ProductEditorFragment(
}
}

protected open fun initCollector() {
@CallSuper
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.productEditorResponse.collectLatest {
if (it.isSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class AlbumListFragment : BaseFragment<FragmentAlbumListBinding>(
setCompleteTextVisibility(args.selectedImageInfo.uris.size)
}
binding.recyclerAlbumList.itemAnimator = null
initListener()
initCollector()
}

override fun onStart() {
Expand Down Expand Up @@ -88,7 +86,7 @@ class AlbumListFragment : BaseFragment<FragmentAlbumListBinding>(
}
}

private fun initListener() {
override fun initListener() {
binding.toolbarAlbumList.run {
textviewAlbumComplete.setOnClickListener {
toProductEditor(args.selectedImageInfo)
Expand All @@ -112,7 +110,7 @@ class AlbumListFragment : BaseFragment<FragmentAlbumListBinding>(
.attachToRecyclerView(binding.recyclerSelectedPicture)
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.event.collect { event ->
handleEvent(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class AlbumSelectFragment : BaseFragment<FragmentAlbumSelectBinding>(
super.onViewCreated(view, savedInstanceState)
viewModel.initAlbumInfo(getString(R.string.album_select_recent_images))
binding.recyclerAlbumSelect.adapter = adapter
if (args.selectedImageInfo.uris.isNotEmpty()) {
binding.toolbarAlbumSelect.run {
textviewAlbumComplete.isEnabled = true
textviewAlbumComplete.setTextColor(ContextCompat.getColor(requireContext(), R.color.black))
textviewAlbumCount.text = args.selectedImageInfo.uris.size.toString()
}
}
}

override fun initListener() {
val toolbarTitle = getString(R.string.album_select_title, args.title)
binding.toolbarAlbumSelect.textviewAlbumTitle.run {
text = SpannableStringBuilder(toolbarTitle).apply {
Expand Down Expand Up @@ -68,17 +78,9 @@ class AlbumSelectFragment : BaseFragment<FragmentAlbumSelectBinding>(
}
}
}
if (args.selectedImageInfo.uris.isNotEmpty()) {
binding.toolbarAlbumSelect.run {
textviewAlbumComplete.isEnabled = true
textviewAlbumComplete.setTextColor(ContextCompat.getColor(requireContext(), R.color.black))
textviewAlbumCount.text = args.selectedImageInfo.uris.size.toString()
}
}
initCollector()
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.albumInfoEvent.collectLatest {
adapter.submitList(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ class ProductListFragment : BaseFragment<FragmentProductListBinding>(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
initListener()
initCollector()
viewModel.initSearchWord(args.searchWord)
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.isRefreshing.collectLatest { state ->
binding.swipeProductList.isRefreshing = state
Expand All @@ -76,7 +74,7 @@ class ProductListFragment : BaseFragment<FragmentProductListBinding>(
}
}

private fun initListener() {
override fun initListener() {
binding.swipeProductList.setOnRefreshListener {
viewModel.requestProductList(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class ProductSearchFragment : BaseFragment<FragmentProductSearchBinding>(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
initCollector()
initListener()
}

private fun initCollector() {
override fun initCollector() {
repeatOnStarted(viewLifecycleOwner) {
viewModel.searchWord.collectLatest {
findNavController().apply {
Expand All @@ -60,7 +58,7 @@ class ProductSearchFragment : BaseFragment<FragmentProductSearchBinding>(
}
}

private fun initListener() {
override fun initListener() {
viewModel.setSearchBar(args.searchWord)
binding.edittextToolbarSearch.run {
// 키보드 올리기 전에 포커싱을 줘야함
Expand Down
Loading

0 comments on commit f0ab3c2

Please sign in to comment.