Skip to content

Commit

Permalink
[#39] Update integration in Readme and Move to extension settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
karntrehan committed Apr 11, 2023
1 parent 01a53e3 commit 235e637
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 117 deletions.
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ We have also built a bunch of additional features on top of ODK collect:
* **Custom theming on form screens**: This feature allows the module to customize the look and feel
of the forms by providing a settings file that can be used to modify the form screens according to
the user's needs.
* **Callbacks on form submission**: This feature allows the module to receive callbacks when a user
* **Callbacks on form submission**: This feature allows the module to receive callbacks when a
user
submits a form, which can be used to perform custom actions based on the form submission.
* **Configuration to submit results to a custom server**: This feature allows the module to send
form submission results to a custom server, which is useful when integrating with other systems.
Expand All @@ -52,10 +53,19 @@ embed ODK directly into them.

## Integration

### via Module
### Step 1: Setup ODK Central

1. Download
the [ODK module](https://github.com/Samagra-Development/odk-collect-extension/tree/main/odk).
To integrate ODK into your existing Android application you would also need to
setup [ODK Central](https://docs.getodk.org/central-intro/) on
a remote server that would host your ODK forms, manage them and contain submissions from users.

More on ODK Central Installation [here](https://docs.getodk.org/central-install/)

### Step 2: Integrate ODK Extensions

#### via Module

1. Download the [ODK module](/odk).
2. Copy the directory in your project folder.
3. Update your app's `settings.gradle` to include the ODK modules.

Expand Down Expand Up @@ -103,10 +113,41 @@ implementation project(':odk:extension')

5. Build your project

### via Gradle dependency
#### via Gradle dependency

**Coming soon**

### Step 3: Configure ODK

Configure settings for ODK to work for you. Duplicate
the [sample-settings.txt](sample/src/main/res/raw/sample-settings.txt) as `settings.json`
in the same folder with the necessary fields. You can then pass the json file to setup ODK as
follows:

```kotlin
ODKInteractor.setupODK(
settingsJson = IOUtils.toString(resources.openRawResource(R.raw.settings)),
...)
```

Note: Don't forget to remove all the comments in sample-settings.txt

All ODK settings can be
found [here](https://docs.getodk.org/collect-import-export/#list-of-keys-for-all-settings)

All extension configurations are inside the `extension` object.

### Step 4: Add google-services.json

ODK Extension supports downloading all the forms as a zip and extracting them to the correct
location. In the current form the zip is downloaded only if a new zip is created. This is done by
saving the hash of the zip on firebase and comparing with the existing zip hash. Hence we need to
create a project on firebase and add it's google-services.json to our project. Detailed
steps [here](https://alphatech.technology/Blog-Entry-srk/Google-Services-Json-bek/).

We are working on making this
optional [here](https://github.com/Samagra-Development/odk-collect-extension/issues/43).

## Usage

Wiki coming soon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
import org.odk.collect.material.MaterialProgressDialogFragment;
import org.odk.collect.permissions.PermissionListener;
import org.odk.collect.permissions.PermissionsChecker;
import org.odk.collect.settings.keys.ExtensionKeys;
import org.odk.collect.settings.keys.ProjectKeys;
import org.odk.collect.settings.keys.ProtectedProjectKeys;
import org.odk.collect.shared.strings.Md5;
Expand Down Expand Up @@ -415,9 +416,9 @@ public void onCreate(Bundle savedInstanceState) {
buttonHolder = findViewById(R.id.buttonholder);

// WARNING: ODK Custom Change
getWindow().setStatusBarColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
getWindow().setStatusBarColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
initToolbar();
buttonHolder.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_FOOTER_COLOR)));
buttonHolder.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_FOOTER_COLOR)));

formIndexAnimationHandler = new FormIndexAnimationHandler(this);
menuDelegate = new FormEntryMenuDelegate(
Expand All @@ -436,16 +437,16 @@ public void onCreate(Bundle savedInstanceState) {
onSwipeForward();
});
// WARNING: ODK Custom changes
nextButton.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
nextButton.setTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
nextButton.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
nextButton.setTextColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
nextButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
nextButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Drawable nextArrow = nextButton.getCompoundDrawables()[2];
if (nextArrow != null) {
nextArrow.setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
Expand All @@ -458,16 +459,16 @@ public void onGlobalLayout() {
onSwipeBackward();
});
// WARNING: ODK Custom changes
backButton.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
backButton.setTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
backButton.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
backButton.setTextColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
backButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
backButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Drawable backArrow = backButton.getCompoundDrawables()[0];
if (backArrow != null) {
backArrow.setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
Expand Down Expand Up @@ -795,12 +796,12 @@ private int getColor(String hash) {
private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
// WARNING: ODK Custom Change
toolbar.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
Drawable drawable = toolbar.getOverflowIcon();
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setOverflowIcon(drawable);
}
setSupportActionBar(toolbar);
Expand Down Expand Up @@ -1019,7 +1020,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
Drawable menuIcon = menu.getItem(i).getIcon();
if (menuIcon != null) {
menu.getItem(i).getIcon().setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.forms.Form;
import org.odk.collect.forms.instances.Instance;
import org.odk.collect.settings.keys.ExtensionKeys;
import org.odk.collect.settings.keys.ProjectKeys;

import java.util.Arrays;
Expand Down Expand Up @@ -85,15 +86,15 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_chooser_list);
// WARNING: Custom ODK changes
getWindow().setStatusBarColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
getWindow().setStatusBarColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
Drawable drawable = toolbar.getOverflowIcon();
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setOverflowIcon(drawable);
}
}
Expand Down Expand Up @@ -165,7 +166,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
Drawable menuIcon = menu.getItem(i).getIcon();
if (menuIcon != null) {
menu.getItem(i).getIcon().setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.odk.collect.android.utilities.PlayServicesChecker;
import org.odk.collect.androidshared.ui.ToastUtils;
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.settings.keys.ExtensionKeys;
import org.odk.collect.settings.keys.ProjectKeys;

import java.util.Arrays;
Expand Down Expand Up @@ -115,15 +116,15 @@ public void onCreate(Bundle savedInstanceState) {
binding = InstanceUploaderListBinding.inflate(LayoutInflater.from(this));
setContentView(binding.getRoot());
// WARNING: Custom ODK changes
getWindow().setStatusBarColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
getWindow().setStatusBarColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setBackgroundColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
Drawable drawable = toolbar.getOverflowIcon();
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setOverflowIcon(drawable);
}
}
Expand Down Expand Up @@ -270,7 +271,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
Drawable menuIcon = menu.getItem(i).getIcon();
if (menuIcon != null) {
menu.getItem(i).getIcon().setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
getColor(settingsProvider.getExtensionSettings().getString(ExtensionKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ApplicationInitializer(
// This has to happen on the main thread but we might call `initialize` from tests
MapView(context).onCreate(null)
}
OsmDroidInitializer.initialize(userAgentProvider.userAgent)
OsmDroidInitializer.initialize(userAgentProvider.getUserAgent(settingsProvider))
} catch (ignore: Exception) {
// ignored
} catch (ignore: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public ODKView(ComponentActivity context, final FormEntryPrompt[] questionPrompt
viewLifecycle,
new FileRequesterImpl(intentLauncher, externalAppIntentProvider, formController),
new StringRequesterImpl(intentLauncher, externalAppIntentProvider, formController),
formController
);
formController,
settingsProvider);

widgets = new ArrayList<>();
widgetsList = findViewById(R.id.widgets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
import org.odk.collect.settings.SettingsProvider;
import org.odk.collect.settings.importing.ProjectDetailsCreatorImpl;
import org.odk.collect.settings.importing.SettingsChangeHandler;
import org.odk.collect.settings.keys.ExtensionKeys;
import org.odk.collect.settings.keys.MetaKeys;
import org.odk.collect.settings.keys.ProjectKeys;
import org.odk.collect.shared.strings.UUIDGenerator;
Expand Down Expand Up @@ -186,11 +187,11 @@ UserAgentProvider providesUserAgent() {

@Provides
@Singleton
public OpenRosaHttpInterface provideHttpInterface(MimeTypeMap mimeTypeMap, UserAgentProvider userAgentProvider) {
public OpenRosaHttpInterface provideHttpInterface(MimeTypeMap mimeTypeMap, UserAgentProvider userAgentProvider, SettingsProvider settingsProvider) {
return new OkHttpConnection(
new OkHttpOpenRosaServerClientProvider(new OkHttpClient()),
new CollectThenSystemContentTypeMapper(mimeTypeMap),
userAgentProvider.getUserAgent()
userAgentProvider.getUserAgent(settingsProvider)
);
}

Expand Down Expand Up @@ -284,15 +285,17 @@ public QRCodeGenerator providesQRCodeGenerator(Context context) {
}

@Provides
public VersionInformation providesVersionInformation() {
//TODO pass from apps
return new VersionInformation(() -> "1");
public VersionInformation providesVersionInformation(SettingsProvider settingsProvider) {
return new VersionInformation(() -> settingsProvider.getExtensionSettings().getString(ExtensionKeys.APP_VERSION));
}

@Provides
public FileProvider providesFileProvider(Context context) {
//TODO pass from apps
return filePath -> getUriForFile(context, ProjectKeys.APP_PROVIDER + ".provider", new File(filePath));
public FileProvider providesFileProvider(Context context, SettingsProvider settingsProvider) {
return filePath -> getUriForFile(
context,
settingsProvider.getExtensionSettings().getString(ExtensionKeys.APP_PROVIDER) + ".provider",
new File(filePath)
);
}

@Provides
Expand Down Expand Up @@ -328,6 +331,7 @@ public ODKAppSettingsImporter providesODKAppSettingsImporter(Context context, Pr
settingsProvider,
Defaults.getUnprotected(),
Defaults.getProtected(),
Defaults.getExtension(),
asList(context.getResources().getStringArray(R.array.project_colors)),
settingsChangeHandler
);
Expand Down Expand Up @@ -635,8 +639,8 @@ public LocationClient providesFusedLocationClient(Application application) {
}

@Provides
public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
return new MediaUtils(intentLauncher, new ContentUriProvider());
public MediaUtils providesMediaUtils(IntentLauncher intentLauncher, SettingsProvider settingsProvider) {
return new MediaUtils(intentLauncher, new ContentUriProvider(), settingsProvider);
}

@Provides
Expand Down
Loading

0 comments on commit 235e637

Please sign in to comment.