Room Database implementation
This commit is contained in:
parent
4d6772aa31
commit
19d9924bac
9 changed files with 223 additions and 3 deletions
|
@ -2,10 +2,10 @@ apply plugin: 'com.android.application'
|
|||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "25.0.3"
|
||||
buildToolsVersion "26.0.1"
|
||||
defaultConfig {
|
||||
applicationId "carbon.crypto.com.carbon"
|
||||
minSdkVersion 21
|
||||
applicationId "cy.agorise.crystalwallet"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
@ -27,4 +27,8 @@ dependencies {
|
|||
compile 'com.android.support:appcompat-v7:26.+'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
|
||||
|
||||
compile 'android.arch.persistence.room:runtime:1.0.0-alpha9';
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package cy.agorise.crystalwallet;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import carbon.crypto.com.carbon.R;
|
||||
|
||||
public class IntroActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_intro);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cy.agorise.crystalwallet.application;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import cy.agorise.crystalwallet.dao.DatabaseConnection;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*/
|
||||
|
||||
public class CrystalApplication extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
//initialize the database
|
||||
DatabaseConnection.getConnection(this.getApplicationContext());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cy.agorise.crystalwallet.dao;
|
||||
|
||||
import android.arch.persistence.db.SupportSQLiteDatabase;
|
||||
import android.arch.persistence.room.*;
|
||||
import android.arch.persistence.room.migration.Migration;
|
||||
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 4/9/2017.
|
||||
*/
|
||||
|
||||
@Database(entities = {AccountSeed.class, CryptoNetAccount.class}, version = 2)
|
||||
public abstract class CrystalDatabase extends RoomDatabase {
|
||||
|
||||
|
||||
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE 'account_seed' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ "'name' TEXT, 'master_seed' NUMERIC)");
|
||||
database.execSQL("CREATE TABLE 'crypto_net_account' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ "'seed_id', "
|
||||
+ "'account_number' INT, 'account_index' INT,"
|
||||
+ "FOREIGN_KEY(seed_id) REFERENCES seed(id))");
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cy.agorise.crystalwallet.dao;
|
||||
|
||||
import android.arch.persistence.room.Room;
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*/
|
||||
|
||||
public class DatabaseConnection {
|
||||
private static final DatabaseConnection instance = new DatabaseConnection();
|
||||
private CrystalDatabase db;
|
||||
|
||||
private DatabaseConnection(){
|
||||
}
|
||||
|
||||
public static CrystalDatabase getConnection(Context context){
|
||||
if (instance.db == null){
|
||||
instance.db = Room.databaseBuilder(context,
|
||||
CrystalDatabase.class, "CrystalWallet.db")
|
||||
.addMigrations(CrystalDatabase.MIGRATION_1_2)
|
||||
.build();
|
||||
}
|
||||
|
||||
return instance.db;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cy.agorise.crystalwallet.models;
|
||||
|
||||
import android.arch.persistence.room.*;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*/
|
||||
@Entity
|
||||
public class AccountSeed {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
private int mId;
|
||||
|
||||
@ColumnInfo(name = "name")
|
||||
private String mName;
|
||||
|
||||
@ColumnInfo(name = "master_seed")
|
||||
private String mMasterSeed;
|
||||
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(int id){
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName(String mName) {
|
||||
this.mName = mName;
|
||||
}
|
||||
|
||||
public String getMasterSeed() {
|
||||
return mMasterSeed;
|
||||
}
|
||||
|
||||
public void setMasterSeed(String mMasterSeed) {
|
||||
this.mMasterSeed = mMasterSeed;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package cy.agorise.crystalwallet.models;
|
||||
|
||||
import android.arch.persistence.room.*;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*/
|
||||
|
||||
@Entity (foreignKeys = @ForeignKey(entity = AccountSeed.class,
|
||||
parentColumns = "id",
|
||||
childColumns = "seed_id"))
|
||||
public class CryptoNetAccount {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
private int mId;
|
||||
|
||||
@ColumnInfo(name = "seed_id")
|
||||
private int mSeedId;
|
||||
|
||||
@ColumnInfo(name = "account_number")
|
||||
private int mAccountNumber;
|
||||
|
||||
@ColumnInfo(name = "account_index")
|
||||
private int mAccountIndex;
|
||||
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(int id){
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public int getSeedId() {
|
||||
return mSeedId;
|
||||
}
|
||||
|
||||
public void setSeedId(int mSeedId) {
|
||||
this.mSeedId = mSeedId;
|
||||
}
|
||||
|
||||
public int getAccountNumber() {
|
||||
return mAccountNumber;
|
||||
}
|
||||
|
||||
public void setAccountNumber(int mAccountNumber) {
|
||||
this.mAccountNumber = mAccountNumber;
|
||||
}
|
||||
|
||||
public int getAccountIndex() {
|
||||
return mAccountIndex;
|
||||
}
|
||||
|
||||
public void setAccountIndex(int mAccountIndex) {
|
||||
this.mAccountIndex = mAccountIndex;
|
||||
}
|
||||
}
|
17
app/src/main/res/layout/activity_intro.xml
Normal file
17
app/src/main/res/layout/activity_intro.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/activity_intro"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="cy.agorise.crystalwallet.IntroActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!" />
|
||||
</RelativeLayout>
|
|
@ -15,6 +15,10 @@ buildscript {
|
|||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
// For Room Persistence Library
|
||||
url "https://maven.google.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue