Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILEAPPS-2089 #300

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView {

val intent = Intent(
requireActivity(),
Class.forName("com.alfresco.content.browse.processes.ProcessDetailActivity"),
Class.forName("com.alfresco.content.process.ProcessFormActivity"),
)
intent.putExtra(Mavericks.KEY_ARG, processEntry)
startActivity(intent)
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ android {
viewBinding = true
}



compileOptions {
coreLibraryDesugaringEnabled true
}
Expand Down
1 change: 1 addition & 0 deletions browse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation project(':viewer-text')
implementation project(':viewer')
implementation project(':component')
implementation project(':process-app')

implementation libs.alfresco.content
implementation libs.alfresco.process
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ subprojects {
afterEvaluate {
if(it.hasProperty('android')) {
android {
compileSdkVersion 33
compileSdkVersion 34

defaultConfig {
minSdkVersion 24
targetSdkVersion 33
targetSdkVersion 34
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
Expand Down
4 changes: 3 additions & 1 deletion data/src/main/kotlin/com/alfresco/content/data/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class Settings(
if (key != IS_PROCESS_ENABLED_KEY) {
AnalyticsManager().theme(prefs.getString(key, "") ?: "")
}
preferenceChangedFlow.tryEmit(key)
key?.apply {
preferenceChangedFlow.tryEmit(this)
}
}

fun observeChanges() {
Expand Down
21 changes: 20 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ lifecycle = "2.6.1"
navigation = "2.6.0"
okhttp = "4.11.0"
test = "1.5.0"
activity-compose = "1.7.0"
compose-bom = "2023.03.00"


moshi = "1.15.0"
retrofit = "2.9.0"

[libraries]
alfresco-auth = "com.alfresco.android:auth:0.8.1-SNAPSHOT"
Expand Down Expand Up @@ -100,6 +106,8 @@ kotlinx-coroutines-test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.2"
leakcanary = "com.squareup.leakcanary:leakcanary-android:2.7"

mavericks = "com.airbnb.android:mavericks:3.0.3"
mavericks-compose = "com.airbnb.android:mavericks-compose:3.0.3"
mavericks-navigation = "com.airbnb.android:mavericks-navigation:3.0.3"
mavericks-testing = "com.airbnb.android:mavericks-testing:3.0.3"

mockito-core = "org.mockito:mockito-core:5.4.0"
Expand All @@ -119,4 +127,15 @@ spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.19.0"

subsamplingimageview = "com.davemorrissey.labs:subsampling-scale-image-view:3.10.0"

timber = "com.jakewharton.timber:timber:5.0.1"
timber = "com.jakewharton.timber:timber:5.0.1"
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
ui = { group = "androidx.compose.ui", name = "ui" }
ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
material3 = { group = "androidx.compose.material3", name = "material3" }
navigation-compose = "androidx.navigation:navigation-compose:2.7.5"

1 change: 1 addition & 0 deletions process-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
69 changes: 69 additions & 0 deletions process-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.alfresco.content.process'
compileSdk 33

defaultConfig {
minSdk 26
targetSdk 33
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.4"
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation project(':base')
implementation project(':common')
implementation project(':data')

implementation libs.androidx.core
implementation libs.androidx.appcompat
implementation libs.androidx.lifecycle.runtime
implementation libs.activity.compose
implementation platform(libs.compose.bom)
implementation libs.ui
implementation libs.ui.graphics
implementation libs.ui.tooling.preview
implementation libs.material3

implementation libs.navigation.compose
implementation libs.mavericks.compose

androidTestImplementation platform(libs.compose.bom)
androidTestImplementation libs.ui.test.junit4
debugImplementation libs.ui.tooling
debugImplementation libs.ui.test.manifest

}
11 changes: 11 additions & 0 deletions process-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name=".ProcessFormActivity"
android:configChanges="orientation|screenSize"
android:exported="false"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.alfresco.content.process

import android.content.Context
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksState
import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ResponseListForm
import com.alfresco.content.data.TaskRepository
import com.alfresco.coroutines.asFlow
import kotlinx.coroutines.launch

data class FormViewState(
val parent: ProcessEntry,
val requestStartForm: Async<ResponseListForm> = Uninitialized,
) : MavericksState {
constructor(target: ProcessEntry) : this(parent = target)
}

class FormViewModel(
state: FormViewState,
val context: Context,
private val repository: TaskRepository,
) : MavericksViewModel<FormViewState>(state) {

init {
getStartForm(state.parent)
}

private fun getStartForm(processEntry: ProcessEntry) {
requireNotNull(processEntry.id)
viewModelScope.launch {
repository::startForm.asFlow(processEntry.id).execute {
when (it) {
is Loading -> copy(requestStartForm = Loading())
is Fail -> copy(requestStartForm = Fail(it.error))
is Success -> {
println("form-data == ${it()}")
copy(requestStartForm = Success(it()))
}

else -> {
this
}
}
}
}
}

companion object : MavericksViewModelFactory<FormViewModel, FormViewState> {

override fun create(
viewModelContext: ViewModelContext,
state: FormViewState,
) = FormViewModel(state, viewModelContext.activity(), TaskRepository())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alfresco.content.process

import android.os.Bundle
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.alfresco.content.process.ui.FormFragment

@Composable
fun NavigationComponent(extras: Bundle?) {
val navController = rememberNavController()

Surface(modifier = Modifier.fillMaxSize()) {
NavHost(navController = navController, startDestination = "first_screen") {
composable("first_screen") {
// Replace with the content of your first fragment
FormFragment(navController = navController, extras)
}
// Add more composable entries for other fragments in your navigation graph
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.alfresco.content.process

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.alfresco.content.process.ui.theme.AlfrescoBaseTheme

class ProcessFormActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AlfrescoBaseTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
NavigationComponent(intent.extras)
}
}
}
}
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
AlfrescoBaseTheme {
NavigationComponent(null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.alfresco.content.process.ui

import android.os.Bundle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.airbnb.mvrx.compose.mavericksActivityViewModel
import com.alfresco.content.process.FormViewModel
import com.alfresco.content.process.ui.components.TextInputField

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FormFragment(navController: NavController, extras: Bundle?) {
val context = LocalContext.current
Scaffold(
topBar = {
TopAppBar(
title = {
Text(text = "Form Details")
},
navigationIcon = {
IconButton(onClick = { /* Handle navigation icon click */ }) {
// Add navigation icon here
}
},
actions = {
// Add actions if any
},
)
},
content = { padding ->
FormDetailScreen(padding)
},
)
}

@Composable
fun FormDetailScreen(padding: PaddingValues) {
// This will get or create a ViewModel scoped to the Activity.
val viewModel: FormViewModel = mavericksActivityViewModel()

Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
TextInputField(1)
// Add more Composables here based on your UI requirements
}
}

@Preview
@Composable
fun PreviewProcessDetailScreen() {
FormDetailScreen(PaddingValues(16.dp))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.alfresco.content.process.ui.components

data class ComponentSettings(
val id: String,
val placeHolder: String,
val isRequired: Boolean,
val isReadOnly: Boolean,
val value: String,
val minLength: Int,
val maxLength: Int,
val minValue: String,
val maxValue: String,
val options: ComponentOptions,
)

data class ComponentOptions(
val id: String,
val name: String,
)
Loading
Loading