Autogenerate Track name from start and end dates.

This commit is contained in:
voussoir 2023-03-26 12:37:57 -07:00
parent 2e884aef02
commit d7caee4131
2 changed files with 21 additions and 1 deletions

View file

@ -108,6 +108,26 @@ data class Track (
{ {
this.trkpts.clear() this.trkpts.clear()
points.forEach { trkpt -> this.trkpts.add(trkpt) } points.forEach { trkpt -> this.trkpts.add(trkpt) }
this.name = suggested_name()
}
fun suggested_name(): String
{
if (trkpts.size == 0)
{
return ""
}
val df = SimpleDateFormat("yyyy-MM-dd")
val start_date = df.format(trkpts.first().time)
val end_date = df.format(trkpts.last().time)
if (start_date == end_date)
{
return "$start_date $device_id"
}
else
{
return "$start_date--$end_date $device_id"
}
} }
} }

View file

@ -594,7 +594,7 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
{ {
return return
} }
val export_name: String = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(track.trkpts.first().time) + " " + track.device_id + Keys.GPX_FILE_EXTENSION val export_name: String = track.name + Keys.GPX_FILE_EXTENSION
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = Keys.MIME_TYPE_GPX type = Keys.MIME_TYPE_GPX