Skip to content

Commit

Permalink
feat(...) : 없는 스터디면 뒤로가라
Browse files Browse the repository at this point in the history
  • Loading branch information
ko0chan committed Apr 7, 2021
1 parent 09bd430 commit 0caf924
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,26 @@ class MyStudyDetailActivity :

binding.topTab.selectTab(binding.topTab.getTabAt(1))

viewModel.getStudy(studyId)

viewModel.studyDetail.observe(this, { studyDetailItem ->
studyInfoItem = studyDetailItem.studyInfoItem
setToolbarTitle(studyInfoItem?.title)

val findFragment = supportFragmentManager.fragments.find { it is NoticeFragment } as NoticeFragment
findFragment.setAuthority(studyInfoItem?.authority.orEmpty())

})

viewModel.toastMessage.observe(this, EventObserver { message ->
toast(message)
setResult(RESULT_OK)
finish()
})
viewModel.run {
getStudy(studyId)
studyDetail.observe(this@MyStudyDetailActivity, { studyDetailItem ->
studyInfoItem = studyDetailItem.studyInfoItem
setToolbarTitle(studyInfoItem?.title)

val findFragment = supportFragmentManager.fragments.find { it is NoticeFragment } as NoticeFragment
findFragment.setAuthority(studyInfoItem?.authority.orEmpty())

})
toastMessage.observe(this@MyStudyDetailActivity, EventObserver { message ->
toast(message)
})
successEvent.observe(this@MyStudyDetailActivity, EventObserver { success ->
if (success) {
setResult(RESULT_OK)
}
finish()
})
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class MyStudyDetailViewModel @Inject constructor(
val studyDetail: LiveData<StudyDetailItem>
get() = _studyDetail

private val _successEvent = MutableLiveData<Event<Boolean>>()
val successEvent: LiveData<Event<Boolean>>
get() = _successEvent

fun getStudy(studyId: Int) {
compositeDisposable += studyRepository
.getStudyDetail(
Expand All @@ -41,9 +45,10 @@ class MyStudyDetailViewModel @Inject constructor(
Logger.d("$it")
}, {
val errorResponse = (it as? HttpException)?.toErrorResponse()
if (errorResponse != null) {
Logger.d("$errorResponse")
}
Logger.d("$errorResponse")
_toastMessage.value = Event(errorResponse?.message.orEmpty())
_successEvent.value = Event(false)

})
}

Expand All @@ -56,6 +61,7 @@ class MyStudyDetailViewModel @Inject constructor(
.subscribe({
delete(studyId)
_toastMessage.value = Event(it.message.orEmpty())
_successEvent.value = Event(true)
Logger.d("$it")
}, {
val errorResponse = (it as? HttpException)?.toErrorResponse()
Expand All @@ -73,6 +79,7 @@ class MyStudyDetailViewModel @Inject constructor(
.subscribe({
deleteAll(studyId)
_toastMessage.value = Event(it.message.orEmpty())
_successEvent.value = Event(true)
Logger.d("$it")
}, {
val errorResponse = (it as? HttpException)?.toErrorResponse()
Expand Down

0 comments on commit 0caf924

Please sign in to comment.