Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Jan 12, 2020
2 parents 37c8f32 + 7fc00f8 commit 9013f90
Show file tree
Hide file tree
Showing 184 changed files with 7,862 additions and 4,306 deletions.
114 changes: 9 additions & 105 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ buildscript {
repositories {
google()
jcenter()

maven {
url "https://plugins.gradle.org/m2/"
}
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:9.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -23,6 +26,9 @@ allprojects {
jcenter()

}

apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "org.jlleitschuh.gradle.ktlint-idea"
}

task clean(type: Delete) {
Expand Down
4 changes: 2 additions & 2 deletions commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

version = "0.5.3"
version = "0.5.7"

android {
compileSdkVersion 28
Expand Down Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc03"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
api 'androidx.room:room-runtime:2.2.2'
api 'androidx.room:room-runtime:2.2.3'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
Expand Down
120 changes: 93 additions & 27 deletions commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ abstract class AbstractTaxon : Parcelable {
@ColumnInfo(name = COLUMN_HERITAGE)
var heritage: Boolean = false

constructor(id: Long,
name: String,
taxonomy: Taxonomy,
description: String? = null,
heritage: Boolean = false) {
constructor(
id: Long,
name: String,
taxonomy: Taxonomy,
description: String? = null,
heritage: Boolean = false
) {
this.id = id
this.name = name
this.taxonomy = taxonomy
this.description = description
this.heritage = heritage
}

constructor(source: Parcel) : this(source.readLong(),
source.readString()!!,
source.readParcelable(Taxonomy::class.java.classLoader)!!,
source.readString(),
source.readByte() == 1.toByte())
constructor(source: Parcel) : this(
source.readLong(),
source.readString()!!,
source.readParcelable(Taxonomy::class.java.classLoader)!!,
source.readString(),
source.readByte() == 1.toByte()
)

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down Expand Up @@ -86,13 +90,17 @@ abstract class AbstractTaxon : Parcelable {
return 0
}

override fun writeToParcel(dest: Parcel?,
flags: Int) {
override fun writeToParcel(
dest: Parcel?,
flags: Int
) {
dest?.also {
it.writeLong(id)
it.writeString(name)
it.writeParcelable(taxonomy,
flags)
it.writeParcelable(
taxonomy,
flags
)
it.writeString(description)
it.writeByte((if (heritage) 1 else 0).toByte()) // as boolean value
}
Expand All @@ -113,24 +121,82 @@ abstract class AbstractTaxon : Parcelable {
* Gets the default projection.
*/
fun defaultProjection(tableAlias: String): Array<Pair<String, String>> {
return arrayOf(column(COLUMN_ID,
tableAlias),
column(COLUMN_NAME,
tableAlias),
*Taxonomy.defaultProjection(tableAlias),
column(COLUMN_DESCRIPTION,
tableAlias),
column(COLUMN_HERITAGE,
tableAlias))
return arrayOf(
column(
COLUMN_ID,
tableAlias
),
column(
COLUMN_NAME,
tableAlias
),
*Taxonomy.defaultProjection(tableAlias),
column(
COLUMN_DESCRIPTION,
tableAlias
),
column(
COLUMN_HERITAGE,
tableAlias
)
)
}

/**
* Gets alias from given column name.
*/
fun getColumnAlias(columnName: String,
tableAlias: String): String {
return column(columnName,
tableAlias).second
fun getColumnAlias(
columnName: String,
tableAlias: String
): String {
return column(
columnName,
tableAlias
).second
}
}

/**
* Filter query builder.
*/
open class Filter(internal val tableAlias: String) {
internal val wheres = mutableListOf<Pair<String, Array<*>?>>()

/**
* Filter by name.
*
* @return this
*/
fun byName(queryString: String?): Filter {
if (queryString.isNullOrBlank()) {
return this
}

this.wheres.add(
Pair(
"(${getColumnAlias(
COLUMN_NAME, tableAlias
)} LIKE ?)",
arrayOf("%$queryString%")
)
)

return this
}

/**
* Builds the WHERE clause as selection for this filter.
*/
fun build(): Pair<String, Array<Any?>> {
val bindArgs = mutableListOf<Any?>()

val whereClauses = this.wheres.joinToString(" AND ") { pair ->
pair.second?.toList()
?.also { bindArgs.addAll(it) }
pair.first
}

return Pair(whereClauses, bindArgs.toTypedArray())
}
}
}
Loading

0 comments on commit 9013f90

Please sign in to comment.