-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4835 from nextcloud/ezaquarii/new-user-model
New user model
- Loading branch information
Showing
16 changed files
with
997 additions
and
161 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/com/nextcloud/client/account/AnonymousUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("", "")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/nextcloud/client/account/RegisteredUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.