// Path: app/src/main/java/huyifei/mymvp/datastorage/room/UserDataBase.java
// @Database(entities = {UserEntity.class},version = 1,exportSchema = false)
// public abstract class UserDataBase extends RoomDatabase {
// 
//     private static UserDataBase INSTANCE;
// 
//     public static UserDataBase getINSTANCE(Context context) {
//         if (INSTANCE == null) {
//             INSTANCE = Room.databaseBuilder(context.getApplicationContext(),UserDataBase.class,"user.db").build();
//         }
//         return INSTANCE;
//     }
// 
//     public static void onDestory(){
//         INSTANCE = null;
//     }
// 
//     public abstract UserDao getUserDao();
// }
// 
// Path: app/src/main/java/huyifei/mymvp/datastorage/room/entity/UserEntity.java
// @Entity(tableName = "user")
// public class UserEntity {
// 
// 
//     @PrimaryKey(autoGenerate = true)
//     private int uid;
// 
//     private String name;
//     private String address;
// 
//     public UserEntity(String name, String address) {
//         this.name = name;
//         this.address = address;
//     }
// 
//     public int getUid() {
//         return uid;
//     }
// 
//     public void setUid(int uid) {
//         this.uid = uid;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getAddress() {
//         return address;
//     }
// 
//     public void setAddress(String address) {
//         this.address = address;
//     }
// }


import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import huyifei.mymvp.R;
import huyifei.mymvp.datastorage.room.UserDataBase;
import huyifei.mymvp.datastorage.room.entity.UserEntity;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
package huyifei.mymvp.datastorage;



public class RoomActivity extends AppCompatActivity {

    private static final String TAG = "RoomActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_room);

        Context context = this;

        findViewById(R.id.add).setOnClickListener(v -> {

            Observable.just(new UserEntity("mike", "beijing"))
                    .subscribeOn(Schedulers.io())
                    .subscribe(userEntity -> UserDataBase.getINSTANCE(context).getUserDao().addUser(userEntity));
        });


        findViewById(R.id.getall).setOnClickListener(v -> {
            UserDataBase.getINSTANCE(context).getUserDao().getAllAsync()
                    .subscribe(userEntities -> {
                        Log.e(TAG, "accept: users ="+userEntities.size() );
// Path: app/src/main/java/huyifei/mymvp/datastorage/room/UserDataBase.java
// @Database(entities = {UserEntity.class},version = 1,exportSchema = false)
// public abstract class UserDataBase extends RoomDatabase {
// 
//     private static UserDataBase INSTANCE;
// 
//     public static UserDataBase getINSTANCE(Context context) {
//         if (INSTANCE == null) {
//             INSTANCE = Room.databaseBuilder(context.getApplicationContext(),UserDataBase.class,"user.db").build();
//         }
//         return INSTANCE;
//     }
// 
//     public static void onDestory(){
//         INSTANCE = null;
//     }
// 
//     public abstract UserDao getUserDao();
// }
// 
// Path: app/src/main/java/huyifei/mymvp/datastorage/room/entity/UserEntity.java
// @Entity(tableName = "user")
// public class UserEntity {
// 
// 
//     @PrimaryKey(autoGenerate = true)
//     private int uid;
// 
//     private String name;
//     private String address;
// 
//     public UserEntity(String name, String address) {
//         this.name = name;
//         this.address = address;
//     }
// 
//     public int getUid() {
//         return uid;
//     }
// 
//     public void setUid(int uid) {
//         this.uid = uid;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getAddress() {
//         return address;
//     }
// 
//     public void setAddress(String address) {
//         this.address = address;
//     }
// }


// Path: app/src/main/java/huyifei/mymvp/datastorage/RoomActivity.java
import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import huyifei.mymvp.R;
import huyifei.mymvp.datastorage.room.UserDataBase;
import huyifei.mymvp.datastorage.room.entity.UserEntity;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;

package huyifei.mymvp.datastorage;



public class RoomActivity extends AppCompatActivity {

    private static final String TAG = "RoomActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_room);

        Context context = this;

        findViewById(R.id.add).setOnClickListener(v -> {

            Observable.just(new UserEntity("mike", "beijing"))
                    .subscribeOn(Schedulers.io())
                    .subscribe(userEntity -> UserDataBase.getINSTANCE(context).getUserDao().addUser(userEntity));
        });


        findViewById(R.id.getall).setOnClickListener(v -> {
            UserDataBase.getINSTANCE(context).getUserDao().getAllAsync()
                    .subscribe(userEntities -> {
                        Log.e(TAG, "accept: users ="+userEntities.size() );
                        for (UserEntity userEntity : userEntities) {