Skip to content

Commit

Permalink
Merge branch 'release/0.2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Jun 7, 2020
2 parents faa8b4c + 8f49fe2 commit 5ec37e1
Show file tree
Hide file tree
Showing 35 changed files with 1,315 additions and 435 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
/build
/captures
/docs/.asciidoctor
/docs/images
/docs/vendor
/docs/*.html
.externalNativeBuild
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:4.0.0'
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
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.6.8"
version = "0.6.9"

android {
compileSdkVersion 29
Expand Down Expand Up @@ -44,7 +44,7 @@ dependencies {
api project(':mountpoint')

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha02"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha03"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.1.0'
Expand Down
52 changes: 52 additions & 0 deletions commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,58 @@ abstract class AbstractTaxon : Parcelable {
return this
}

/**
* Filter by taxonomy.
*
* @return this
*/
fun byTaxonomy(taxonomy: Taxonomy): Filter {
if (taxonomy.isAny()) {
return this
}

if (taxonomy.group == Taxonomy.ANY) {
return byKingdom(taxonomy.kingdom)
}

this.wheres.add(
Pair(
"((${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_KINGDOM,
tableAlias
)} = ?) AND (${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_GROUP,
tableAlias
)} = ?))",
arrayOf(
taxonomy.kingdom,
taxonomy.group
)
)
)

return this
}

/**
* Filter by taxonomy kingdom.
*
* @return this
*/
fun byKingdom(kingdom: String): Filter {
this.wheres.add(
Pair(
"(${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_KINGDOM,
tableAlias
)} = ?)",
arrayOf(kingdom)
)
)

return this
}

/**
* Builds the WHERE clause as selection for this filter.
*/
Expand Down
60 changes: 7 additions & 53 deletions commons/src/main/java/fr/geonature/commons/data/Taxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ class Taxon : AbstractTaxon {
)
)
} catch (e: Exception) {
Log.w(
TAG,
e
)
e.message?.run {
Log.w(
TAG,
this
)
}

null
}
Expand All @@ -145,53 +147,5 @@ class Taxon : AbstractTaxon {
/**
* Filter query builder.
*/
class Filter : AbstractTaxon.Filter(TABLE_NAME) {

/**
* Filter by taxonomy.
*
* @return this
*/
fun byTaxonomy(taxonomy: Taxonomy): Filter {
if (taxonomy.isAny()) {
return this
}

if (taxonomy.group == Taxonomy.ANY) {
return byKingdom(taxonomy.kingdom)
}

this.wheres.add(
Pair(
"((${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_KINGDOM, tableAlias
)} = ?) AND (${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_GROUP,
tableAlias
)} = ?))",
arrayOf(taxonomy.kingdom, taxonomy.group)
)
)

return this
}

/**
* Filter by taxonomy kingdom.
*
* @return this
*/
fun byKingdom(kingdom: String): Filter {
this.wheres.add(
Pair(
"(${Taxonomy.getColumnAlias(
Taxonomy.COLUMN_KINGDOM, tableAlias
)} = ?)",
arrayOf(kingdom)
)
)

return this
}
}
class Filter : AbstractTaxon.Filter(TABLE_NAME)
}
10 changes: 6 additions & 4 deletions commons/src/main/java/fr/geonature/commons/data/TaxonArea.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ data class TaxonArea(
)
)
} catch (e: Exception) {
Log.w(
TAG,
e
)
e.message?.run {
Log.w(
TAG,
this
)
}

null
}
Expand Down
36 changes: 36 additions & 0 deletions commons/src/main/java/fr/geonature/commons/data/TaxonWithArea.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,40 @@ class TaxonWithArea : AbstractTaxon {
}
}
}

/**
* Filter query builder.
*/
class Filter : AbstractTaxon.Filter(Taxon.TABLE_NAME) {

/**
* Filter by area 'colors'.
*
* @return this
*/
fun byAreaColors(vararg color: String): AbstractTaxon.Filter {
if (color.isEmpty()) {
return this
}

this.wheres.add(
Pair(
"(${getColumnAlias(
TaxonArea.COLUMN_COLOR,
TaxonArea.TABLE_NAME
)} IN (${color.filter { it != "none" }
.joinToString(", ") { "'${it}'" }})${color.find { it == "none" }
?.let {
" OR (${getColumnAlias(
TaxonArea.COLUMN_COLOR,
TaxonArea.TABLE_NAME
)} IS NULL)"
} ?: ""})",
null
)
)

return this
}
}
}
Loading

0 comments on commit 5ec37e1

Please sign in to comment.