|
@@ -26,14 +26,24 @@ import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.platform.ViewCompositionStrategy
|
|
|
import androidx.fragment.app.Fragment
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
|
import com.nextcloud.client.assistant.AssistantScreen
|
|
|
import com.nextcloud.client.assistant.AssistantViewModel
|
|
|
+import com.nextcloud.common.NextcloudClient
|
|
|
+import com.nextcloud.common.User
|
|
|
import com.nextcloud.utils.extensions.getSerializableArgument
|
|
|
import com.owncloud.android.R
|
|
|
import com.owncloud.android.databinding.FragmentComposeViewBinding
|
|
|
+import com.owncloud.android.lib.common.OwnCloudClientFactory
|
|
|
+import com.owncloud.android.lib.common.accounts.AccountUtils
|
|
|
+import com.owncloud.android.lib.common.utils.Log_OC
|
|
|
import com.owncloud.android.ui.fragment.FileFragment
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.withContext
|
|
@@ -71,18 +81,31 @@ class ComposeFragment : FileFragment() {
|
|
|
@Composable
|
|
|
private fun Content(destination: ComposeDestinations?) {
|
|
|
val floatingActionButton: FloatingActionButton = requireActivity().findViewById(R.id.fab_main)
|
|
|
+ var nextcloudClient by remember { mutableStateOf<NextcloudClient?>(null) }
|
|
|
|
|
|
- return when (destination) {
|
|
|
- ComposeDestinations.AssistantScreen -> {
|
|
|
- AssistantScreen(
|
|
|
- viewModel = AssistantViewModel(
|
|
|
- context = requireContext(),
|
|
|
- user = containerActivity.storageManager.user
|
|
|
- ),
|
|
|
- floatingActionButton
|
|
|
- )
|
|
|
- }
|
|
|
- else -> {
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ nextcloudClient = getNextcloudClient()
|
|
|
+ }
|
|
|
+
|
|
|
+ return if (destination == ComposeDestinations.AssistantScreen && nextcloudClient != null) {
|
|
|
+ AssistantScreen(
|
|
|
+ viewModel = AssistantViewModel(
|
|
|
+ client = nextcloudClient!!
|
|
|
+ ),
|
|
|
+ floatingActionButton
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private suspend fun getNextcloudClient(): NextcloudClient? {
|
|
|
+ return withContext(Dispatchers.IO) {
|
|
|
+ try {
|
|
|
+ OwnCloudClientFactory.createNextcloudClient(containerActivity.storageManager.user, requireContext())
|
|
|
+ } catch (e: AccountUtils.AccountNotFoundException) {
|
|
|
+ Log_OC.e(this, "Error caught at init of AssistantRepository", e)
|
|
|
+ null
|
|
|
}
|
|
|
}
|
|
|
}
|