-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
114 changed files
with
5,600 additions
and
322 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package fr.geonature.commons.data | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import android.provider.BaseColumns | ||
import androidx.room.ColumnInfo | ||
import androidx.room.PrimaryKey | ||
|
||
/** | ||
* Base taxon. | ||
* | ||
* @author [S. Grimault](mailto:[email protected]) | ||
*/ | ||
abstract class AbstractTaxon : Parcelable { | ||
|
||
/** | ||
* The unique ID of the taxon. | ||
*/ | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo(name = COLUMN_ID) | ||
var id: Long | ||
|
||
/** | ||
* The default name of the taxon. | ||
*/ | ||
@ColumnInfo(name = COLUMN_NAME) | ||
var name: String | ||
|
||
/** | ||
* The description of the taxon. | ||
*/ | ||
@ColumnInfo(name = COLUMN_DESCRIPTION) | ||
var description: String? | ||
|
||
/** | ||
* Whether the taxon is part of the heritage. | ||
*/ | ||
@ColumnInfo(name = COLUMN_HERITAGE) | ||
var heritage: Boolean = false | ||
|
||
constructor(id: Long, | ||
name: String, | ||
description: String?, | ||
heritage: Boolean = false) { | ||
this.id = id | ||
this.name = name | ||
this.description = description | ||
this.heritage = heritage | ||
} | ||
|
||
constructor(source: Parcel) : this(source.readLong(), | ||
source.readString() ?: "", | ||
source.readString(), | ||
source.readByte() == 1.toByte()) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is AbstractTaxon) return false | ||
|
||
if (id != other.id) return false | ||
if (name != other.name) return false | ||
if (description != other.description) return false | ||
if (heritage != other.heritage) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = id.hashCode() | ||
result = 31 * result + name.hashCode() | ||
result = 31 * result + (description?.hashCode() ?: 0) | ||
result = 31 * result + heritage.hashCode() | ||
|
||
return result | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
override fun writeToParcel(dest: Parcel?, | ||
flags: Int) { | ||
dest?.writeLong(id) | ||
dest?.writeString(name) | ||
dest?.writeString(description) | ||
dest?.writeByte((if (heritage) 1 else 0).toByte()) // as boolean value | ||
} | ||
|
||
companion object { | ||
|
||
/** | ||
* The name of the 'ID' column. | ||
*/ | ||
const val COLUMN_ID = BaseColumns._ID | ||
|
||
const val COLUMN_NAME = "name" | ||
const val COLUMN_DESCRIPTION = "description" | ||
const val COLUMN_HERITAGE = "heritage" | ||
|
||
val DEFAULT_PROJECTION = arrayOf(COLUMN_ID, | ||
COLUMN_NAME, | ||
COLUMN_DESCRIPTION, | ||
COLUMN_HERITAGE) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
commons/src/main/java/fr/geonature/commons/data/Converters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fr.geonature.commons.data | ||
|
||
import androidx.room.TypeConverter | ||
import java.util.Date | ||
|
||
/** | ||
* Type converters. | ||
* | ||
* @author [S. Grimault](mailto:[email protected]) | ||
*/ | ||
object Converters { | ||
|
||
/** | ||
* Converts timestamp to Date. | ||
*/ | ||
@TypeConverter | ||
@JvmStatic | ||
fun fromTimestamp(value: Long?): Date? { | ||
return value?.let { Date(it) } | ||
} | ||
|
||
/** | ||
* Converts Date to timestamp. | ||
*/ | ||
@TypeConverter | ||
@JvmStatic | ||
fun dateToTimestamp(date: Date?): Long? { | ||
return date?.time | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.