Skip to content

Commit da6d07d

Browse files
committed
wip
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent f35583f commit da6d07d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

app/src/androidTest/java/com/owncloud/android/ui/fragment/UnifiedSearchFragmentIT.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class UnifiedSearchFragmentIT : AbstractIT() {
6767
scenario.onActivity { activity ->
6868
val sut = UnifiedSearchFragment.newInstance(null, null, "/")
6969
val testViewModel = UnifiedSearchViewModel(activity.application)
70+
testViewModel.setCurrentAccountProvider(activity.userAccountManager)
7071
testViewModel.setConnectivityService(activity.connectivityServiceMock)
7172
val localRepository = UnifiedSearchFakeRepository()
7273
testViewModel.setRepository(localRepository)

app/src/main/java/com/owncloud/android/ui/unifiedsearch/UnifiedSearchViewModel.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.owncloud.android.lib.common.utils.Log_OC
2828
import com.owncloud.android.ui.asynctasks.GetRemoteFileTask
2929
import com.owncloud.android.ui.fragment.UnifiedSearchFragmentScreenState
3030
import javax.inject.Inject
31+
import kotlinx.coroutines.CoroutineExceptionHandler
3132
import kotlinx.coroutines.Dispatchers
3233
import kotlinx.coroutines.launch
3334
import kotlinx.coroutines.withContext
@@ -59,6 +60,10 @@ class UnifiedSearchViewModel(application: Application) :
5960
private var results: MutableMap<ProviderID, UnifiedSearchMetadata> = mutableMapOf()
6061
private var searchResultsVersion = 0
6162

63+
private val sectionBuildErrorHandler = CoroutineExceptionHandler { _, throwable ->
64+
Log_OC.e(TAG, "Cannot build search result sections", throwable)
65+
}
66+
6267
override val screenState: MutableLiveData<UnifiedSearchFragmentScreenState> =
6368
MutableLiveData(UnifiedSearchFragmentScreenState.ShowingContent)
6469
override val isLoading = MutableLiveData(false)
@@ -208,7 +213,7 @@ class UnifiedSearchViewModel(application: Application) :
208213

209214
val version = ++searchResultsVersion
210215

211-
viewModelScope.launch(Dispatchers.IO) {
216+
viewModelScope.launch(Dispatchers.IO + sectionBuildErrorHandler) {
212217
val sections = buildSections(snapshot)
213218

214219
withContext(Dispatchers.Main) {
@@ -274,6 +279,11 @@ class UnifiedSearchViewModel(application: Application) :
274279
this.connectivityService = connectivityService
275280
}
276281

282+
@VisibleForTesting
283+
fun setCurrentAccountProvider(currentAccountProvider: CurrentAccountProvider) {
284+
this.currentAccountProvider = currentAccountProvider
285+
}
286+
277287
override fun updateScreenState(state: UnifiedSearchFragmentScreenState) {
278288
screenState.value = state
279289
}

0 commit comments

Comments
 (0)