增加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

1
modules/mogo-module-navi/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,42 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":libraries:mogo-map")
implementation project(":libraries:mogo-map-api")
implementation project(":foudations:mogo-utils")
api project(":foudations:mogo-commons")
api project(':services:mogo-service-api')
implementation project(':modules:mogo-module-common')
implementation project(':modules:mogo-module-map')
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
implementation rootProject.ext.dependencies.room
implementation rootProject.ext.dependencies.roomAnnotationProcessor
implementation rootProject.ext.dependencies.roomRxjava
annotationProcessor rootProject.ext.dependencies.aroutercompiler
}

View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

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>