class AuthActivity : AppCompatActivity() {
private val locationListener = object : LocationListener {
override fun onLocationChanged(location: Location) {
showLocation(location)
}
override fun onProviderDisabled(provider: String) {
}
override fun onProviderEnabled(provider: String) {
}
override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
}
}
companion object {
var GPS: Location? = null
private val PERMISSION_GPS_CODE = 101
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_auth)
val textview = findViewById<TextView>(R.id.GPS)
setUpLocationListener(this)
// textview.text = GPS?.longitude.toString() + " " + GPS?.latitude.toString()
}
fun showLocation(location: Location) {
val textview = findViewById<TextView>(R.id.GPS)
textview.text = GPS?.longitude.toString() + " " + GPS?.latitude.toString()
}
fun setUpLocationListener(context: Context) {
val permissionStatus = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
1000,
2.0F,
locationListener)
GPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), PERMISSION_GPS_CODE)
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
when(requestCode) {
PERMISSION_GPS_CODE -> {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setUpLocationListener(this)
} else {
}
return
}
else -> {
}
}
}
}
package com.example.learnkotlin
import android.Manifest
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.content.Context
import android.Manifest.permission
import android.app.Activity
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
class MainActivity : AppCompatActivity() {
fun getGPS(context: Context, activity: Activity): Location? {
val position = Position()
position.SetUpLocationListener(this, this)
var gps = position.imHere
return gps
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun auth(view: View) {
val text = "Text!!!"
val gps = getGPS(this, this)
val intent = Intent(this, AuthActivity::class.java)
intent.putExtra(AuthActivity.TEXT, text)
intent.putExtra(AuthActivity.GPS_data, gps.toString())
startActivity(intent)
}
}
class Position : LocationListener {
var imHere: Location? = null
private val PERMISSION_GPS_CODE = 101
fun SetUpLocationListener(context: Context, activity: MainActivity) {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val locationListener = Position()
val permissionStatus = ContextCompat.checkSelfPermission(context, permission.ACCESS_FINE_LOCATION)
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
5000,
10.0F,
locationListener)
} else {
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), PERMISSION_GPS_CODE)
}
imHere = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
}
override fun onProviderDisabled(p0: String?) {}
override fun onProviderEnabled(p0: String?) {}
override fun onStatusChanged(p0: String?, p1: Int, p2: Bundle?) {}
override fun onLocationChanged(p0: Location?) {}
}
val permissionStatus = ContextCompat.checkSelfPermission(context, permission.ACCESS_FINE_LOCATION)
if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
5000,
10.0F,
locationListener)
} else {
ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 101)
}
class Order(models.Model):
order_id = models.fk()
position = models.CharField()
size = models.CharField()
quantity = models.IntegerField()
color = models.CharField()
<div class="col">
<div class="contact_cart d-flex align-items-center justify-content-center">
<div class="test d-flex align-items-center justify-content-center">Человек</div> <br>
Исполнительный директор
</div>
</div>
<div class="col">
<div class="contact_cart">
<h3 class="d-flex align-items-center justify-content-center">Человек</h3>
Исполнительный директор
</div>
</div>
def my_path(obj, name):
return 'user_{0}/{1}'.format(obj.item.client.company, name)
class ItemChat(models.Model):
class Meta:
verbose_name = "ItemChat"
verbose_name_plural = "ItemChats"
def __str__(self):
return item.client
item = models.ForeignKey(Order, on_delete=models.SET_NULL, blank=True, null=True)
personal = models.ForeignKey(PersonalProfile, on_delete=models.SET_NULL, blank=True, null=True)
client = models.ForeignKey(ClientProfile, on_delete=models.SET_NULL, blank=True, null=True)
comment = models.CharField(blank=True, null=True, max_length=50)
design_img = models.ImageField(blank=True, null=True, upload_to=my_path)