Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
adrcotfas committed Jan 21, 2023
1 parent 8cb5fba commit ac6a350
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ class BackupFragment : BottomSheetDialogFragment() {

private fun exportCsv() {
val sessionsLiveData = sessionViewModel.allSessions
sessionsLiveData.observe(viewLifecycleOwner, { sessions: List<Session> ->
sessionsLiveData.observe(viewLifecycleOwner) { sessions: List<Session> ->
if (sessions.isEmpty()) {
Toast.makeText(
requireActivity(),
R.string.backup_no_completed_sessions,
Toast.LENGTH_SHORT
).show()
Toast.makeText(
requireActivity(),
R.string.backup_no_completed_sessions,
Toast.LENGTH_SHORT
).show()
dismiss()
} else {
BackupOperations.doExportToCSV(lifecycleScope, requireContext(), sessions)
}
})
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ class AllSessionsFragment : Fragment(), OnLabelSelectedListener {
val view = binding.root
mRecyclerView = binding.mainRecylcerView
mRecyclerView!!.layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
labelsViewModel.labels.observe(viewLifecycleOwner, { labels: List<Label> ->
labelsViewModel.labels.observe(viewLifecycleOwner) { labels: List<Label> ->
mAdapter = AllSessionsAdapter(labels)
mRecyclerView!!.adapter = mAdapter
labelsViewModel.crtExtendedLabel.observe(
viewLifecycleOwner,
{ refreshCurrentLabel() })
viewLifecycleOwner
) { refreshCurrentLabel() }
mRecyclerView!!.addItemDecoration(
DividerItemDecoration(
activity, LinearLayoutManager.VERTICAL
Expand Down Expand Up @@ -116,45 +116,45 @@ class AllSessionsFragment : Fragment(), OnLabelSelectedListener {
}
})
)
})
}
return view
}

private fun refreshCurrentLabel() {
if (labelsViewModel!!.crtExtendedLabel.value != null && mAdapter != null) {
when (labelsViewModel!!.crtExtendedLabel.value!!.title) {
if (labelsViewModel.crtExtendedLabel.value != null && mAdapter != null) {
when (labelsViewModel.crtExtendedLabel.value!!.title) {
getString(R.string.label_all) -> {
sessionsLiveDataAll.observe(viewLifecycleOwner, { sessions: List<Session> ->
sessionsLiveDataAll.observe(viewLifecycleOwner) { sessions: List<Session> ->
sessionsLiveDataUnlabeled.removeObservers(this)
sessionsLiveDataCrtLabel.removeObservers(this)
mAdapter!!.setData(sessions)
mSessions = sessions
updateRecyclerViewVisibility()
})
}
}
"unlabeled" -> {
sessionsLiveDataUnlabeled.observe(
viewLifecycleOwner,
{ sessions: List<Session> ->
sessionsLiveDataAll.removeObservers(this)
sessionsLiveDataCrtLabel.removeObservers(this)
mAdapter!!.setData(sessions)
mSessions = sessions
updateRecyclerViewVisibility()
})
viewLifecycleOwner
) { sessions: List<Session> ->
sessionsLiveDataAll.removeObservers(this)
sessionsLiveDataCrtLabel.removeObservers(this)
mAdapter!!.setData(sessions)
mSessions = sessions
updateRecyclerViewVisibility()
}
}
else -> {
sessionsLiveDataCrtLabel =
sessionViewModel!!.getSessions(labelsViewModel!!.crtExtendedLabel.value!!.title)
sessionViewModel.getSessions(labelsViewModel.crtExtendedLabel.value!!.title)
sessionsLiveDataCrtLabel.observe(
viewLifecycleOwner,
{ sessions: List<Session> ->
sessionsLiveDataAll.removeObservers(this)
sessionsLiveDataUnlabeled.removeObservers(this)
mAdapter!!.setData(sessions)
mSessions = sessions
updateRecyclerViewVisibility()
})
viewLifecycleOwner
) { sessions: List<Session> ->
sessionsLiveDataAll.removeObservers(this)
sessionsLiveDataUnlabeled.removeObservers(this)
mAdapter!!.setData(sessions)
mSessions = sessions
updateRecyclerViewVisibility()
}
}
}
}
Expand Down Expand Up @@ -188,8 +188,8 @@ class AllSessionsFragment : Fragment(), OnLabelSelectedListener {
if (mSelectedEntries.size == 1) {
val sessionId = mAdapter!!.mSelectedEntries[0]
sessionViewModel.getSession(sessionId).observe(
this@AllSessionsFragment,
{ session: Session? -> mSessionToEdit = session })
this@AllSessionsFragment
) { session: Session? -> mSessionToEdit = session }
}
}
}
Expand Down

0 comments on commit ac6a350

Please sign in to comment.