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

[REFACTOR] VISIBLE 처리 로직 변경 및 코드 정리 #142

Merged
merged 4 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CommunityFragment :
super.onViewCreated(view, savedInstanceState)
binding.communityViewModel = communityViewModel
binding.lifecycleOwner = viewLifecycleOwner
binding.lifecycleOwner = viewLifecycleOwner
initView()
}

Expand All @@ -41,8 +40,12 @@ class CommunityFragment :
setCommunityAdapter()
setObserver()
setFilterClickObserve()
setSearchClickListener()
setFloatingClickListener()
setInitClickListener()
}

private fun initData() {
communityViewModel.getPostData()
myPageViewModel.getNickName()
}

private fun setCommunityAdapter() {
Expand All @@ -51,7 +54,6 @@ class CommunityFragment :
putExtra(POST_PK, it.id)
})
}
communityAdapter.notifyDataSetChanged()
with(binding) {
rvCommunity.adapter = communityAdapter
rvCommunity.layoutManager = LinearLayoutManager(requireContext())
Expand All @@ -72,23 +74,9 @@ class CommunityFragment :
}
}

private fun initData() {
communityViewModel.getPostData()
myPageViewModel.getNickName()
}

private fun setSearchClickListener() {
binding.ivCommunityMagnifyGlass.setOnClickListener {
val intent = Intent(requireContext(), SearchInputActivity::class.java)
startActivity(intent)
}
}

private fun setFloatingClickListener() {
binding.ivCommunityFloatingButton.setOnClickListener {
val intent = Intent(context, CommunityPostCreateActivity::class.java)
startActivity(intent)
}
private fun setInitClickListener() {
binding.ivCommunityMagnifyGlass.setOnClickListener { SearchInputActivity.start(requireContext()) }
binding.ivCommunityFloatingButton.setOnClickListener { CommunityPostCreateActivity.start(requireContext()) }
}

private fun setFilterClickObserve() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fork.spoonfeed.presentation.ui.community.view

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
Expand All @@ -13,6 +15,7 @@ import com.fork.spoonfeed.presentation.base.BaseViewUtil.BaseCategoryBottomDialo
import com.fork.spoonfeed.presentation.base.BaseViewUtil.BaseCategoryBottomDialogFragment.Companion.FINANCE
import com.fork.spoonfeed.presentation.ui.community.adapter.TabLayoutAdapter
import com.fork.spoonfeed.presentation.ui.community.viewmodel.SearchViewModel
import com.fork.spoonfeed.presentation.ui.policylist.view.PolicyListActivity
import com.fork.spoonfeed.presentation.util.setBackBtnClickListener
import com.fork.spoonfeed.presentation.util.setTextColor
import com.fork.spoonfeed.presentation.util.setTextSize
Expand Down Expand Up @@ -98,5 +101,10 @@ class SearchInputActivity :

companion object {
const val POST_CATEGORY = "com.fork.spoonfeed.presentation.ui.community.view POST_CATEGORY"

fun start(context: Context) {
val intent = Intent(context, SearchInputActivity::class.java)
context.startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fork.spoonfeed.presentation.ui.communitypost.view

import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Typeface
Expand All @@ -22,6 +23,7 @@ import com.fork.spoonfeed.R
import com.fork.spoonfeed.data.remote.model.user.ResponseUserData
import com.fork.spoonfeed.databinding.ActivityCommunityPostCreateBinding
import com.fork.spoonfeed.presentation.base.BaseViewUtil
import com.fork.spoonfeed.presentation.ui.community.view.SearchInputActivity
import com.fork.spoonfeed.presentation.ui.communitypost.viewmodel.CommunityPostCreateViewModel
import com.fork.spoonfeed.presentation.util.dpToPx
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -54,7 +56,7 @@ class CommunityPostCreateActivity :
}
}

fun checkFromInfo(activityResult: ActivityResult): Boolean {
private fun checkFromInfo(activityResult: ActivityResult): Boolean {
return activityResult.data?.getStringExtra(CommunityPostInfoUpdateActivity.INFO_NOT_UPDATE_RESULT_KEY) == null
}

Expand All @@ -73,13 +75,12 @@ class CommunityPostCreateActivity :
setOnClickListener(true, postId)
} else {
setOnClickListener(false, postId)

}
}

private fun setEditObserve() {
with(binding) {
communityPostCreateViewModel.postDetailData.observe(this@CommunityPostCreateActivity, {
communityPostCreateViewModel.postDetailData.observe(this@CommunityPostCreateActivity) {
tvCommunityPostCreateCategory.text = it.category
etCommunityPostCreateTitle.setText(it.title)
etCommunityPostCreateContent.setText(it.content)
Expand All @@ -92,9 +93,9 @@ class CommunityPostCreateActivity :
tvCommunityPostCreateCategory.setTextColor(getColor(R.color.dwelling_blue))
}
val typeFaceBold = Typeface.createFromAsset(assets, "suit_bold.otf")
binding.tvCommunityPostCreateCategory.setTypeface(typeFaceBold)
binding.tvCommunityPostCreateCategory.typeface = typeFaceBold

})
}
}
}

Expand Down Expand Up @@ -128,28 +129,24 @@ class CommunityPostCreateActivity :
}

private fun setObserver() {
communityPostCreateViewModel.category.observe(this, {
communityPostCreateViewModel.category.observe(this) {
communityPostCreateViewModel.isValid()
})
communityPostCreateViewModel.title.observe(this, {
}
communityPostCreateViewModel.title.observe(this) {
communityPostCreateViewModel.isValid()
})
communityPostCreateViewModel.content.observe(this, {
}
communityPostCreateViewModel.content.observe(this) {
communityPostCreateViewModel.isValid()
})
communityPostCreateViewModel.isValid.observe(this, {
}
communityPostCreateViewModel.isValid.observe(this) {
setNextButtonActive(it)
})
communityPostCreateViewModel.sendSuccess.observe(this, {
if (it) {
finish()
}
})
communityPostCreateViewModel.patchSuccess.observe(this, {
if (it) {
finish()
}
})
}
communityPostCreateViewModel.sendSuccess.observe(this) {
if (it) finish()
}
communityPostCreateViewModel.patchSuccess.observe(this) {
if (it) finish()
}
}


Expand Down Expand Up @@ -200,7 +197,6 @@ class CommunityPostCreateActivity :
private fun showMenu() {
val items = resources.getStringArray(R.array.category_popup)

// TODO 텍스트 스타일 적용이 안되는 문제 해결 필요
val popupAdapter =
object : ArrayAdapter<String>(baseContext, R.layout.item_category_popup, items) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
Expand Down Expand Up @@ -243,5 +239,9 @@ class CommunityPostCreateActivity :

companion object {
const val POST_ID = "POSTID"
fun start(context: Context) {
val intent = Intent(context, CommunityPostCreateActivity::class.java)
context.startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MyLikePolicyAdapter(
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyLikePolicyAdapter.MyLikePolicyHomeViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyLikePolicyHomeViewHolder {
if (!::inflater.isInitialized) //변수를 객체로 엑세스하여 객체에 대한 속성 참조
inflater = LayoutInflater.from(parent.context)
val binding = ItemInterastedPolicyBinding.inflate(inflater, parent, false)
Expand All @@ -51,13 +51,11 @@ class MyLikePolicyAdapter(
}

override fun getItemCount() =
if (DEFAULT_COUNT < currentList.size) {
3
} else {
currentList.size
}
if (DEFAULT_COUNT < currentList.size) 3
else currentList.size


override fun onBindViewHolder(holder: MyLikePolicyAdapter.MyLikePolicyHomeViewHolder, position: Int) {
override fun onBindViewHolder(holder: MyLikePolicyHomeViewHolder, position: Int) {
holder.onBind(getItem(position), clickListener)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fork.spoonfeed.presentation.ui.home.view

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
Expand All @@ -17,7 +16,6 @@ import com.fork.spoonfeed.presentation.ui.home.viewmodel.HomeViewModel
import com.fork.spoonfeed.presentation.ui.mypage.view.InterestedPolicyActivity
import com.fork.spoonfeed.presentation.ui.policylist.view.DetailInfoActivity
import com.fork.spoonfeed.presentation.ui.policylist.view.PolicyListActivity
import com.fork.spoonfeed.presentation.util.LinearLayoutManagerWrapper
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -27,6 +25,7 @@ class HomeFragment : BaseViewUtil.BaseFragment<FragmentHomeBinding>(R.layout.fra

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel=homeViewModel
initView()
}

Expand All @@ -39,7 +38,6 @@ class HomeFragment : BaseViewUtil.BaseFragment<FragmentHomeBinding>(R.layout.fra
initClick()
setMyLikePolicyListAdapter()
setMyLikePolicyListObserve()
setMyPolicyListEmptyObserve()
initData()
}

Expand Down Expand Up @@ -71,16 +69,4 @@ class HomeFragment : BaseViewUtil.BaseFragment<FragmentHomeBinding>(R.layout.fra
myLikePolicyAdapter.submitList(myLikePolicyList)
}
}

private fun setMyPolicyListEmptyObserve() {
homeViewModel.isMyLikePolicyListEmpty.observe(viewLifecycleOwner) { isMyLikePolicyListEmpty ->
if (isMyLikePolicyListEmpty) {
binding.rvHomeInterastedPolicyList.visibility = View.GONE
binding.ctlHomeNoInterastedPolicyList.visibility = View.VISIBLE
} else {
binding.ctlHomeNoInterastedPolicyList.visibility = View.GONE
binding.rvHomeInterastedPolicyList.visibility = View.VISIBLE
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HomeViewModel @Inject constructor(
fun getMyLikePolicy() {
viewModelScope.launch {
_myLikePolicyList.value = userRepository.getUserLikePolicy().data.policy
_isMyLikePolicyListEmpty.value = _myLikePolicyList.value!![0].name.isEmpty() == true
_isMyLikePolicyListEmpty.value = _myLikePolicyList.value!!.isEmpty() == true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InterestedPolicyActivity : BaseViewUtil.BaseAppCompatActivity<ActivityInte

companion object {
fun start(context: Context) {
val intent = Intent(context, MyLikePolicyAdapter::class.java)
val intent = Intent(context, InterestedPolicyActivity::class.java)
context.startActivity(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
_myLikePolicyList.value = userRepository.getUserLikePolicy().data.policy
_isMyLikePolicyListEmpty.value =
_myLikePolicyList.value!![0]?.name.isEmpty() == true
_myLikePolicyList.value!!.isEmpty() == true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PolicyListActivity :

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LifeCycleEventLogger(javaClass.name).registerLogger(lifecycle)
binding.policyListViewModel = policyListViewModel
binding.lifecycleOwner = this
initView()
Expand Down Expand Up @@ -90,7 +89,7 @@ class PolicyListActivity :
}

private fun moveToMenu(targetFragment: String) {
startActivity(Intent(baseContext, MainActivity::class.java).apply {
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra(MainActivity.BOTTOM_MOVE, targetFragment)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -115,15 +114,7 @@ class PolicyListActivity :
}
}

/* private fun setFilterCategoryLayout(category: String) {
when (category) {
ALL -> policyMenuAdapter.clickFilter(ALL) //binding.tvPolicylistFilter.text = ALL
DWELLING -> policyMenuAdapter.clickFilter(DWELLING) //binding.tvPolicylistFilter.text = DWELLING
FINANCE -> policyMenuAdapter.clickFilter(FINANCE) //binding.tvPolicylistFilter.text = FINANCE
}
}*/

private fun setPolicyListAdapter() {
private fun setPolicyListAdapter() {
policyListAdapter = PolicyListAdapter(this, policyListViewModel) {
Intent(this, DetailInfoActivity::class.java).apply {
putExtra(DetailInfoActivity.POST_PK, it.id)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_policy_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="32dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="24dp"
android:overScrollMode="never"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

<data>

<import type="android.view.View" />

<variable
name="viewModel"
type="com.fork.spoonfeed.presentation.ui.home.viewmodel.HomeViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -287,7 +292,7 @@
android:id="@+id/ctl_home_no_interasted_policy_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:visibility="@{viewModel.isMyLikePolicyListEmpty ? View.VISIBLE : View.GONE }"
app:layout_constraintBottom_toBottomOf="@+id/iv_interasted_policy_background"
app:layout_constraintEnd_toEndOf="@id/iv_interasted_policy_background"
app:layout_constraintStart_toStartOf="@id/iv_interasted_policy_background"
Expand Down Expand Up @@ -320,6 +325,7 @@
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
android:overScrollMode="never"
android:visibility="@{viewModel.isMyLikePolicyListEmpty ? View.GONE : View.VISIBLE}"
app:layout_constraintBottom_toBottomOf="@id/iv_interasted_policy_background"
app:layout_constraintEnd_toEndOf="@+id/iv_interasted_policy_background"
app:layout_constraintStart_toStartOf="@+id/iv_interasted_policy_background"
Expand Down