Skip to content

Commit

Permalink
nearby agrodealers
Browse files Browse the repository at this point in the history
  • Loading branch information
MuindiStephen committed Aug 19, 2024
1 parent b28c9f7 commit 8be7bf3
Show file tree
Hide file tree
Showing 35 changed files with 3,011 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ dependencies {

implementation files('libs/A26Library-debug.aar') // vpos

implementation files('libs/dpuareu.jar')



// Sweet Alert Dialog
implementation 'cn.pedant.sweetalert:library:1.3'
}
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<activity
android:name=".ui.activities.DetailedFarmCycleActivity"
android:exported="false" />

<activity
android:name="com.steve_md.smartmkulima.utils.services.PrintServiceActivity"
android:exported="false" />
<activity
android:name=".ui.activities.FarmManagementActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.steve_md.smartmkulima.adapter

import android.location.Location
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.gms.maps.model.LatLng
import com.steve_md.smartmkulima.R
import com.steve_md.smartmkulima.model.AgroDealer

class AgrodealerAdapter(
private val agrodealers: List<AgroDealer>,
private val userLocation: LatLng,
private val onClickListener: OnClickListener
) : RecyclerView.Adapter<AgrodealerAdapter.AgrodealerViewHolder>() {

class AgrodealerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val nameTextView: TextView = view.findViewById(R.id.agrodealer_name)
val contactTextView: TextView = view.findViewById(R.id.textViewPhone)
val tvEmail: TextView = view.findViewById(R.id.textViewEmail)
val distanceTextView : TextView = view.findViewById(R.id.tvLocation)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AgrodealerViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_agrodealer, parent, false)
return AgrodealerViewHolder(view)
}

override fun onBindViewHolder(holder: AgrodealerViewHolder, position: Int) {
val agrodealer = agrodealers[position]
holder.nameTextView.text = agrodealer.name
holder.contactTextView.text = agrodealer.phone
holder.tvEmail.text = agrodealer.email

// Calculate the distance between the user's location and the agrodealer
val agrovetLatLng = LatLng(agrodealer.latitude, agrodealer.longitude)
val distance = calculateDistance(userLocation, agrovetLatLng)
holder.distanceTextView.text = String.format("%.2f km away", distance / 1000)

holder.itemView.setOnClickListener {
onClickListener.onClick(agrodealer = agrodealer)
}
}

override fun getItemCount(): Int = agrodealers.size

private fun calculateDistance(startLatLng: LatLng, endLatLng: LatLng): Float {
val results = FloatArray(1)
Location.distanceBetween(
startLatLng.latitude, startLatLng.longitude,
endLatLng.latitude, endLatLng.longitude,
results
)
return results[0]
}

class OnClickListener(val clickListener: (agrodealer: AgroDealer) -> Unit) {
fun onClick(agrodealer: AgroDealer) = clickListener(agrodealer)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.steve_md.smartmkulima.model

import android.os.Parcelable
import com.google.android.gms.maps.model.LatLng
import kotlinx.parcelize.Parcelize

/**
* A data class to represent agro-dealer data / supplier data
*/
data class AgroDealerData(
val name:String,
val latitude:Double,
val longitude:Double
)


@Parcelize
data class AgroDealer(
val name: String,
val phone: String,
val email: String,
val latitude: Double,
val longitude:Double,
val servicesOffered: String,
val categories: String,
val leasingOptionsAvailable: String,
val leasingDetails: String
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class HireFarmEquipmentsFragment : Fragment() {

(activity as AppCompatActivity).supportActionBar?.hide()


farmEquipmentsRecylerView = view.findViewById(R.id.farmEquipmentsRecyclerView)

setUpBinding()

/**
* Passing @param FarmEquipment as an argument
*/
farmEquipmentsAdapter =
FarmEquipmentAdapter(FarmEquipmentAdapter.OnClickListener { farmEquipment ->
Timber.i("Farm Equipments: ${farmEquipment.name}")
Expand Down
Loading

0 comments on commit 8be7bf3

Please sign in to comment.