Skip to content

Commit

Permalink
Use a more appropriated function to retrieve the accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgardep committed Oct 27, 2021
1 parent 4172ab2 commit e736b18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.owncloud.android.dependecyinjection

import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.authentication.AccountUtils
import com.owncloud.android.data.ClientManager
Expand Down Expand Up @@ -63,7 +64,7 @@ val remoteDataSourceModule = module {
single { OwnCloudAccount(get(), androidContext()) }
single { SingleSessionManager.getDefaultSingleton().getClientFor(get(), androidContext()) }

single { ClientManager(get(), get(), get()) }
single { ClientManager(get(), get(), get(), MainApp.accountType) }

single<CapabilityService> { OCCapabilityService(get()) }
single<FileService> { OCFileService(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import com.owncloud.android.lib.resources.users.services.implementation.OCUserSe
class ClientManager(
private val accountManager: AccountManager,
private val preferencesProvider: SharedPreferencesProvider,
val context: Context
val context: Context,
val accountType: String,
) {
// This client will maintain cookies across the whole login process.
private var ownCloudClient: OwnCloudClient? = null
Expand Down Expand Up @@ -69,14 +70,14 @@ class ClientManager(
val account: Account? = if (accountName.isNullOrBlank()) {
getCurrentAccount()
} else {
accountManager.accounts.firstOrNull { it.name == accountName }
accountManager.getAccountsByType(accountType).firstOrNull { it.name == accountName }
}
val ownCloudAccount = OwnCloudAccount(account, context)
return SingleSessionManager.getDefaultSingleton().getClientFor(ownCloudAccount, context)
}

private fun getCurrentAccount(): Account? {
val ocAccounts = accountManager.accounts
val ocAccounts = accountManager.getAccountsByType(accountType)

val accountName = preferencesProvider.getString(SELECTED_ACCOUNT, null)

Expand Down

0 comments on commit e736b18

Please sign in to comment.