Giter Club home page Giter Club logo

android-data-binding-command's Introduction

Android Data Binding Command

Command design pattern implementation for Android Data Binding

Demo

gif2

How to start?

Step 1. Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

Step 2. Add the dependency

	dependencies {
	        compile 'com.github.radzio:android-data-binding-command:1.0.4'
	}

Share this release:

Make sure that you are using Android Data Binding

  • In your main build.gradle you have gradle plugin 1.5.0 or newer:
classpath 'com.android.tools.build:gradle:1.5.0'
  • In your app build.gradle you've enabled databinding:
    dataBinding {
        enabled = true
    }

Add to your code

Modify your layout, add bind:command="@{viewModel.myCommand}"

        <android.support.design.widget.FloatingActionButton
            bind:command="@{viewModel.myCommand}"
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            android:src="@android:drawable/ic_dialog_email"/>

Add in your binding class

    public ICommand myCommand = new Command()
    {
        @Override
        public void execute()
        {
            MainActivityViewModel.this.view.showMessage("Hello from Command!");
        }
    };

Command features

Each command implements ICommand interface

    public interface ICommand extends Observable
    {
        @Bindable
        boolean isEnabled();
    
        void isEnabled(boolean isEnabled);
    
        @Bindable
        boolean isRefreshing();
    
        void isRefreshing(boolean isRefreshing);
    
        void execute();
    }

You can use isEnabled and isRefreshing properties in your java code and xml layouts:

     <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:layout_below="@+id/button"
            bind:command="@{viewModel.enableButtonCommand}"
            android:text="@{viewModel.buttonCommand.enabled ? `Disable Timer` : `Enable Timer`}"
            android:enabled="@{viewModel.buttonCommand.refreshing == false}"
            android:layout_centerHorizontal="true"/>

android-data-binding-command's People

Contributors

radzio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

android-data-binding-command's Issues

Data binding with library

Hey developers, How can I use data binding in my application because I am new to data binding concept ?
I have an application module and one android lib. Module which has all the entites those are used in app module l..
So how can I use data binding in my app with lib. Module..
Which also include dynamic inflation of view based on parameter in some of the entities in library module 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.