Skip to content

Commit

Permalink
Merge branch 'release/0.0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Sep 14, 2019
2 parents cd4d309 + cd81c3d commit 6b47ebe
Show file tree
Hide file tree
Showing 114 changed files with 5,600 additions and 322 deletions.
13 changes: 3 additions & 10 deletions .idea/codeStyles/Project.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.

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.40'
ext.kotlin_version = '1.3.50'

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

dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.5.0'
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
16 changes: 9 additions & 7 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.1.2"
version = "0.3.1"

android {
compileSdkVersion 28
Expand Down Expand Up @@ -42,18 +42,20 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"

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

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'org.mockito:mockito-core:2.27.0'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'org.mockito:mockito-core:3.0.0'
testImplementation 'org.robolectric:robolectric:4.3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
105 changes: 105 additions & 0 deletions commons/src/main/java/fr/geonature/commons/data/AbstractTaxon.kt
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 commons/src/main/java/fr/geonature/commons/data/Converters.kt
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
}
}
68 changes: 34 additions & 34 deletions commons/src/main/java/fr/geonature/commons/data/InputObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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.PrimaryKey
import fr.geonature.commons.util.get

/**
* Describes an input observer.
Expand All @@ -19,22 +21,22 @@ data class InputObserver(
/**
* The unique ID of the input observer.
*/
@PrimaryKey(autoGenerate = true) @ColumnInfo(index = true,
name = COLUMN_ID) var id: Long,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(index = true,
name = COLUMN_ID)
var id: Long,

/**
* The last name of the input observer.
*/
@ColumnInfo(name = COLUMN_LASTNAME) var lastname: String?,
@ColumnInfo(name = COLUMN_LASTNAME)
var lastname: String?,

/**
* The first name of the input observer.
*/
@ColumnInfo(name = COLUMN_FIRSTNAME) var firstname: String?) : Parcelable {

private constructor(builder: Builder) : this(builder.id!!,
builder.lastname,
builder.firstname)
@ColumnInfo(name = COLUMN_FIRSTNAME)
var firstname: String?) : Parcelable {

private constructor(source: Parcel) : this(source.readLong(),
source.readString(),
Expand All @@ -51,23 +53,10 @@ data class InputObserver(
dest?.writeString(firstname)
}

data class Builder(var id: Long? = null,
var lastname: String? = null,
var firstname: String? = null) {
fun id(id: Long) = apply { this.id = id }
fun lastname(lastname: String?) = apply { this.lastname = lastname }
fun firstname(firstname: String?) = apply { this.firstname = firstname }

@Throws(java.lang.IllegalArgumentException::class)
fun build() : InputObserver {
if (id == null) throw IllegalArgumentException("InputObserver with null ID is not allowed")

return InputObserver(this)
}
}

companion object {

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

/**
* The name of the 'observers' table.
*/
Expand All @@ -88,6 +77,10 @@ data class InputObserver(
*/
const val COLUMN_FIRSTNAME = "firstname"

val DEFAULT_PROJECTION = arrayOf(COLUMN_ID,
COLUMN_LASTNAME,
COLUMN_FIRSTNAME)

/**
* Create a new [InputObserver] from the specified [Cursor].
*
Expand All @@ -100,22 +93,29 @@ data class InputObserver(
return null
}

return InputObserver(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID)),
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_LASTNAME)),
cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_FIRSTNAME)))
return try {
InputObserver(requireNotNull(cursor.get(COLUMN_ID)),
cursor.get(COLUMN_LASTNAME),
cursor.get(COLUMN_FIRSTNAME))
}
catch (iae: IllegalArgumentException) {
Log.w(TAG,
iae.message)

null
}
}

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

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

override fun newArray(size: Int): Array<InputObserver?> {
return arrayOfNulls(size)
}
override fun newArray(size: Int): Array<InputObserver?> {
return arrayOfNulls(size)
}
}
}
}
11 changes: 5 additions & 6 deletions commons/src/main/java/fr/geonature/commons/data/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fr.geonature.commons.data

import android.content.Context
import android.net.Uri
import android.net.Uri.withAppendedPath
import fr.geonature.commons.R

/**
Expand All @@ -24,15 +25,13 @@ object Provider {
/**
* Build resource [Uri].
*/
fun buildUri(
resource: String,
path: String = ""): Uri {
fun buildUri(resource: String,
vararg path: String): Uri {

val baseUri = Uri.parse("content://$AUTHORITY/$resource")

return if (path.isEmpty()) baseUri
else Uri.withAppendedPath(
baseUri,
path)
else withAppendedPath(baseUri,
path.asSequence().filter { it.isNotBlank() }.joinToString("/"))
}
}
Loading

0 comments on commit 6b47ebe

Please sign in to comment.