/com.divankits.mvc

Android MVC Framework

Primary LanguageJavaMIT LicenseMIT

Android MVC Framework

Current Version 2.2.0

Samples

  1. Todo List

How to use

  1. Clone a copy of the repo
$ git clone git://Rmanaf/com.divankits.mvc.git
  1. Add module in your project

  2. Create a model and assign view by using "@View" annotation

@View(R.layout.test_view)
public class TestModel extends Model {

    public CharSequence Title = "Test"
    
    public String Description;

    ...

}
  1. Create layout for model
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/title_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    ...
  1. Bind view components to the model fields
@View(R.layout.test_view)
public class TestModel extends Model {

    @Bind(value = R.id.title_txt , set = "setText" , converter = CharSequenceToStringValueConverter.class)
    public String Title;

    /* For custom components :
    
    @Bind(value = R.id.title_txt , set = "method name" , get = "method name" , converter = <ValueConverter>.class)
    public CharSequence Title;

    */
...
  1. Create a controller
public class TestController extends Controller {

    public TestController() {

        setModel(new TestModel())

    }

}
  1. Add a FrameLayout in your main layout
...

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

...
  1. Add controller instance to activity
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new TestController(this , R.id.placeholder);
    }

}

For more information visit Wiki page

License

This project is licensed under the terms of the MIT license