Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use case injection #25

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.omh.android.storage.api

import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.storage.api.domain.repository.FileRepository
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCase

abstract class OmhStorageClient protected constructor(
protected val authClient: OmhAuthClient
Expand All @@ -12,5 +13,13 @@ abstract class OmhStorageClient protected constructor(
fun build(authClient: OmhAuthClient): OmhStorageClient
}

abstract fun getRepository(): FileRepository
protected abstract fun getRepository(): FileRepository

/*
* TODO: This must return an asynchronous task that can be executed with any library
* capable to manage this. In the future, this task must be implemented from auth
HectorNarvaez marked this conversation as resolved.
Show resolved Hide resolved
* and will not return an use case
*/
@SuppressWarnings("ForbiddenComment")
fun listFiles() = GetFilesListWithParentIdUseCase(getRepository())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.omh.android.auth.api.OmhAuthClient
import com.omh.android.auth.api.OmhAuthProvider
import com.omh.android.storage.api.OmhStorageClient
import com.omh.android.storage.api.OmhStorageProvider
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCase
import com.omh.android.storage.sample.BuildConfig
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -39,8 +38,4 @@ class SingletonModule {
fun providesOmhStorageClient(omhAuthClient: OmhAuthClient): OmhStorageClient {
return OmhStorageProvider.provideStorageClient(omhAuthClient)
}

@Provides
fun providesGetFilesListWithParentIdUseCase(omhStorageClient: OmhStorageClient) =
GetFilesListWithParentIdUseCase(omhStorageClient.getRepository())
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.lifecycle.viewModelScope
import com.omh.android.storage.sample.util.LOG_MESSAGE_EVENT
import com.omh.android.storage.sample.util.TAG_VIEW_UPDATE
import com.omh.android.storage.sample.util.launchSafe
import kotlinx.coroutines.CoroutineDispatcher

abstract class BaseViewModel<State : ViewState, Event : ViewEvent> : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.omh.android.storage.sample.presentation.file_viewer

import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCase
import com.omh.android.storage.api.OmhStorageClient
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCaseParams
import com.omh.android.storage.api.domain.usecase.OmhResult
import com.omh.android.storage.sample.di.DefaultDispatcher
import com.omh.android.storage.sample.presentation.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Inject

@HiltViewModel
class FileViewerViewModel @Inject constructor(
private val getFilesListWithParentIdUseCase: GetFilesListWithParentIdUseCase,
private val omhStorageClient: OmhStorageClient
) : BaseViewModel<FileViewerViewState, FileViewerViewEvent>() {

var isGridLayoutManager = true
Expand All @@ -33,9 +31,10 @@ class FileViewerViewModel @Inject constructor(
private suspend fun refreshFileListEvent(parentId: String = "root") {
setState(FileViewerViewState.Loading)

val listFiles = omhStorageClient.listFiles()
Anwera64 marked this conversation as resolved.
Show resolved Hide resolved

when (
val result =
getFilesListWithParentIdUseCase(GetFilesListWithParentIdUseCaseParams(parentId))
val result = listFiles(GetFilesListWithParentIdUseCaseParams(parentId))
) {
is OmhResult.OmhSuccess -> {
setState(FileViewerViewState.Content(result.data.files))
Expand Down