Storing Path name with her stop's
This commit is contained in:
@@ -12,7 +12,8 @@ object PathContract {
|
|||||||
const val SQL_CREATE_ENTRIES =
|
const val SQL_CREATE_ENTRIES =
|
||||||
"CREATE TABLE ${PathEntry.TABLE_NAME} (" +
|
"CREATE TABLE ${PathEntry.TABLE_NAME} (" +
|
||||||
"${BaseColumns._ID} INTEGER PRIMARY KEY," +
|
"${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}"
|
const val SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ${PathEntry.TABLE_NAME}"
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ object StopContract {
|
|||||||
const val LATITUDE = "latitude"
|
const val LATITUDE = "latitude"
|
||||||
const val LONGITUDE = "longitude"
|
const val LONGITUDE = "longitude"
|
||||||
const val ORDER = "'order'"
|
const val ORDER = "'order'"
|
||||||
|
const val PATH_ID = "path_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
const val SQL_CREATE_ENTRIES =
|
const val SQL_CREATE_ENTRIES =
|
||||||
@@ -16,7 +17,9 @@ object StopContract {
|
|||||||
"${BaseColumns._ID} INTEGER PRIMARY KEY," +
|
"${BaseColumns._ID} INTEGER PRIMARY KEY," +
|
||||||
"${StopEntry.LATITUDE} DOUBLE, "+
|
"${StopEntry.LATITUDE} DOUBLE, "+
|
||||||
"${StopEntry.LONGITUDE} 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}"
|
const val SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS ${StopEntry.TABLE_NAME}"
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
package com.example.busroute
|
package com.example.busroute
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.location.Address
|
import android.location.Address
|
||||||
import android.location.Geocoder
|
import android.location.Geocoder
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.PersistableBundle
|
import android.os.PersistableBundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.EditText
|
||||||
import android.widget.ScrollView
|
import android.widget.ScrollView
|
||||||
import android.widget.TableLayout
|
import android.widget.TableLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.children
|
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.BigDecimal
|
||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
@@ -27,6 +33,8 @@ class ValidateMarker: AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val geocoder = Geocoder(this, Locale.getDefault())
|
val geocoder = Geocoder(this, Locale.getDefault())
|
||||||
|
val dbHelper = DbHelper(this)
|
||||||
|
|
||||||
setContentView(R.layout.marker_form)
|
setContentView(R.layout.marker_form)
|
||||||
val table = findViewById<TableLayout>(R.id.table)
|
val table = findViewById<TableLayout>(R.id.table)
|
||||||
val markers: ArrayList<String>? = intent.extras?.getStringArrayList(MARKERS)
|
val markers: ArrayList<String>? = intent.extras?.getStringArrayList(MARKERS)
|
||||||
@@ -48,5 +56,34 @@ class ValidateMarker: AppCompatActivity() {
|
|||||||
text.text = newText
|
text.text = newText
|
||||||
table.addView(text)
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user