Remove commit parameter, do it on the caller side.

This commit is contained in:
voussoir 2023-11-30 17:41:00 -08:00
parent 0fc6971d9d
commit 52dbae2f41
5 changed files with 28 additions and 46 deletions

View file

@ -55,29 +55,21 @@ class Database(val trackbook: Trackbook)
this.connection.endTransaction() this.connection.endTransaction()
} }
fun delete_trkpt(device_id: String, time: Long, commit: Boolean=false) fun delete_trkpt(device_id: String, time: Long)
{ {
Log.i("VOUSSOIR", "Database.delete_trkpt") Log.i("VOUSSOIR", "Database.delete_trkpt")
begin_transaction() begin_transaction()
connection.delete("trkpt", "device_id = ? AND time = ?", arrayOf(device_id, time.toString())) connection.delete("trkpt", "device_id = ? AND time = ?", arrayOf(device_id, time.toString()))
if (commit)
{
this.commit()
}
} }
fun delete_trkpt_start_end(device_id: String, start_time: Long, end_time: Long, commit: Boolean=false) fun delete_trkpt_start_end(device_id: String, start_time: Long, end_time: Long)
{ {
Log.i("VOUSSOIR", "Track.delete ${device_id} ${start_time} -- ${end_time}.") Log.i("VOUSSOIR", "Track.delete ${device_id} ${start_time} -- ${end_time}.")
this.begin_transaction() this.begin_transaction()
this.connection.delete("trkpt", "device_id = ? AND time >= ? AND time <= ?", arrayOf(device_id, start_time.toString(), end_time.toString())) this.connection.delete("trkpt", "device_id = ? AND time >= ? AND time <= ?", arrayOf(device_id, start_time.toString(), end_time.toString()))
if (commit)
{
this.commit()
}
} }
fun insert_trkpt(trkpt: Trkpt, commit: Boolean=false) fun insert_trkpt(trkpt: Trkpt)
{ {
Log.i("VOUSSOIR", "Database.insert_trkpt") Log.i("VOUSSOIR", "Database.insert_trkpt")
val values = ContentValues().apply { val values = ContentValues().apply {
@ -92,10 +84,6 @@ class Database(val trackbook: Trackbook)
} }
begin_transaction() begin_transaction()
connection.insert("trkpt", null, values) connection.insert("trkpt", null, values)
if (commit)
{
this.commit()
}
} }
fun select_trkpt_start_end(device_id: String, start_time: Long, end_time: Long, max_accuracy: Float=Keys.DEFAULT_MAX_ACCURACY, order: String="ASC"): Iterator<Trkpt> fun select_trkpt_start_end(device_id: String, start_time: Long, end_time: Long, max_accuracy: Float=Keys.DEFAULT_MAX_ACCURACY, order: String="ASC"): Iterator<Trkpt>
@ -159,18 +147,14 @@ class Database(val trackbook: Trackbook)
} }
} }
fun delete_homepoint(id: Long, commit: Boolean=false) fun delete_homepoint(id: Long)
{ {
Log.i("VOUSSOIR", "Database.delete_homepoint") Log.i("VOUSSOIR", "Database.delete_homepoint")
begin_transaction() begin_transaction()
connection.delete("homepoints", "id = ?", arrayOf(id.toString())) connection.delete("homepoints", "id = ?", arrayOf(id.toString()))
if (commit)
{
this.commit()
}
} }
fun insert_homepoint(id: Long, name: String, latitude: Double, longitude: Double, radius: Double, commit: Boolean=false) fun insert_homepoint(id: Long, name: String, latitude: Double, longitude: Double, radius: Double)
{ {
Log.i("VOUSSOIR", "Database.insert_homepoint") Log.i("VOUSSOIR", "Database.insert_homepoint")
val values = ContentValues().apply { val values = ContentValues().apply {
@ -182,13 +166,9 @@ class Database(val trackbook: Trackbook)
} }
begin_transaction() begin_transaction()
connection.insert("homepoints", null, values) connection.insert("homepoints", null, values)
if (commit)
{
this.commit()
}
} }
fun update_homepoint(id: Long, name: String, radius: Double, commit: Boolean=false) fun update_homepoint(id: Long, name: String, radius: Double)
{ {
Log.i("VOUSSOIR", "Database.update_homepoint") Log.i("VOUSSOIR", "Database.update_homepoint")
val values = ContentValues().apply { val values = ContentValues().apply {
@ -197,13 +177,9 @@ class Database(val trackbook: Trackbook)
} }
begin_transaction() begin_transaction()
connection.update("homepoints", values, "id = ?", arrayOf(id.toString())) connection.update("homepoints", values, "id = ?", arrayOf(id.toString()))
if (commit)
{
this.commit()
}
} }
fun update_trkpt(trkpt: Trkpt, commit: Boolean=false) fun update_trkpt(trkpt: Trkpt)
{ {
Log.i("VOUSSOIR", "Database.update_trkpt") Log.i("VOUSSOIR", "Database.update_trkpt")
val values = ContentValues().apply { val values = ContentValues().apply {
@ -216,10 +192,6 @@ class Database(val trackbook: Trackbook)
} }
begin_transaction() begin_transaction()
connection.update("trkpt", values, "device_id = ? AND time = ?", arrayOf(trkpt.device_id, trkpt.time.toString())) connection.update("trkpt", values, "device_id = ? AND time = ?", arrayOf(trkpt.device_id, trkpt.time.toString()))
if (commit)
{
this.commit()
}
} }
private fun initialize_tables() private fun initialize_tables()

View file

@ -168,8 +168,8 @@ class MapFragment : Fragment()
latitude=point.latitude, latitude=point.latitude,
longitude=point.longitude, longitude=point.longitude,
radius=radius, radius=radius,
commit=true,
) )
trackbook.database.commit()
trackbook.load_homepoints() trackbook.load_homepoints()
create_homepoint_overlays() create_homepoint_overlays()
dialog.dismiss() dialog.dismiss()
@ -548,14 +548,16 @@ class MapFragment : Fragment()
val save_button: Button = dialog.findViewById(R.id.homepoint_save_button) val save_button: Button = dialog.findViewById(R.id.homepoint_save_button)
delete_button.text = "Delete" delete_button.text = "Delete"
delete_button.setOnClickListener { delete_button.setOnClickListener {
trackbook.database.delete_homepoint(homepoint.id, commit=true) trackbook.database.delete_homepoint(homepoint.id)
trackbook.database.commit()
trackbook.load_homepoints() trackbook.load_homepoints()
create_homepoint_overlays() create_homepoint_overlays()
dialog.dismiss() dialog.dismiss()
} }
save_button.setOnClickListener { save_button.setOnClickListener {
val radius = radius_input.text.toString().toDoubleOrNull() ?: 25.0 val radius = radius_input.text.toString().toDoubleOrNull() ?: 25.0
trackbook.database.update_homepoint(homepoint.id, name=name_input.text.toString(), radius=radius, commit=true) trackbook.database.update_homepoint(homepoint.id, name=name_input.text.toString(), radius=radius)
trackbook.database.commit()
trackbook.load_homepoints() trackbook.load_homepoints()
create_homepoint_overlays() create_homepoint_overlays()
dialog.dismiss() dialog.dismiss()

View file

@ -271,7 +271,8 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
Log.i("VOUSSOIR", selected.rendered_by_polyline?.actualPoints?.size.toString()) Log.i("VOUSSOIR", selected.rendered_by_polyline?.actualPoints?.size.toString())
selected.rendered_by_polyline?.setPoints(ArrayList(selected.rendered_by_polyline?.actualPoints)) selected.rendered_by_polyline?.setPoints(ArrayList(selected.rendered_by_polyline?.actualPoints))
Log.i("VOUSSOIR", selected.rendered_by_polyline?.actualPoints?.size.toString()) Log.i("VOUSSOIR", selected.rendered_by_polyline?.actualPoints?.size.toString())
trackbook.database.delete_trkpt(selected.device_id, selected.time, commit=true) trackbook.database.delete_trkpt(selected.device_id, selected.time)
trackbook.database.commit()
deselect_trkpt() deselect_trkpt()
mapView.invalidate() mapView.invalidate()
} }
@ -454,7 +455,10 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
} }
override fun onMarkerDragEnd(marker: Marker?) override fun onMarkerDragEnd(marker: Marker?)
{ {
selected_trkpt?.let { trackbook.database.update_trkpt(it, commit=true) } selected_trkpt?.let {
trackbook.database.update_trkpt(it)
trackbook.database.commit()
}
} }
}) })
@ -631,7 +635,8 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
mid_location.accuracy = 0f mid_location.accuracy = 0f
val mid_trkpt = Trkpt(trkpt.device_id, mid_location) val mid_trkpt = Trkpt(trkpt.device_id, mid_location)
deselect_trkpt() deselect_trkpt()
trackbook.database.insert_trkpt(mid_trkpt, commit=true) trackbook.database.insert_trkpt(mid_trkpt)
trackbook.database.commit()
requery_and_render.run() requery_and_render.run()
select_trkpt_by_timestamp(mid_trkpt.time) select_trkpt_by_timestamp(mid_trkpt.time)
return return
@ -695,7 +700,7 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
trkpt.latitude = new_location.latitude trkpt.latitude = new_location.latitude
trkpt.longitude = new_location.longitude trkpt.longitude = new_location.longitude
trkpt.altitude = a.altitude + (ele_span * proportion) trkpt.altitude = a.altitude + (ele_span * proportion)
trackbook.database.update_trkpt(trkpt, commit=false) trackbook.database.update_trkpt(trkpt)
} }
trackbook.database.commit() trackbook.database.commit()
} }
@ -862,8 +867,8 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
track.device_id, track.device_id,
track.trkpts.first().time, track.trkpts.first().time,
track.trkpts.last().time, track.trkpts.last().time,
commit=true,
) )
trackbook.database.commit()
handler.removeCallbacks(requery_and_render) handler.removeCallbacks(requery_and_render)
handler.postDelayed(requery_and_render, RERENDER_DELAY) handler.postDelayed(requery_and_render, RERENDER_DELAY)
} }

View file

@ -68,19 +68,22 @@ class Trackbook : Application()
{ {
Log.i("VOUSSOIR", "Trackbook.load_database") Log.i("VOUSSOIR", "Trackbook.load_database")
val folder = PreferencesHelper.load_database_folder() val folder = PreferencesHelper.load_database_folder()
this.database.commit()
if (this.database.ready) if (this.database.ready)
{ {
Log.i("VOUSSOIR", "Trackbook.load_database: closing and re-opening.")
this.database.commit()
this.database.close() this.database.close()
} }
if (folder == "") if (folder == "")
{ {
Log.i("VOUSSOIR", "Trackbook.load_database: folder came up blank.")
this.database.ready = false this.database.ready = false
return return
} }
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
{ {
this.database.connect(File(folder + "/trkpt_${PreferencesHelper.load_device_id()}.db")) val device_id = PreferencesHelper.load_device_id()
this.database.connect(File(folder + "/trkpt_${device_id}.db"))
this.load_homepoints() this.load_homepoints()
} }
else else

View file

@ -449,7 +449,7 @@ class TrackerService: Service()
} }
val trkpt = Trkpt(device_id=device_id, location=location) val trkpt = Trkpt(device_id=device_id, location=location)
trackbook.database.insert_trkpt(trkpt, commit=false) trackbook.database.insert_trkpt(trkpt)
if (trkpt.accuracy <= max_accuracy) if (trkpt.accuracy <= max_accuracy)
{ {