Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Reformat all the code
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Jun 21, 2017
1 parent 93024e3 commit abab594
Show file tree
Hide file tree
Showing 41 changed files with 1,014 additions and 1,021 deletions.
7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="io.kolumbus.demo"
<manifest package="io.kolumbus.demo"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
Expand All @@ -9,9 +8,9 @@
android:theme="@style/kolumbus_Theme">
<activity android:name=".DemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
124 changes: 62 additions & 62 deletions app/src/main/kotlin/io/kolumbus/demo/DemoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,72 @@ import io.kolumbus.demo.model.Product
import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmList
import java.util.*
import java.util.Random

class DemoActivity : Activity() {
private val CATEGORIES_COUNT = 100
private val MAX_LINKED_CATEGORIES = 50
private val PRODUCTS_COUNT = 1000

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Realm.init(this)

val realmConfiguration = RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build()
Realm.setDefaultConfiguration(realmConfiguration)

this.fillDatabase()

with(Kolumbus) {
explore(realmConfiguration)
navigate(this@DemoActivity)
}
}

private fun fillDatabase() {
with(Realm.getDefaultInstance()) {
executeTransaction {
val random = Random()
val categoriesCount = this.where(Category::class.java).count()
val productsCount = this.where(Product::class.java).count()

for (i in 1..CATEGORIES_COUNT) {
with(createObject(Category::class.java, (categoriesCount + i).toInt())) {
color = random.nextColor()
name = "Category $id"
}
}

for (i in 1..PRODUCTS_COUNT) {
with(createObject(Product::class.java, (productsCount + i).toInt())) {
categories = RealmList<Category>()

for (j in 0..(random.nextInt(MAX_LINKED_CATEGORIES) - 1)) {
val category = where(Category::class.java).equalTo("id", random.nextInt(CATEGORIES_COUNT - 1) + 1).findFirst()

if (!(categories as RealmList<Category>).contains(category)) {
(categories as RealmList<Category>).add(category)
}
}

description = "<b>Lorem ipsum</b> dolor sit amet, <i>consectetur adipiscing</i> elit. <b><u>Maecenas mollis</u></b> eget nibh et condimentum."
name = "Product $id"
}
}
}

close()
}
}
private val CATEGORIES_COUNT = 100
private val MAX_LINKED_CATEGORIES = 50
private val PRODUCTS_COUNT = 1000

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Realm.init(this)

val realmConfiguration = RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build()
Realm.setDefaultConfiguration(realmConfiguration)

this.fillDatabase()

with(Kolumbus) {
explore(realmConfiguration)
navigate(this@DemoActivity)
}
}

private fun fillDatabase() {
with(Realm.getDefaultInstance()) {
executeTransaction {
val random = Random()
val categoriesCount = this.where(Category::class.java).count()
val productsCount = this.where(Product::class.java).count()

for (i in 1..CATEGORIES_COUNT) {
with(createObject(Category::class.java, (categoriesCount + i).toInt())) {
color = random.nextColor()
name = "Category $id"
}
}

for (i in 1..PRODUCTS_COUNT) {
with(createObject(Product::class.java, (productsCount + i).toInt())) {
categories = RealmList<Category>()

for (j in 0..(random.nextInt(MAX_LINKED_CATEGORIES) - 1)) {
val category = where(Category::class.java).equalTo("id", random.nextInt(CATEGORIES_COUNT - 1) + 1).findFirst()

if (!(categories as RealmList<Category>).contains(category)) {
(categories as RealmList<Category>).add(category)
}
}

description = "<b>Lorem ipsum</b> dolor sit amet, <i>consectetur adipiscing</i> elit. <b><u>Maecenas mollis</u></b> eget nibh et condimentum."
name = "Product $id"
}
}
}

close()
}
}
}

fun Random.nextColor(): String {
fun Random.nextColorHex(): String {
return Integer.toHexString(this.nextInt(256)).padStart(2, '0')
}
fun Random.nextColorHex(): String {
return Integer.toHexString(this.nextInt(256)).padStart(2, '0')
}

return "#${this.nextColorHex()}${this.nextColorHex()}${this.nextColorHex()}"
return "#${this.nextColorHex()}${this.nextColorHex()}${this.nextColorHex()}"
}
8 changes: 4 additions & 4 deletions app/src/main/kotlin/io/kolumbus/demo/model/Category.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import io.realm.RealmObject
import io.realm.annotations.PrimaryKey

open class Category : RealmObject() {
open var color = ""
@PrimaryKey
open var id = 0
open var name = ""
open var color = ""
@PrimaryKey
open var id = 0
open var name = ""
}
10 changes: 5 additions & 5 deletions app/src/main/kotlin/io/kolumbus/demo/model/Product.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import io.realm.RealmObject
import io.realm.annotations.PrimaryKey

open class Product : RealmObject() {
open var description = ""
@PrimaryKey
open var id = 0
open var name = ""
open var categories: RealmList<Category>? = null
open var description = ""
@PrimaryKey
open var id = 0
open var name = ""
open var categories: RealmList<Category>? = null
}
2 changes: 1 addition & 1 deletion kolumbus-no-op/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<manifest package="io.kolumbus"/>
<manifest package="io.kolumbus" />
22 changes: 11 additions & 11 deletions kolumbus-no-op/src/main/kotlin/io/kolumbus/Architect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import io.realm.RealmList
import io.realm.RealmModel

open class Architect {
open fun displayAny(textView: TextView, value: Any) = Unit
open fun displayAny(textView: TextView, value: Any) = Unit

open fun displayBoolean(textView: TextView, value: Boolean) = Unit
open fun displayBoolean(textView: TextView, value: Boolean) = Unit

open fun displayColor(textView: TextView, value: String, color: Int) = Unit
open fun displayColor(textView: TextView, value: String, color: Int) = Unit

open fun displayEmpty(textView: TextView) = Unit
open fun displayEmpty(textView: TextView) = Unit

open fun displayFloat(textView: TextView, value: Float) = Unit
open fun displayFloat(textView: TextView, value: Float) = Unit

open fun displayInt(textView: TextView, value: Int) = Unit
open fun displayInt(textView: TextView, value: Int) = Unit

open fun displayNull(textView: TextView) = Unit
open fun displayNull(textView: TextView) = Unit

open fun <T : RealmModel> displayRealmList(textView: TextView, value: RealmList<T>, type: Class<out RealmModel>) = Unit
open fun <T : RealmModel> displayRealmList(textView: TextView, value: RealmList<T>, type: Class<out RealmModel>) = Unit

open fun <T : RealmModel> displayRealmModel(textView: TextView, value: T) = Unit
open fun <T : RealmModel> displayRealmModel(textView: TextView, value: T) = Unit

open fun displayString(textView: TextView, value: String) = Unit
open fun displayString(textView: TextView, value: String) = Unit

open fun displayUrl(textView: TextView, value: String) = Unit
open fun displayUrl(textView: TextView, value: String) = Unit
}
14 changes: 7 additions & 7 deletions kolumbus-no-op/src/main/kotlin/io/kolumbus/Kolumbus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import android.content.Context
import io.realm.RealmConfiguration

object Kolumbus {
@JvmStatic
fun build() = this
@JvmStatic
fun build() = this

fun explore(configuration: RealmConfiguration) = this
fun explore(configuration: RealmConfiguration) = this

fun forget(configuration: RealmConfiguration) = this
fun forget(configuration: RealmConfiguration) = this

fun forgetAll() = Unit
fun forgetAll() = Unit

fun navigate(context: Context) = Unit
fun navigate(context: Context) = Unit

fun withArchitect(architect: Architect) = this
fun withArchitect(architect: Architect) = this
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import android.content.Context
import io.realm.RealmModel

class TableActivity {
companion object {
fun start(context: Context, table: Class<out RealmModel>?) = Unit
companion object {
fun start(context: Context, table: Class<out RealmModel>?) = Unit

fun <T : RealmModel> start(context: Context, table: Class<out T>?, items: Array<out T>?) = Unit
}
fun <T : RealmModel> start(context: Context, table: Class<out T>?, items: Array<out T>?) = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import android.content.Context
import io.realm.RealmModel

class TableInfoActivity {
companion object {
fun start(context: Context, table: Class<out RealmModel>?) = Unit
}
companion object {
fun start(context: Context, table: Class<out RealmModel>?) = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.kolumbus.activity
import android.content.Context

class TablesActivity {
companion object {
fun start(context: Context) = Unit
}
companion object {
fun start(context: Context) = Unit
}
}
52 changes: 26 additions & 26 deletions kolumbus/src/main/kotlin/io/kolumbus/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ import io.realm.annotations.PrimaryKey
import java.lang.reflect.Field
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.util.*
import java.util.Comparator

object Analyzer {
fun getAccessors(table: Class<out RealmModel>?, fields: List<Field>): Map<String, Method?> {
val methods = table?.declaredMethods?.map { it.name } ?: emptyList()
fun getAccessors(table: Class<out RealmModel>?, fields: List<Field>): Map<String, Method?> {
val methods = table?.declaredMethods?.map { it.name } ?: emptyList()

return fields.associate {
it.name to if (methods.contains("get${it.name.capitalize()}")) {
table?.getMethod("get${it.name.capitalize()}")
} else if (methods.contains("is${it.name.capitalize()}")) {
table?.getMethod("is${it.name.capitalize()}")
} else {
null
}
}.filterValues { it != null }
}
return fields.associate {
it.name to if (methods.contains("get${it.name.capitalize()}")) {
table?.getMethod("get${it.name.capitalize()}")
} else if (methods.contains("is${it.name.capitalize()}")) {
table?.getMethod("is${it.name.capitalize()}")
} else {
null
}
}.filterValues { it != null }
}

fun getRealmFields(table: Class<out RealmModel>?): List<Field> {
return table?.declaredFields?.filter {
!Modifier.isStatic(it.modifiers) && !it.isAnnotationPresent(Ignore::class.java)
}?.sortedWith(Comparator { first, second ->
if (first.isAnnotationPresent(PrimaryKey::class.java) && !second.isAnnotationPresent(PrimaryKey::class.java)) {
-1
} else if (!first.isAnnotationPresent(PrimaryKey::class.java) && second.isAnnotationPresent(PrimaryKey::class.java)) {
1
} else {
first.name.compareTo(second.name)
}
}) ?: emptyList()
}
fun getRealmFields(table: Class<out RealmModel>?): List<Field> {
return table?.declaredFields?.filter {
!Modifier.isStatic(it.modifiers) && !it.isAnnotationPresent(Ignore::class.java)
}?.sortedWith(Comparator { first, second ->
if (first.isAnnotationPresent(PrimaryKey::class.java) && !second.isAnnotationPresent(PrimaryKey::class.java)) {
-1
} else if (!first.isAnnotationPresent(PrimaryKey::class.java) && second.isAnnotationPresent(PrimaryKey::class.java)) {
1
} else {
first.name.compareTo(second.name)
}
}) ?: emptyList()
}
}
Loading

0 comments on commit abab594

Please sign in to comment.