-
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
44 changed files
with
1,756 additions
and
226 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | ||
} | ||
|
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
164 changes: 164 additions & 0 deletions
164
commons/src/main/java/fr/geonature/commons/data/Nomenclature.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,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) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.