@@ -17,6 +17,7 @@ import jp.co.yumemi.android.code_check.R
17
17
import jp.co.yumemi.android.code_check.databinding.PageSearchBinding
18
18
import jp.co.yumemi.android.code_check.organisms.repository_list_view.RepositoryListViewAdapter
19
19
import jp.co.yumemi.android.code_check.pages.detail.DetailViewData
20
+ import kotlinx.coroutines.flow.filterNotNull
20
21
import kotlinx.coroutines.launch
21
22
import timber.log.Timber
22
23
import java.io.IOException
@@ -73,39 +74,44 @@ class SearchFragment : Fragment(R.layout.page_search) {
73
74
// ViewModel と表示の結びつけ
74
75
viewLifecycleOwner.lifecycleScope.launch {
75
76
repeatOnLifecycle(Lifecycle .State .STARTED ) {
77
+ launch {
78
+ viewModel.error.filterNotNull().collect { e ->
79
+ when (e) {
80
+ is IllegalArgumentException ,
81
+ is IndexOutOfBoundsException -> NavGraphEntryPointDirections .navShowNotifyDialog(
82
+ title = getString(R .string.page_search_error_title_invalid),
83
+ message = getString(R .string.page_search_error_message_invalid),
84
+ )
85
+
86
+ is IOException -> NavGraphEntryPointDirections .navShowNotifyDialog(
87
+ title = getString(R .string.page_search_error_title_http),
88
+ message = getString(R .string.page_search_error_message_offline),
89
+ )
90
+
91
+ else -> {
92
+ Timber .e(e)
93
+ NavGraphEntryPointDirections .navShowNotifyDialog(
94
+ title = getString(R .string.page_search_error_title_http),
95
+ message = getString(R .string.page_search_error_message_http),
96
+ )
97
+ }
98
+ }.also {
99
+ findNavController().navigate(it)
100
+ viewModel.showedError()
101
+ }
102
+ }
103
+ }
104
+
76
105
launch {
77
106
viewModel.isLoading.collect {
78
107
binding?.pageSearchLoading?.isVisible = it
79
108
}
80
109
}
81
110
82
111
launch {
83
- viewModel.searchResult.collect { result ->
84
- result?.onSuccess {
85
- binding?.pageSearchList?.adapter?.submitList(it)
86
- binding?.pageSearchListEmpty?.isVisible = it.isEmpty()
87
- }?.onFailure { e ->
88
- when (e) {
89
- is IllegalArgumentException ,
90
- is IndexOutOfBoundsException -> NavGraphEntryPointDirections .navShowNotifyDialog(
91
- title = getString(R .string.page_search_error_title_invalid),
92
- message = getString(R .string.page_search_error_message_invalid),
93
- )
94
-
95
- is IOException -> NavGraphEntryPointDirections .navShowNotifyDialog(
96
- title = getString(R .string.page_search_error_title_http),
97
- message = getString(R .string.page_search_error_message_offline),
98
- )
99
-
100
- else -> {
101
- Timber .e(e)
102
- NavGraphEntryPointDirections .navShowNotifyDialog(
103
- title = getString(R .string.page_search_error_title_http),
104
- message = getString(R .string.page_search_error_message_http),
105
- )
106
- }
107
- }.also { findNavController().navigate(it) }
108
- }
112
+ viewModel.repositories.filterNotNull().collect {
113
+ binding?.pageSearchList?.adapter?.submitList(it)
114
+ binding?.pageSearchListEmpty?.isVisible = it.isEmpty()
109
115
}
110
116
}
111
117
}
0 commit comments