Browse Source

Rebase master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
7b1c6e4648

+ 97 - 0
app/src/main/java/com/nextcloud/ui/composeComponents/SimpleAlertDialog.kt

@@ -0,0 +1,97 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Alper Ozturk
+ * Copyright (C) 2024 Alper Ozturk
+ * Copyright (C) 2024 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.ui.composeComponents
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
+import com.owncloud.android.R
+
+@Composable
+fun SimpleAlertDialog(
+    backgroundColor: Color,
+    textColor: Color,
+    titleId: Int,
+    description: String?,
+    heightFraction: Float? = null,
+    content: @Composable (() -> Unit)? = null,
+    onComplete: () -> Unit,
+    dismiss: () -> Unit
+) {
+    val modifier = if (heightFraction != null) {
+        Modifier
+            .fillMaxWidth()
+            .fillMaxHeight(heightFraction)
+    } else {
+        Modifier.fillMaxWidth()
+    }
+
+    AlertDialog(
+        containerColor = backgroundColor,
+        onDismissRequest = { dismiss() },
+        title = {
+            Text(text = stringResource(id = titleId), color = textColor)
+        },
+        text = {
+            Column(modifier = modifier) {
+                if (description != null) {
+                    Text(text = description, color = textColor)
+                }
+
+                content?.let {
+                    Spacer(modifier = Modifier.height(16.dp))
+
+                    content()
+                }
+            }
+        },
+        confirmButton = {
+            TextButton(onClick = {
+                onComplete()
+                dismiss()
+            }) {
+                Text(
+                    stringResource(id = R.string.common_ok),
+                    color = textColor
+                )
+            }
+        },
+        dismissButton = {
+            TextButton(onClick = { dismiss() }) {
+                Text(
+                    stringResource(id = R.string.common_cancel),
+                    color = textColor
+                )
+            }
+        }
+    )
+}

+ 26 - 13
app/src/main/java/com/nextcloud/ui/composeFragment/ComposeFragment.kt

@@ -25,13 +25,18 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.LayoutInflater
 import android.view.View
 import android.view.View
 import android.view.ViewGroup
 import android.view.ViewGroup
+import androidx.compose.runtime.Composable
 import androidx.compose.ui.platform.ViewCompositionStrategy
 import androidx.compose.ui.platform.ViewCompositionStrategy
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.Fragment
+import com.google.android.material.floatingactionbutton.FloatingActionButton
 import com.nextcloud.client.assistant.AssistantScreen
 import com.nextcloud.client.assistant.AssistantScreen
 import com.nextcloud.client.assistant.AssistantViewModel
 import com.nextcloud.client.assistant.AssistantViewModel
 import com.nextcloud.utils.extensions.getSerializableArgument
 import com.nextcloud.utils.extensions.getSerializableArgument
+import com.owncloud.android.R
 import com.owncloud.android.databinding.FragmentComposeViewBinding
 import com.owncloud.android.databinding.FragmentComposeViewBinding
 import com.owncloud.android.ui.fragment.FileFragment
 import com.owncloud.android.ui.fragment.FileFragment
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
 
 
 class ComposeFragment : FileFragment() {
 class ComposeFragment : FileFragment() {
 
 
@@ -54,26 +59,34 @@ class ComposeFragment : FileFragment() {
 
 
         binding.composeView.apply {
         binding.composeView.apply {
             setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
             setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
-            setContent {
-                when (destination) {
-                    ComposeDestinations.AssistantScreen -> {
-                        AssistantScreen(
-                            viewModel = AssistantViewModel(
-                                context = requireContext(),
-                                user = containerActivity.storageManager.user
-                            )
-                        )
-                    }
 
 
-                    else -> {
-                    }
-                }
+            setContent {
+                Content(destination)
             }
             }
         }
         }
 
 
         return binding.root
         return binding.root
     }
     }
 
 
+    @Composable
+    private fun Content(destination: ComposeDestinations?) {
+        val floatingActionButton: FloatingActionButton = requireActivity().findViewById(R.id.fab_main)
+
+        return when (destination) {
+            ComposeDestinations.AssistantScreen -> {
+                AssistantScreen(
+                    viewModel = AssistantViewModel(
+                        context = requireContext(),
+                        user = containerActivity.storageManager.user
+                    ),
+                    floatingActionButton
+                )
+            }
+            else -> {
+            }
+        }
+    }
+
     override fun onDestroyView() {
     override fun onDestroyView() {
         super.onDestroyView()
         super.onDestroyView()
         _binding = null
         _binding = null