GithubHelp home page GithubHelp logo

fossabot / databinding-watchdog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 4332weizi/databinding-watchdog

0.0 0.0 0.0 715 KB

Interface generator for observable field in android DataBinding.

Java 100.00%

databinding-watchdog's Introduction

DataBinding-Watchdog

Deprecated! Use LiveData instead.

Interface generator and property change binding tool for observable field in android DataBinding.

  • Generate callback interface for observable fields annotated with @WatchThis.
  • Bind callback with onPropertyChanged event.

Download

dependencies {
    compile 'io.auxo.databinding.watchdog:watchdog:2.0.0'
    annotationProcessor 'io.auxo.databinding.watchdog:compiler:2.0.0'
}

Watchdog FOSSA Status

Before

    public class ViewModel{
        public final BaseObservable a = new BaseObservable();
        public final ObservableInt b = new ObservableInt();
        public final ObservableField<String> c = new ObservableField<>();
    }

    public class DemoActivity extends Activity{
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.content);
            ViewModel viewModel = new ViewModel();
            binding.setVariable(BR.data, viewModel);

            initA(viewModel);
            initB(viewModel);
            initC(viewModel);
        }
        protected void initA(ViewModel viewModel){
            viewModel.a.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
                @Override
                public void onPropertyChanged(Observable observable, int i) {

                }
            });
        }
        protected void initB(ViewModel viewModel){
            viewModel.b.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
                @Override
                public void onPropertyChanged(Observable observable, int i) {

                }
            });
        }
        protected void initC(ViewModel viewModel){
            viewModel.c.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
                @Override
                public void onPropertyChanged(Observable observable, int i) {

                }
            });
        }
    }

After

    public class ViewModel {
        @WatchThis(method = "OnAChange")
        public final BaseObservable a = new BaseObservable();
        @WatchThis
        public final ObservableInt b = new ObservableInt();
        @WatchThis
        public final ObservableField<String> c = new ObservableField<>();
    }

    public class DemoActivity extends Activity implements IViewModelCallbacks {
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.content);
            ViewModel viewModel = new ViewModel();
            binding.setVariable(BR.data, viewModel);

            Watchdog.watch(viewModel)
                    .addWatcher(this);
        }
        @Override
        public void OnAChange(BaseObservable observableField, int fieldId) {
        }
        @Override
        public void b(ObservableInt observableField, int fieldId) {
        }
        @Override
        public void c(ObservableField<String> observableField, int fieldId) {
        }
    }

License

FOSSA Status

databinding-watchdog's People

Contributors

4332weizi avatar fossabot avatar

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.