Add new activity to list actual marker for future edit in a form

This commit is contained in:
clement
2024-07-08 11:20:50 +02:00
parent eb93531816
commit f7a8720669
7 changed files with 61 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ dependencies {
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.play.services.location)
implementation(libs.androidx.appcompat)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

View File

@@ -23,10 +23,13 @@
android:theme="@style/Theme.BusRoute">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ValidateMarker"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.AppCompat"/>
</application>
</manifest>

View File

@@ -1,6 +1,7 @@
package com.example.busroute
import org.osmdroid.views.overlay.Marker
import java.io.Serializable
data class BusStop(val marker: Marker){
override fun toString(): String {

View File

@@ -62,6 +62,9 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
val dbHelper = DbHelper(this)
isLocationPermissionGranted()
val geocoder = Geocoder(this, Locale.getDefault())
@@ -99,14 +102,20 @@ class MainActivity : ComponentActivity() {
val saveMarkButton = findViewById<Button>(R.id.saveMark)
saveMarkButton.setOnClickListener{
val db = dbHelper.writableDatabase
var stringList: ArrayList<String> = ArrayList<String>()
busStopList.forEach {
val values = ContentValues().apply {
put(StopContract.StopEntry.LATITUDE, it.marker.position.latitude)
put(StopContract.StopEntry.LONGITUDE, it.marker.position.longitude)
put(StopContract.StopEntry.ORDER, busStopList.indexOf(it))
}
val newRowId = db?.insert(StopContract.StopEntry.TABLE_NAME, null, values)
stringList.add(it.toString())
//val newRowId = db?.insert(StopContract.StopEntry.TABLE_NAME, null, values)
}
val intent = Intent(saveMarkButton.context, ValidateMarker::class.java)
intent.putExtra(ValidateMarker.MARKERS, stringList)
startActivity(intent)
val dbread = dbHelper.readableDatabase
val projection = arrayOf(BaseColumns._ID, StopContract.StopEntry.LATITUDE, StopContract.StopEntry.LONGITUDE, StopContract.StopEntry.ORDER)
val selection = ""
@@ -181,7 +190,7 @@ class MainActivity : ComponentActivity() {
locationOverlay.enableFollowLocation()
map.overlays.add(locationOverlay)
isLocationPermissionGranted()
// val locationClient = LocationServices.getFusedLocationProviderClient(this)
//
// locationRequest = LocationRequest.Builder(Priority.PRIORITY_BALANCED_POWER_ACCURACY,60)

View File

@@ -0,0 +1,31 @@
package com.example.busroute
import android.content.ContentValues
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.TableLayout
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.children
import java.util.ArrayList
class ValidateMarker: AppCompatActivity() {
companion object{
const val MARKERS = "MARKERS"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.marker_form)
val table = findViewById<TableLayout>(R.id.table)
val markers: ArrayList<String>? = intent.extras?.getStringArrayList(MARKERS)
markers!!.forEach{
val text = TextView(this)
text.text = it
table.addView(text)
}
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="16dp" />
</GridLayout>