Skip to content

Commit

Permalink
Merge branch 'release/0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Jun 21, 2020
2 parents b74dd57 + ee84e5a commit 5e0005a
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 72 deletions.
48 changes: 42 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,61 @@

GeoNature Android mobile application for Occtax module.

## Settings

Example:

```json
{
"area_observation_duration": 365,
"map": {
"show_scale": true,
"show_compass": true,
"max_bounds": [
[47.253369, -1.605721],
[47.173845, -1.482811]
],
"center": [47.225827, -1.55447],
"start_zoom": 10.0,
"min_zoom": 8.0,
"max_zoom": 19.0,
"min_zoom_editing": 12.0,
"layers": [
{
"label": "Nantes",
"source": "nantes.mbtiles"
}
]
}
}
```

### Parameters description

| Parameter | UI | Description | Default value |
| --------------------------- | ------- | ------------------------------------------------------------------------------ | ------------- |
| `area_observation_duration` | ☐ | Area observation duration period (in days) | 365 |
| `map` | ☐ | Maps settings (cf. https://github.com/PnX-SI/gn_mobile_maps/tree/develop/maps) | |

## Upgrade git sub modules

Do **NOT** modify directly any git sub modules (e.g. `commons`, `mountpoint`, `viewpager` and `maps`).
Any changes should be made from each underlying git repository:

* `commons`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
* `mountpoint`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
* `viewpager`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
* `maps`: [gn_mobile_maps](https://github.com/PnX-SI/gn_mobile_maps) git repository
- `commons`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
- `mountpoint`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
- `viewpager`: [gn_mobile_core](https://github.com/PnX-SI/gn_mobile_core) git repository
- `maps`: [gn_mobile_maps](https://github.com/PnX-SI/gn_mobile_maps) git repository

```bash
./upgrade_submodules.sh
```

## Troubleshooting

* Kotlin error, Redeclaration from class within imported module:
- Kotlin error, Redeclaration from class within imported module:

clean project from menu *Build -> Clean Project*, then rebuild project.
clean project from menu _Build -> Clean Project_, then rebuild project.

## Full Build

Expand Down
2 changes: 1 addition & 1 deletion occtax/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

version = "0.3.3"
version = "0.3.4"

android {
compileSdkVersion 29
Expand Down
44 changes: 30 additions & 14 deletions occtax/src/main/java/fr/geonature/occtax/settings/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import fr.geonature.maps.settings.MapSettings
*
* @author [S. Grimault](mailto:sebastien.grimault@gmail.com)
*/
data class AppSettings(var mapSettings: MapSettings? = null) : IAppSettings {
data class AppSettings(
var areaObservationDuration: Int = DEFAULT_AREA_OBSERVATION_DURATION,
var mapSettings: MapSettings? = null
) : IAppSettings {

private constructor(source: Parcel) : this(source.readParcelable(MapSettings::class.java.classLoader) as MapSettings?)
private constructor(source: Parcel) : this(
source.readInt(),
source.readParcelable(MapSettings::class.java.classLoader) as MapSettings?
)

override fun describeContents(): Int {
return 0
Expand All @@ -22,34 +28,44 @@ data class AppSettings(var mapSettings: MapSettings? = null) : IAppSettings {
dest: Parcel?,
flags: Int
) {
dest?.writeParcelable(
dest?.also {
it.writeInt(areaObservationDuration)
it.writeParcelable(
mapSettings,
0
)
)
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as AppSettings
if (other !is AppSettings) return false

if (areaObservationDuration != other.areaObservationDuration) return false
if (mapSettings != other.mapSettings) return false

return true
}

override fun hashCode(): Int {
return mapSettings.hashCode()
var result = areaObservationDuration
result = 31 * result + (mapSettings?.hashCode() ?: 0)

return result
}

companion object CREATOR : Parcelable.Creator<AppSettings> {
override fun createFromParcel(parcel: Parcel): AppSettings {
return AppSettings(parcel)
}
companion object {
const val DEFAULT_AREA_OBSERVATION_DURATION = 365

@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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import fr.geonature.occtax.settings.AppSettings
*
* @author [S. Grimault](mailto:sebastien.grimault@gmail.com)
*/
class OnAppSettingsJsonReaderListenerImpl : AppSettingsJsonReader.OnAppSettingsJsonReaderListener<AppSettings> {
class OnAppSettingsJsonReaderListenerImpl :
AppSettingsJsonReader.OnAppSettingsJsonReaderListener<AppSettings> {

override fun createAppSettings(): AppSettings {
return AppSettings()
Expand All @@ -23,10 +24,13 @@ class OnAppSettingsJsonReaderListenerImpl : AppSettingsJsonReader.OnAppSettingsJ
appSettings: AppSettings
) {
when (keyName) {
"area_observation_duration" -> appSettings.areaObservationDuration = reader.nextInt()
"map" -> {
if (reader.peek() == JsonToken.BEGIN_OBJECT) {
readMapSettings(reader,
appSettings)
readMapSettings(
reader,
appSettings
)
} else {
reader.skipValue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class InputPagerFragmentActivity : AbstractNavigationHistoryPagerFragmentActivit
)
put(
R.string.pager_fragment_taxa_title,
TaxaFragment.newInstance()
TaxaFragment.newInstance(appSettings.areaObservationDuration)
)
put(
R.string.pager_fragment_information_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import fr.geonature.occtax.settings.AppSettings

/**
* Apply filters on taxa list.
Expand Down Expand Up @@ -37,7 +38,11 @@ class TaxaFilterActivity : AppCompatActivity(), TaxaFilterFragment.OnTaxaFilterF
EXTRA_WITH_AREA_OBSERVATION,
false
),
*selectedFilters.toTypedArray()
intent.getIntExtra(
EXTRA_AREA_OBSERVATION_DURATION,
AppSettings.DEFAULT_AREA_OBSERVATION_DURATION
),
* selectedFilters.toTypedArray()
)
)
.commit()
Expand Down Expand Up @@ -83,10 +88,12 @@ class TaxaFilterActivity : AppCompatActivity(), TaxaFilterFragment.OnTaxaFilterF

const val EXTRA_SELECTED_FILTERS = "extra_selected_filters"
const val EXTRA_WITH_AREA_OBSERVATION = "extra_with_area_observation"
const val EXTRA_AREA_OBSERVATION_DURATION = "extra_area_observation_duration"

fun newIntent(
context: Context,
withAreaObservation: Boolean = false,
areaObservationDuration: Int = AppSettings.DEFAULT_AREA_OBSERVATION_DURATION,
vararg filter: Filter<*>
): Intent {
return Intent(
Expand All @@ -97,6 +104,10 @@ class TaxaFilterActivity : AppCompatActivity(), TaxaFilterFragment.OnTaxaFilterF
EXTRA_WITH_AREA_OBSERVATION,
withAreaObservation
)
putExtra(
EXTRA_AREA_OBSERVATION_DURATION,
areaObservationDuration
)
putExtra(
EXTRA_SELECTED_FILTERS,
filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView
import fr.geonature.commons.data.Taxonomy
import fr.geonature.commons.data.helper.Provider
import fr.geonature.occtax.R
import fr.geonature.occtax.settings.AppSettings

/**
* [Fragment] to let the user to apply filters on taxa list.
Expand Down Expand Up @@ -137,8 +138,17 @@ class TaxaFilterFragment : Fragment() {
) {
progressBar?.visibility = View.VISIBLE

if (arguments?.getBoolean(ARG_WITH_AREA_OBSERVATION, false) == true) {
loadFilterAreaObservation()
if (arguments?.getBoolean(
ARG_WITH_AREA_OBSERVATION,
false
) == true
) {
loadFilterAreaObservation(
arguments?.getInt(
ARG_AREA_OBSERVATION_DURATION,
AppSettings.DEFAULT_AREA_OBSERVATION_DURATION
) ?: AppSettings.DEFAULT_AREA_OBSERVATION_DURATION
)
}

LoaderManager.getInstance(this)
Expand All @@ -165,17 +175,17 @@ class TaxaFilterFragment : Fragment() {
listener = null
}

private fun loadFilterAreaObservation(duration: Int = 365) {
private fun loadFilterAreaObservation(duration: Int) {
val context = context ?: return

val formatDuration: (Int) -> String = {
when {
(it >= 365) -> context.resources.getQuantityString(
(it % 365 == 0) -> context.resources.getQuantityString(
R.plurals.duration_year,
(it / 365),
(it / 365)
)
(it >= 30) -> context.resources.getQuantityString(
(it % 30 == 0) -> context.resources.getQuantityString(
R.plurals.duration_month,
(it / 30),
(it / 30)
Expand Down Expand Up @@ -247,6 +257,7 @@ class TaxaFilterFragment : Fragment() {
private val TAG = TaxaFilterFragment::class.java.name

private const val ARG_WITH_AREA_OBSERVATION = "arg_with_area_observation"
private const val ARG_AREA_OBSERVATION_DURATION = "arg_area_observation_duration"
private const val ARG_FILTERS = "arg_filters"
private const val LOADER_TAXONOMY = 1

Expand All @@ -256,13 +267,21 @@ class TaxaFilterFragment : Fragment() {
* @return A new instance of [TaxaFilterFragment]
*/
@JvmStatic
fun newInstance(withAreaObservation: Boolean = false, vararg filter: Filter<*>) =
fun newInstance(
withAreaObservation: Boolean = false,
areaObservationDuration: Int = AppSettings.DEFAULT_AREA_OBSERVATION_DURATION,
vararg filter: Filter<*>
) =
TaxaFilterFragment().apply {
arguments = Bundle().apply {
putBoolean(
ARG_WITH_AREA_OBSERVATION,
withAreaObservation
)
putInt(
ARG_AREA_OBSERVATION_DURATION,
areaObservationDuration
)
putParcelableArray(
ARG_FILTERS,
filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import fr.geonature.commons.util.ThemeUtils
import fr.geonature.occtax.R
import fr.geonature.occtax.input.Input
import fr.geonature.occtax.input.InputTaxon
import fr.geonature.occtax.settings.AppSettings
import fr.geonature.occtax.ui.input.IInputFragment
import fr.geonature.viewpager.ui.AbstractPagerFragmentActivity
import fr.geonature.viewpager.ui.IValidateFragment
Expand Down Expand Up @@ -350,6 +351,10 @@ class TaxaFragment : Fragment(),
TaxaFilterActivity.newIntent(
context,
!savedState.getString(KEY_SELECTED_FEATURE_ID).isNullOrEmpty(),
arguments?.getInt(
ARG_AREA_OBSERVATION_DURATION,
AppSettings.DEFAULT_AREA_OBSERVATION_DURATION
) ?: AppSettings.DEFAULT_AREA_OBSERVATION_DURATION,
*getSelectedFilters().toTypedArray()
),
RESULT_FILTER
Expand Down Expand Up @@ -600,6 +605,7 @@ class TaxaFragment : Fragment(),

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

private const val ARG_AREA_OBSERVATION_DURATION = "arg_area_observation_duration"
private const val LOADER_TAXA = 1
private const val LOADER_TAXON = 2
private const val RESULT_FILTER = 3
Expand All @@ -614,6 +620,14 @@ class TaxaFragment : Fragment(),
* @return A new instance of [TaxaFragment]
*/
@JvmStatic
fun newInstance() = TaxaFragment()
fun newInstance(areaObservationDuration: Int = AppSettings.DEFAULT_AREA_OBSERVATION_DURATION) =
TaxaFragment().apply {
arguments = Bundle().apply {
putInt(
ARG_AREA_OBSERVATION_DURATION,
areaObservationDuration
)
}
}
}
}
4 changes: 2 additions & 2 deletions occtax/src/test/java/fr/geonature/occtax/input/InputTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.geonature.occtax.input
import android.os.Parcel
import fr.geonature.commons.data.Taxon
import fr.geonature.commons.data.Taxonomy
import fr.geonature.commons.util.IsoDateUtils
import fr.geonature.commons.util.toDate
import java.util.Date
import org.junit.Assert.assertEquals
import org.junit.Test
Expand Down Expand Up @@ -34,7 +34,7 @@ class InputTest {
null,
133
)
date = IsoDateUtils.toDate("2016-10-28") ?: Date()
date = toDate("2016-10-28") ?: Date()
setPrimaryInputObserverId(1L)
addInputObserverId(5L)
addInputObserverId(2L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fr.geonature.commons.data.Taxon
import fr.geonature.commons.data.Taxonomy
import fr.geonature.commons.input.AbstractInputTaxon
import fr.geonature.commons.input.io.InputJsonReader
import fr.geonature.commons.util.IsoDateUtils.toDate
import fr.geonature.commons.util.toDate
import fr.geonature.occtax.FixtureHelper.getFixture
import fr.geonature.occtax.input.CountingMetadata
import fr.geonature.occtax.input.Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.geonature.occtax.input.io
import fr.geonature.commons.data.Taxon
import fr.geonature.commons.data.Taxonomy
import fr.geonature.commons.input.io.InputJsonWriter
import fr.geonature.commons.util.IsoDateUtils.toDate
import fr.geonature.commons.util.toDate
import fr.geonature.occtax.FixtureHelper.getFixture
import fr.geonature.occtax.input.CountingMetadata
import fr.geonature.occtax.input.Input
Expand Down
Loading

0 comments on commit 5e0005a

Please sign in to comment.