-
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
167 changed files
with
7,809 additions
and
1,713 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -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()) | ||
|
||
|
@@ -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 | ||
|
Oops, something went wrong.