Skip to content

Instantly share code, notes, and snippets.

@mislavs
Created June 14, 2015 12:41
Show Gist options
  • Save mislavs/c12f690a0a46f7f08f42 to your computer and use it in GitHub Desktop.
Save mislavs/c12f690a0a46f7f08f42 to your computer and use it in GitHub Desktop.
Book details activity using the databinding library.
package com.msvs.bookshelf.activities;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.msvs.bookshelf.R;
import com.msvs.bookshelf.databinding.ActivityBookDetailsActivityDataBindingDemoBinding;
import com.msvs.bookshelf.model.entities.Book;
import com.msvs.bookshelf.model.repositories.BooksRepository;
import com.squareup.picasso.Picasso;
public class BookDetailsActivityDataBindingDemo extends AppCompatActivity {
public static final String ARG_BOOK_ID = "detailsBookId";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityBookDetailsActivityDataBindingDemoBinding binding =
DataBindingUtil.setContentView(this,
R.layout.activity_book_details_activity_data_binding_demo);
long mBookId = getIntent().getExtras().getLong(ARG_BOOK_ID);
Book book = BooksRepository.getInstance().getBook(mBookId);
binding.setBook(book);
}
//TODO: move to the BindingUtils class
@BindingAdapter({"bind:imageUrl"})
public static void loadBookCover(ImageView imageView, String url){
Picasso.with(imageView.getContext()).load(url).into(imageView);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment