Skip to content

Commit

Permalink
Merge branch 'release/2.4.1-rc4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrimault committed Feb 21, 2023
2 parents 3dd8eb9 + 8cee4db commit b4db34e
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 103 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [2.4.1-rc4](https://github.com/PnX-SI/gn_mobile_occtax/releases/tag/2.4.1-rc4) (2023-02-21, pre-release)

### 🚀 Corrections

* Gestion des médias sur la partie dénombrement (https://github.com/PnX-SI/gn_mobile_occtax/issues/84)
* Accélérer la saisie en permettant de mémoriser les dernières nomenclatures saisies sur la partie
dénombrement (https://github.com/PnX-SI/gn_mobile_occtax/issues/169).

### ⚠️ Notes de version

* Code de version : 3163

## [2.4.1-rc3](https://github.com/PnX-SI/gn_mobile_occtax/releases/tag/2.4.1-rc3) (2023-02-15, pre-release)

### 🚀 Nouveautés
Expand Down
4 changes: 2 additions & 2 deletions occtax/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId "fr.geonature.occtax2"
minSdkVersion 26
targetSdkVersion 31
versionCode 3137
versionName "2.4.1-rc3"
versionCode 3163
versionName "2.4.1-rc4"
buildConfigField "String", "BUILD_DATE", "\"" + new Date().getTime() + "\""
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
archivesBaseName = project.name + "-" + versionName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class EditableNomenclatureTypeAdapter(private val listener: OnEditableNomenclatu
value = nomenclatureAdapter.getNomenclatureValue(position)
.let { nomenclature ->
PropertyValue.Nomenclature(
nomenclature.code,
code,
nomenclature.defaultLabel,
nomenclature.id
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package fr.geonature.occtax.features.record.data

import android.content.Context
import android.webkit.MimeTypeMap
import fr.geonature.occtax.features.record.domain.CountingRecord
import fr.geonature.occtax.features.record.domain.TaxonRecord
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.toList
import org.tinylog.Logger
import java.io.File

/**
Expand All @@ -23,13 +25,25 @@ class MediaRecordLocalDataSourceImpl(private val context: Context) : IMediaRecor
context,
countingRecord
)
.also {
Logger.debug { "load all medias from '$it'..." }
}
.walkTopDown()
.asFlow()
.filter { file -> file.isFile && file.canWrite() }
.filter { file ->
file.isFile && file.canWrite() && file.toURI()
val mimetype = file.toURI()
.toURL()
.run { openConnection().contentType }
?.startsWith("image/") == true
?: file.extension.takeIf { it.isNotEmpty() }
?.let {
MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(it)
}

Logger.debug { "loading file '${file.name}' (mime-type: $mimetype)" }

file.isFile && file.canWrite() && mimetype?.startsWith("image/") == true
}
.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ class ObservationRecordLocalDataSourceImpl(
observationRecord.copy(status = ObservationRecord.Status.TO_SYNC)
.apply { module.module = geoNatureModuleName }

delete(observationRecord.internalId)
if (preferenceManager.contains(buildInputPreferenceKey(observationRecord.internalId))) {
preferenceManager
.edit()
.remove(buildInputPreferenceKey(observationRecord.internalId))
.apply()
}

return withContext(dispatcher) {
val inputAsJson =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import fr.geonature.commons.interactor.BaseResultUseCase
import fr.geonature.commons.lifecycle.BaseViewModel
import fr.geonature.occtax.features.record.domain.ObservationRecord
import fr.geonature.occtax.features.record.usecase.DeleteObservationRecordUseCase
import fr.geonature.occtax.features.record.usecase.EditObservationRecordUseCase
import fr.geonature.occtax.features.record.usecase.ExportObservationRecordUseCase
import fr.geonature.occtax.features.record.usecase.GetAllObservationRecordsUseCase
import fr.geonature.occtax.features.record.usecase.LoadAllMediaRecordUseCase
import fr.geonature.occtax.features.record.usecase.SaveObservationRecordUseCase
import fr.geonature.occtax.features.record.usecase.SetDefaultNomenclatureValuesUseCase
import fr.geonature.occtax.settings.AppSettings
import org.tinylog.kotlin.Logger
import javax.inject.Inject
Expand All @@ -26,8 +25,7 @@ import javax.inject.Inject
class ObservationRecordViewModel @Inject constructor(
private val getAllObservationRecordsUseCase: GetAllObservationRecordsUseCase,
private val saveObservationRecordUseCase: SaveObservationRecordUseCase,
private val setDefaultNomenclatureValuesUseCase: SetDefaultNomenclatureValuesUseCase,
private val loadAllMediaRecordUseCase: LoadAllMediaRecordUseCase,
private val editObservationRecordUseCase: EditObservationRecordUseCase,
private val deleteObservationRecordUseCase: DeleteObservationRecordUseCase,
private val exportObservationRecordUseCase: ExportObservationRecordUseCase
) : BaseViewModel() {
Expand Down Expand Up @@ -59,53 +57,33 @@ class ObservationRecordViewModel @Inject constructor(
}

/**
* Edit current [ObservationRecord].
* Start edit the given [ObservationRecord].
*
* @param observationRecord the [ObservationRecord] to edit
*/
fun edit(observationRecord: ObservationRecord) {
_observationRecord.value = observationRecord
}

/**
* Loads and set all default nomenclature values to the given [ObservationRecord].
*
* @param observationRecord the [ObservationRecord] to update
*/
fun loadDefaultNomenclatureValues(observationRecord: ObservationRecord) {
fun startEdit(observationRecord: ObservationRecord) {
Logger.info { "loading default nomenclature values from record '${observationRecord.internalId}'..." }

setDefaultNomenclatureValuesUseCase(
SetDefaultNomenclatureValuesUseCase.Params(observationRecord),
editObservationRecordUseCase(
EditObservationRecordUseCase.Params(observationRecord),
viewModelScope
) {
it.fold(
onSuccess = { observationRecordUpdated ->
Logger.info { "default nomenclature values successfully loaded for record '${observationRecordUpdated.internalId}'" }

_observationRecord.value = observationRecordUpdated
},
::handleError
)
}
}

fun loadAllMedias(observationRecord: ObservationRecord) {
Logger.info { "loading all local medias from record '${observationRecord.internalId}'..." }

loadAllMediaRecordUseCase(
LoadAllMediaRecordUseCase.Params(observationRecord),
viewModelScope
) {
it.fold(
onSuccess = { observationRecordUpdated ->
Logger.info { "all medias successfully loaded for record '${observationRecordUpdated.internalId}'" }

_observationRecord.value = observationRecordUpdated
},
::handleError
)
}
/**
* Edit the current [ObservationRecord].
*
* @param observationRecord the [ObservationRecord] to edit
*/
fun edit(observationRecord: ObservationRecord) {
_observationRecord.value = observationRecord
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fr.geonature.occtax.features.record.usecase

import fr.geonature.commons.interactor.BaseResultUseCase
import fr.geonature.occtax.features.record.domain.ObservationRecord
import org.tinylog.kotlin.Logger
import javax.inject.Inject

/**
* Start editing the given [ObservationRecord].
*
* @author S. Grimault
*
* @see SetDefaultNomenclatureValuesUseCase
* @see LoadAllMediaRecordUseCase
*/
class EditObservationRecordUseCase @Inject constructor(
private val setDefaultNomenclatureValuesUseCase: SetDefaultNomenclatureValuesUseCase,
private val loadAllMediaRecordUseCase: LoadAllMediaRecordUseCase
) :
BaseResultUseCase<ObservationRecord, EditObservationRecordUseCase.Params>() {

override suspend fun run(params: Params): Result<ObservationRecord> {
Logger.info { "loading default nomenclature values from record '${params.observationRecord.internalId}'..." }

var result =
setDefaultNomenclatureValuesUseCase.run(SetDefaultNomenclatureValuesUseCase.Params(params.observationRecord))

if (result.isFailure) {
Logger.error { "failed to load default nomenclature values from record '${params.observationRecord.internalId}" }
return result
}

val observationRecordUpdated = result.getOrNull() ?: params.observationRecord

Logger.info { "default nomenclature values successfully loaded for record '${observationRecordUpdated.internalId}'" }
Logger.info { "loading all local medias from record '${observationRecordUpdated.internalId}'..." }

result =
loadAllMediaRecordUseCase.run(LoadAllMediaRecordUseCase.Params(observationRecordUpdated))

if (result.isFailure) {
Logger.warn { "failed to load all local medias from record '${observationRecordUpdated.internalId}'" }
return result
}

Logger.info { "all medias successfully loaded for record '${observationRecordUpdated.internalId}'" }

return result
}

data class Params(val observationRecord: ObservationRecord)
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class InputPagerFragmentActivity : AbstractPagerFragmentActivity(),

Logger.info { "loading observation record: ${observationRecord.id}" }

observationRecordViewModel.loadDefaultNomenclatureValues(observationRecord)
observationRecordViewModel.loadAllMedias(observationRecord)
observationRecordViewModel.startEdit(observationRecord)

pageFragmentViewModel.set(
R.string.pager_fragment_observers_and_date_input_title to ObserversAndDateInputFragment.newInstance(
Expand Down Expand Up @@ -188,6 +187,7 @@ class InputPagerFragmentActivity : AbstractPagerFragmentActivity(),
?: emptyArray()
),
R.string.pager_fragment_counting_title to CountingFragment.newInstance(
saveDefaultValues = appSettings.nomenclatureSettings?.saveDefaultValues ?: false,
*appSettings.nomenclatureSettings?.counting?.toTypedArray()
?: emptyArray()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CountingFragment : AbstractInputFragment() {
private var recyclerView: RecyclerView? = null
private var emptyTextView: TextView? = null
private var fab: ExtendedFloatingActionButton? = null
private var redirectToEditCountingMetadataActivity = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -196,7 +197,8 @@ class CountingFragment : AbstractInputFragment() {

adapter?.setItems(counting)

if (counting.isEmpty()) {
if (counting.isEmpty() && redirectToEditCountingMetadataActivity) {
redirectToEditCountingMetadataActivity = false
launchEditCountingMetadataActivity()
}
}
Expand All @@ -209,6 +211,10 @@ class CountingFragment : AbstractInputFragment() {
context,
taxonRecord,
countingRecord,
arguments?.getBoolean(
ARG_SAVE_DEFAULT_VALUES,
false
) ?: false,
*(arguments?.getParcelableArray(ARG_PROPERTIES)
?.map { it as PropertySettings }
?.toTypedArray() ?: emptyArray())
Expand Down Expand Up @@ -273,6 +279,7 @@ class CountingFragment : AbstractInputFragment() {

companion object {

private const val ARG_SAVE_DEFAULT_VALUES = "arg_save_default_values"
private const val ARG_PROPERTIES = "arg_properties"

/**
Expand All @@ -281,8 +288,15 @@ class CountingFragment : AbstractInputFragment() {
* @return A new instance of [CountingFragment]
*/
@JvmStatic
fun newInstance(vararg propertySettings: PropertySettings) = CountingFragment().apply {
fun newInstance(
saveDefaultValues: Boolean = false,
vararg propertySettings: PropertySettings
) = CountingFragment().apply {
arguments = Bundle().apply {
putBoolean(
ARG_SAVE_DEFAULT_VALUES,
saveDefaultValues
)
putParcelableArray(
ARG_PROPERTIES,
propertySettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,30 @@ class EditCountingMetadataActivity : AppCompatActivity(),
return
}

countingRecord = intent.getParcelableExtra(EXTRA_COUNTING_RECORD) ?: taxonRecord.counting.create()
countingRecord =
intent.getParcelableExtra(EXTRA_COUNTING_RECORD) ?: taxonRecord.counting.create()

isNew = countingRecord.isEmpty()
setTitle(if (countingRecord.isEmpty()) R.string.activity_counting_add_title else R.string.activity_counting_edit_title)

if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(
android.R.id.content,
EditCountingMetadataFragment.newInstance(
taxonRecord,
countingRecord,
*(intent.getParcelableArrayExtra(EXTRA_PROPERTIES)
?.map { it as PropertySettings }
?.toTypedArray() ?: emptyArray())
.apply {
replace(
android.R.id.content,
EditCountingMetadataFragment.newInstance(
taxonRecord,
countingRecord,
intent.getBooleanExtra(
EXTRA_SAVE_DEFAULT_VALUES,
false
),
*(intent.getParcelableArrayExtra(EXTRA_PROPERTIES)
?.map { it as PropertySettings }
?.toTypedArray() ?: emptyArray())
)
)
)
}
.commit()
}
}
Expand Down Expand Up @@ -125,12 +132,14 @@ class EditCountingMetadataActivity : AppCompatActivity(),

const val EXTRA_TAXON_RECORD = "extra_taxon_record"
const val EXTRA_COUNTING_RECORD = "extra_counting_record"
const val EXTRA_SAVE_DEFAULT_VALUES = "extra_save_default_values"
const val EXTRA_PROPERTIES = "extra_properties"

fun newIntent(
context: Context,
taxonRecord: TaxonRecord,
countingRecord: CountingRecord? = null,
saveDefaultValues: Boolean = false,
vararg propertySettings: PropertySettings
): Intent {
return Intent(
Expand All @@ -147,6 +156,10 @@ class EditCountingMetadataActivity : AppCompatActivity(),
countingRecord
)
}
putExtra(
EXTRA_SAVE_DEFAULT_VALUES,
saveDefaultValues
)
putExtra(
EXTRA_PROPERTIES,
propertySettings
Expand Down
Loading

0 comments on commit b4db34e

Please sign in to comment.