├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── app ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── layout │ │ │ └── db_activity.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── android │ │ │ └── persistence │ │ │ └── codelab │ │ │ ├── step5_solution │ │ │ ├── PersistenceApplication.java │ │ │ ├── CustomResultUserActivity.java │ │ │ └── CustomResultViewModel.java │ │ │ └── realmdb │ │ │ ├── utils │ │ │ ├── Realm+Dao.kt │ │ │ ├── LiveRealmData.java │ │ │ └── DatabaseInitializer.java │ │ │ ├── Loan.java │ │ │ ├── Book.java │ │ │ ├── User.java │ │ │ ├── UserDao.java │ │ │ ├── LoanDao.java │ │ │ └── BookDao.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── .gitignore ├── .idea ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── misc.xml └── runConfigurations │ └── Step_5___Solution.xml ├── settings.gradle ├── gradle.properties ├── CONTRIBUTING.md ├── gradlew.bat ├── gradlew └── LICENSE /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmaxwell2003/android-persistence/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | build/ 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue May 23 11:24:55 EDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/step5_solution/PersistenceApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.android.persistence.codelab.step5_solution; 2 | 3 | import android.app.Application; 4 | 5 | import io.realm.Realm; 6 | import io.realm.RealmConfiguration; 7 | 8 | public class PersistenceApplication extends Application { 9 | 10 | @Override 11 | public void onCreate() { 12 | super.onCreate(); 13 | Realm.init(this); 14 | Realm.setDefaultConfiguration( 15 | new RealmConfiguration.Builder() 16 | .inMemory() 17 | .build()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':app' 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/utils/Realm+Dao.kt: -------------------------------------------------------------------------------- 1 | @file:JvmName("RealmUtils") // pretty name for utils class if called from 2 | package com.example.android.persistence.codelab.realmdb.utils 3 | 4 | import com.example.android.persistence.codelab.realmdb.BookDao 5 | import com.example.android.persistence.codelab.realmdb.LoanDao 6 | import com.example.android.persistence.codelab.realmdb.UserDao 7 | import io.realm.Realm 8 | import io.realm.RealmModel 9 | import io.realm.RealmResults 10 | 11 | fun Realm.userModel(): UserDao = UserDao(this) 12 | fun Realm.bookModel(): BookDao = BookDao(this) 13 | fun Realm.loanModel(): LoanDao = LoanDao(this) 14 | 15 | fun RealmResults.asLiveData() = LiveRealmData(this) 16 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/google/home/jalc/sw/android-sdks/android-sdk-linux/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #3F51B5 20 | #303F9F 21 | #FF4081 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 16dp 20 | 16dp 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Persistence codelab 19 | Books borrowed by Mike: 20 | Refresh 21 | Young users: 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/utils/LiveRealmData.java: -------------------------------------------------------------------------------- 1 | package com.example.android.persistence.codelab.realmdb.utils; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | 5 | import io.realm.RealmChangeListener; 6 | import io.realm.RealmModel; 7 | import io.realm.RealmResults; 8 | 9 | /** 10 | * Class connecting the Realm lifecycle to that of LiveData objects. 11 | */ 12 | public class LiveRealmData extends LiveData> { 13 | 14 | private RealmResults results; 15 | private final RealmChangeListener> listener = new RealmChangeListener>() { 16 | @Override 17 | public void onChange(RealmResults results) { setValue(results);} 18 | }; 19 | 20 | public LiveRealmData(RealmResults realmResults) { 21 | results = realmResults; 22 | } 23 | 24 | @Override 25 | protected void onActive() { 26 | results.addChangeListener(listener); 27 | } 28 | 29 | @Override 30 | protected void onInactive() { 31 | results.removeChangeListener(listener); 32 | } 33 | 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/Loan.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.realmdb; 18 | 19 | import java.util.Date; 20 | 21 | import io.realm.RealmModel; 22 | import io.realm.annotations.RealmClass; 23 | 24 | @RealmClass 25 | public class Loan implements RealmModel { 26 | 27 | public Date startTime; 28 | public Date endTime; 29 | public Book book; 30 | public User user; 31 | 32 | public Loan() {} 33 | 34 | public Loan(Date startTime, Date endTime, Book book, User user) { 35 | this.startTime = startTime; 36 | this.endTime = endTime; 37 | this.book = book; 38 | this.user = user; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.realmdb; 18 | 19 | 20 | import io.realm.RealmList; 21 | import io.realm.RealmModel; 22 | import io.realm.annotations.PrimaryKey; 23 | import io.realm.annotations.RealmClass; 24 | 25 | @RealmClass 26 | public class Book implements RealmModel { 27 | 28 | @PrimaryKey 29 | public String id; 30 | public String title; 31 | private RealmList loans; 32 | 33 | public Book() {} 34 | 35 | public Book(String id, String title) { 36 | this.id = id; 37 | this.title = title; 38 | } 39 | 40 | public RealmList getLoans() { 41 | return loans; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017, The Android Open Source Project 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # Project-wide Gradle settings. 18 | 19 | # IDE (e.g. Android Studio) users: 20 | # Gradle settings configured through the IDE *will override* 21 | # any settings specified in this file. 22 | 23 | # For more details on how to configure your build environment visit 24 | # http://www.gradle.org/docs/current/userguide/build_environment.html 25 | 26 | # Specifies the JVM arguments used for the daemon process. 27 | # The setting is particularly useful for tweaking memory settings. 28 | org.gradle.jvmargs=-Xmx1536m 29 | 30 | # When configured, Gradle will run in incubating parallel mode. 31 | # This option should only be used with decoupled projects. More details, visit 32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 33 | # org.gradle.parallel=true 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.realmdb; 18 | 19 | import io.realm.RealmList; 20 | import io.realm.RealmModel; 21 | import io.realm.annotations.PrimaryKey; 22 | import io.realm.annotations.RealmClass; 23 | 24 | @RealmClass 25 | public class User implements RealmModel { 26 | 27 | @PrimaryKey 28 | public String id; 29 | public String name; 30 | public String lastName; 31 | public int age; 32 | private RealmList loans; 33 | 34 | public User() {} 35 | 36 | public User(String id, String name, String lastName, int age) { 37 | this.id = id; 38 | this.name = name; 39 | this.lastName = lastName; 40 | this.age = age; 41 | } 42 | 43 | public RealmList getLoans() { 44 | return loans; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 9 | 10 | * If you are an individual writing original source code and you're sure you 11 | own the intellectual property, then you'll need to sign an [individual CLA] 12 | (https://cla.developers.google.com). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then you'll need to sign a [corporate CLA] 15 | (https://cla.developers.google.com). 16 | * Please make sure you sign both, Android and Google CLA 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | 22 | ## Contributing A Patch 23 | 24 | 1. Submit an issue describing your proposed change to the repo in question. 25 | 1. The repo owner will respond to your issue promptly. 26 | 1. If your proposed change is accepted, and you haven't already done so, sign a 27 | Contributor License Agreement (see details above). 28 | 1. Fork the desired repo, develop and test your code changes. 29 | 1. Ensure that your code adheres to the existing style in the sample to which 30 | you are contributing. Refer to the 31 | [Android Code Style Guide] 32 | (https://source.android.com/source/code-style.html) for the 33 | recommended coding standards for this organization. 34 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 35 | 1. Submit a pull request. 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.realmdb; 18 | 19 | import io.realm.Realm; 20 | import io.realm.RealmResults; 21 | 22 | public class UserDao { 23 | 24 | private Realm realm; 25 | 26 | public UserDao(Realm realm) { this.realm = realm; } 27 | 28 | public User createOrUpdate(User user) { 29 | if (user != null) { 30 | user = realm.copyToRealmOrUpdate(user); 31 | } 32 | return user; 33 | } 34 | 35 | /** 36 | * Additional example custom finder methods. Unused by the app currently. 37 | */ 38 | public RealmResults loadAllUsers() { 39 | return realm.where(User.class).findAll(); 40 | } 41 | 42 | public User loadUserById(String id) { 43 | return realm.where(User.class).equalTo("id", id).findFirst(); 44 | } 45 | 46 | public RealmResults findByNameAndLastName(String firstName, String lastName) { 47 | return realm.where(User.class) 48 | .equalTo("name", firstName) 49 | .equalTo("lastName", lastName) 50 | .findAll(); 51 | } 52 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/realmdb/LoanDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.realmdb; 18 | 19 | 20 | import com.example.android.persistence.codelab.realmdb.utils.LiveRealmData; 21 | 22 | import java.util.Date; 23 | 24 | import io.realm.Realm; 25 | 26 | import static com.example.android.persistence.codelab.realmdb.utils.RealmUtils.asLiveData; 27 | 28 | public class LoanDao { 29 | 30 | private Realm mRealm; 31 | 32 | public LoanDao(Realm realm) { this.mRealm = realm; } 33 | 34 | public void addLoan(final Date from, final Date to, final String userId, final String bookId) { 35 | User user = mRealm.where(User.class).equalTo("id", userId).findFirst(); 36 | Book book = mRealm.where(Book.class).equalTo("id", bookId).findFirst(); 37 | Loan loan = new Loan(from, to, book, user); 38 | mRealm.insert(loan); 39 | } 40 | 41 | public LiveRealmData findLoansByNameAfter(final String userName, final Date after) { 42 | return asLiveData(mRealm.where(Loan.class) 43 | .like("user.name", userName) 44 | .greaterThan("endTime", after) 45 | .findAllAsync()); 46 | } 47 | 48 | 49 | /** 50 | * Additional example custom finder methods. Unused by the app currently. 51 | */ 52 | 53 | public LiveRealmData findAllLoans() { 54 | return asLiveData(mRealm.where(Loan.class).findAllAsync()); 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/persistence/codelab/step5_solution/CustomResultUserActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.persistence.codelab.step5_solution; 18 | 19 | import android.arch.lifecycle.LifecycleActivity; 20 | import android.arch.lifecycle.Observer; 21 | import android.arch.lifecycle.ViewModelProviders; 22 | import android.os.Bundle; 23 | import android.support.annotation.Nullable; 24 | import android.view.View; 25 | import android.widget.TextView; 26 | 27 | import com.example.android.codelabs.persistence.R; 28 | 29 | 30 | public class CustomResultUserActivity extends LifecycleActivity { 31 | 32 | private CustomResultViewModel mShowUserViewModel; 33 | private TextView mBooksTextView; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.db_activity); 39 | mBooksTextView = (TextView) findViewById(R.id.books_tv); 40 | 41 | // Android will instantiate my ViewModel for me, and the best part is 42 | // the viewModel will survive configurationChanges! 43 | mShowUserViewModel = ViewModelProviders.of(this).get(CustomResultViewModel.class); 44 | 45 | // We'll observe updates to our LiveData loan string. 46 | mShowUserViewModel.getLoansResult().observe(this, new Observer() { 47 | @Override 48 | public void onChanged(@Nullable final String result) { 49 | mBooksTextView.setText(result); 50 | } 51 | }); 52 | } 53 | 54 | public void onRefreshBtClicked(View view) { 55 | mShowUserViewModel.simulateDataUpdates(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/db_activity.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 25 | 26 | 29 | 30 | 34 | 35 | 36 | 41 | 42 | 47 | 48 |