|
|
|
@ -1,8 +1,7 @@
|
|
|
|
|
package fr.iut.cinecool.fragments
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
|
import android.content.Context.LOCATION_SERVICE
|
|
|
|
|
import android.location.LocationManager
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
@ -10,17 +9,16 @@ import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import android.widget.EditText
|
|
|
|
|
import android.widget.ImageView
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
|
import androidx.core.content.ContextCompat.getSystemService
|
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
|
import fr.iut.cinecool.R
|
|
|
|
|
import fr.iut.cinecool.databinding.FragmentLoginBinding
|
|
|
|
|
import fr.iut.cinecool.databinding.FragmentMoviesBinding
|
|
|
|
|
|
|
|
|
|
class LoginFragment : Fragment() {
|
|
|
|
|
private var locationManager : LocationManager? = null
|
|
|
|
|
private var _binding: FragmentLoginBinding? = null
|
|
|
|
|
private val binding get() = _binding!!
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
@ -30,56 +28,14 @@ class LoginFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
//locationManager = this.context?.let { getSystemService(it,LOCATION_SERVICE) } as LocationManager?
|
|
|
|
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
val loginButton = view.findViewById<ImageView>(R.id.loginButton)
|
|
|
|
|
loginButton.setOnClickListener(){
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this.requireContext(),
|
|
|
|
|
Manifest.permission.ACCESS_FINE_LOCATION) !==
|
|
|
|
|
PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
if (ActivityCompat.shouldShowRequestPermissionRationale(
|
|
|
|
|
this.requireContext() as Activity,
|
|
|
|
|
Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
|
this.requireContext() as Activity,
|
|
|
|
|
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1)
|
|
|
|
|
} else {
|
|
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
|
this.requireContext() as Activity,
|
|
|
|
|
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>,
|
|
|
|
|
grantResults: IntArray) {
|
|
|
|
|
when (requestCode) {
|
|
|
|
|
1 -> {
|
|
|
|
|
if (grantResults.isNotEmpty() && grantResults[0] ==
|
|
|
|
|
PackageManager.PERMISSION_GRANTED
|
|
|
|
|
) {
|
|
|
|
|
if ((this.requireContext().let {
|
|
|
|
|
ContextCompat.checkSelfPermission(
|
|
|
|
|
it,
|
|
|
|
|
Manifest.permission.ACCESS_FINE_LOCATION
|
|
|
|
|
)
|
|
|
|
|
} == PackageManager.PERMISSION_GRANTED)) {
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
this.requireContext(),
|
|
|
|
|
"Permission Granted",
|
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
|
).show()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this.requireContext(), "Permission Denied", Toast.LENGTH_SHORT)
|
|
|
|
|
.show()
|
|
|
|
|
}
|
|
|
|
|
login()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
login()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun login(){
|
|
|
|
|
val name = view?.findViewById<EditText>(R.id.name)?.text
|
|
|
|
|
if (name != null) {
|
|
|
|
|