Skip to content

Commit

Permalink
Updated to Realm 5.0.0 and Android Studio 3.1
Browse files Browse the repository at this point in the history
Changed package name
Removed unused test folders
  • Loading branch information
chronvas committed Apr 1, 2018
1 parent 29e186d commit 04951e0
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 154 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
Expand All @@ -21,6 +18,7 @@
bin/
gen/
out/
app/release/

# Gradle files
.gradle/
Expand All @@ -43,8 +41,7 @@ captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/libraries
.idea/

# Keystore files
*.jks
12 changes: 4 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.chronvas.realmtesting"
applicationId "com.chronvas.realmtesting"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
Expand All @@ -21,11 +21,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
testCompile 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
}

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chronvas.realmtesting">
package="com.chronvas.realmtesting">

<application
android:name=".app.App"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.chronvas.realmtesting;
package com.chronvas.realmtesting;

import android.os.Bundle;
import android.support.annotation.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.chronvas.realmtesting;
package com.chronvas.realmtesting;

import io.realm.RealmObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.chronvas.realmtesting;
package com.chronvas.realmtesting;

import android.content.res.Resources;
import android.util.Log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.chronvas.realmtesting;
package com.chronvas.realmtesting;

/**
* Created by chronvas on 30/9/2016.
Expand Down
70 changes: 70 additions & 0 deletions app/src/main/java/com/chronvas/realmtesting/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.chronvas.realmtesting.app;

import android.app.Application;

import com.chronvas.realmtesting.R;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import io.realm.Realm;
import io.realm.RealmConfiguration;

public class App extends Application {

private static final String testDbFileName = "testdb.realm";
//Overwrite database on Application startup? - Optional
private static final boolean shouldOverwriteDatabaseOnAppStartup = true;

@Override
public void onCreate() {
super.onCreate();

if (shouldOverwriteDatabaseOnAppStartup) {
copyBundledRealmFile(this.getResources().openRawResource(R.raw.testdb), testDbFileName);
} else {
//check if the db is already in place
if (!fileFound(testDbFileName, this.getFilesDir())) {
copyBundledRealmFile(this.getResources().openRawResource(R.raw.testdb), testDbFileName);
}
}

//Config Realm for the application
Realm.init(this);
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(testDbFileName)
.build();

Realm.setDefaultConfiguration(realmConfiguration);
}

private void copyBundledRealmFile(InputStream inputStream, String outFileName) {
try {
File file = new File(this.getFilesDir(), outFileName);
FileOutputStream outputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, bytesRead);
}
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public boolean fileFound(String name, File file) {
File[] list = file.listFiles();
if (list != null)
for (File fil : list) {
if (fil.isDirectory()) {
fileFound(name, fil);
} else if (name.equalsIgnoreCase(fil.getName())) {
return true;
}
}
return false;
}
}
71 changes: 0 additions & 71 deletions app/src/main/java/com/example/chronvas/realmtesting/app/App.java

This file was deleted.

39 changes: 20 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

android:orientation="vertical"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.chronvas.realmtesting.MainActivity">

android:orientation="vertical"
tools:context="com.chronvas.realmtesting.MainActivity">

<Button
android:paddingTop="8dp"
android:text="Import from Json"
android:id="@+id/importbtn"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/importbtn"
style="@android:style/Widget.Button" />
android:text="Import from Json"
/>

<Button
android:text="count People"
android:id="@+id/count"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/count"
style="@android:style/Widget.Button" />
android:text="count People"
/>

<Button
android:text="Change 1st person's name"
android:id="@+id/changename"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/changename"
style="@android:style/Widget.Button" />
android:text="Change 1st person's name"
/>

<Button
android:text="View 1st person"
android:id="@+id/viewname"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/viewname"
style="@android:style/Widget.Button" />
android:text="View 1st person"
/>
</LinearLayout>

This file was deleted.

5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ buildscript {
maven { url "https://maven.google.com" }
mavenCentral()
mavenLocal()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "io.realm:realm-gradle-plugin:4.3.1"
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "io.realm:realm-gradle-plugin:5.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit 04951e0

Please sign in to comment.