-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jedlix/feature/1.4.0
Version 1.4.0
- Loading branch information
Showing
31 changed files
with
705 additions
and
185 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
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
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
59 changes: 59 additions & 0 deletions
59
example/src/main/java/com/jedlix/sdk/example/adapter/ButtonListAdapter.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,59 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.BindingAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.jedlix.sdk.example.databinding.ViewButtonRowBinding | ||
import com.jedlix.sdk.example.model.Button | ||
|
||
class ButtonListAdapter : RecyclerView.Adapter<ButtonListAdapter.ButtonViewHolder>() { | ||
|
||
companion object { | ||
@BindingAdapter("modelButtons") | ||
@JvmStatic | ||
fun bindModelButtons(recyclerView: RecyclerView, buttons: List<Button>?) { | ||
(recyclerView.adapter as? ButtonListAdapter)?.buttons = buttons ?: emptyList() | ||
} | ||
} | ||
|
||
class ButtonViewHolder(val binding: ViewButtonRowBinding) : RecyclerView.ViewHolder(binding.root) | ||
|
||
private var buttons: List<Button> = emptyList() | ||
@SuppressLint("NotifyDataSetChanged") | ||
set(value) { | ||
field = value | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemCount(): Int = buttons.size | ||
|
||
override fun onBindViewHolder(holder: ButtonViewHolder, position: Int) { | ||
holder.binding.button.apply { | ||
val modelButton = buttons.getOrNull(position) | ||
text = modelButton?.title | ||
setOnClickListener { modelButton?.action?.invoke() } | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ButtonViewHolder( | ||
ViewButtonRowBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
example/src/main/java/com/jedlix/sdk/example/adapter/ConnectSessionViewModelAdapter.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,61 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.BindingAdapter | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.jedlix.sdk.example.databinding.ViewConnectSessionViewModelRowBinding | ||
import com.jedlix.sdk.example.viewModel.ConnectSessionViewModel | ||
|
||
class ConnectSessionViewModelAdapter(val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<ConnectSessionViewModelAdapter.ViewHolder>() { | ||
|
||
companion object { | ||
@BindingAdapter("connectSessionViewModels") | ||
@JvmStatic | ||
fun bindModelButtons(recyclerView: RecyclerView, connectSessionViewModels: List<ConnectSessionViewModel>?) { | ||
(recyclerView.adapter as? ConnectSessionViewModelAdapter)?.connectSessionViewModels = connectSessionViewModels ?: emptyList() | ||
} | ||
} | ||
|
||
class ViewHolder(val binding: ViewConnectSessionViewModelRowBinding) : RecyclerView.ViewHolder(binding.root) | ||
|
||
private var connectSessionViewModels: List<ConnectSessionViewModel> = emptyList() | ||
@SuppressLint("NotifyDataSetChanged") | ||
set(value) { | ||
field = value | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemCount(): Int = connectSessionViewModels.size | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.binding.apply { | ||
viewModel = connectSessionViewModels[position] | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( | ||
ViewConnectSessionViewModelRowBinding.inflate(LayoutInflater.from(parent.context), parent, false).apply { | ||
lifecycleOwner = this@ConnectSessionViewModelAdapter.lifecycleOwner | ||
buttons.adapter = ButtonListAdapter() | ||
} | ||
) | ||
} |
63 changes: 63 additions & 0 deletions
63
...ple/src/main/java/com/jedlix/sdk/example/adapter/GroupedConnectSessionViewModelAdapter.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,63 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.BindingAdapter | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.jedlix.sdk.example.databinding.ViewConnectSessionViewModelRowBinding | ||
import com.jedlix.sdk.example.databinding.ViewGroupedConnectSessionViewModelRowBinding | ||
import com.jedlix.sdk.example.viewModel.GroupedConnectSessionViewModel | ||
|
||
class GroupedConnectSessionViewModelAdapter(private val lifecycleOwner: LifecycleOwner) : RecyclerView.Adapter<GroupedConnectSessionViewModelAdapter.ViewHolder>() { | ||
|
||
companion object { | ||
@BindingAdapter("groupedConnectSessionViewModels") | ||
@JvmStatic | ||
fun bindModelButtons(recyclerView: RecyclerView, connectSessionViewModels: List<GroupedConnectSessionViewModel>?) { | ||
(recyclerView.adapter as? GroupedConnectSessionViewModelAdapter)?.groupedConnectSessionViewModels = connectSessionViewModels ?: emptyList() | ||
} | ||
} | ||
|
||
class ViewHolder(val binding: ViewGroupedConnectSessionViewModelRowBinding) : RecyclerView.ViewHolder(binding.root) | ||
|
||
private var groupedConnectSessionViewModels: List<GroupedConnectSessionViewModel> = emptyList() | ||
@SuppressLint("NotifyDataSetChanged") | ||
set(value) { | ||
field = value | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemCount(): Int = groupedConnectSessionViewModels.size | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.binding.apply { | ||
viewModel = groupedConnectSessionViewModels[position] | ||
|
||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( | ||
ViewGroupedConnectSessionViewModelRowBinding.inflate(LayoutInflater.from(parent.context), parent, false).apply { | ||
lifecycleOwner = this@GroupedConnectSessionViewModelAdapter.lifecycleOwner | ||
connectSessions.adapter = ConnectSessionViewModelAdapter(this@GroupedConnectSessionViewModelAdapter.lifecycleOwner) | ||
} | ||
) | ||
} |
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
37 changes: 37 additions & 0 deletions
37
example/src/main/java/com/jedlix/sdk/example/viewModel/ChargerViewModel.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,37 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.viewModel | ||
|
||
import com.jedlix.sdk.example.model.Button | ||
import com.jedlix.sdk.model.Charger | ||
import com.jedlix.sdk.model.ChargerConnectSession | ||
|
||
class ChargerViewModel( | ||
charger: Charger, | ||
connectSession: ChargerConnectSession?, | ||
private val resumeConnectSession: (ChargerConnectSession) -> Unit, | ||
private val removeCharger: (Charger) -> Unit | ||
) : ConnectSessionViewModel { | ||
|
||
override val title = charger.detail.fullName | ||
override val buttons = listOfNotNull( | ||
connectSession?.let { Button("Resume") { resumeConnectSession(it) } }, | ||
Button("Remove") { removeCharger(charger) } | ||
) | ||
|
||
private val Charger.Detail.fullName: String get() = listOfNotNull(brand, model).joinToString(" ") | ||
} |
47 changes: 47 additions & 0 deletions
47
example/src/main/java/com/jedlix/sdk/example/viewModel/ChargingLocationViewModel.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,47 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.viewModel | ||
|
||
import com.jedlix.sdk.example.model.Button | ||
import com.jedlix.sdk.model.Charger | ||
import com.jedlix.sdk.model.ChargerConnectSession | ||
import com.jedlix.sdk.model.ChargingLocation | ||
|
||
class ChargingLocationViewModel( | ||
private val chargingLocation: ChargingLocation, | ||
chargers: List<Charger>, | ||
private val chargerSessions: List<ChargerConnectSession>, | ||
private val startChargerConnectSession: (ChargingLocation) -> Unit, | ||
private val resumeConnectSession: (ChargerConnectSession) -> Unit, | ||
private val removeCharger: (Charger) -> Unit | ||
) : GroupedConnectSessionViewModel { | ||
|
||
override val title = chargingLocation.address.let { listOfNotNull(it.street, it.houseNumber, it.city).joinToString(", ") } | ||
override val connectSessionViewModels = chargers.map { charger -> | ||
ChargerViewModel(charger, chargerSessions.firstOrNull { it.chargerId == charger.id }, resumeConnectSession, removeCharger) | ||
}.ifEmpty { | ||
val connectSessionWithoutVehicle = chargerSessions.firstOrNull { it.chargingLocationId == chargingLocation.id && it.chargerId.isNullOrEmpty() } | ||
listOf( | ||
object : ConnectSessionViewModel { | ||
override val title: String = if (connectSessionWithoutVehicle != null) "Unfinished connect session" else "No Chargers found" | ||
override val buttons: List<Button> = listOf( | ||
connectSessionWithoutVehicle?.let { Button("Resume") { resumeConnectSession(it) } } ?: Button("Connect") { startChargerConnectSession(chargingLocation) } | ||
) | ||
} | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
example/src/main/java/com/jedlix/sdk/example/viewModel/ConnectSessionViewModel.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,29 @@ | ||
/* | ||
* Copyright 2022 Jedlix B.V. The Netherlands | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.jedlix.sdk.example.viewModel | ||
|
||
import com.jedlix.sdk.example.model.Button | ||
|
||
interface ConnectSessionViewModel { | ||
val title: String | ||
val buttons: List<Button> | ||
} | ||
|
||
interface GroupedConnectSessionViewModel { | ||
val title: String | ||
val connectSessionViewModels: List<ConnectSessionViewModel> | ||
} |
Oops, something went wrong.