Переглянути джерело

Add Jetpack Compose feature

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 рік тому
батько
коміт
6afa518e2a

+ 11 - 0
app/build.gradle

@@ -223,6 +223,7 @@ android {
         dataBinding true
         viewBinding true
         aidl true
+        compose = true
     }
 
     compileOptions {
@@ -246,6 +247,10 @@ android {
         // Adds exported schema location as test app assets.
         androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
     }
+
+    composeOptions {
+        kotlinCompilerExtensionVersion = "1.5.9"
+    }
 }
 
 dependencies {
@@ -255,6 +260,12 @@ dependencies {
         exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
     }
 
+    // Jetpack Compose
+    implementation(platform("androidx.compose:compose-bom:2024.02.00"))
+    implementation("androidx.compose.ui:ui")
+    implementation("androidx.compose.ui:ui-graphics")
+    implementation("androidx.compose.material3:material3")
+
     compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
     // remove after entire switch to lib v2
     implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2

+ 43 - 0
app/src/main/java/com/nextcloud/client/assistant/AsssistantScreen.kt

@@ -0,0 +1,43 @@
+/*
+ * 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.client.assistant
+
+import androidx.compose.foundation.ExperimentalFoundationApi
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.material3.Scaffold
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+
+@OptIn(ExperimentalFoundationApi::class)
+@Composable
+fun AssistantScreen() {
+    Scaffold {
+        LazyColumn(modifier = Modifier.padding(it)) {
+            stickyHeader {
+                Text(text = "AssistantScreen")
+            }
+
+        }
+    }
+}

+ 26 - 0
app/src/main/java/com/nextcloud/ui/composeFragment/ComposeDestinations.kt

@@ -0,0 +1,26 @@
+/*
+ * 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.composeFragment
+
+enum class ComposeDestinations {
+    AssistantScreen
+}

+ 74 - 0
app/src/main/java/com/nextcloud/ui/composeFragment/ComposeFragment.kt

@@ -0,0 +1,74 @@
+/*
+ * 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.composeFragment
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.compose.ui.platform.ViewCompositionStrategy
+import androidx.fragment.app.Fragment
+import com.nextcloud.client.assistant.AssistantScreen
+import com.nextcloud.utils.extensions.getSerializableArgument
+import com.owncloud.android.databinding.FragmentComposeViewBinding
+
+class ComposeFragment : Fragment() {
+
+    private var _binding: FragmentComposeViewBinding? = null
+
+    private val binding get() = _binding!!
+    private var destination: ComposeDestinations? = null
+
+    companion object {
+        const val destinationKey = "destinationKey"
+    }
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
+    ): View {
+        _binding = FragmentComposeViewBinding.inflate(inflater, container, false)
+        destination = arguments.getSerializableArgument(destinationKey, ComposeDestinations::class.java)
+
+        binding.composeView.apply {
+            setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
+            setContent {
+                when(destination) {
+                    ComposeDestinations.AssistantScreen -> {
+                        AssistantScreen()
+                    }
+                    else -> {
+
+                    }
+                }
+            }
+        }
+
+        return binding.root
+    }
+
+    override fun onDestroyView() {
+        super.onDestroyView()
+        _binding = null
+    }
+}

+ 19 - 6
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -74,6 +74,8 @@ import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.common.NextcloudClient;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.ui.ChooseAccountDialogFragment;
+import com.nextcloud.ui.composeFragment.ComposeDestinations;
+import com.nextcloud.ui.composeFragment.ComposeFragment;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.PassCodeManager;
@@ -404,8 +406,8 @@ public abstract class DrawerActivity extends ToolbarActivity
     }
 
     /**
-     * Open app store page of specified app or search for specified string.
-     * Will attempt to open browser when no app store is available.
+     * Open app store page of specified app or search for specified string. Will attempt to open browser when no app
+     * store is available.
      *
      * @param string packageName or url-encoded search string
      * @param search false -> show app corresponding to packageName; true -> open search for string
@@ -543,7 +545,18 @@ public abstract class DrawerActivity extends ToolbarActivity
             intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
             startActivity(intent);
         } else if (itemId == R.id.nav_assistant) {
-            // TODO ADD JETPACK Compose PAGE
+            // FIXME Back navigation is broken, create general function to switch to Jetpack Compose
+            ComposeFragment composeFragment = new ComposeFragment();
+            Bundle bundle = new Bundle();
+            bundle.putSerializable(ComposeFragment.destinationKey, ComposeDestinations.AssistantScreen);
+            composeFragment.setArguments( bundle);
+
+            getSupportFragmentManager()
+                .beginTransaction()
+                .replace(R.id.left_fragment_container, composeFragment)
+                .commit();
+
+
             Log_OC.w(TAG, "ADD JETPACK Compose PAGE");
         } else {
             if (menuItem.getItemId() >= MENU_ITEM_EXTERNAL_LINK &&
@@ -695,8 +708,8 @@ public abstract class DrawerActivity extends ToolbarActivity
     /**
      * Enable or disable interaction with all drawers.
      *
-     * @param lockMode The new lock mode for the given drawer. One of {@link DrawerLayout#LOCK_MODE_UNLOCKED}, {@link
-     *                 DrawerLayout#LOCK_MODE_LOCKED_CLOSED} or {@link DrawerLayout#LOCK_MODE_LOCKED_OPEN}.
+     * @param lockMode The new lock mode for the given drawer. One of {@link DrawerLayout#LOCK_MODE_UNLOCKED},
+     *                 {@link DrawerLayout#LOCK_MODE_LOCKED_CLOSED} or {@link DrawerLayout#LOCK_MODE_LOCKED_OPEN}.
      */
     public void setDrawerLockMode(int lockMode) {
         if (mDrawerLayout != null) {
@@ -1158,7 +1171,7 @@ public abstract class DrawerActivity extends ToolbarActivity
         return true;
     }
 
-    public AppPreferences getAppPreferences(){
+    public AppPreferences getAppPreferences() {
         return preferences;
     }
 

+ 31 - 0
app/src/main/res/layout/fragment_compose_view.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ 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/>.
+  -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <androidx.compose.ui.platform.ComposeView
+        android:id="@+id/compose_view"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 2
appscan/build.gradle

@@ -10,11 +10,11 @@ apply plugin: 'kotlin-android'
 
 android {
     namespace 'com.nextcloud.appscan'
-    compileSdk 33
+    compileSdk 34
 
     defaultConfig {
         minSdk 21
-        targetSdk 33
+        targetSdk 34
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }

+ 2 - 2
gradle/wrapper/gradle-wrapper.properties

@@ -1,7 +1,7 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
 networkTimeout=10000
 validateDistributionUrl=true
 zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
+zipStorePath=wrapper/dists