-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: implement connector details dialog
- Loading branch information
1 parent
3266c62
commit abea9f2
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
app/src/main/java/net/vonforst/evmap/fragment/ConnectorDetailsDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters