diff --git a/app/build.gradle b/app/build.gradle index 89e1efc..ac8ee2f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'com.neenbedankt.android-apt' android { compileSdkVersion 26 @@ -10,6 +11,11 @@ android { versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + javaCompileOptions { + annotationProcessorOptions { + arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] + } + } } buildTypes { release { @@ -28,7 +34,7 @@ dependencies { 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'; + apt "android.arch.persistence.room:compiler:1.0.0-alpha9"; } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index faaad25..04eb050 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,15 +1,16 @@ + package="cy.agorise.crystalwallet"> - + diff --git a/app/src/main/java/carbon/crypto/com/carbon/MainActivity.java b/app/src/main/java/carbon/crypto/com/carbon/MainActivity.java index 42b3035..174a61a 100644 --- a/app/src/main/java/carbon/crypto/com/carbon/MainActivity.java +++ b/app/src/main/java/carbon/crypto/com/carbon/MainActivity.java @@ -3,6 +3,8 @@ package carbon.crypto.com.carbon; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import cy.agorise.crystalwallet.R; + public class MainActivity extends AppCompatActivity { @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java index 41e0d7e..4c833bc 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/IntroActivity.java @@ -3,8 +3,6 @@ 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 diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java index 2d975f0..4d33b2c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -2,7 +2,7 @@ package cy.agorise.crystalwallet.application; import android.app.Application; -import cy.agorise.crystalwallet.dao.DatabaseConnection; +import cy.agorise.crystalwallet.dao.CrystalDatabase; /** * Created by Henry Varona on 6/9/2017. @@ -15,6 +15,7 @@ public class CrystalApplication extends Application { super.onCreate(); //initialize the database - DatabaseConnection.getConnection(this.getApplicationContext()); + CrystalDatabase db = CrystalDatabase.getAppDatabase(this.getApplicationContext()); + db.accountSeedDao().getAll(); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java new file mode 100644 index 0000000..7abbce2 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java @@ -0,0 +1,19 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.AccountSeed; + +/** + * Created by Henry Varona on 10/9/2017. + */ + +@Dao +public interface AccountSeedDao { + + @Query("SELECT * FROM account_seed") + List getAll(); +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java new file mode 100644 index 0000000..11f6dc3 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java @@ -0,0 +1,20 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Created by Henry Varona on 10/9/2017. + */ + +@Dao +public interface CryptoNetAccountDao { + + @Query("SELECT * FROM crypto_net_account") + List getAll(); +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index 31b7445..e7eb916 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.dao; import android.arch.persistence.db.SupportSQLiteDatabase; import android.arch.persistence.room.*; import android.arch.persistence.room.migration.Migration; +import android.content.Context; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoNetAccount; @@ -11,9 +12,25 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount; * Created by Henry Varona on 4/9/2017. */ -@Database(entities = {AccountSeed.class, CryptoNetAccount.class}, version = 2) +@Database(entities = {AccountSeed.class/*, CryptoNetAccount.class*/}, version = 2) public abstract class CrystalDatabase extends RoomDatabase { + private static CrystalDatabase instance; + + public abstract AccountSeedDao accountSeedDao(); + public abstract CryptoNetAccountDao cryptoNetAccountDao(); + + public static CrystalDatabase getAppDatabase(Context context) { + if (instance == null) { + instance = + Room.databaseBuilder(context, + CrystalDatabase.class, "CrystalWallet.db") + .allowMainThreadQueries() + .addMigrations(MIGRATION_1_2) + .build(); + } + return instance; + } static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/DatabaseConnection.java b/app/src/main/java/cy/agorise/crystalwallet/dao/DatabaseConnection.java deleted file mode 100644 index 2d71438..0000000 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/DatabaseConnection.java +++ /dev/null @@ -1,27 +0,0 @@ -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; - } -} diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/AccountSeed.java b/app/src/main/java/cy/agorise/crystalwallet/models/AccountSeed.java index 055195e..f2c67f9 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/AccountSeed.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/AccountSeed.java @@ -5,7 +5,7 @@ import android.arch.persistence.room.*; /** * Created by Henry Varona on 6/9/2017. */ -@Entity +@Entity(tableName = "account_seed") public class AccountSeed { @PrimaryKey(autoGenerate = true) diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java index 58b1b62..694f0d1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -6,7 +6,9 @@ import android.arch.persistence.room.*; * Created by Henry Varona on 6/9/2017. */ -@Entity (foreignKeys = @ForeignKey(entity = AccountSeed.class, +@Entity (tableName = "crypto_net_account", + indices = {@Index("id"),@Index("seed_id")}, + foreignKeys = @ForeignKey(entity = AccountSeed.class, parentColumns = "id", childColumns = "seed_id")) public class CryptoNetAccount { diff --git a/build.gradle b/build.gradle index 9f820f7..6dbbf1f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' - + classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }