This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventLiveData extends LiveData<Object> { | |
private final int mSubject; | |
private final LifecycleRegistryOwner mLifecycle; | |
public EventLiveData(@LiveDataBus.Subject int subject, @NonNull LifecycleRegistryOwner lifecycle) { | |
mSubject = subject; | |
mLifecycle = lifecycle; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class LiveDataBus { | |
private static SparseArray<Map<LifecycleRegistryOwner, EventLiveData>> sSubjectMap = new SparseArray<>(); | |
public static final int SUBJECT_DATA_LOADED = 0, SUBJECT_DOWNLOAD_COMPLETE = 1; | |
@Retention(SOURCE) | |
@IntDef({SUBJECT_DATA_LOADED, SUBJECT_DOWNLOAD_COMPLETE}) | |
@interface Subject { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Zoo myZoo = new Zoo(); | |
Animal elephant = new Animal(); | |
Animal giraffe = new Animal(); | |
// To-one relation: Set the Zoo that an animal belongs to and save it to the database | |
elephant.zoo.setTarget(myZoo); | |
animalBox.put(elephant); | |
// To-one relation: Get the Zoo that an animal belongs to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Zoo { | |
@Id | |
private long id; | |
// a Zoo can have many Animals | |
@Backlink | |
ToMany<Animal> animals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BoxStore boxStore = App.getApp().getBoxStore(); | |
Box<Animal> animalBox = boxStore.boxFor(Animal.class); | |
// loads all animals | |
List<Animal> animals = animalBox.getAll(); | |
// find a specific animal in the database | |
long myDogId = 12; | |
Animal myDog = animalBox.get(myDogId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App extends Application { | |
private static App sApp; | |
private BoxStore mBoxStore; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
sApp = this; | |
mBoxStore = MyObjectBox.builder().androidContext(App.this).build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Animal { | |
@Id(assignable = true) | |
private long id; | |
private String name; | |
private boolean flying; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.constraint.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<android.support.constraint.Guideline | |
android:id="@+id/guideline1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
app:layout_constraintGuide_percent="0.25"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.constraint.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TextView | |
android:id="@+id/textView1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
app:layout_constraintLeft_toLeftOf="parent" | |
android:background="@android:color/holo_blue_bright" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<TextView | |
android:id="@+id/textView1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentLeft="true" | |
android:background="@android:color/holo_blue_bright" |