//-- Código que carga la fotografia p.btnCargar.setOnClickListener { val g =…
- User
//-- Código que carga la fotografia p.btnCargar.setOnClickListener { val g = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI) startActivityForResult(g, 10) }
//-- Guardar datos en el Firestore p.btnGuardar.setOnClickListener { val mensaje = AlertDialog.Builder(this) mensaje.setTitle(“Advertencia”) mensaje.setMessage(“Esta seguro de guardar el Registro…?”) mensaje.setPositiveButton(“Si”, DialogInterface.OnClickListener{ dialog, which -> if ( rutaFoto == null) { guardarFoto(“”) } if (rutaFoto != null) { val nombreArchivo = UUID.randomUUID().toString() val ref = FirebaseStorage.getInstance().getReference(“/fotos/nombreArchivo”) ref.putFile(rutaFoto!!).addOnSuccessListener { ref.downloadUrl.addOnCompleteListener { guardarFoto(it.toString()) } } .addOnFailureListener { mensaje.setTitle(“Advertencia”) mensaje.setMessage(“Esta seguro de guardar el Registro…?”) } } })
//-- Caso NO mensaje.setNegativeButton(“No”, DialogInterface.OnClickListener { dialog, which -> dialog.cancel() })
mensaje.show() }
//-- Cerrar sessión p.btnCerrar.setOnClickListener { FirebaseAuth.getInstance().signOut() val i = Intent(this, MainActivity::class.java) i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) startActivity(i) }
//-- Limpiar datos p.btnNuevo.setOnClickListener { limpiarTexto() p.txtDoc.requestFocus() }
//— Buscar Registro por DNI p.btnBuscar.setOnClickListener { val v = AlertDialog.Builder(this) v.setTitle(“INGRESE DOCUMENTO DE IDENTIDAD”) val entrada = EditText(this) entrada.setHint(“Documento de identidad”) entrada.inputType = InputType.TYPE_CLASS_NUMBER v.setView(entrada) v.setPositiveButton(“OK”, DialogInterface.OnClickListener { dialog, which -> if(entrada.text.length > 0) { db.collection(“contactos”) .whereEqualTo(“dni”, entrada.text.toString()) .get() .addOnSuccessListener { doc -> limpiarTexto() var sw = 0 for(d in doc){ p.txtDoc.setText(d.data[“dni”].toString()) p.txtApe.setText(d.data[“apellido”].toString()) p.txtNom.setText(d.data[“nombre”].toString()) p.txtDir.setText(d.data[“direccion”].toString()) p.txtTel.setText(d.data[“telefono”].toString()) p.txtCor.setText(d.data[“correo”].toString()) var ruta = d.data[“ruta”].toString() if (ruta.toString().length > 0) { Picasso.get().load(ruta).into(p.foto) } sw = 1 break } if (sw == 0) { Toast.makeText(this, “Contactos no Existe…!”, Toast.LENGTH_SHORT).show() } } } }) v.show() }
}
//---- Función Guardar Foto------ fun guardarFoto(ruta:String){ val regContacto=db.collection(“contactos”) var dni=p.txtDoc.text.toString() var apellido=p.txtApe.text.toString() var nombre=p.txtNom.text.toString() var direccion=p.txtDir.text.toString() var telefono=p.txtTel.text.toString() var correo=p.txtCor.text.toString() var reg=Contacto(dni,apellido,nombre,direccion,telefono,correo,ruta) regContacto.add(reg) .addOnSuccessListener {it Toast.makeText(this, “Se Registraron los Datos Correctamente con el ID: {it.id}”, Toast.LENGTH_SHORT).show() } .addOnFailureListener { Toast.makeText(this, “Error al Registrar Datos del Contacto…!”, Toast.LENGTH_SHORT).show() } }
- Assistant