Skip to content

Commit

Permalink
refactor: removed account parameter and init block from `DrawerVi…
Browse files Browse the repository at this point in the history
…ewModel` to avoid null account
  • Loading branch information
joragua committed Jan 9, 2025
1 parent ed52ffb commit 79d71a2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,18 @@ import kotlinx.coroutines.launch
import timber.log.Timber

class DrawerViewModel(
getStoredQuotaAsStreamUseCase: GetStoredQuotaAsStreamUseCase,
private val getStoredQuotaAsStreamUseCase: GetStoredQuotaAsStreamUseCase,
private val removeAccountUseCase: RemoveAccountUseCase,
private val getUserQuotasUseCase: GetUserQuotasUseCase,
private val localStorageProvider: LocalStorageProvider,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val contextProvider: ContextProvider,
accountName: String,
) : ViewModel() {

private val _userQuota = MutableStateFlow<Event<UIResult<Flow<UserQuota?>>>?>(null)
val userQuota: StateFlow<Event<UIResult<Flow<UserQuota?>>>?> = _userQuota

init {
fun getUserQuota(accountName: String) {
runUseCaseWithResult(
coroutineDispatcher = coroutinesDispatcherProvider.io,
requiresConnection = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ import timber.log.Timber
*/
abstract class DrawerActivity : ToolbarActivity() {

private val drawerViewModel by viewModel<DrawerViewModel> {
parametersOf(
account?.name
)
}
private val drawerViewModel by viewModel<DrawerViewModel>()
private val capabilitiesViewModel by viewModel<CapabilityViewModel> {
parametersOf(
account?.name
Expand Down Expand Up @@ -460,6 +456,7 @@ abstract class DrawerActivity : ToolbarActivity() {
account = account,
displayRadius = currentAccountAvatarRadiusDimension
)
drawerViewModel.getUserQuota(account.name)
updateQuota()
}
}
Expand Down Expand Up @@ -543,7 +540,6 @@ abstract class DrawerActivity : ToolbarActivity() {
it.isDrawerIndicatorEnabled = true
}
}
updateQuota()
setOnAccountsUpdatedListener()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.owncloud.android.domain.user.usecases.GetStoredQuotaAsStreamUseCase
import com.owncloud.android.domain.user.usecases.GetUserQuotasUseCase
import com.owncloud.android.presentation.common.DrawerViewModel
import com.owncloud.android.providers.ContextProvider
import com.owncloud.android.testutil.OC_ACCOUNT_NAME
import com.owncloud.android.usecases.accounts.RemoveAccountUseCase
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -81,7 +80,6 @@ class DrawerViewModelTest : ViewModelTest() {
localStorageProvider = localStorageProvider,
coroutinesDispatcherProvider = coroutineDispatcherProvider,
contextProvider = contextProvider,
accountName = OC_ACCOUNT_NAME
)
}

Expand Down

0 comments on commit 79d71a2

Please sign in to comment.