Skip to content

Commit

Permalink
WIP: implement connector details dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Dec 17, 2023
1 parent 3266c62 commit abea9f2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.vonforst.evmap.api.availability

import android.content.Context
import android.os.Parcelable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parcelize
import net.vonforst.evmap.addDebugInterceptors
import net.vonforst.evmap.api.RateLimitInterceptor
import net.vonforst.evmap.api.await
Expand Down Expand Up @@ -154,7 +156,8 @@ data class ChargeLocationStatus(
val totalChargepoints = status.map { it.key.count }.sum()
}

enum class ChargepointStatus {
@Parcelize
enum class ChargepointStatus : Parcelable {
AVAILABLE, UNKNOWN, CHARGING, OCCUPIED, FAULTED
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package net.vonforst.evmap.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import net.vonforst.evmap.api.availability.ChargeLocationStatus
import net.vonforst.evmap.api.availability.ChargepointStatus
import net.vonforst.evmap.databinding.DialogDataSourceSelectBinding
import net.vonforst.evmap.model.Chargepoint
import net.vonforst.evmap.model.FILTERS_DISABLED
import net.vonforst.evmap.storage.PreferenceDataSource
import net.vonforst.evmap.ui.MaterialDialogFragment

class ConnectorDetailsDialog : MaterialDialogFragment() {
private lateinit var binding: DialogDataSourceSelectBinding
var okListener: ((String) -> Unit)? = null

companion object {
fun getInstance(
chargepoint: Chargepoint,
status: List<ChargepointStatus>,
evseIds: List<String>? = null
): ConnectorDetailsDialog {
val dialog = ConnectorDetailsDialog()
dialog.arguments = Bundle().apply {
putParcelable("chargepoint", chargepoint)
putParcelableArrayList("status", ArrayList(status))
putStringArrayList("evseIds", evseIds?.let { ArrayList(it) })
}
return dialog
}
}

override fun createView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = DialogDataSourceSelectBinding.inflate(inflater, container, false)
prefs = PreferenceDataSource(requireContext())
return binding.root
}

override fun onStart() {
super.onStart()

setFullSize()
}

private lateinit var prefs: PreferenceDataSource

override fun initView(view: View, savedInstanceState: Bundle?) {
val args = requireArguments()
binding.btnCancel.visibility =
if (args.getBoolean("cancel_enabled")) View.VISIBLE else View.GONE

if (prefs.dataSourceSet) {
when (prefs.dataSource) {
"goingelectric" -> binding.rgDataSource.rbGoingElectric.isChecked = true
"openchargemap" -> binding.rgDataSource.rbOpenChargeMap.isChecked = true
}
}

binding.btnCancel.setOnClickListener {
dismiss()
}
binding.btnOK.setOnClickListener {
val result = if (binding.rgDataSource.rbGoingElectric.isChecked) {
"goingelectric"
} else if (binding.rgDataSource.rbOpenChargeMap.isChecked) {
"openchargemap"
} else {
return@setOnClickListener
}
prefs.dataSource = result
prefs.filterStatus = FILTERS_DISABLED
okListener?.let { listener ->
listener(result)
}
prefs.dataSourceSet = true
dismiss()
}
}
}
15 changes: 14 additions & 1 deletion app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,20 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
}

binding.detailView.connectors.apply {
adapter = ConnectorAdapter()
adapter = ConnectorAdapter().apply {
onClickListener = { item ->
vm.availability.value?.data?.let {
item.status?.let { status ->
val dialog = ConnectorDetailsDialog.getInstance(
item.chargepoint,
status,
it.evseIds?.get(item.chargepoint)
)
dialog.show(parentFragmentManager, null)
}
}
}
}
itemAnimator = null
layoutManager =
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
Expand Down

0 comments on commit abea9f2

Please sign in to comment.