Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/#163-fix-c…
Browse files Browse the repository at this point in the history
…ategory-item-click
  • Loading branch information
murjune committed Jul 23, 2022
2 parents c9814c8 + a722e71 commit c9c61d3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class NewRuleActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
binding = ActivityNewRuleBinding.inflate(layoutInflater)
setContentView(binding.root)
val categoryName = intent.getStringExtra("categoryName") ?: ""
val categoryId = intent.getStringExtra("categoryId") ?: ""
viewModel.setCategoryName(categoryId, categoryName)
binding.cvNewRuleScreen.setContent {
NewRulesScreen(
viewModel,
Expand All @@ -24,7 +27,7 @@ class NewRuleActivity : AppCompatActivity() {
initStatusBarColor()
}

private fun initStatusBarColor(){
private fun initStatusBarColor() {
window.statusBarColor = getColor(R.color.hous_blue_bg)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class NewRulesViewModel @Inject constructor(
it.ruleName.isNotEmpty() &&
it.categoryName.isNotEmpty() &&
(uiState.value.checkBoxState == State.SELECT || isDayCheck())
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(3000L), false)
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(3000L), false)

init {
viewModelScope.launch {
Expand Down Expand Up @@ -76,14 +77,12 @@ class NewRulesViewModel @Inject constructor(
_uiState.value = _uiState.value.copy(ruleName = rule)
}

fun setCategoryName(
categoryId: String,
category: String
) {
fun setCategoryName(categoryId: String, category: String) {
_uiState.value = _uiState.value.copy(
categoryId = categoryId,
categoryName = category
)
Log.d("viewModel", "$categoryId $category")
}

fun setCheckBoxState(where: String, state: State) {
Expand Down Expand Up @@ -144,7 +143,7 @@ class NewRulesViewModel @Inject constructor(
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
} else {
_uiState.value = _uiState.value.copy(ManagerList = listOf(Manager()))
_uiState.value = _uiState.value.copy(checkBoxState = State.UNSELECT)
setCheckBoxState("deleteManager", State.UNSELECT)
}
}

Expand Down Expand Up @@ -215,18 +214,17 @@ class NewRulesViewModel @Inject constructor(
when (dayData.dayState) {
State.UNSELECT -> {
tempDay.add(DayData(d.day, State.SELECT))
_uiState.value = _uiState.value.copy(checkBoxState = State.BLOCK)
setCheckBoxState("changeDayState Unselect", State.BLOCK)
}
State.SELECT -> {
tempDay.add(DayData(d.day, State.UNSELECT))
if (uiState.value.ManagerList.size == 1) {
var isCheck = false
var isCheck = true
uiState.value.ManagerList[0].dayDataList.forEach { dayData ->
if (dayData.dayState == State.SELECT) isCheck = true
if (dayData.dayState == State.SELECT) isCheck = false
}
if (isCheck && uiState.value.ManagerList[0].managerHomie.userName == "담당자 없음")
_uiState.value =
_uiState.value.copy(checkBoxState = State.UNSELECT)
setCheckBoxState("changeDayState select", State.UNSELECT)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class ProfileFragment : Fragment() {
private val binding get() = _binding!!
private val viewModel: ProfileViewModel by viewModels()

override fun onResume() {
super.onResume()
viewModel.getProfileDate()
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.lifecycle.viewModelScope
import com.hous.hous_aos.data.entity.Homie
import com.hous.hous_aos.data.repository.ProfileRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlinx.coroutines.launch

@HiltViewModel
class ProfileViewModel @Inject constructor(
Expand All @@ -18,6 +18,10 @@ class ProfileViewModel @Inject constructor(
val profileData get() = _profileData

init {
getProfileDate()
}

fun getProfileDate() {
viewModelScope.launch {
profileRepository.getUserProfile()
.onSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.hous.hous_aos.data.model.response.TempManagerRequest
import com.hous.hous_aos.data.repository.RulesTodayRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import java.util.stream.Collectors.toList
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -55,6 +54,12 @@ class RulesViewModel @Inject constructor(
private var _ruleTableSize = MutableLiveData<Int>(0)
val ruleTableSize get() = _ruleTableSize

private var _categoryName = MutableLiveData("")
val categoryName get() = _categoryName

private var _categoryId = MutableLiveData("")
val categoryId get() = _categoryId

init {
viewModelScope.launch {
rulesTodayRepository.getTodayTodayInfoList("")
Expand Down Expand Up @@ -198,6 +203,8 @@ class RulesViewModel @Inject constructor(
* 카테고리 아이콘 클릭시 Rule Table 받아오기*/
fun fetchToRulesTableList(position: Int) {
val categoryId = categoryOfRuleList.value!![position].id
_categoryName.value = categoryOfRuleList.value!![position].categoryName
_categoryId.value = categoryOfRuleList.value!![position].id
Log.d("RulesViewModel", "categoryId: $categoryId")
viewModelScope.launch {
rulesTodayRepository.getRuleTableInfoList("", categoryId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class RulesTableFragment : Fragment() {
observeRulesTable()
clickPlusButton()
}

private fun initConcatAdapter() {
conCatAdapter = ConcatAdapter(keyRulesAdapter, generalRulesAdapter)
binding.rvRulesTable.adapter = conCatAdapter
Expand All @@ -60,6 +61,8 @@ class RulesTableFragment : Fragment() {
private fun clickPlusButton() {
binding.clPlusRules.setOnClickListener {
val intent = Intent(activity, NewRuleActivity::class.java)
intent.putExtra("categoryName", viewModel.categoryName.value)
intent.putExtra("categoryId", viewModel.categoryId.value)
startActivity(intent)
}
}
Expand Down

0 comments on commit c9c61d3

Please sign in to comment.