-
Notifications
You must be signed in to change notification settings - Fork 92
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 #733 from nextcloud/profile
Profile page
- Loading branch information
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...oidTest/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperationIT.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 Library is available under MIT license | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2021 Tobias Kaminsky | ||
* Copyright (C) 2021 Nextcloud GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
package com.nextcloud.android.lib.resources.profile | ||
|
||
import com.owncloud.android.AbstractIT | ||
import com.owncloud.android.lib.resources.status.GetStatusRemoteOperation | ||
import com.owncloud.android.lib.resources.status.NextcloudVersion.Companion.nextcloud_23 | ||
import com.owncloud.android.lib.resources.status.OwnCloudVersion | ||
import org.junit.Assert | ||
import org.junit.Assume | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.util.ArrayList | ||
|
||
class GetHoverCardRemoteOperationIT : AbstractIT() { | ||
@Before | ||
fun before() { | ||
val result = GetStatusRemoteOperation(context).execute(client) | ||
Assert.assertTrue(result.isSuccess) | ||
val data = result.data as ArrayList<Any> | ||
val ownCloudVersion = data[0] as OwnCloudVersion | ||
Assume.assumeTrue(ownCloudVersion.isNewerOrEqual(nextcloud_23)) | ||
} | ||
|
||
@Test | ||
fun testHoverCard() { | ||
val result = GetHoverCardRemoteOperation(nextcloudClient.userId) | ||
.execute(nextcloudClient) | ||
Assert.assertTrue(result.isSuccess) | ||
val hoverCard = result.resultData | ||
Assert.assertEquals(nextcloudClient.userId, hoverCard?.userId) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/nextcloud/android/lib/resources/profile/Action.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,37 @@ | ||
/* Nextcloud Android Library is available under MIT license | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2021 Tobias Kaminsky | ||
* Copyright (C) 2021 Nextcloud GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
package com.nextcloud.android.lib.resources.profile | ||
|
||
/** | ||
* Action of HoverCard data model | ||
*/ | ||
data class Action( | ||
var appId: String, | ||
var title: String, | ||
var icon: String, | ||
var hyperlink: String | ||
) |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.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,78 @@ | ||
/* Nextcloud Android Library is available under MIT license | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2021 Tobias Kaminsky | ||
* Copyright (C) 2021 Nextcloud GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
package com.nextcloud.android.lib.resources.profile | ||
|
||
import com.google.gson.reflect.TypeToken | ||
import com.nextcloud.common.NextcloudClient | ||
import com.nextcloud.operations.GetMethod | ||
import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
import com.owncloud.android.lib.common.utils.Log_OC | ||
import com.owncloud.android.lib.ocs.ServerResponse | ||
import com.owncloud.android.lib.resources.OCSRemoteOperation | ||
import org.apache.commons.httpclient.HttpStatus | ||
|
||
/** | ||
* Get hoverCard of an user | ||
*/ | ||
class GetHoverCardRemoteOperation(private val userId: String) : OCSRemoteOperation<HoverCard?>() { | ||
@Suppress("TooGenericExceptionCaught") | ||
override fun run(client: NextcloudClient): RemoteOperationResult<HoverCard?> { | ||
var result: RemoteOperationResult<HoverCard?> | ||
var getMethod: GetMethod? = null | ||
try { | ||
getMethod = | ||
GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + userId + JSON_FORMAT, true) | ||
val status = client.execute(getMethod) | ||
if (status == HttpStatus.SC_OK) { | ||
val hoverCard: HoverCard = getServerResponse<ServerResponse<HoverCard>>( | ||
getMethod, | ||
object : TypeToken<ServerResponse<HoverCard>?>() {} | ||
) | ||
.ocs.data | ||
result = RemoteOperationResult(true, getMethod) | ||
result.setResultData(hoverCard) | ||
} else { | ||
result = RemoteOperationResult(false, getMethod) | ||
} | ||
} catch (e: Exception) { | ||
result = RemoteOperationResult(e) | ||
Log_OC.e( | ||
TAG, "Get hoverCard for user " + userId + " failed: " + result.logMessage, | ||
result.exception | ||
) | ||
} finally { | ||
getMethod?.releaseConnection() | ||
} | ||
return result | ||
} | ||
|
||
companion object { | ||
private val TAG = GetHoverCardRemoteOperation::class.java.simpleName | ||
private const val DIRECT_ENDPOINT = "/ocs/v2.php/hovercard/v1/" | ||
private const val JSON_FORMAT = "?format=json" | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/nextcloud/android/lib/resources/profile/HoverCard.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,38 @@ | ||
/* Nextcloud Android Library is available under MIT license | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2021 Tobias Kaminsky | ||
* Copyright (C) 2021 Nextcloud GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
package com.nextcloud.android.lib.resources.profile | ||
|
||
import java.util.ArrayList | ||
|
||
/** | ||
* HoverCard data model | ||
*/ | ||
data class HoverCard( | ||
val userId: String, | ||
val displayName: String, | ||
val actions: List<Action> = ArrayList() | ||
) |