Impala - Divanhub

 

Impala

The development repository of Impala is already available on the Github website. As soon as possible we will publish it on the Maven repository for more accessibility purposes; but now, we are getting ready to make things even easier. For this purpose, we are working on an online visual programming application which outputs will use this package as a backbone.

 

What is this article about?

In this package, a controller is intended to handle elements bound together between Layouts and Models, like MVC design pattern. It also supports features like DI (Dependency Injection), Input Validation, and Value Modifiers. Designing mobile applications could be faster and easier as a consequence of pattern we used in "Impala" package.

 

Why or When to use it?

Imagine you have encountered with the design of multiple forms with a couple of inputs. All of them must be validated and map to your data source, and also you want to switch between them due to several events would trigger by multiple services, With regard to that, All of those forms contains animated elements, This package could put your mind at ease. You don't have to stick involved in designing backend.

 

How does it work?

In the following steps, we will reveal that how to use this package in an Android project...

>The first step is initializing Impala in application startup.

```java

import com.github.rmanaf.impala.Impala;

public class MainActivity extends Activity {

...

@Override
protected void onStart(){

super.onStart();

// Initialize Impala
Impala.init(this , R.id.wrapper );
Impala.run(MyController.class);

}

...

}
```
>You have to add wrapper in your activity layout.

```xml

<FrameLayout android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>

```
And also You need a controller
```java

import com.github.rmanaf.impala.core.Controller;

public class MyController extends Controller {

public void Index(){

view("Index" , new MyModel());

}

}
```
>Now its time to design a model that's bound to a layout. Here is a simple model code
```java
import com.github.rmanaf.impala.core.Model;
import com.github.rmanaf.impala.forms.Bind;
import com.github.rmanaf.impala.forms.View;

/**
* attach view to model
*/
@View(R.layout.my_layout)
public class MyModel extends Model {

/**
* bind property to TextView component
* value is component id
* set is setter method name
*/

@Bind(value = R.id.greeting , set = "setText")
public CharSequence greeting = "Hello World!";

}
```
>And at last model layout
```xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/greeting"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</android.support.constraint.ConstraintLayout>
```

That's it, Already this project using Impala to render layouts

 

To read more go to the project wiki page.

Newsletter and Subscribtion

Receive updates and latest news direct from our team. Simply enter your email below :