Skip to content

Commit

Permalink
Add enum for logging mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kamathprasad9 committed Mar 26, 2024
1 parent 7585d4b commit 2b5c57e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import com.fieldbook.tracker.R
import com.fieldbook.tracker.activities.PreferencesActivity
import com.fieldbook.tracker.utilities.GeoNavHelper
import dagger.hilt.android.AndroidEntryPoint
import org.phenoapps.security.Security
import javax.inject.Inject
Expand Down Expand Up @@ -187,13 +188,13 @@ class GeoNavPreferencesFragment : PreferenceFragmentCompat(),
val geoNavLoggingMode = findPreference<ListPreference>(GeneralKeys.GEONAV_LOGGING_MODE)
val currentMode = preferences.getString(GeneralKeys.GEONAV_LOGGING_MODE, "0")

if (currentMode == "0") {
if (currentMode == GeoNavHelper.GeoNavLoggingMode.OFF.value) {
geoNavLoggingMode?.summary = getString(R.string.pref_geonav_log_off_description)
geoNavLoggingMode?.setIcon(R.drawable.ic_note_off_outline)
} else if (currentMode == "1") {
} else if (currentMode == GeoNavHelper.GeoNavLoggingMode.LIMITED.value) {
geoNavLoggingMode?.summary = getString(R.string.pref_geonav_log_limited_description)
geoNavLoggingMode?.setIcon(R.drawable.ic_note_outline)
} else if (currentMode == "2") {
} else if (currentMode == GeoNavHelper.GeoNavLoggingMode.FULL.value) {
geoNavLoggingMode?.summary = getString(R.string.pref_geonav_log_full_description)
geoNavLoggingMode?.setIcon(R.drawable.ic_note_multiple_outline)
} else {
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/com/fieldbook/tracker/utilities/GeoNavHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
alt = alt.substring(0, altLength - 1) //drop the "M"

//always log location updates for full log
if (currentLoggingMode() == "2") {
if (currentLoggingMode() == GeoNavLoggingMode.FULL.value) {

val geoNavLine = GeoNavLine(
startLat = lat,
Expand Down Expand Up @@ -706,7 +706,7 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
* Starts a file in storage/geonav/log.txt
*/
fun setupGeoNavLogger() {
if (currentLoggingMode() != "0") {
if (currentLoggingMode() != GeoNavLoggingMode.OFF.value) {
try {
val resolver: ContentResolver = controller.getContext().contentResolver
val geoNavFolder = getDirectory(controller.getContext(), R.string.dir_geonav)
Expand All @@ -732,18 +732,18 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
var limitedGeoNavLogFile: DocumentFile? = null
var fullGeoNavLogFile: DocumentFile? = null

if (currentLoggingMode() == "1" || currentLoggingMode() == "3")
if (currentLoggingMode() == GeoNavLoggingMode.LIMITED.value || currentLoggingMode() == GeoNavLoggingMode.BOTH.value)
limitedGeoNavLogFile = geoNavFolder.findFile(limitedModeFileName)

if (currentLoggingMode() == "2" || currentLoggingMode() == "3")
if (currentLoggingMode() == GeoNavLoggingMode.FULL.value || currentLoggingMode() == GeoNavLoggingMode.BOTH.value)
fullGeoNavLogFile = geoNavFolder.findFile(fullModeFileName)

// flags if new file(s) have to be created
var isLimitedLogNew = false
var isFullLogNew = false

// handle limited mode
if (currentLoggingMode() == "1" || currentLoggingMode() == "3"){
if (currentLoggingMode() == GeoNavLoggingMode.LIMITED.value || currentLoggingMode() == GeoNavLoggingMode.BOTH.value){
if (limitedGeoNavLogFile == null) {
limitedGeoNavLogFile = geoNavFolder.createFile("*/csv", limitedModeFileName)
isLimitedLogNew = true
Expand All @@ -769,7 +769,7 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
}

// handle full mode
if (currentLoggingMode() == "2" || currentLoggingMode() == "3"){
if (currentLoggingMode() == GeoNavLoggingMode.FULL.value || currentLoggingMode() == GeoNavLoggingMode.BOTH.value){
if (fullGeoNavLogFile == null) {
fullGeoNavLogFile = geoNavFolder.createFile("*/csv", fullModeFileName)
isFullLogNew = true
Expand Down Expand Up @@ -909,8 +909,8 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController

mInternalLocation = location

//always log location updates for verbose log
if (currentLoggingMode() == "2") {
//always log location updates for full log
if (currentLoggingMode() == GeoNavLoggingMode.FULL.value) {

val geoNavLine = GeoNavLine(
startLat = location.latitude.toString(),
Expand All @@ -932,4 +932,11 @@ class GeoNavHelper @Inject constructor(private val controller: CollectController
fun getAverageHandler(): Handler? {
return averageHandler
}

enum class GeoNavLoggingMode (val value: String) {
OFF("0"),
LIMITED("1"),
FULL("2"),
BOTH("3")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fieldbook.tracker.utilities

import android.content.SharedPreferences
import android.location.Location
import com.fieldbook.tracker.R
import com.fieldbook.tracker.database.models.ObservationUnitModel
import com.fieldbook.tracker.preferences.GeneralKeys
import com.google.gson.Gson
Expand Down Expand Up @@ -224,7 +225,8 @@ class GeodeticUtils {
//after a full run of IZ, update the last CLOSEST_UPDATE to CLOSEST_FINAL
izLogArray.findLast { it.closest == CLOSEST_UPDATE.toString() }?.closest = CLOSEST_FINAL.toString()

if (currentLoggingMode == "1" || currentLoggingMode == "3") {
// limited mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.LIMITED.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print only the closest plant to the log
izLogArray.forEach {
if (it.closest == CLOSEST_FINAL.toString()) writeGeoNavLog(
Expand All @@ -234,7 +236,9 @@ class GeodeticUtils {
)
}
}
if (currentLoggingMode == "2" || currentLoggingMode == "3") {

// full mode
if (currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.FULL.value || currentLoggingMode == GeoNavHelper.GeoNavLoggingMode.BOTH.value) {
//print the entire array to log
izLogArray.forEach { writeGeoNavLog(preferences, fullLog, it) }
}
Expand Down

0 comments on commit 2b5c57e

Please sign in to comment.