diff --git a/app/build.gradle b/app/build.gradle
index 5250fd8..7a4e1c2 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -53,6 +53,7 @@ dependencies {
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:okhttp:4.9.3"
+
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
@@ -68,4 +69,6 @@ dependencies {
//for fragment
implementation 'com.google.android.material:material:1.5.0'
+ //maps
+ implementation 'com.google.android.gms:play-services-location:19.0.1'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e0ded09..e93bdba 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,8 @@
+
+
lateinit var imgFile:File
lateinit var sharedPref:SharedPreferences
+ lateinit var fusedLocationProviderClient: FusedLocationProviderClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -51,12 +59,16 @@ class CreatePost : AppCompatActivity() {
.compress(512)
.saveDir(getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!).start()
}
+
+ fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
+ fetchLocation()
+
sharedPref = getSharedPreferences("SP", Context.MODE_PRIVATE)
actv = binding.dropMenu
adapterItems = ArrayAdapter(this,R.layout.list_item,items)
actv.setAdapter(adapterItems)
- actv.setOnItemClickListener(OnItemClickListener { parent, view, position, id ->
+ actv.setOnItemClickListener(OnItemClickListener { parent, _, position, _ -> //parent,view, position, id
val item = parent.getItemAtPosition(position).toString()
Toast.makeText(applicationContext, "Item: $item", Toast.LENGTH_SHORT).show()
})
@@ -88,13 +100,52 @@ class CreatePost : AppCompatActivity() {
if(resultCode== Activity.RESULT_OK && requestCode== ImagePicker.REQUEST_CODE) {
-// binding.ivGriImg.setImageBitmap()
+
+
binding.ivGriImg.setImageURI(data?.data)
- Log.d("Asach","${data?.data}")
+ Log.d("ImgFile3","${data?.data}")
imgFile = data?.data?.toFile()!!
+
+
+ }
+
+
+ }
+ private fun fetchLocation(){
+ val task = fusedLocationProviderClient.lastLocation
+ Log.d("fetchLocation","In task listener")
+ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED &&
+ ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED){
+ ActivityCompat.requestPermissions(this,arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),101)
+ return
}
+ task.addOnSuccessListener {
+ if (it!=null){
+
+ Toast.makeText(applicationContext,"${it.latitude} ${it.longitude}",Toast.LENGTH_LONG).show()
+ lateinit var add : String
+ try {
+ add = getAddress(it.latitude, it.longitude)
+ }
+ catch (e:Exception){
+ e.printStackTrace()
+ }
+ binding.tvLocation.setText(add)
+
+ Log.d("fetchLocation found",add)
+ Toast.makeText(applicationContext,add,Toast.LENGTH_LONG).show()
+ }
+
+ }
+ }
+ private fun getAddress(lat: Double, lng: Double): String {
+ val geocoder = Geocoder(this)
+ val list = geocoder.getFromLocation(lat, lng, 1)
+ return list[0].getAddressLine(0)
}
private fun create_gri(imgFile: File,
diff --git a/app/src/main/java/com/harshad/projectclean/MainActivity.kt b/app/src/main/java/com/harshad/projectclean/MainActivity.kt
index 940ddef..fec0c3e 100644
--- a/app/src/main/java/com/harshad/projectclean/MainActivity.kt
+++ b/app/src/main/java/com/harshad/projectclean/MainActivity.kt
@@ -3,13 +3,22 @@ package com.harshad.projectclean
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
+import android.content.pm.PackageManager
+import android.location.Geocoder
+import android.location.Location
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
-import com.harshad.projectclean.APIRequests.ApiClient
-import com.harshad.projectclean.APIRequests.grievance_data_class.*
+import android.widget.Toast
+import androidx.core.app.ActivityCompat
+import com.google.android.gms.location.*
import com.harshad.projectclean.databinding.ActivityMainBinding
+import java.lang.Exception
+import com.google.android.gms.location.LocationCallback
+import com.google.android.gms.location.LocationRequest.PRIORITY_HIGH_ACCURACY
+import com.google.android.gms.tasks.CancellationToken
+
//import okhttp3.MediaType.Companion.toMediaType
//import okhttp3.MultipartBody
//import okhttp3.RequestBody.Companion.asRequestBody
@@ -25,6 +34,9 @@ class MainActivity : AppCompatActivity() {
lateinit var sharedPref : SharedPreferences
private var isRemembered = false
+ private lateinit var fusedLocationClient: FusedLocationProviderClient
+ lateinit var fusedLocationProviderClient: FusedLocationProviderClient
+
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -33,6 +45,10 @@ class MainActivity : AppCompatActivity() {
setContentView(view)
binding.btnLogout.setVisibility(View.INVISIBLE)
+ fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
+ fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this)
+ fetchLocation()
+
sharedPref = getSharedPreferences("SP", Context.MODE_PRIVATE)
binding.btnDisplayGri.setOnClickListener {
val intent = Intent(this, DisplayGrievance::class.java)
@@ -85,4 +101,66 @@ class MainActivity : AppCompatActivity() {
}
+
+
+ private fun fetchLocation(){
+ val mLocationRequest = LocationRequest.create()
+ .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
+ .setInterval(10 * 1000)
+ .setFastestInterval(1 * 1000)
+ val task = fusedLocationProviderClient.lastLocation
+ Log.d("fetchLocation","In task listener")
+ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED &&
+ ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
+ != PackageManager.PERMISSION_GRANTED){
+ ActivityCompat.requestPermissions(this,arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),101)
+ ActivityCompat.requestPermissions(this,arrayOf(android.Manifest.permission.ACCESS_COARSE_LOCATION),101)
+ return
+ }
+
+
+
+ fusedLocationClient.lastLocation
+ .addOnSuccessListener { location->
+ if (location != null) {
+ Log.d("fetchLocation1","${location.latitude}" )
+ Log.d("fetchLocation2","${location.longitude}" )
+ binding.tvDemoText.setText("${location.latitude}")
+ }
+
+ }
+ .addOnFailureListener {
+ Toast.makeText(this, "Failed on getting current location",
+ Toast.LENGTH_LONG).show()
+ binding.tvDemoText.setText("Fail")
+ }
+ Log.d("fetchLocation","In IF task listener")
+ task.addOnSuccessListener {location->
+ Log.d("fetchLocation","${location}")
+ if (location!=null){
+
+ Toast.makeText(applicationContext,"${location.latitude} ${location.longitude}", Toast.LENGTH_LONG).show()
+ lateinit var add : String
+ try {
+ add = getAddress(location.latitude, location.longitude)
+ }
+ catch (e: Exception){
+ e.printStackTrace()
+ }
+ //binding.tvLocation.setText(add)
+
+ Log.d("fetchLocation found",add)
+ Toast.makeText(applicationContext,add, Toast.LENGTH_LONG).show()
+ }
+ Log.d("fetchLocation","wrong IF")
+
+ }
+ }
+ private fun getAddress(lat: Double, lng: Double): String {
+ val geocoder = Geocoder(this)
+ val list = geocoder.getFromLocation(lat, lng, 1)
+ return list[0].getAddressLine(0)
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/harshad/projectclean/ProfileSetup.kt b/app/src/main/java/com/harshad/projectclean/ProfileSetup.kt
index 0c0fbb9..afde9f7 100644
--- a/app/src/main/java/com/harshad/projectclean/ProfileSetup.kt
+++ b/app/src/main/java/com/harshad/projectclean/ProfileSetup.kt
@@ -23,6 +23,7 @@ class ProfileSetup : AppCompatActivity() {
binding = ActivityProfileSetupBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
+
sharedPref = getSharedPreferences("SP", Context.MODE_PRIVATE)
binding.edUsername.setText(sharedPref.getString("username","none"))
binding.edEmail.setText(sharedPref.getString("email","none"))
@@ -48,10 +49,10 @@ class ProfileSetup : AppCompatActivity() {
binding.profileImage.setImageURI(data?.data)
- Log.d("Asach","${data?.data}")
+ Log.d("ImageFile","${data?.data}")
var s1= data?.data?.toFile()
- Log.d("Bdach",s1.toString())
+ Log.d("IMGfile",s1.toString())
}
diff --git a/app/src/main/res/layout/activity_create_post.xml b/app/src/main/res/layout/activity_create_post.xml
index 2622092..14dba37 100644
--- a/app/src/main/res/layout/activity_create_post.xml
+++ b/app/src/main/res/layout/activity_create_post.xml
@@ -72,7 +72,7 @@
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:scaleX="1"
- android:text="@string/demoLatlong"
+ android:text=""
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />