Skip to content
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
57 changes: 57 additions & 0 deletions src/main/java/com/nextcloud/client/account/AnonymousUser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account

import android.accounts.Account
import android.content.Context
import android.net.Uri
import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
import java.net.URI

/**
* This object represents anonymous user, ie. user that did not log in the Nextcloud server.
* It serves as a semantically correct "empty value", allowing simplification of logic
* in various components requiring user data, such as DB queries.
*/
internal class AnonymousUser(private val accountType: String) : User {

companion object {
@JvmStatic
fun fromContext(context: Context): AnonymousUser {
val type = context.getString(R.string.account_type)
return AnonymousUser(type)
}
}

override val accountName: String = "anonymous"
override val server = Server(URI.create(""), MainApp.MINIMUM_SUPPORTED_SERVER_VERSION)

override fun toPlatformAccount(): Account {
return Account(accountName, accountType)
}

override fun toOwnCloudAccount(): OwnCloudAccount {
return OwnCloudAccount(Uri.EMPTY, OwnCloudBasicCredentials("", ""))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

import android.accounts.Account;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* This interface provides access to currently selected user Account.
* This interface provides access to currently selected user.
*
* @see UserAccountManager
*/
@FunctionalInterface
public interface CurrentAccountProvider {
/**
* Get currently active account.
* Get currently active account.
*
* @return Currently selected {@link Account} or first valid {@link Account} registered in OS or null, if not available at all.
*/
@Deprecated
@Nullable
Account getCurrentAccount();

/**
* Get currently active user profile. If there is no actice user, anonymous user is returned.
*
* @return User profile. Profile is never null.
*/
@NonNull
default User getUser() {
return new AnonymousUser("dummy");
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/nextcloud/client/account/RegisteredUser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account

import android.accounts.Account
import com.owncloud.android.lib.common.OwnCloudAccount

/**
* This class represents normal user logged into the Nextcloud server.
*/
internal class RegisteredUser(
private val account: Account,
private val ownCloudAccount: OwnCloudAccount,
override val server: Server
) : User {

override val accountName: String get() {
return account.name
}

override fun toPlatformAccount(): Account {
return account
}

override fun toOwnCloudAccount(): OwnCloudAccount {
return ownCloudAccount
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/nextcloud/client/account/Server.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account

import com.owncloud.android.lib.resources.status.OwnCloudVersion
import java.net.URI

/**
* This object provides all information necessary to interact
* with backend server.
*/
data class Server(val uri: URI, val version: OwnCloudVersion)
53 changes: 53 additions & 0 deletions src/main/java/com/nextcloud/client/account/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2019 Chris Narkiewicz
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.account

import android.accounts.Account
import com.owncloud.android.lib.common.OwnCloudAccount

interface User {
val accountName: String
val server: Server

/**
* This is temporary helper method created to facilitate incremental refactoring.
* Code using legacy platform Account can be partially converted to instantiate User
* object and use account instance when required.
*
* This method calls will allow tracing code awaiting further refactoring.
*
* @return Account instance that is associated with this User object.
*/
@Deprecated("Temporary workaround")
fun toPlatformAccount(): Account

/**
* This is temporary helper method created to facilitate incremental refactoring.
* Code using legacy ownCloud account can be partially converted to instantiate User
* object and use account instance when required.
*
* This method calls will allow tracing code awaiting further refactoring.
*
* @return OwnCloudAccount instance that is associated with this User object.
*/
@Deprecated("Temporary workaround")
fun toOwnCloudAccount(): OwnCloudAccount
}
19 changes: 19 additions & 0 deletions src/main/java/com/nextcloud/client/account/UserAccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

import android.accounts.Account;

import com.nextcloud.java.util.Optional;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -51,6 +54,22 @@ public interface UserAccountManager extends CurrentAccountProvider {
@NonNull
Account[] getAccounts();

/**
* Get configured nextcloud user accounts
* @return List of users or empty list, if users are not registered.
*/
@NonNull
List<User> getAllUsers();

/**
* Get user with a specific account name.
*
* @param accountName Account name of the requested user
* @return User or empty optional if user does not exist.
*/
@NonNull
Optional<User> getUser(CharSequence accountName);

/**
* Check if Nextcloud account is registered in {@link android.accounts.AccountManager}
*
Expand Down
Loading