mirror of
https://github.com/Aviortheking/CA-Mad-Rental.git
synced 2025-04-22 10:52:12 +00:00
Favorites function now works
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
b7d5af23d6
commit
d81b9f3799
@ -30,9 +30,6 @@ class DetailsActivity: AppCompatActivity() {
|
||||
button.setOnClickListener {
|
||||
val dao = AppDatabaseHelper.getDatabase(this)
|
||||
.vehicleDAO()
|
||||
val res = dao
|
||||
.find(id.toLong())
|
||||
println(res)
|
||||
|
||||
try {
|
||||
dao.insert(Vehicle(
|
||||
|
@ -11,10 +11,11 @@ import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.ca_kotlin.adapters.CountryAdapter
|
||||
import com.example.ca_kotlin.adapters.VehicleAdapter
|
||||
import com.example.ca_kotlin.api.ApiClient
|
||||
import com.example.ca_kotlin.api.Vehicles
|
||||
import com.example.ca_kotlin.dao.AppDatabaseHelper
|
||||
import com.example.ca_kotlin.dao.Vehicle
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
@ -45,7 +46,7 @@ class MainActivity : AppCompatActivity() {
|
||||
progressDialog.setCancelable(false)
|
||||
progressDialog.show()
|
||||
|
||||
val adapter = CountryAdapter(data)
|
||||
val adapter = VehicleAdapter(data)
|
||||
recycler.adapter = adapter
|
||||
|
||||
val switch = findViewById<Switch>(R.id.switch1)
|
||||
@ -62,20 +63,23 @@ class MainActivity : AppCompatActivity() {
|
||||
global(adapter, recycler, progressDialog)
|
||||
}
|
||||
|
||||
fun favorites(adapter: CountryAdapter, recycler: RecyclerView, progressDialog: ProgressDialog) {
|
||||
private fun favorites(adapter: VehicleAdapter, recycler: RecyclerView, progressDialog: ProgressDialog) {
|
||||
val vehicles = AppDatabaseHelper.getDatabase(this)
|
||||
.vehicleDAO()
|
||||
.getVehicles()
|
||||
|
||||
val filteredData = data.filter { dVehicle -> (vehicles.find { it.vehicleId == dVehicle.vehicleId }) != null }
|
||||
data.clear()
|
||||
data.addAll(vehicles as ArrayList<Vehicles>)
|
||||
println(vehicles)
|
||||
data.addAll(filteredData)
|
||||
println(filteredData)
|
||||
adapter.update(data.clone() as ArrayList<Vehicles>)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun global(adapter: CountryAdapter, recycler: RecyclerView, progressDialog: ProgressDialog) {
|
||||
private fun global(adapter: VehicleAdapter, recycler: RecyclerView, progressDialog: ProgressDialog) {
|
||||
ApiClient.getClient.getVehicles().enqueue(object : Callback<List<Vehicles>> {
|
||||
override fun onResponse(call: Call<List<Vehicles>>?, response: Response<List<Vehicles>>?) {
|
||||
|
||||
data.clear()
|
||||
data.addAll(response!!.body()!!)
|
||||
adapter.update(data.clone() as ArrayList<Vehicles>)
|
||||
adapter.notifyDataSetChanged()
|
||||
|
@ -13,7 +13,7 @@ import com.example.ca_kotlin.api.Vehicles
|
||||
import com.squareup.picasso.Picasso
|
||||
|
||||
// Adapter for the CountrySelector
|
||||
class CountryAdapter(list: ArrayList<Vehicles>) : RecyclerView.Adapter<CountryAdapter.CountryViewHolder>() {
|
||||
class VehicleAdapter(list: ArrayList<Vehicles>) : RecyclerView.Adapter<VehicleAdapter.CountryViewHolder>() {
|
||||
|
||||
private var list: ArrayList<Vehicles> = ArrayList()
|
||||
|
@ -32,9 +32,10 @@
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switch1"
|
||||
android:layout_width="88dp"
|
||||
android:showText="false"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Favoris"
|
||||
android:textColor="#FFFFFF"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -6,7 +6,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.0'
|
||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
Loading…
x
Reference in New Issue
Block a user