Skip to content

Commit

Permalink
renamed sample & updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham7109 committed Aug 13, 2024
1 parent d68b919 commit d663f99
Show file tree
Hide file tree
Showing 27 changed files with 61 additions and 80 deletions.
30 changes: 0 additions & 30 deletions edit-feature-forms/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions edit-feature-forms/README.metadata.json

This file was deleted.

File renamed without changes.
45 changes: 45 additions & 0 deletions edit-features-using-feature-forms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Edit features using feature forms

Display and edit feature attributes using feature forms

![Image of edit features using feature forms](edit-features-using-feature-forms.png)

## Use case

Feature forms help enhance the accuracy, efficiency, and user experience of attribute editing in your application. Forms can be authored as part of the WebMap using Field Maps Designer or using Web Map Viewer. This allows for a simplified user experience to edit feature attribute data on the web-map.

## How to use the sample

Tap a feature on the feature form map to open a bottom sheet displaying the list of form elements. Select through the list of elements to view the contingent value field groups and edit elements to update the field values. Tap the submit icon to commit the changes on the web map.

## How it works

1. Add a feature form enabled web-map to the MapView using `PortalItem` URL and itemID.
2. When the map is tapped, perform an identity operation to check if the tapped location is an `ArcGISFeature` and the `FeatureLayer.featureFormDefinition` is not null, indicating the feature layer does have an associated feature form definition.
3. Create a `FeatureForm()` object using the identified `ArcGISFeature` and the `FeatureLayer.featureFormDefinition`.
4. On the screen within a bottom sheet, use the `FeatureForm` Toolkit component to display the feature form configuration by providing the created `featureForm` object.
5. Optionally, you can add a `validationErrorVisibility` option to the `FeatureForm` Toolkit component that determines the behavior of when the validation errors are visible.
6. Once edits are added to the form fields, check to verify that there are no validation errors using `featureForm.validationErrors`. The list will be empty if there are no errors.
7. To commit edits on the service geodatabase:
1. Call `featureForm.finishEditing()` to save edits to the database.
2. Retrieve the backing service feature table's geodatabase using `(featureForm.feature.featureTable as? ServiceFeatureTable).serviceGeodatabase`.
3. Verify the service geodatabase can commit changes back to the service using `serviceGeodatabase.serviceInfo?.canUseServiceGeodatabaseApplyEdits`
4. If apply edits are allowed, call `serviceGeodatabase.applyEdits()` to apply local edits to the online service.


## Relevant API

* ArcGISFeature
* FeatureForm
* FeatureLayer
* FieldFormElement
* GroupFormElement
* ServiceFeatureTable

## Additional information

This sample uses the FeatureForm and GeoViewCompose Toolkit modules to be able to implement a Composable MapView which displays a Composable FeatureForm UI.

## Tags

compose, edits, feature, featureforms, form, geoviewcompose, jetpack, toolkit
2 changes: 2 additions & 0 deletions edit-features-using-feature-forms/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
compileSdk = libs.versions.compileSdk.get().toInt()

defaultConfig {
applicationId = "com.esri.arcgismaps.sample.editfeatureforms"
applicationId = "com.esri.arcgismaps.sample.editfeaturesusingfeatureforms"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = libs.versions.versionCode.get().toInt()
Expand All @@ -31,7 +31,7 @@ android {
kotlinCompilerExtensionVersion = libs.versions.kotlinCompilerExt.get()
}

namespace = "com.esri.arcgismaps.sample.editfeatureforms"
namespace = "com.esri.arcgismaps.sample.editfeaturesusingfeatureforms"
}

dependencies {
Expand Down
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
*
*/

package com.esri.arcgismaps.sample.editfeatureforms
package com.esri.arcgismaps.sample.editfeaturesusingfeatureforms

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.editfeatureforms.components.MapViewModel
import com.esri.arcgismaps.sample.editfeatureforms.screens.MainScreen
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components.MapViewModel
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.screens.MainScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme

class MainActivity : ComponentActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/

package com.esri.arcgismaps.sample.editfeatureforms.components
package com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components

import android.app.Application
import android.widget.Toast
Expand Down Expand Up @@ -141,8 +141,8 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
var result = Result.success(Unit)
featureForm.finishEditing().onSuccess {
serviceFeatureTable.serviceGeodatabase?.let { database ->
if (database.serviceInfo?.canUseServiceGeodatabaseApplyEdits == true) {
database.applyEdits().onFailure {
if (serviceGeodatabase.serviceInfo?.canUseServiceGeodatabaseApplyEdits == true) {
serviceGeodatabase.applyEdits().onFailure {
result = Result.failure(it)
}
} else {
Expand Down Expand Up @@ -208,8 +208,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
}?.let {
val feature = it as ArcGISFeature
val layer = feature.featureTable!!.layer as FeatureLayer
val featureForm =
FeatureForm(feature, layer.featureFormDefinition!!)
val featureForm = FeatureForm(feature, layer.featureFormDefinition!!)
// select the feature
layer.selectFeature(feature)
// set the UI to an editing state with the FeatureForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/

package com.esri.arcgismaps.sample.editfeatureforms.screens
package com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.screens

import android.util.Log
import android.widget.Toast
Expand All @@ -28,7 +28,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
Expand All @@ -50,7 +49,6 @@ import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.material3.Typography
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -61,7 +59,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -71,10 +68,10 @@ import com.arcgismaps.toolkit.featureforms.FeatureForm
import com.arcgismaps.toolkit.featureforms.ValidationErrorVisibility
import com.arcgismaps.toolkit.featureforms.theme.FeatureFormDefaults
import com.arcgismaps.toolkit.geoviewcompose.MapView
import com.esri.arcgismaps.sample.editfeatureforms.R
import com.esri.arcgismaps.sample.editfeatureforms.components.ErrorInfo
import com.esri.arcgismaps.sample.editfeatureforms.components.MapViewModel
import com.esri.arcgismaps.sample.editfeatureforms.components.UIState
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.R
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components.ErrorInfo
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components.MapViewModel
import com.esri.arcgismaps.sample.editfeaturesusingfeatureforms.components.UIState
import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -185,7 +182,6 @@ fun MainScreen(mapViewModel: MapViewModel) {
)
)
)

}
}
}
Expand Down

0 comments on commit d663f99

Please sign in to comment.