Skip to content

Instantly share code, notes, and snippets.

@Zhuinden
Created December 22, 2017 13:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Zhuinden/a0913b637e537de540e5485cdba2a9bb to your computer and use it in GitHub Desktop.
Monarchy 2: Mapped
public class MainActivity
extends AppCompatActivity {
MappedDogAdapter mappedDogAdapter;
LiveData<List<Dog>> dogs;
Observer<List<Dog>> observer = dogs -> {
mappedDogAdapter.updateData(dogs);
};
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@Inject
Monarchy monarchy;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mappedDogAdapter = new MappedDogAdapter();
dogs = monarchy.findAllMappedWithChanges(
realm -> realm.where(RealmDog.class),
from -> Dog.create(from.getName()));
dogs.observe(this, observer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment