Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagegroovy
themeMidnight
dependencies {
    compile('org.smartregister:opensrp-client-native-form:1.0.0-SNAPSHOT@aar') {
        transitive = true
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }
    compile('org.smartregister:opensrp-client-core:1.0.0-SNAPSHOT@aar') {
        transitive = true
        exclude group: 'com.github.bmelnychuk', module: 'atv'
    }
    compile('org.smartregister:opensrp-client-immunization:1.0.0-SNAPSHOT@aar') {
        transitive = true
    }
    compile ('org.smartregister:opensrp-client-growth-monitoring:1.0.0-SNAPSHOT@aar') {
        transitive = true
    }
...
}
NB: When transitive is set to true, the dependencies of that module will also be included.

Initializing a module

Module that use shared resources, that is, opensrp OpenSRP context (org.smartregister.Context) and database (net.sqlcipher.database.SQLiteOpenHelper) should be initialized when the application starts.

...

The app should have one instance of opensrp of OpenSRP context, which is created by the application and passed to the modules.

Each module that uses shared resources has a Singleton module library class that's used to access the context and database components e.g. org.smartregister.CoreLibrary


To create a unique opensrp unique OpenSRP context in Android android.app.Application class, the the code block below.

...

Code Block
languagejava
themeDJango
public class YourApplication extends DrishtiApplication {
   
	...

	@Override
    public Repository getRepository() {
        try {
            if (repository == null) {
                repository = new YourRepository(getInstance().getApplicationContext(), context());
                
				// Initialize local repositories
 				uniqueIdRepository();
				...
            }
        } catch (UnsatisfiedLinkError e) {
            logError("Error on getRepository: " + e);

        }
        return repository;
    }

	// Initializing a local repository
	public UniqueIdRepository uniqueIdRepository() {
        if (uniqueIdRepository == null) {
            uniqueIdRepository = new UniqueIdRepository((YourRepository) getRepository());
        }
        return uniqueIdRepository;
    }

	// Accessing a module repository
	public VaccineRepository vaccineRepository() {
        return ImmunizationLibrary.getInstance().vaccineRepository();
    }  

...
}
NB: Only initialize local repository. Module repositories are accessed using its library getInstance method.


The table below shows the modules, their shared resources and how they are initialized.

ModuleShared Resources

Initialization

Opensrp ContextDatabase
Corerequired-


Code Block
languagejava
themeDJango
CoreLibrary.init(context());


Native Form--

-

Growth Monitoringrequiredrequired


Code Block
languagejava
themeDJango
GrowthMonitoringLibrary.init(context(), getRepository());  


Immunizationrequiredrequired


Code Block
languagejava
themeDJango
ImmunizationLibrary.init(context(), getRepository(), createCommonFtsObject());  


NB: Native form is not initialized because it does not require the shared resources.


To initialize modules in your Android android.app.Application, checkout the code below.

Code Block
languagejava
themeDJango
public class YourApplication extends DrishtiApplication {
    ...

    @Override
    public void onCreate() {
        super.onCreate();

		...

   		//Initialize Modules
        CoreLibrary.init(context());
        GrowthMonitoringLibrary.init(context(), getRepository());
        ImmunizationLibrary.init(context(), getRepository(), createCommonFtsObject());
    }
...
}

Code CleanUp



Hacks/Tricks/Tweaks

1. Do not include launcher intent filter in your library

...