Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Oct 10, 2019
2 parents 6b47ebe + 7e11bab commit 40517d0
Show file tree
Hide file tree
Showing 44 changed files with 1,756 additions and 226 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
6 changes: 3 additions & 3 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.3.1"
version = "0.3.8"

android {
compileSdkVersion 28
Expand Down Expand Up @@ -46,10 +46,10 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"

implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha04"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-beta01"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
api 'androidx.room:room-runtime:2.1.0'
api 'androidx.room:room-runtime:2.2.0'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
Expand Down
18 changes: 14 additions & 4 deletions commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Parcel
import android.os.Parcelable
import android.provider.BaseColumns
import androidx.room.ColumnInfo
import androidx.room.PrimaryKey
import androidx.room.Embedded

/**
* Base taxon.
Expand All @@ -16,7 +16,6 @@ abstract class AbstractTaxon : Parcelable {
/**
* The unique ID of the taxon.
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = COLUMN_ID)
var id: Long

Expand All @@ -26,6 +25,9 @@ abstract class AbstractTaxon : Parcelable {
@ColumnInfo(name = COLUMN_NAME)
var name: String

@Embedded
val taxonomy: Taxonomy

/**
* The description of the taxon.
*/
Expand All @@ -40,16 +42,19 @@ abstract class AbstractTaxon : Parcelable {

constructor(id: Long,
name: String,
description: 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.readString()!!,
source.readParcelable(Taxonomy::class.java.classLoader)!!,
source.readString(),
source.readByte() == 1.toByte())

Expand All @@ -59,6 +64,7 @@ abstract class AbstractTaxon : Parcelable {

if (id != other.id) return false
if (name != other.name) return false
if (taxonomy != other.taxonomy) return false
if (description != other.description) return false
if (heritage != other.heritage) return false

Expand All @@ -68,6 +74,7 @@ abstract class AbstractTaxon : Parcelable {
override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + taxonomy.hashCode()
result = 31 * result + (description?.hashCode() ?: 0)
result = 31 * result + heritage.hashCode()

Expand All @@ -82,6 +89,8 @@ abstract class AbstractTaxon : Parcelable {
flags: Int) {
dest?.writeLong(id)
dest?.writeString(name)
dest?.writeParcelable(taxonomy,
flags)
dest?.writeString(description)
dest?.writeByte((if (heritage) 1 else 0).toByte()) // as boolean value
}
Expand All @@ -99,6 +108,7 @@ abstract class AbstractTaxon : Parcelable {

val DEFAULT_PROJECTION = arrayOf(COLUMN_ID,
COLUMN_NAME,
*Taxonomy.DEFAULT_PROJECTION,
COLUMN_DESCRIPTION,
COLUMN_HERITAGE)
}
Expand Down
27 changes: 11 additions & 16 deletions commons/src/main/java/fr/geonature/commons/data/AppSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ import android.database.Cursor
import android.os.Parcel
import android.os.Parcelable
import fr.geonature.commons.util.IsoDateUtils.toDate
import java.util.*
import java.util.Date

/**
* Synchronization status.
*
* @author [S. Grimault](mailto:[email protected])
*/
data class AppSync(
var packageId: String?, var lastSync: Date? = null, var inputsToSynchronize: Int = 0
) : Parcelable {
data class AppSync(var packageId: String?,
var lastSync: Date? = null,
var inputsToSynchronize: Int = 0) : Parcelable {

private constructor(source: Parcel) : this(
source.readString(), source.readSerializable() as Date, source.readInt()
)
private constructor(source: Parcel) : this(source.readString(),
source.readSerializable() as Date,
source.readInt())

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel?, flags: Int) {
override fun writeToParcel(dest: Parcel?,
flags: Int) {
dest?.writeString(packageId)
dest?.writeSerializable(lastSync)
dest?.writeInt(inputsToSynchronize)
Expand All @@ -49,14 +50,8 @@ data class AppSync(
}

val appSync = AppSync(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_ID)))
appSync.lastSync = toDate(
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_LAST_SYNC))
)
appSync.inputsToSynchronize = cursor.getInt(
cursor.getColumnIndexOrThrow(
COLUMN_INPUTS_TO_SYNCHRONIZE
)
)
appSync.lastSync = toDate(cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_LAST_SYNC)))
appSync.inputsToSynchronize = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_INPUTS_TO_SYNCHRONIZE))

return appSync
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ data class InputObserver(
* The unique ID of the input observer.
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(index = true,
name = COLUMN_ID)
@ColumnInfo(name = COLUMN_ID)
var id: Long,

/**
Expand Down
164 changes: 164 additions & 0 deletions commons/src/main/java/fr/geonature/commons/data/Nomenclature.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package fr.geonature.commons.data

import android.database.Cursor
import android.os.Parcel
import android.os.Parcelable
import android.provider.BaseColumns
import android.util.Log
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.ForeignKey.CASCADE
import androidx.room.PrimaryKey
import fr.geonature.commons.util.get

/**
* Describes a nomenclature item.
*
* @author [S. Grimault](mailto:[email protected])
*/
@Entity(tableName = Nomenclature.TABLE_NAME)
open class Nomenclature : Parcelable {

/**
* The unique ID of this nomenclature.
*/
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = COLUMN_ID)
var id: Long

@ColumnInfo(name = COLUMN_CODE)
var code: String

@ColumnInfo(name = COLUMN_HIERARCHY)
var hierarchy: String

@ColumnInfo(name = COLUMN_DEFAULT_LABEL)
var defaultLabel: String

@ForeignKey(entity = NomenclatureType::class,
parentColumns = [NomenclatureType.COLUMN_ID],
childColumns = [COLUMN_TYPE_ID],
onDelete = CASCADE)
@ColumnInfo(name = COLUMN_TYPE_ID)
var typeId: Long

constructor(id: Long,
code: String,
hierarchy: String,
defaultLabel: String,
typeId: Long) {
this.id = id
this.code = code
this.hierarchy = hierarchy
this.defaultLabel = defaultLabel
this.typeId = typeId
}

internal constructor(source: Parcel) : this(source.readLong(),
source.readString()!!,
source.readString()!!,
source.readString()!!,
source.readLong())

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Nomenclature) return false

if (id != other.id) return false
if (code != other.code) return false
if (hierarchy != other.hierarchy) return false
if (defaultLabel != other.defaultLabel) return false
if (typeId != other.typeId) return false

return true
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + code.hashCode()
result = 31 * result + hierarchy.hashCode()
result = 31 * result + defaultLabel.hashCode()
result = 31 * result + typeId.hashCode()

return result
}

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel?,
flags: Int) {
dest?.writeLong(id)
dest?.writeString(code)
dest?.writeString(hierarchy)
dest?.writeString(defaultLabel)
dest?.writeLong(typeId)
}

companion object {

private val TAG = Nomenclature::class.java.name

/**
* The name of the 'nomenclatures' table.
*/
const val TABLE_NAME = "nomenclatures"

/**
* The name of the 'ID' column.
*/
const val COLUMN_ID = BaseColumns._ID

const val COLUMN_CODE = "code"
const val COLUMN_HIERARCHY = "hierarchy"
const val COLUMN_DEFAULT_LABEL = "default_label"
const val COLUMN_TYPE_ID = "type_id"

val DEFAULT_PROJECTION = arrayOf(COLUMN_ID,
COLUMN_CODE,
COLUMN_HIERARCHY,
COLUMN_DEFAULT_LABEL,
COLUMN_TYPE_ID)

/**
* Create a new [Nomenclature] from the specified [Cursor].
*
* @param cursor A valid [Cursor]
*
* @return A newly created [Nomenclature] instance
*/
fun fromCursor(cursor: Cursor): Nomenclature? {
if (cursor.isClosed) {
return null
}

return try {
Nomenclature(requireNotNull(cursor.get(COLUMN_ID)),
requireNotNull(cursor.get(COLUMN_CODE)),
requireNotNull(cursor.get(COLUMN_HIERARCHY)),
requireNotNull(cursor.get(COLUMN_DEFAULT_LABEL)),
requireNotNull(cursor.get(COLUMN_TYPE_ID)))
}
catch (iae: IllegalArgumentException) {
Log.w(TAG,
iae.message)

null
}
}

@JvmField
val CREATOR: Parcelable.Creator<Nomenclature> = object : Parcelable.Creator<Nomenclature> {

override fun createFromParcel(source: Parcel): Nomenclature {
return Nomenclature(source)
}

override fun newArray(size: Int): Array<Nomenclature?> {
return arrayOfNulls(size)
}
}
}
}
Loading

0 comments on commit 40517d0

Please sign in to comment.