增加room模块

This commit is contained in:
zhangyuanzhen
2019-12-31 16:19:49 +08:00
parent 1b029249a1
commit 8340fff2f5
11 changed files with 262 additions and 55 deletions

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.navi" />

View File

@@ -0,0 +1,33 @@
package com.mogo.module.navi.database;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import com.mogo.module.navi.database.bean.POIInfo;
import com.mogo.module.navi.database.dao.POIDao;
/**
* @author zyz
* 2019-08-15.
*/
@Database(entities = { POIInfo.class}, version = 1)
public abstract class AppDataBase extends RoomDatabase {
public abstract POIDao poiDao();
private static volatile AppDataBase INSTANCE;
public static AppDataBase getDatabase(Context context){
if (INSTANCE == null) {
synchronized (AppDataBase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
AppDataBase.class, "android_room_dev.db").build();
}
}
}
return INSTANCE;
}
}

View File

@@ -0,0 +1,64 @@
package com.mogo.module.navi.database.bean;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import org.jetbrains.annotations.NotNull;
/**
* @author zyz
* 2019-08-15.
*/
@Entity
public class POIInfo {
@PrimaryKey
@NotNull
public String pId;
private String name;
private String address;
private double lat;
private double lot;
public POIInfo(String pId, String name, String address, double lat, double lot) {
this.pId = pId;
this.name = name;
this.address = address;
this.lat = lat;
this.lot = lot;
}
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;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLot() {
return lot;
}
public void setLot(double lot) {
this.lot = lot;
}
}

View File

@@ -0,0 +1,32 @@
package com.mogo.module.navi.database.dao;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.mogo.module.navi.database.bean.POIInfo;
import io.reactivex.Flowable;
import java.util.List;
/**
* @author zyz
* 2019-08-15.
*/
@Dao
public interface POIDao {
/**
* 插入地址信息
* @param poiInfos GEO信息
* @return
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
List<Long> insert(POIInfo... poiInfos);
/**
* 获取地址列表
* @return
*/
@Query("SELECT * from poiinfo")
Flowable<List<POIInfo>> load();
}

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">mogo-module-navi</string>
</resources>