|
| 1 | +/* |
| 2 | + * Nextcloud - Android Client |
| 3 | + * |
| 4 | + * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | +package com.owncloud.android.ui.asynctasks |
| 8 | + |
| 9 | +import androidx.fragment.app.FragmentActivity |
| 10 | +import androidx.lifecycle.lifecycleScope |
| 11 | +import com.nextcloud.android.lib.resources.profile.GetHoverCardRemoteOperation |
| 12 | +import com.nextcloud.client.account.User |
| 13 | +import com.nextcloud.client.network.ClientFactory |
| 14 | +import com.owncloud.android.R |
| 15 | +import com.owncloud.android.lib.common.utils.Log_OC |
| 16 | +import com.owncloud.android.ui.fragment.ProfileBottomSheetDialog |
| 17 | +import com.owncloud.android.utils.DisplayUtils |
| 18 | +import com.owncloud.android.utils.theme.ViewThemeUtils |
| 19 | +import kotlinx.coroutines.Dispatchers |
| 20 | +import kotlinx.coroutines.launch |
| 21 | +import kotlinx.coroutines.withContext |
| 22 | + |
| 23 | +class RetrieveHoverCardAsyncTask( |
| 24 | + private val user: User, |
| 25 | + private val userId: String, |
| 26 | + private val activity: FragmentActivity, |
| 27 | + private val clientFactory: ClientFactory, |
| 28 | + private val viewThemeUtils: ViewThemeUtils |
| 29 | +) { |
| 30 | + companion object { |
| 31 | + private const val TAG = "RetrieveHoverCardAsyncTask" |
| 32 | + } |
| 33 | + |
| 34 | + @Suppress("TooGenericExceptionCaught") |
| 35 | + fun execute() { |
| 36 | + activity.lifecycleScope.launch { |
| 37 | + val result = withContext(Dispatchers.IO) { |
| 38 | + val client = clientFactory.createNextcloudClient(user) |
| 39 | + val operationResult = GetHoverCardRemoteOperation(userId).execute(client) |
| 40 | + return@withContext try { |
| 41 | + if (operationResult.isSuccess) { |
| 42 | + operationResult.getResultData() |
| 43 | + } else { |
| 44 | + null |
| 45 | + } |
| 46 | + } catch (e: Exception) { |
| 47 | + Log_OC.e(TAG, "exception: $e") |
| 48 | + null |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + withContext(Dispatchers.Main) { |
| 53 | + if (result?.actions.isNullOrEmpty()) { |
| 54 | + DisplayUtils.showSnackMessage(activity, R.string.no_actions) |
| 55 | + return@withContext |
| 56 | + } |
| 57 | + |
| 58 | + ProfileBottomSheetDialog( |
| 59 | + activity, |
| 60 | + user, |
| 61 | + result, |
| 62 | + viewThemeUtils |
| 63 | + ) |
| 64 | + .show() |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments