Skip to content

Commit

Permalink
Merge branch 'release/0.1.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Dec 18, 2019
2 parents da6f24a + ef6e5de commit 37c8f32
Show file tree
Hide file tree
Showing 167 changed files with 7,809 additions and 1,713 deletions.
21 changes: 21 additions & 0 deletions .idea/codeStyles/Project.xml

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

674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions artwork/sync_launcher.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 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.50'
ext.kotlin_version = '1.3.61'

repositories {
google()
Expand All @@ -10,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.3'
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.4.2"
version = "0.5.3"

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-rc01"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-rc03"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
api 'androidx.room:room-runtime:2.2.1'
api 'androidx.room:room-runtime:2.2.2'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
Expand Down
43 changes: 32 additions & 11 deletions commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Parcelable
import android.provider.BaseColumns
import androidx.room.ColumnInfo
import androidx.room.Embedded
import fr.geonature.commons.data.helper.EntityHelper.column

/**
* Base taxon.
Expand Down Expand Up @@ -87,12 +88,14 @@ abstract class AbstractTaxon : Parcelable {

override fun writeToParcel(dest: Parcel?,
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
dest?.also {
it.writeLong(id)
it.writeString(name)
it.writeParcelable(taxonomy,
flags)
it.writeString(description)
it.writeByte((if (heritage) 1 else 0).toByte()) // as boolean value
}
}

companion object {
Expand All @@ -106,10 +109,28 @@ abstract class AbstractTaxon : Parcelable {
const val COLUMN_DESCRIPTION = "description"
const val COLUMN_HERITAGE = "heritage"

val DEFAULT_PROJECTION = arrayOf(COLUMN_ID,
COLUMN_NAME,
*Taxonomy.DEFAULT_PROJECTION,
COLUMN_DESCRIPTION,
COLUMN_HERITAGE)
/**
* Gets the default projection.
*/
fun defaultProjection(tableAlias: String): Array<Pair<String, String>> {
return arrayOf(column(COLUMN_ID,
tableAlias),
column(COLUMN_NAME,
tableAlias),
*Taxonomy.defaultProjection(tableAlias),
column(COLUMN_DESCRIPTION,
tableAlias),
column(COLUMN_HERITAGE,
tableAlias))
}

/**
* Gets alias from given column name.
*/
fun getColumnAlias(columnName: String,
tableAlias: String): String {
return column(columnName,
tableAlias).second
}
}
}
60 changes: 49 additions & 11 deletions commons/src/main/java/fr/geonature/commons/data/AppSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ package fr.geonature.commons.data
import android.database.Cursor
import android.os.Parcel
import android.os.Parcelable
import fr.geonature.commons.util.IsoDateUtils.toDate
import android.util.Log
import fr.geonature.commons.data.helper.EntityHelper.column
import fr.geonature.commons.data.helper.get
import java.util.Date

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

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

Expand All @@ -25,35 +27,71 @@ data class AppSync(var packageId: String?,

override fun writeToParcel(dest: Parcel?,
flags: Int) {
dest?.writeString(packageId)
dest?.writeSerializable(lastSync)
dest?.writeInt(inputsToSynchronize)
dest?.also {
it.writeString(packageId)
it.writeSerializable(lastSync)
it.writeInt(inputsToSynchronize)
}
}

companion object {

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

const val TABLE_NAME = "app_sync"
const val COLUMN_ID = "package_id"
const val COLUMN_LAST_SYNC = "last_sync"
const val COLUMN_INPUTS_TO_SYNCHRONIZE = "inputs_to_synchronize"

/**
* Gets the default projection.
*/
fun defaultProjection(tableAlias: String = TABLE_NAME): Array<Pair<String, String>> {
return arrayOf(column(COLUMN_ID,
tableAlias),
column(COLUMN_LAST_SYNC,
tableAlias),
column(COLUMN_INPUTS_TO_SYNCHRONIZE,
tableAlias))
}

/**
* Gets alias from given column name.
*/
fun getColumnAlias(columnName: String,
tableAlias: String = TABLE_NAME): String {
return column(columnName,
tableAlias).second
}

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

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))
return try {
AppSync(requireNotNull(cursor.get(getColumnAlias(COLUMN_ID,
tableAlias))),
cursor.get(getColumnAlias(COLUMN_LAST_SYNC,
tableAlias)),
requireNotNull(cursor.get(getColumnAlias(COLUMN_INPUTS_TO_SYNCHRONIZE,
tableAlias),
0)))
}
catch (e: Exception) {
Log.w(TAG,
e.message)

return appSync
null
}
}

@JvmField
Expand Down
Loading

0 comments on commit 37c8f32

Please sign in to comment.