Skip to content

Commit

Permalink
Merge branch 'release/1.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Feb 7, 2021
2 parents 0a84d5f + 1fb168f commit 1474ebd
Show file tree
Hide file tree
Showing 90 changed files with 1,080 additions and 923 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/build
/captures
/docs/.asciidoctor
/docs/images/uml
/docs/vendor
/docs/*.html
.externalNativeBuild
6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

1 change: 1 addition & 0 deletions .idea/gradle.xml

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

25 changes: 25 additions & 0 deletions .idea/jarRepositories.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/misc.xml

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

6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.4.21'

repositories {
google()
Expand All @@ -12,9 +12,9 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:9.1.1"
classpath "org.jlleitschuh.gradle:ktlint-gradle:9.4.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
31 changes: 16 additions & 15 deletions commons/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

version = "0.7.6"
version = "0.8.0"

android {
compileSdkVersion 29
Expand Down Expand Up @@ -43,21 +42,23 @@ dependencies {

api project(':mountpoint')

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha03"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"

implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-rc01"
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'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
api 'androidx.room:room-runtime:2.2.5'

testImplementation 'androidx.test:core:1.2.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'com.google.android.material:material:1.3.0-rc01'

api 'androidx.room:room-runtime:2.2.6'

testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'junit:junit:4.13'
testImplementation 'androidx.test:core:1.3.0'
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.mockito:mockito-core:3.0.0'
testImplementation 'org.robolectric:robolectric:4.3.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import fr.geonature.commons.data.helper.get
@Entity(
tableName = DefaultNomenclature.TABLE_NAME,
primaryKeys = [DefaultNomenclature.COLUMN_MODULE, DefaultNomenclature.COLUMN_NOMENCLATURE_ID],
foreignKeys = [ForeignKey(
entity = Nomenclature::class,
parentColumns = [Nomenclature.COLUMN_ID],
childColumns = [DefaultNomenclature.COLUMN_NOMENCLATURE_ID],
onDelete = ForeignKey.CASCADE
)]
foreignKeys = [
ForeignKey(
entity = Nomenclature::class,
parentColumns = [Nomenclature.COLUMN_ID],
childColumns = [DefaultNomenclature.COLUMN_NOMENCLATURE_ID],
onDelete = ForeignKey.CASCADE
)
]
)
open class DefaultNomenclature : Parcelable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ import fr.geonature.commons.data.helper.get
tableName = NomenclatureTaxonomy.TABLE_NAME,
primaryKeys = [NomenclatureTaxonomy.COLUMN_NOMENCLATURE_ID, Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP],
indices = [Index(value = [Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP])],
foreignKeys = [ForeignKey(
entity = Nomenclature::class,
parentColumns = [Nomenclature.COLUMN_ID],
childColumns = [NomenclatureTaxonomy.COLUMN_NOMENCLATURE_ID],
onDelete = ForeignKey.CASCADE
), ForeignKey(
entity = Taxonomy::class,
parentColumns = [Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP],
childColumns = [Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP],
onDelete = ForeignKey.CASCADE
)]
foreignKeys = [
ForeignKey(
entity = Nomenclature::class,
parentColumns = [Nomenclature.COLUMN_ID],
childColumns = [NomenclatureTaxonomy.COLUMN_NOMENCLATURE_ID],
onDelete = ForeignKey.CASCADE
), ForeignKey(
entity = Taxonomy::class,
parentColumns = [Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP],
childColumns = [Taxonomy.COLUMN_KINGDOM, Taxonomy.COLUMN_GROUP],
onDelete = ForeignKey.CASCADE
)
]
)
class NomenclatureTaxonomy(
@ColumnInfo(name = COLUMN_NOMENCLATURE_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import fr.geonature.commons.data.helper.get
*/
@Entity(
tableName = NomenclatureType.TABLE_NAME,
indices = [Index(
value = [NomenclatureType.COLUMN_MNEMONIC],
unique = true
)]
indices = [
Index(
value = [NomenclatureType.COLUMN_MNEMONIC],
unique = true
)
]
)
data class NomenclatureType(

Expand Down
2 changes: 1 addition & 1 deletion commons/src/main/java/fr/geonature/commons/data/Taxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ class Taxon : AbstractTaxon {
/**
* Order by query builder.
*/
class OrderBy: AbstractTaxon.OrderBy(TABLE_NAME)
class OrderBy : AbstractTaxon.OrderBy(TABLE_NAME)
}
14 changes: 8 additions & 6 deletions commons/src/main/java/fr/geonature/commons/data/TaxonArea.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import java.util.Date
@Entity(
tableName = TaxonArea.TABLE_NAME,
primaryKeys = [TaxonArea.COLUMN_TAXON_ID, TaxonArea.COLUMN_AREA_ID],
foreignKeys = [ForeignKey(
entity = Taxon::class,
parentColumns = [AbstractTaxon.COLUMN_ID],
childColumns = [TaxonArea.COLUMN_TAXON_ID],
onDelete = ForeignKey.CASCADE
)]
foreignKeys = [
ForeignKey(
entity = Taxon::class,
parentColumns = [AbstractTaxon.COLUMN_ID],
childColumns = [TaxonArea.COLUMN_TAXON_ID],
onDelete = ForeignKey.CASCADE
)
]
)
@TypeConverters(Converters::class)
data class TaxonArea(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class TaxonWithArea : AbstractTaxon {
TaxonArea.COLUMN_COLOR,
TaxonArea.TABLE_NAME
)} IN (${color.filter { it != "none" }
.joinToString(", ") { "'${it}'" }})${color.find { it == "none" }
.joinToString(", ") { "'$it'" }})${color.find { it == "none" }
?.let {
" OR (${getColumnAlias(
TaxonArea.COLUMN_COLOR,
Expand All @@ -159,5 +159,5 @@ class TaxonWithArea : AbstractTaxon {
/**
* Order by query builder.
*/
class OrderBy: AbstractTaxon.OrderBy(Taxon.TABLE_NAME)
class OrderBy : AbstractTaxon.OrderBy(Taxon.TABLE_NAME)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Taxonomy : Parcelable {

@ColumnInfo(name = COLUMN_KINGDOM)
var kingdom: String

@ColumnInfo(name = COLUMN_GROUP)
var group: String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ object EntityHelper {
columnName: String,
tableAlias: String? = null
): Pair<String, String> {
return Pair("${tableAlias.orEmpty()}${if (tableAlias.isNullOrBlank()) "" else "."}\"$columnName\"",
"${tableAlias.orEmpty()}${if (tableAlias.isNullOrBlank()) "" else "_"}$columnName")
return Pair(
"${tableAlias.orEmpty()}${if (tableAlias.isNullOrBlank()) "" else "."}\"$columnName\"",
"${tableAlias.orEmpty()}${if (tableAlias.isNullOrBlank()) "" else "_"}$columnName"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ object Provider {
val baseUri = Uri.parse("content://$AUTHORITY/$resource")

return if (path.isEmpty()) baseUri
else withAppendedPath(baseUri,
else withAppendedPath(
baseUri,
path.asSequence().filter { it.isNotBlank() }.joinToString("/")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ class SQLiteSelectQueryBuilder private constructor(private val tables: MutableSe
this.orderBy.joinToString(", ")
.let { if (it.isEmpty()) it else "ORDER BY $it" }

val sql = """
val sql =
"""
|SELECT ${if (this.columns.isNotEmpty() && this.distinct) "DISTINCT " else ""}$selectedColumns
|FROM $tables
|$joinClauses
Expand All @@ -333,11 +334,11 @@ class SQLiteSelectQueryBuilder private constructor(private val tables: MutableSe
|$orderByClauses
|${this.limit}
""".trimMargin()
.trim()
.replace(
"\n{2,}".toRegex(RegexOption.MULTILINE),
"\n"
)
.trim()
.replace(
"\n{2,}".toRegex(RegexOption.MULTILINE),
"\n"
)

Log.d(
TAG,
Expand Down
14 changes: 7 additions & 7 deletions commons/src/main/java/fr/geonature/commons/input/InputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class InputManager<I : AbstractInput> private constructor(
*/
suspend fun readInputs(): List<I> = withContext(IO) {
preferenceManager.all.filterKeys { it.startsWith("${KEY_PREFERENCE_INPUT}_") }
.values.mapNotNull { if (it is String && !it.isBlank()) inputJsonReader.read(it) else null }
.values.mapNotNull { if (it is String && it.isNotBlank()) inputJsonReader.read(it) else null }
.sortedBy { it.id }
.also { inputs.postValue(it) }
}
Expand Down Expand Up @@ -174,14 +174,14 @@ class InputManager<I : AbstractInput> private constructor(
* @return `true` if the given [AbstractInput] has been successfully exported, `false` otherwise
*/
suspend fun exportInput(input: I): Boolean {
val inputExportFile = withContext(IO) {
val inputExportFile = getInputExportFile(input)
val inputExportFile = getInputExportFile(input)

@Suppress("BlockingMethodInNonBlockingContext")
withContext(IO) {
inputJsonWriter.write(
FileWriter(inputExportFile),
input
)

return@withContext inputExportFile
}

Log.i(
Expand All @@ -205,11 +205,11 @@ class InputManager<I : AbstractInput> private constructor(
}

@Throws(IOException::class)
private fun getInputExportFile(input: AbstractInput): File {
private suspend fun getInputExportFile(input: AbstractInput): File = withContext(IO) {
val inputDir = FileUtils.getInputsFolder(application)
inputDir.mkdirs()

return File(
return@withContext File(
inputDir,
"input_${input.module}_${input.id}.json"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ open class InputViewModel<I : AbstractInput>(
inputJsonWriterListener: InputJsonWriter.OnInputJsonWriterListener<I>
) : AndroidViewModel(application) {

private val inputManager = InputManager.getInstance(application,
inputJsonReaderListener,
inputJsonWriterListener)
private val inputManager = InputManager.getInstance(
application,
inputJsonReaderListener,
inputJsonWriterListener
)

private var deletedInputToRestore: I? = null

Expand All @@ -45,7 +47,7 @@ open class InputViewModel<I : AbstractInput>(
*
* @param id The [AbstractInput] ID to read. If omitted, read the current saved [AbstractInput].
*/
fun readInput(id: Long? = null): LiveData<I> {
open fun readInput(id: Long? = null): LiveData<I> {
viewModelScope.launch {
inputManager.readInput(id)
}
Expand Down Expand Up @@ -123,7 +125,8 @@ open class InputViewModel<I : AbstractInput>(
*
* @author [S. Grimault](mailto:[email protected])
*/
class Factory<T : InputViewModel<I>, I : AbstractInput>(val creator: () -> T) : ViewModelProvider.Factory {
class Factory<T : InputViewModel<I>, I : AbstractInput>(val creator: () -> T) :
ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST") return creator() as T
}
Expand Down
Loading

0 comments on commit 1474ebd

Please sign in to comment.