Storing Path name with her stop's

This commit is contained in:
clement
2024-07-09 17:48:08 +02:00
parent 1e7b729e4f
commit a744faf0d2
3 changed files with 43 additions and 2 deletions

View File

@@ -12,7 +12,8 @@ object PathContract {
const val SQL_CREATE_ENTRIES =
"CREATE TABLE ${PathEntry.TABLE_NAME} (" +
"${BaseColumns._ID} INTEGER PRIMARY KEY," +
"${PathEntry.PATH_NAME} TEXT)"
"${PathEntry.PATH_NAME} TEXT"+
")"
const val SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ${PathEntry.TABLE_NAME}"
}

View File

@@ -9,6 +9,7 @@ object StopContract {
const val LATITUDE = "latitude"
const val LONGITUDE = "longitude"
const val ORDER = "'order'"
const val PATH_ID = "path_id"
}
const val SQL_CREATE_ENTRIES =
@@ -16,7 +17,9 @@ object StopContract {
"${BaseColumns._ID} INTEGER PRIMARY KEY," +
"${StopEntry.LATITUDE} DOUBLE, "+
"${StopEntry.LONGITUDE} DOUBLE, "+
"${StopEntry.ORDER} INTEGER)"
"${StopEntry.ORDER} INTEGER, "+
"${StopEntry.PATH_ID} INTEGER"+
")"
const val SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ${StopEntry.TABLE_NAME}"
}

View File

@@ -1,17 +1,23 @@
package com.example.busroute
import android.app.AlertDialog
import android.content.ContentValues
import android.location.Address
import android.location.Geocoder
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.Button
import android.widget.EditText
import android.widget.ScrollView
import android.widget.TableLayout
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.children
import com.example.busroute.Database.DbHelper
import com.example.busroute.Database.PathContract
import com.example.busroute.Database.StopContract
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.ArrayList
@@ -27,6 +33,8 @@ class ValidateMarker: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val geocoder = Geocoder(this, Locale.getDefault())
val dbHelper = DbHelper(this)
setContentView(R.layout.marker_form)
val table = findViewById<TableLayout>(R.id.table)
val markers: ArrayList<String>? = intent.extras?.getStringArrayList(MARKERS)
@@ -48,5 +56,34 @@ class ValidateMarker: AppCompatActivity() {
text.text = newText
table.addView(text)
}
val validateButton = findViewById<Button>(R.id.validate_form)
validateButton.setOnClickListener{
val db = dbHelper.writableDatabase
val newPath = ContentValues().apply {
put(PathContract.PathEntry.PATH_NAME, findViewById<EditText>(R.id.route_name).text.toString())
}
val newPathRowId = db?.insert(PathContract.PathEntry.TABLE_NAME, null, newPath)
if(newPathRowId?.toInt() != -1){
markers.forEach {
val values = ContentValues().apply {
put(StopContract.StopEntry.LATITUDE, it.split(" | ")[0].toDouble())
put(StopContract.StopEntry.LONGITUDE, it.split(" | ")[1].toDouble())
put(StopContract.StopEntry.ORDER, markers.indexOf(it))
put(StopContract.StopEntry.PATH_ID, newPathRowId)
}
val newRowId = db?.insert(StopContract.StopEntry.TABLE_NAME, null, values)
}
val alert = AlertDialog.Builder(this).setTitle("Route sauvegardée").setMessage("Le trajet à été créer !")
alert.show()
alert.setOnDismissListener{
db.close()
finish()
}
}
}
}
}