├── .gitignore
├── .idea
└── codeStyleSettings.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── gfx
│ │ └── android
│ │ └── orma_kotlin_example
│ │ ├── App.kt
│ │ ├── BenchmarkFragment.kt
│ │ ├── DataClass.kt
│ │ ├── HandWrittenOpenHelper.kt
│ │ ├── Item.kt
│ │ ├── Location.kt
│ │ ├── MainActivity.kt
│ │ ├── OrmaHolder.kt
│ │ ├── OrmaTodo.kt
│ │ ├── RealmTodo.kt
│ │ └── User.kt
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ ├── fragment_benchmark.xml
│ ├── item.xml
│ └── item_result.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── circle.yml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea/*
5 | !.idea/codeStyleSettings.xml
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
370 |
371 |
372 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Orma-Kotlin-Example [](https://circleci.com/gh/gfx/OrmaWithKotlin)
2 |
3 | Example Kotlin app for [Android Orma](https://github.com/gfx/Android-Orma/issues).
4 |
5 | Note that `OrmaDatabase` can't be handled by Dagger2+kapt because of kapt restrictions, as of Kotlin 1.0.2.
6 |
7 | Use singleton instances instead.
8 |
9 | ## See Also
10 |
11 | * https://github.com/JetBrains/kotlin
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.1.0'
3 | repositories {
4 | jcenter()
5 | }
6 | dependencies {
7 | classpath 'io.realm:realm-gradle-plugin:3.0.0'
8 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
9 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
10 | }
11 | }
12 |
13 | apply plugin: 'com.android.application'
14 | apply plugin: 'kotlin-android'
15 | apply plugin: 'kotlin-android-extensions'
16 | apply plugin: 'kotlin-kapt'
17 | apply plugin: 'realm-android'
18 |
19 | android {
20 | compileSdkVersion 25
21 | buildToolsVersion '25.0.2'
22 | dataBinding.enabled = true
23 | defaultConfig {
24 | applicationId "com.github.gfx.android.orma_example_kotlin"
25 | minSdkVersion 16
26 | targetSdkVersion 25
27 | versionCode 1
28 | versionName '1.0.0'
29 | }
30 | buildTypes {
31 | release {
32 | minifyEnabled false
33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34 | }
35 | }
36 | lintOptions {
37 | abortOnError false
38 | disable 'SetTextI18n'
39 | textReport true
40 | textOutput 'stdout'
41 | }
42 | packagingOptions {
43 | exclude 'META-INF/LICENSE.txt'
44 | exclude 'META-INF/services/javax.annotation.processing.Processor'
45 | }
46 | productFlavors {
47 | }
48 | }
49 |
50 | dependencies {
51 | kapt 'com.github.gfx.android.orma:orma-processor:4.2.1'
52 | compile 'com.github.gfx.android.orma:orma:4.2.1'
53 | kapt 'com.android.databinding:compiler:2.3.0'
54 | compile 'com.android.support:appcompat-v7:25.2.0'
55 | compile 'com.android.support:cardview-v7:25.2.0'
56 | compile 'com.android.support:design:25.2.0'
57 | compile 'io.reactivex.rxjava2:rxjava:2.0.6'
58 | compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
59 | compile 'com.jakewharton.threetenabp:threetenabp:1.0.4'
60 | compile 'com.facebook.stetho:stetho:1.4.2'
61 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
62 | }
63 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /opt/brew/opt/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/App.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import android.app.Application
4 | import io.realm.Realm
5 |
6 | class App: Application() {
7 | override fun onCreate() {
8 | super.onCreate()
9 |
10 | OrmaHolder.initialize(this)
11 | Realm.init(this)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/BenchmarkFragment.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma.example.fragment
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.database.sqlite.SQLiteDatabase
6 | import android.os.Bundle
7 | import android.support.v4.app.Fragment
8 | import android.util.Log
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.widget.ArrayAdapter
13 | import android.widget.Toast
14 | import com.github.gfx.android.orma.AccessThreadConstraint
15 | import com.github.gfx.android.orma.example.handwritten.HandWrittenOpenHelper
16 | import com.github.gfx.android.orma_kotlin_example.OrmaDatabase
17 | import com.github.gfx.android.orma_kotlin_example.OrmaTodo
18 | import com.github.gfx.android.orma_kotlin_example.RealmTodo
19 | import com.github.gfx.android.orma_kotlin_example.databinding.FragmentBenchmarkBinding
20 | import com.github.gfx.android.orma_kotlin_example.databinding.ItemResultBinding
21 | import io.reactivex.Single
22 | import io.reactivex.android.schedulers.AndroidSchedulers
23 | import io.reactivex.schedulers.Schedulers
24 | import io.realm.Realm
25 | import io.realm.RealmConfiguration
26 | import io.realm.Sort
27 | import java.util.*
28 | import java.util.concurrent.TimeUnit
29 | import java.util.concurrent.atomic.AtomicInteger
30 |
31 | class BenchmarkFragment : Fragment() {
32 |
33 | internal val titlePrefix = "title "
34 |
35 | internal val contentPrefix = "content content content\n" + "content content content\n" + "content content content\n" + " "
36 |
37 | internal lateinit var orma: OrmaDatabase
38 |
39 | internal lateinit var hw: HandWrittenOpenHelper
40 |
41 | internal lateinit var binding: FragmentBenchmarkBinding
42 |
43 | internal lateinit var adapter: ResultAdapter
44 |
45 | override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
46 | binding = FragmentBenchmarkBinding.inflate(inflater, container, false)
47 |
48 | adapter = ResultAdapter(context)
49 | binding.list.setAdapter(adapter)
50 |
51 | binding.run.setOnClickListener({ v -> run() })
52 |
53 | return binding.getRoot()
54 | }
55 |
56 | override fun onResume() {
57 | super.onResume()
58 |
59 | val realmConf = RealmConfiguration.Builder().build()
60 | Realm.setDefaultConfiguration(realmConf)
61 | Realm.deleteRealm(realmConf)
62 |
63 | Schedulers.io().createWorker().schedule {
64 | context.deleteDatabase("orma-benchmark.db")
65 | orma = OrmaDatabase.builder(context)
66 | .name("orma-benchmark.db")
67 | .readOnMainThread(AccessThreadConstraint.NONE)
68 | .writeOnMainThread(AccessThreadConstraint.NONE)
69 | .trace(false)
70 | .build()
71 | orma.migrate()
72 | }
73 |
74 | context.deleteDatabase("hand-written.db")
75 | hw = HandWrittenOpenHelper(context, "hand-written.db")
76 | }
77 |
78 | override fun onPause() {
79 | super.onPause()
80 | }
81 |
82 | internal fun run() {
83 | Log.d(TAG, "Start performing a set of benchmarks")
84 |
85 | adapter.clear()
86 |
87 | val realm = Realm.getDefaultInstance()
88 | realm.executeTransaction { r -> r.delete(RealmTodo::class.java) }
89 | realm.close()
90 |
91 | hw.writableDatabase.execSQL("DELETE FROM todo")
92 |
93 | orma.deleteFromOrmaTodo().executeAsSingle().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).flatMap({ integer -> startInsertWithOrma() }).flatMap({ result ->
94 | adapter.add(result)
95 | startInsertWithRealm() // Realm objects can only be accessed on the thread they were created.
96 | }).flatMap({ result ->
97 | adapter.add(result)
98 | startInsertWithHandWritten()
99 | }).flatMap({ result ->
100 | adapter.add(result)
101 | startSelectAllWithOrma()
102 | }).flatMap({ result ->
103 | adapter.add(result)
104 | startSelectAllWithRealm() // Realm objects can only be accessed on the thread they were created.
105 | }).flatMap({ result ->
106 | adapter.add(result)
107 | startSelectAllWithHandWritten()
108 | }).subscribe(
109 | { result -> adapter.add(result) },
110 | { error ->
111 | Log.wtf(TAG, error)
112 | Toast.makeText(context, error.message, Toast.LENGTH_LONG).show()
113 |
114 | })
115 | }
116 |
117 | internal fun startInsertWithOrma(): Single {
118 | return Single.fromCallable {
119 | val result = runWithBenchmark( {
120 | orma.transactionSync({
121 | val now = System.currentTimeMillis()
122 |
123 | val statement = orma.prepareInsertIntoOrmaTodo()
124 |
125 | for (i in 0..N_ITEMS - 1) {
126 | val todo = OrmaTodo(0, titlePrefix + 1, contentPrefix + 1, false, Date(now))
127 | statement.execute(todo)
128 | }
129 | })
130 | })
131 | Result("Orma/insert", result)
132 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
133 | }
134 |
135 | internal fun startInsertWithRealm(): Single {
136 | return Single.fromCallable {
137 | val result = runWithBenchmark( {
138 | val realm = Realm.getDefaultInstance()
139 | realm.executeTransaction { r ->
140 | val now = System.currentTimeMillis()
141 |
142 | for (i in 0..N_ITEMS - 1) {
143 | val todo = r.createObject(RealmTodo::class.java)
144 |
145 | todo.title = titlePrefix + i
146 | todo.content = contentPrefix + i
147 | todo.createdTime = Date(now)
148 | }
149 | }
150 | realm.close()
151 | })
152 | Result("Realm/insert", result)
153 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
154 | }
155 |
156 | internal fun startInsertWithHandWritten(): Single {
157 | return Single.fromCallable {
158 | val result = runWithBenchmark({
159 | val db = hw.writableDatabase
160 | db.beginTransaction()
161 |
162 | val inserter = db.compileStatement(
163 | "INSERT INTO todo (title, content, done, createdTime) VALUES (?, ?, ?, ?)")
164 |
165 | val now = System.currentTimeMillis()
166 |
167 | for (i in 1..N_ITEMS) {
168 | inserter.bindAllArgsAsStrings(arrayOf(titlePrefix + i, // title
169 | contentPrefix + i, // content
170 | "0", // done
171 | now.toString())// createdTime
172 | )
173 | inserter.executeInsert()
174 | }
175 |
176 | db.setTransactionSuccessful()
177 | db.endTransaction()
178 | })
179 | Result("HandWritten/insert", result)
180 |
181 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
182 | }
183 |
184 | internal fun startSelectAllWithOrma(): Single {
185 | return Single.fromCallable {
186 | val result = runWithBenchmark({
187 | val count = AtomicInteger()
188 |
189 | val todos = orma.selectFromOrmaTodo().orderByCreatedTimeAsc()
190 |
191 | for (todo in todos) {
192 | @SuppressWarnings("unused")
193 | val title = todo.title
194 | @SuppressWarnings("unused")
195 | val content = todo.content
196 | @SuppressWarnings("unused")
197 | val createdTime = todo.createdTime
198 |
199 | count.incrementAndGet()
200 | }
201 |
202 | if (todos.count() !== count.get()) {
203 | throw AssertionError("unexpected get: " + count.get())
204 | }
205 | Log.d(TAG, "Orma/forEachAll count: " + count)
206 | })
207 | Result("Orma/forEachAll", result)
208 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
209 | }
210 |
211 | internal fun startSelectAllWithRealm(): Single {
212 | return Single.fromCallable {
213 | val result = runWithBenchmark({
214 | val count = AtomicInteger()
215 | val realm = Realm.getDefaultInstance()
216 | val results = realm.where(RealmTodo::class.java).findAllSorted("createdTime", Sort.ASCENDING)
217 | for (todo in results) {
218 | @SuppressWarnings("unused")
219 | val title = todo.title
220 | @SuppressWarnings("unused")
221 | val content = todo.content
222 | @SuppressWarnings("unused")
223 | val createdTime = todo.createdTime
224 |
225 | count.incrementAndGet()
226 | }
227 | if (results.size != count.get()) {
228 | throw AssertionError("unexpected get: " + count.get())
229 | }
230 | realm.close()
231 |
232 | Log.d(TAG, "Realm/forEachAll count: " + count)
233 | })
234 | Result("Realm/forEachAll", result)
235 | }
236 | }
237 |
238 | internal fun startSelectAllWithHandWritten(): Single {
239 | return Single.fromCallable {
240 | val result = runWithBenchmark({
241 | val count = AtomicInteger()
242 |
243 | val db = hw.readableDatabase
244 | val cursor = db.query(
245 | "todo",
246 | arrayOf("id, title, content, done, createdTime"),
247 | null, null, null, null, "createdTime ASC" // whereClause, whereArgs, groupBy, having, orderBy
248 | )
249 |
250 | if (cursor.moveToFirst()) {
251 | val titleIndex = cursor.getColumnIndexOrThrow("title")
252 | val contentIndex = cursor.getColumnIndexOrThrow("content")
253 | val createdTimeIndex = cursor.getColumnIndexOrThrow("createdTime")
254 | do {
255 | @SuppressWarnings("unused")
256 | val title = cursor.getString(titleIndex)
257 | @SuppressWarnings("unused")
258 | val content = cursor.getString(contentIndex)
259 | @SuppressWarnings("unused")
260 | val createdTime = Date(cursor.getLong(createdTimeIndex))
261 |
262 | count.incrementAndGet()
263 | } while (cursor.moveToNext())
264 | }
265 | cursor.close()
266 |
267 | val dbCount = longForQuery(db, "SELECT COUNT(*) FROM todo", null)
268 | if (dbCount != count.get().toLong()) {
269 | throw AssertionError("unexpected get: " + count.get() + " != " + dbCount)
270 | }
271 |
272 | Log.d(TAG, "HandWritten/forEachAll count: " + count)
273 | })
274 | Result("HandWritten/forEachAll", result)
275 | }.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
276 | }
277 |
278 | internal class Result(val title: String, val elapsedMillis: Long)
279 |
280 | internal class ResultAdapter(context: Context) : ArrayAdapter(context, 0) {
281 |
282 | override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
283 | @SuppressLint("ViewHolder") val binding = ItemResultBinding.inflate(LayoutInflater.from(context), parent, false)
284 |
285 | val result = getItem(position)!!
286 | binding.title.setText(result.title)
287 | binding.elapsed.setText("${result.elapsedMillis}ms")
288 |
289 | return binding.getRoot()
290 | }
291 | }
292 |
293 | companion object {
294 |
295 | internal val TAG = BenchmarkFragment::class.java.simpleName
296 |
297 | internal val N_ITEMS = 10
298 |
299 | internal val N_OPS = 100
300 |
301 | fun newInstance(): Fragment {
302 | return BenchmarkFragment()
303 | }
304 |
305 | internal fun longForQuery(db: SQLiteDatabase, sql: String, args: Array?): Long {
306 | val cursor = db.rawQuery(sql, args)
307 | cursor.moveToFirst()
308 | val value = cursor.getLong(0)
309 | cursor.close()
310 | return value
311 | }
312 |
313 | internal fun runWithBenchmark(task: () -> Unit): Long {
314 | val t0 = System.nanoTime()
315 |
316 | for (i in 0..N_OPS - 1) {
317 | task()
318 | }
319 |
320 | return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t0)
321 | }
322 | }
323 |
324 | }
325 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/DataClass.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 |
4 | import android.support.annotation.Nullable
5 | import com.github.gfx.android.orma.annotation.Column
6 | import com.github.gfx.android.orma.annotation.PrimaryKey
7 | import com.github.gfx.android.orma.annotation.Setter
8 | import com.github.gfx.android.orma.annotation.Table
9 |
10 | @Table
11 | data class DataClass
12 | (
13 | @Setter("id") @PrimaryKey var id: Long,
14 | @Setter("todo") @Column @Nullable var todo: OrmaTodo?,
15 | @Setter("content") @Column @Nullable var content: String?
16 | )
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/HandWrittenOpenHelper.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma.example.handwritten
2 |
3 | import android.content.Context
4 | import android.database.sqlite.SQLiteDatabase
5 | import android.database.sqlite.SQLiteOpenHelper
6 |
7 | class HandWrittenOpenHelper(context: Context, name: String) : SQLiteOpenHelper(context, name, null, HandWrittenOpenHelper.VERSION) {
8 |
9 | override fun onCreate(db: SQLiteDatabase) {
10 | db.execSQL("CREATE TABLE todo ("
11 | + "id INTEGER PRIMARY KEY,"
12 | + "title TEXT NOT NULL,"
13 | + "content TEXT NULL,"
14 | + "done BOOLEAN NOT NULL,"
15 | + "createdTime INTEGER NOT NULL"
16 | + ")")
17 | db.execSQL("CREATE INDEX title_on_todo ON todo (title)")
18 | db.execSQL("CREATE INDEX createdTime_on_todo ON todo (createdTime)")
19 | }
20 |
21 | override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
22 | db.execSQL("DROP TABLE todo")
23 | }
24 |
25 | override fun onDowngrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
26 | // nop
27 | }
28 |
29 | companion object {
30 |
31 | internal val VERSION = 4
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/Item.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 FUJI Goro (gfx).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.github.gfx.android.orma_kotlin_example
18 |
19 | import android.support.annotation.Nullable
20 | import com.github.gfx.android.orma.annotation.Column
21 | import com.github.gfx.android.orma.annotation.PrimaryKey
22 | import com.github.gfx.android.orma.annotation.Setter
23 | import com.github.gfx.android.orma.annotation.Table
24 | import java.sql.Timestamp
25 |
26 | @Table
27 | class Item {
28 |
29 | @PrimaryKey(autoincrement = true) val id: Long
30 |
31 | @Column val content: String
32 |
33 | @Nullable
34 | @Column val user: User?
35 |
36 | @Column val createdTime: Timestamp
37 |
38 | constructor(
39 | @Setter("id") id: Long,
40 | @Setter("content") content: String,
41 | @Setter("user") user: User?,
42 | @Setter("createdTime") createdTime: Timestamp) {
43 | this.id = id
44 | this.content = content
45 | this.user = user
46 | this.createdTime = createdTime
47 | }
48 |
49 | constructor(id: Long, content: String) {
50 | this.id = id
51 | this.content = content
52 | this.user = null
53 | this.createdTime = Timestamp(System.currentTimeMillis())
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/Location.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import com.github.gfx.android.orma.annotation.Column
4 | import com.github.gfx.android.orma.annotation.Setter
5 | import com.github.gfx.android.orma.annotation.Table
6 |
7 | @Table
8 | data class Location(
9 | @Setter("latitude") @Column val latitude: Double,
10 | @Setter("longitude") @Column val longitude: Double) {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 |
6 | class MainActivity : AppCompatActivity() {
7 |
8 | override fun onCreate(savedInstanceState: Bundle?) {
9 | super.onCreate(savedInstanceState)
10 | setContentView(R.layout.activity_main)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/OrmaHolder.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import android.content.Context
4 |
5 | object OrmaHolder {
6 | lateinit var ORMA: OrmaDatabase;
7 |
8 | fun initialize(context: Context) {
9 | ORMA = OrmaDatabase.builder(context).build();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/OrmaTodo.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import com.github.gfx.android.orma.annotation.Column
4 | import com.github.gfx.android.orma.annotation.PrimaryKey
5 | import com.github.gfx.android.orma.annotation.Setter
6 | import com.github.gfx.android.orma.annotation.Table
7 | import java.util.*
8 |
9 | @Table
10 | data class OrmaTodo(
11 | @Setter("id") @PrimaryKey var id: Long,
12 | @Setter("title") @Column(indexed = true) var title: String,
13 | @Setter("content") @Column var content: String,
14 | @Setter("done") @Column var done: Boolean,
15 | @Setter("createdTime") @Column(indexed = true) var createdTime: Date
16 | ) {
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/RealmTodo.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import io.realm.RealmObject
4 | import io.realm.annotations.Index
5 | import java.util.*
6 |
7 | open class RealmTodo : RealmObject() {
8 |
9 | // The primary key is generated by Realm
10 |
11 | @Index
12 | var title: String? = null
13 |
14 | var content: String? = null
15 |
16 | var done: Boolean = false
17 |
18 | @Index
19 | var createdTime: Date = Date()
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/gfx/android/orma_kotlin_example/User.kt:
--------------------------------------------------------------------------------
1 | package com.github.gfx.android.orma_kotlin_example
2 |
3 | import com.github.gfx.android.orma.annotation.Column
4 | import com.github.gfx.android.orma.annotation.PrimaryKey
5 | import com.github.gfx.android.orma.annotation.Table
6 |
7 | @Table
8 | class User {
9 | @PrimaryKey(autoincrement = true) var id: Long = 0
10 |
11 | @Column var name: String? = null
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_benchmark.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
24 |
25 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_result.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
21 |
22 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Orma-Kotlin-Example
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:2.3.0'
7 | }
8 | }
9 |
10 | allprojects {
11 | repositories {
12 | jcenter()
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | java:
3 | version: oraclejdk8
4 | environment:
5 | TERM: dumb
6 | GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx1560m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false'
7 | dependencies:
8 | pre:
9 | - echo y | android -s update sdk -u -a -t "tools" # update Android SDK that includes sdkmanager(1)
10 | - mkdir -p "$ANDROID_HOME"/licenses
11 | - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME"/licenses/android-sdk-license
12 | - $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" "extras;android;m2repository"
13 | test:
14 | override:
15 | - ./gradlew --info check
16 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfx/OrmaWithKotlin/7004eeefe963a30648d3afa05145df52fc1beebe/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Oct 14 11:28:51 JST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------