Skip to content

Commit

Permalink
Merge branch 'release/0.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Mar 28, 2020
2 parents ce81b13 + 15b3c9d commit 23e2af4
Show file tree
Hide file tree
Showing 106 changed files with 1,086 additions and 439 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/Project.xml

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

28 changes: 28 additions & 0 deletions artwork/ic_sync.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 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.6.2"
version = "0.6.3"

android {
compileSdkVersion 28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ object DeviceUtils {

val isPostLollipop: Boolean
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP

val isPostOreo: Boolean
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
}
24 changes: 15 additions & 9 deletions sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Synchronize local database through GeoNature API:

- Users (e.g. Observers)
- Users (i.e. Observers)
- Taxa (with "color" by areas and taxonomy)
- Dataset
- Nomenclature
Expand All @@ -18,19 +18,25 @@ Example:

```json
{
"application_id": 3,
"users_menu_id": 1,
"taxref_list_id": 100
"geonature_url": "http://demo.geonature/geonature",
"taxhub_url": "http://demo.geonature/taxhub",
"uh_application_id": 3,
"observers_list_id": 1,
"taxa_list_id": 100
}
```

### Parameters description

| Parameter | UI | Description |
| ---------------- | ------- | -------------------------------- |
| `application_id` | ☐ | GeoNature application ID |
| `users_menu_id` | ☐ | GeoNature selected users menu ID |
| `taxref_list_id` | ☐ | GeoNature selected taxa list ID |
| Parameter | UI | Description | Default value |
| ------------------- | ------- | ------------------------------------------------------ | ------------- |
| `geonature_url` | ☑ | GeoNature URL | |
| `taxhub_url` | ☑ | TaxHub URL | |
| `uh_application_id` | ☐ | GeoNature application ID | |
| `observers_list_id` | ☐ | GeoNature selected users menu ID | |
| `taxa_list_id` | ☐ | GeoNature selected taxa list ID | |
| `page_size` | ☐ | Default page size while fetching paginated values | 1000 |
| `page_max_retry` | ☐ | Max attempt to fetch data according to given page size | 20 |

## Content Provider

Expand Down
12 changes: 8 additions & 4 deletions sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"

version = "0.2.5"
version = "0.2.6"

android {
compileSdkVersion 28
Expand All @@ -13,6 +13,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

defaultConfig {
applicationId "fr.geonature.sync"
minSdkVersion 21
Expand Down Expand Up @@ -61,11 +65,11 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'androidx.core:core-ktx:1.3.0-alpha01'
implementation 'androidx.core:core-ktx:1.3.0-alpha02'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.work:work-runtime:2.3.2'
implementation 'androidx.work:work-runtime-ktx:2.3.2'
implementation 'androidx.work:work-runtime:2.3.3'
implementation 'androidx.work:work-runtime-ktx:2.3.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha05'
Expand Down
2 changes: 1 addition & 1 deletion sync/src/debug/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:fillColor="#000000"
android:pathData="M55,26V25h53v1z" />
<path
android:fillAlpha="0.4"
android:fillAlpha="1.0"
android:fillColor="@color/accent"
android:pathData="M54,25V0h54v25z" />
<path
Expand Down
Binary file modified sync/src/debug/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sync/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions sync/src/main/java/fr/geonature/sync/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package fr.geonature.sync

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.util.Log
import androidx.core.app.NotificationManagerCompat
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import fr.geonature.commons.util.DeviceUtils
import fr.geonature.mountpoint.util.MountPointUtils.getExternalStorage
import fr.geonature.mountpoint.util.MountPointUtils.getInternalStorage
import fr.geonature.sync.sync.CheckInputsToSynchronizeWorker
import java.util.concurrent.TimeUnit

/**
* Base class to maintain global application state.
Expand All @@ -23,9 +32,51 @@ class MainApplication : Application() {
TAG,
"external storage: " + getExternalStorage(this)
)

checkInputsToSynchronize()
}

private fun checkInputsToSynchronize() {
val notificationManager = NotificationManagerCompat.from(this)
configureSyncChannel(notificationManager)
val workManager: WorkManager = WorkManager.getInstance(this)

val request = PeriodicWorkRequestBuilder<CheckInputsToSynchronizeWorker>(
15,
TimeUnit.MINUTES
).addTag(CheckInputsToSynchronizeWorker.CHECK_INPUTS_TO_SYNC_WORKER_TAG)
.build()

workManager.enqueueUniquePeriodicWork(
CheckInputsToSynchronizeWorker.CHECK_INPUTS_TO_SYNC_WORKER,
ExistingPeriodicWorkPolicy.REPLACE,
request
)
}

private fun configureSyncChannel(notificationManager: NotificationManagerCompat): NotificationChannel? {
if (DeviceUtils.isPostOreo) {
val channel = NotificationChannel(
SYNC_CHANNEL_ID,
getText(R.string.sync_channel_name),
NotificationManager.IMPORTANCE_LOW
).apply {
description = getString(R.string.sync_channel_description)
setShowBadge(true)
}

// register this channel with the system
notificationManager.createNotificationChannel(channel)

return channel
}

return null
}

companion object {
private val TAG = MainApplication::class.java.name

const val SYNC_CHANNEL_ID = "sync_channel"
}
}
29 changes: 23 additions & 6 deletions sync/src/main/java/fr/geonature/sync/api/GeoNatureAPIClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,24 @@ class GeoNatureAPIClient private constructor(
geoNatureService = Retrofit.Builder()
.baseUrl("$geoNatureBaseUrl/")
.client(client)
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create()))
.addConverterFactory(
GsonConverterFactory.create(
GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
.create()
)
)
.build()
.create(GeoNatureService::class.java)

taxHubService = Retrofit.Builder()
.baseUrl("$taxHubBaseUrl/")
.client(client)
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create()))
.addConverterFactory(
GsonConverterFactory.create(
GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
.create()
)
)
.build()
.create(TaxHubService::class.java)
}
Expand Down Expand Up @@ -128,12 +138,19 @@ class GeoNatureAPIClient private constructor(
return taxHubService.getTaxonomyRanks()
}

fun getTaxref(listId: Int): Call<List<Taxref>> {
return taxHubService.getTaxref(listId)
fun getTaxref(listId: Int, limit: Int? = null, offset: Int? = null): Call<List<Taxref>> {
return taxHubService.getTaxref(
listId,
limit,
offset
)
}

fun getTaxrefAreas(): Call<List<TaxrefArea>> {
return geoNatureService.getTaxrefAreas()
fun getTaxrefAreas(limit: Int? = null, offset: Int? = null): Call<List<TaxrefArea>> {
return geoNatureService.getTaxrefAreas(
limit,
offset
)
}

fun getNomenclatures(): Call<List<NomenclatureType>> {
Expand Down
6 changes: 5 additions & 1 deletion sync/src/main/java/fr/geonature/sync/api/GeoNatureService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

/**
* GeoNature API interface definition.
Expand Down Expand Up @@ -45,7 +46,10 @@ interface GeoNatureService {
): Call<List<User>>

@GET("api/synthese/color_taxon")
fun getTaxrefAreas(): Call<List<TaxrefArea>>
fun getTaxrefAreas(
@Query("limit") limit: Int? = null,
@Query("offset") offset: Int? = null
): Call<List<TaxrefArea>>

@GET("api/nomenclatures/nomenclatures/taxonomy")
fun getNomenclatures(): Call<List<NomenclatureType>>
Expand Down
9 changes: 5 additions & 4 deletions sync/src/main/java/fr/geonature/sync/api/TaxHubService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

/**
* TaxHub API interface definition.
Expand All @@ -16,10 +17,10 @@ interface TaxHubService {
@GET("api/taxref/regnewithgroupe2")
fun getTaxonomyRanks(): Call<ResponseBody>

// TODO: fetch all taxa
@GET("api/taxref/allnamebylist/{id}?limit=10000")
@GET("api/taxref/allnamebylist/{id}")
fun getTaxref(
@Path("id")
listId: Int
@Path("id") listId: Int,
@Query("limit") limit: Int? = null,
@Query("offset") offset: Int? = null
): Call<List<Taxref>>
}
42 changes: 32 additions & 10 deletions sync/src/main/java/fr/geonature/sync/settings/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ import fr.geonature.commons.settings.IAppSettings
* @author [S. Grimault](mailto:[email protected])
*/
data class AppSettings(
var geoNatureServerUrl: String? = null,
var taxHubServerUrl: String? = null,
var applicationId: Int = 0,
var usersMenuId: Int = 0,
var taxrefListId: Int = 0
var usersListId: Int = 0,
var taxrefListId: Int = 0,
var pageSize: Int = DEFAULT_PAGE_SIZE,
var pageMaxRetry: Int = DEFAULT_PAGE_MAX_RETRY
) : IAppSettings {

private constructor(source: Parcel) : this(source.readInt())
private constructor(source: Parcel) : this(
source.readString(),
source.readString(),
source.readInt(),
source.readInt(),
source.readInt(),
source.readInt(),
source.readInt()
)

override fun describeContents(): Int {
return 0
Expand All @@ -26,19 +38,29 @@ data class AppSettings(
flags: Int
) {
dest?.also {
it.writeString(geoNatureServerUrl)
it.writeString(taxHubServerUrl)
it.writeInt(applicationId)
it.writeInt(usersMenuId)
it.writeInt(usersListId)
it.writeInt(taxrefListId)
it.writeInt(pageSize)
it.writeInt(pageMaxRetry)
}
}

companion object CREATOR : Parcelable.Creator<AppSettings> {
override fun createFromParcel(parcel: Parcel): AppSettings {
return AppSettings(parcel)
}
companion object {
const val DEFAULT_PAGE_SIZE = 1000
const val DEFAULT_PAGE_MAX_RETRY = 20

@JvmField
val CREATOR: Parcelable.Creator<AppSettings> = object : Parcelable.Creator<AppSettings> {
override fun createFromParcel(parcel: Parcel): AppSettings {
return AppSettings(parcel)
}

override fun newArray(size: Int): Array<AppSettings?> {
return arrayOfNulls(size)
override fun newArray(size: Int): Array<AppSettings?> {
return arrayOfNulls(size)
}
}
}
}
Loading

0 comments on commit 23e2af4

Please sign in to comment.