Introduction


DGBootstrap is the library that includes the four basic libraries of the Digipolitan framework, DGFoundation, DGSQL, DGSQLite and DGNetwork. He is made to allow you to develop an application using all our non GUI features (Dependency injection, cache repositories, model factories etc…)


It automatically configure the DependencyInjectorManager to allow the use of SQLite and some other features like the UsageManager (to execute a tast at the first launch or every x launches)



This sample’s purpose is to show you the different steps to create a simple app using DGBootstrap and be ready for your project development.



Android


Prerequisites

Android Studio


Sample

We will create the two main classes defining an Android application, the Application and the Activity and configure the manifest.
Here is a screenshot of our project structure


Getting started Android

Including dependencies

You need to declare the Digipolitan maven repository to be able to resolve maven dependencies. Simply declare it in your project build.gradle file :

		
allprojects {
	repositories {
	jcenter()
		maven {
			url 'http://maven.digipolitan.com/libs-release/' 
		} 
	}
}
		
	

And declare a dependency for DGBootstrap in your app module :

		
dependencies {
	compile 'com.android.support:appcompat-v7:21.0.2'
	compile 'com.digipolitan.libraries:DGBootstrap:1.0'
}
		
	

Here the sample requires appcompat-v7 and DGBootstrap.


Creating the Application

The Application object is the shared Context of your application code, you can override some methods to customize it

		
public class Application extends AbstractApplication{

	@Override
	protected void bootstrap() {
		super.bootstrap();
		// here you can add your own modules to the dependency manager
	}
	
	@Override
	protected void rebootApplication() {
		//called when app is restored from background since getResetDuration() you can tell your restored activity to do some stuff via getCurrentActivity()
	}
	
	@Override
	public long getResetDuration() {
		//you need to override this method to specify the duration(in millis) the app needs to be in background to be reset
		return (long) (DateUtils.MINUTE_TIME_IN_MILLIS * 2.5);
	}
}
		
	

Creating the Activity

You need to override DGAbstractActivity, to be sure that the Application is notified of the current Activity displayed.

		
public class MainActivity extends DGAbstractActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		LogManager.d("Activity Created!");
	}
	
	@Override
	protected int getLayoutRes() {
		return R.layout.activity_main;
	}
}
		
	

Configuring the manifest

Now we need to configure the manifest to declare our application, activity and set the environment

		
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.digipolitan.libraries.bootstrap.bootstrapsample" >
	<application
	android:name=".application.Application"
	android:allowBackup="true"
	android:icon="@drawable/ic_launcher"
	android:label="@string/app_name"
	android:theme="@style/AppTheme" >
		<meta-data android:name="com.digipolitan.libraries.foundation.environment" android:value="@string/environment_type_debug"></meta-data>
	
		<activity
			android:name=".application.activities.MainActivity"
			android:label="@string/app_name" >
		
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>
	</application>
</manifest>
		
	

If you launch the app you should see an entry in the LogCat :

  com.digipolitan.libraries.bootstrap.bootstrapsample D/[MainActivity][onCreate:14]﹕ Activity Created!


iOS


Cocoapods


1. You can integrate DGBootstrap via CocoaPods, simply declare a dependency to the framework you want in your PodFile. Here is a sample integration for DGBootstrap :

		
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '5.1.1'

pod 'DGBootstrap'
		
	

2. Open the terminal, to browse to your project directory and type

		
pod install
		
	

3. You need to close your project and open the workspace generating by Cocoapod.



Nota : For more information about CocoaPods we suggest you to visit their website : http://cocoapods.org

Drag & Drop

1. You need to download the DGBootstrap framework.


Then you have to drag and drop the framework into your project to use it.



Bootstrap iOS - Step 1


2. You also need to add SystemConfiguration.framework and libsqlite3.dylib into your project

Bootstrap iOS - Step 2



Bootstrap iOS - Step 3 Bootstrap iOS - Step 4




3. Edit your AppDelegate by extending DGBAppDelegate

		
#import <DGBootstrap/DGBAppDelegate.h>

@class UIWindow;

@interface AppDelegate : DGBAppDelegate

@property (strong, nonatomic) UIWindow *window;

@end
		
	

4. You need to implement the method bootApplication into DGBAppDelegate.m

		
- (void) bootApplication {
	/** 
	Put your custom code here.
	For example you can instantiate your custom viewcontroller and attach it to the window.
	*/
}
		
	

5. You need to modify the default implementation of application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

		
- (BOOL) application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions {
	return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
		
	

6. Take a cup of coffee and have FUN