Trying to make a best practice app #3 — Bleeding edge

Patryk Poborca
AndroidPub
Published in
2 min readJul 23, 2015

So this is just a quick update about design decisions and being stubborn. So in my first post I stated that I was going to implement MVP as my architecture and use the android DataBinding Library to “Find views by ID”

Sadly, this has quickly resulted in several weird compilation errors. Both databinding and Dagger library’s generate at runtime, leading to some awkward scenarios from time to time. Case in point, I setup this nice little base viewmodel Activity/Fragment class, however after brief success the databinding library started to dissapear!

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.LayoutRes;
import android.support.v7.app.AppCompatActivity;

/**
* Created by Patryk on 7/13/2015.
*/
public abstract class BaseViewModelActivity<T extends BaseViewModel, G extends ViewDataBinding> extends AppCompatActivity {


private G mBinding;

@Override
public void onResume() {
super.onResume();
getViewModel().onAttachToView();
}

@Override
public void onPause() {
super.onPause();
getViewModel().onDetachFromView();
}

protected void setBindingView(@LayoutRes int layout){
mBinding = DataBindingUtil.setContentView(this, layout);
}

protected G getBinding(){
return mBinding;
}

public abstract T getViewModel();
}

As you can see, I added a little transparent databinding getter, so that I could easily lookup views by doing

getBinding().someViewWithID.doSomething()

This brings us to my quick post’s topic. Don’t be stubborn. I realized that MVP wasn’t what I wanted to do when I realized that even though it would increase how verbose my project would also slow down my development cycle. So I decided to stick to the tried and true, MVVM, allowing me to explore RxJava better than I otherwise would. With this databinding mess and its unreliability at compile, I have decided that I will fallback on Butterknife.

That’s all folks!

--

--