Skip to content

Commit

Permalink
Added: Layout for mapping farm location in satellite map
Browse files Browse the repository at this point in the history
  • Loading branch information
MuindiStephen committed Aug 22, 2024
1 parent baab333 commit 63a4f1a
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AgrodealerAdapter(
val distanceTextView : TextView = view.findViewById(R.id.tvLocation)
val viewAgroDealerMoreDetailsTV : TextView = view.findViewById(R.id.tvViewMoreDetailAboutAgroDealer)
val itemAG: ConstraintLayout = view.findViewById(R.id.itemAG)
val agroDealerBuildingLoc: TextView = view.findViewById(R.id.textViewBuilding)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AgrodealerViewHolder {
Expand All @@ -43,6 +44,8 @@ class AgrodealerAdapter(
holder.nameTextView.text = agrodealer.name
holder.contactTextView.text = agrodealer.phone
holder.tvEmail.text = agrodealer.email
holder.agroDealerBuildingLoc.text = agrodealer.buildingLocation


// Calculate the distance between the user's location and the agrodealer
val agrovetLatLng = LatLng(agrodealer.latitude, agrodealer.longitude)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ data class AgroDealer(
val servicesOffered: String,
val categories: String,
val leasingOptionsAvailable: String,
val leasingDetails: String
val leasingDetails: String,
val buildingLocation: String
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
Expand Down Expand Up @@ -184,20 +183,38 @@ class LocateAgriTechCompaniesFragment : Fragment() , OnMapReadyCallback {

// Add filtered Agro-Dealers Markers to the map
for (agrodealer in agrodealers) {
val location = LatLng(agrodealer.latitude, agrodealer.longitude)
val location2 = LatLng(agrodealer.latitude, agrodealer.longitude)
googleMap.addMarker(
MarkerOptions()
.position(location)
.position(location2)
.title(agrodealer.name)
)?.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
}

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLatLng, 18f))

if (agrodealers.isNotEmpty()) {
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLatLng, 18f))

val userLatLng1 = LatLng(it.latitude, it.longitude)
val agrodealers1 = getAgroDealersData().filter { agrovet ->
val agrovetLatLng = LatLng(agrovet.latitude, agrovet.longitude)
calculateDistance(userLatLng1, agrovetLatLng) <= SEARCH_RADIUS_METERS
}

// googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLatLng, 18f))
view?.findViewById<TextView>(R.id.textViewAgrodealersNotavailable)?.visibility = View.GONE
view?.findViewById<LottieAnimationView>(R.id.LottieNoRecords)?.visibility = View.GONE

for (agrodealer in agrodealers1) {
val location1 = LatLng(agrodealer.latitude, agrodealer.longitude)
googleMap.addMarker(
MarkerOptions()
.position(location1)
.title(agrodealer.name)
)?.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
}

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLatLng1, 18f))
}

if(agrodealers.isEmpty()) {
Expand Down Expand Up @@ -238,18 +255,19 @@ class LocateAgriTechCompaniesFragment : Fragment() , OnMapReadyCallback {
return listOf(

// Near Bung-oma Town
AgroDealer("SIKATA AGRITECH FARMERS CHOICE","254712907551", "sikataagrifarm@gmail.com",0.5929, 34.5429839,"Fertilizer","Agricultural","true","6 months duration, monthly payment terms"),
AgroDealer("ROSE AGRITECH COMPANY", "0740408989" ,"roseag@gmail.com",0.5960, 34.543333,"Fertilizer","Agricultural","true","1 year duration, monthly payment terms"),
AgroDealer("JOSEMO AGRITECH & DISTRIBUTORS BUNGOMA", "0791347689","josemoagrodealers@yahoo.com",0.565110, 34.5431684,"Fertilizer","Agricultural","true","3 months duration, weekly payment terms"),
AgroDealer("OMUSALE AGRITECH & AGROVET","0747909084","info@omusale.com", 0.565095, 34.5431600,"Fertilizer","Agricultural","true","1 months duration, weekly payment terms"),
AgroDealer("MULTIDUSH AGRITECH & AGROVET SUPPLIES", "","info@multidushagritechsupplies.co.ke", 0.565100, 34.545406,"Fertilizer","Agricultural","true","2 months duration, monthly payment terms"),
AgroDealer("SIKATA AGRITECH FARMERS CHOICE","254712907551", "sikataagrifarm@gmail.com",0.5929, 34.5429839,"Fertilizer","Agricultural","true","6 months duration, monthly payment terms","Caxton House, Room 2"),
AgroDealer("ROSE AGRITECH COMPANY", "0740408989" ,"roseag@gmail.com",0.5960, 34.543333,"Fertilizer","Agricultural","true","1 year duration, monthly payment terms","Township building"),
AgroDealer("JOSEMO AGRITECH & DISTRIBUTORS BUNGOMA", "0791347689","josemoagrodealers@yahoo.com",0.565110, 34.5431684,"Fertilizer","Agricultural","true","3 months duration, weekly payment terms","CBD 1st building"),
AgroDealer("OMUSALE AGRITECH & AGROVET","0747909084","info@omusale.com", 0.565095, 34.5431600,"Fertilizer","Agricultural","true","1 months duration, weekly payment terms","Opp-national bank"),
AgroDealer("MULTIDUSH AGRITECH & AGROVET SUPPLIES", "","info@multidushagritechsupplies.co.ke", 0.565100, 34.545406,"Fertilizer","Agricultural","true","2 months duration, monthly payment terms","KFA building"),

// Near Nairobi
AgroDealer("Farmers Solution Agrovet","254700932932", "farmerssolutionagrovet@gmail.com",-1.2860464,36.8026465,"Agrochemicals","Agricultural inputs","false","Leasing is not available"),
AgroDealer("Mifugo Agrovet centre","254701898905", "info@mifugoagrovetcentre.co.ke",-1.286548536,36.8067588,"Fertilizers, farm machinery","Agricultural","true","6 months duration, monthly payment terms"),
AgroDealer("Lessos Agrovets","25479053721", "info@lessonsagrovets.com",-1.2720571,36.7961583,"Fertilizers, farm machinery","Agricultural","true","1 month duration, weekly payment terms"),
AgroDealer("Kazi Agrodealers","254759007001", "info@kaziagridealers.com",-0.6068996,36.9981162,"Fertilizers, farm machinery","Agricultural","true","1 year duration, monthly payment terms"),
AgroDealer("DIHA AGRO DEALERS","254745003225", "info@dihaagridealers.com",-0.6799296,36.7066032,"Fertilizers, farm machinery","Agricultural","true","1 month duration, weekly payment terms"),
AgroDealer("Farmers Solution Agrovet","254700932932", "farmerssolutionagrovet@gmail.com",-1.2860464,36.8026465,"Agrochemicals","Agricultural inputs","false","Leasing is not available","Business Center,Slip road/Kijabe"),
AgroDealer("Mifugo Agrovet centre","254701898905", "info@mifugoagrovetcentre.co.ke",-1.286548536,36.8067588,"Fertilizers, farm machinery","Agricultural","true","6 months duration, monthly payment terms","Haile Selassie Ave, next JTM building"),
AgroDealer("Lessos Agrovets","0712046859", "info@lessonsagrovets.com",-1.2720571,36.7961583,"Fertilizers, farm machinery","Agricultural","true","1 month duration, weekly payment terms","Kapsabet Street, Baraton Building"),
AgroDealer("DIHA AGRO DEALERS","254745003225", "info@dihaagridealers.com",-0.6799296,36.7066032,"Fertilizers, farm machinery","Agricultural","true","1 month duration, weekly payment terms","Mururi, Kwa John store"),
AgroDealer("Jumbo Agrovet Limited","254722510291", "info@jumboagrovetltd.com",-1.2885866,36.2516181,"Agrochemicals","Agricultural","true","1 year, 6 months payment terms","Lotus House, Hailes Selassie, Nairobi"),



// Near Kiambu
Expand All @@ -271,7 +289,7 @@ class LocateAgriTechCompaniesFragment : Fragment() , OnMapReadyCallback {
// Near Kitui

// Near Machakos
AgroDealer("Farmsquare Agro Dealers","254712505038", "farmsquareagrodealers@gmail.com",-1.2262432,37.1600463,"Fertilizers, farm machinery","Agricultural","true","2 months duration, monthly payment terms"),
AgroDealer("Farmsquare Agro Dealers","254712505038", "farmsquareagrodealers@gmail.com",-1.2262432,37.1600463,"Fertilizers, farm machinery","Agricultural","true","2 months duration, monthly payment terms","Kamba Building"),
// Near Naivasha

// Near Nakuru
Expand Down Expand Up @@ -325,6 +343,7 @@ class LocateAgriTechCompaniesFragment : Fragment() , OnMapReadyCallback {
override fun onResume() {
super.onResume()
mapView.onResume()
promptUserForLocationPermissions()
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.steve_md.smartmkulima.ui.fragments.main

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.steve_md.smartmkulima.R


class MappingFarmLocationWihPinsFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_mapping_farm_location_wih_pins, container, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var map: HashMap<String, String> = HashMap()
class SuccessfulPaymentFragment : Fragment() {


private lateinit var binding:FragmentSuccessfulPaymentBinding
private lateinit var binding: FragmentSuccessfulPaymentBinding
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_redo_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z"/>

</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_save_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>

</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_touch_app_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M9,11.24V7.5C9,6.12 10.12,5 11.5,5S14,6.12 14,7.5v3.74c1.21,-0.81 2,-2.18 2,-3.74C16,5.01 13.99,3 11.5,3S7,5.01 7,7.5C7,9.06 7.79,10.43 9,11.24zM18.84,15.87l-4.54,-2.26c-0.17,-0.07 -0.35,-0.11 -0.54,-0.11H13v-6C13,6.67 12.33,6 11.5,6S10,6.67 10,7.5v10.74c-3.6,-0.76 -3.54,-0.75 -3.67,-0.75c-0.31,0 -0.59,0.13 -0.79,0.33l-0.79,0.8l4.94,4.94C9.96,23.83 10.34,24 10.75,24h6.79c0.75,0 1.33,-0.55 1.44,-1.28l0.75,-5.27c0.01,-0.07 0.02,-0.14 0.02,-0.2C19.75,16.63 19.37,16.09 18.84,15.87z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragments.main.MappingFarmLocationWihPinsFragment">


<com.google.android.gms.maps.MapView
android:id="@+id/mapViewSatellite"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonStartMapping"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginStart="@dimen/_32dp"
android:layout_marginEnd="@dimen/_16dp"
android:text="Start Mapping"
android:fontFamily="@font/montserrat_medium"
android:textAllCaps="false"
android:drawableLeft="@drawable/baseline_touch_app_24"
android:layout_marginBottom="@dimen/_32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/buttonSaveMappedArea"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginStart="@dimen/_32dp"
android:layout_marginEnd="@dimen/_16dp"
android:text="Save Mapped Area"
android:fontFamily="@font/montserrat_medium"
android:textAllCaps="false"
android:backgroundTint="@color/light_blue"
android:visibility="invisible"
android:drawableLeft="@drawable/baseline_touch_app_24"
android:layout_marginBottom="@dimen/_32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/buttonRedoMapping"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginStart="@dimen/_32dp"
android:layout_marginEnd="@dimen/_16dp"
android:text="Redo Mapping"
android:fontFamily="@font/montserrat_medium"
android:textAllCaps="false"
android:visibility="invisible"
android:backgroundTint="@color/light_blue"
android:drawableLeft="@drawable/baseline_redo_24"
android:layout_marginBottom="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="@font/montserrat_semibold"
android:text="Services:"
android:text="Products:"
app:layout_constraintStart_toStartOf="@+id/textView88"
app:layout_constraintTop_toBottomOf="@+id/textView88" />

Expand Down Expand Up @@ -95,6 +95,7 @@
android:layout_marginTop="16dp"
android:fontFamily="@font/montserrat_semibold"
android:text="Leasing Options: "
android:visibility="invisible"
app:layout_constraintStart_toStartOf="@+id/textView92"
app:layout_constraintTop_toBottomOf="@+id/textView92" />

Expand All @@ -104,6 +105,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="true"
android:visibility="invisible"
android:fontFamily="@font/montserrat_semibold"
app:layout_constraintBottom_toBottomOf="@+id/textView94"
app:layout_constraintStart_toEndOf="@+id/textView94"
Expand All @@ -115,6 +117,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Leasing Details: "
android:visibility="invisible"
android:fontFamily="@font/montserrat_semibold"
app:layout_constraintStart_toStartOf="@+id/textView94"
app:layout_constraintTop_toBottomOf="@+id/textView94" />
Expand All @@ -125,6 +128,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="@dimen/_8dp"
android:visibility="invisible"
android:fontFamily="@font/montserrat_semibold"
android:text="6 months duration, monthly payment terms"
app:layout_constraintBottom_toBottomOf="@+id/textView96"
Expand Down
21 changes: 17 additions & 4 deletions app/src/main/res/layout/item_agrodealer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
android:id="@+id/imageView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_10dp"
android:layout_marginTop="10dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
app:layout_constraintStart_toStartOf="@+id/agrodealer_name"
app:layout_constraintTop_toBottomOf="@+id/agrodealer_name"
app:layout_constraintStart_toStartOf="@+id/textViewBuilding"
app:layout_constraintTop_toBottomOf="@+id/textViewBuilding"
app:srcCompat="@drawable/ic_call_24" />

<TextView
Expand Down Expand Up @@ -139,7 +139,20 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.911" />
app:layout_constraintVertical_bias="0.95" />

<TextView
android:id="@+id/textViewBuilding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="CBD House, Room 1"
android:clickable="true"
android:focusable="true"
android:fontFamily="@font/montserrat_semibold"
android:foreground="?android:selectableItemBackground"
app:layout_constraintStart_toStartOf="@+id/agrodealer_name"
app:layout_constraintTop_toBottomOf="@+id/agrodealer_name" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Expand Down

0 comments on commit 63a4f1a

Please sign in to comment.