Skip to content

Commit

Permalink
[D83T-66] 스튜디오 일정등록 페이지 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
YHKOO95 committed Mar 3, 2023
1 parent 5a4278b commit 44226f4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.d83t.bpm.presentation.ui.main.home

import android.content.Intent
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.d83t.bpm.presentation.R
import com.d83t.bpm.presentation.base.BaseFragment
import com.d83t.bpm.presentation.databinding.FragmentHomeBinding
import com.d83t.bpm.presentation.ui.main.home.recommend.HomeRecommendFragment
import com.d83t.bpm.presentation.ui.schedule.ScheduleActivity
import com.d83t.bpm.presentation.util.repeatCallDefaultOnStarted
import com.d83t.bpm.presentation.util.showToast
import com.google.android.material.tabs.TabLayout
Expand All @@ -15,6 +19,8 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::inflate) {

private lateinit var scheduleResultLauncher: ActivityResultLauncher<Intent>

override val viewModel: HomeViewModel by viewModels()

private val fragmentList: List<Fragment> by lazy {
Expand All @@ -31,6 +37,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
lifecycleOwner = viewLifecycleOwner
}

scheduleResultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
viewModel.refreshUserSchedule()
}

setUpPager()
}

Expand All @@ -56,11 +67,18 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
HomeViewEvent.ClickSearch -> {
requireContext().showToast("검색페이지 이동")
}
HomeViewEvent.ClickSchedule -> {
goToSchedule()
}
}
}
}
}

private fun goToSchedule() {
scheduleResultLauncher.launch(ScheduleActivity.newIntent(requireContext()))
}

private fun setUpPager() {
binding.pager.adapter = HomePagerAdapter(requireActivity(), fragmentList)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package com.d83t.bpm.presentation.ui.main.home

sealed interface HomeViewEvent {
object ClickSearch : HomeViewEvent
object ClickSchedule : HomeViewEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ class HomeViewModel @Inject constructor(
}
}

fun clickSchedule(){
viewModelScope.launch {
_event.emit(HomeViewEvent.ClickSchedule)
}
}

fun refreshUserSchedule(){
viewModelScope.launch {
_state.emit(HomeState.Init)
}
}

}
1 change: 1 addition & 0 deletions presentation/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:onClick="@{() -> vm.clickSchedule()}"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="@color/gray_02"
app:cardCornerRadius="12dp"
Expand Down

0 comments on commit 44226f4

Please sign in to comment.