-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b28c9f7
commit 8be7bf3
Showing
35 changed files
with
3,011 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/steve_md/smartmkulima/adapter/AgroDealersAdapter.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 @@ | ||
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) | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
app/src/main/java/com/steve_md/smartmkulima/model/AgriTechCompany.kt
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/steve_md/smartmkulima/model/AgroDealerData.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,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 |
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
Oops, something went wrong.