Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into CU09
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/es/unex/giis/asee/gepeto/view/LoginActivity.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/EquipamientoFragment.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/HomeActivity.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/SettingsFragment.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/recetas/FavoritasFragment.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/recetas/HistorialFragment.kt
#	app/src/main/java/es/unex/giis/asee/gepeto/view/home/recetas/RecetaDetailFragment.kt
  • Loading branch information
COLOSO70 committed Nov 23, 2023
2 parents e222734 + e1960c6 commit cd86ce7
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions app/src/main/java/es/unex/giis/asee/gepeto/view/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,75 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun readSettings(){
val preferences = PreferenceManager.getDefaultSharedPreferences(this).all

val rememberMe = preferences["rememberme"] as Boolean? ?: false
val username = preferences["username"] as String? ?: ""
val password = preferences["password"] as String? ?: ""

if (rememberMe) {
binding.etUsername.setText(username)
binding.etPassword.setText(password)
}
}

private fun setUpUI() {
//get attributes from xml using binding
}

private fun setUpListeners() {
with(binding) {

btLogin.setOnClickListener {
correctLogin()
}

btRegister.setOnClickListener {
navigateToJoin()
}

btRestore.setOnClickListener {
navigateToRestore()
}

}
}

private fun correctLogin(){
val credentialCheck = CredentialCheck.login(binding.etUsername.text.toString(), binding.etPassword.text.toString())

if (credentialCheck.fail) {
notifyInvalidCredentials(credentialCheck.msg)
return
}

lifecycleScope.launch{
val user = db?.userDao()?.findByName(binding.etUsername.text.toString()) //?: User(-1, etUsername.text.toString(), etPassword.text.toString())
if (user != null) {
// db.userDao().insert(User(-1, etUsername.text.toString(), etPassword.text.toString()))
val passwordCheck = CredentialCheck.passwordOk(binding.etPassword.text.toString(), user.password)
if (passwordCheck.fail) notifyInvalidCredentials(passwordCheck.msg)
else Toast.makeText(this@LoginActivity, "Login successful", Toast.LENGTH_SHORT).show()
}
else notifyInvalidCredentials("Invalid username")
}
}

private fun navigateToJoin() {
JoinActivity.start(this, responseLauncher)
}

private fun navigateToRestore() {
val showPopUp = PopUpFragment()
showPopUp.show(supportFragmentManager, "showPopUp")
}


private fun notifyInvalidCredentials(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}

private fun correctLogin(){
val credentialCheck = CredentialCheck.login(binding.etUsername.text.toString(), binding.etPassword.text.toString())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package es.unex.giis.asee.gepeto.view

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import es.unex.giis.asee.gepeto.database.GepetoDatabase
import es.unex.giis.asee.gepeto.databinding.FragmentRestorePopUpBinding
import es.unex.giis.asee.gepeto.model.User
import es.unex.giis.asee.gepeto.utils.CredentialCheck
import kotlinx.coroutines.launch

class PopUpFragment : DialogFragment() {

//binding
private lateinit var binding: FragmentRestorePopUpBinding

private lateinit var db: GepetoDatabase

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentRestorePopUpBinding.inflate(inflater, container, false)

db = GepetoDatabase.getInstance(requireContext())!!

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

with(binding) {
//boton que llama a la funcion que cambia la contraseña
restorebtn.setOnClickListener {
restorePassword()
dismiss()
}
}
}

//funcion que cambia la contraseña del usuario que se la ha olvidado
private fun restorePassword() {
with(binding) {
val username = restUsername.text.toString()
val newPassword = newPassword.text.toString()

//dado el nombre de usuario, se busca en la base de datos y se actualiza la contraseña antigua por la nueva
lifecycleScope.launch {
//comprueba si la contraseña es correcta
val check = CredentialCheck.newPasswordOk(newPassword)
if (check.fail) {
Toast.makeText(context, check.msg, Toast.LENGTH_SHORT).show()
return@launch
}
else{
val user = db?.userDao()?.findByName(restUsername.text.toString()) //?: User(-1, etUsername.text.toString(), etPassword.text.toString())
if (user != null) {
Toast.makeText(context, "Contraseña cambiada", Toast.LENGTH_SHORT).show()
db?.userDao()?.update(User(user.userId, username, newPassword))
} else {
Toast.makeText(context, "Usuario no encontrado", Toast.LENGTH_SHORT).show()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class EquipamientoFragment : Fragment() {

private val binding get() = _binding


private fun getEquipamientos () : TreeSet<String> {
val equipamientos = Session.getValue("equipamientosSeleccionados") as TreeSet<*>? ?: TreeSet<String>()
val equipamientosFiltrados = TreeSet<String>(equipamientosDeCocina)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,43 @@ class HomeActivity :
navController.navigate(action)
}

override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp(appBarConfiguration)
|| super.onSupportNavigateUp()
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.appbar_menu, menu)

// Configure the search info and add any event listeners.
return super.onCreateOptionsMenu(menu)
}

fun mostrarLupaAppbar ( mostrar: Boolean ) {
val searchView = binding.toolbar.menu.findItem(R.id.action_search)
if (searchView != null)
searchView.isVisible = mostrar
}

override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
R.id.action_settings -> {
// User chooses the "Settings" item. Show the app settings UI.
val action = RecetasFragmentDirections.actionHomeToSettingsFragment()
navController.navigate(action)
true
}

else -> {
// The user's action isn't recognized.
// Invoke the superclass to handle it.
super.onOptionsItemSelected(item)
}
}
override fun onRecetaClick(receta: Receta) {
val action = RecetasFragmentDirections.actionRecetasFragmentToRecetaDetailFragment(receta)
navController.navigate(action)
}

override fun onReceta2Click(receta: Receta) {
val action = RecetasFragmentDirections.actionRecetasFragmentToRecetaDetailFragment(receta)
navController.navigate(action)
Expand All @@ -136,11 +173,6 @@ class HomeActivity :
navController.navigate(action)
}

override fun onGenerarRecetaClick(receta: Receta) {
val action = ObservacionesFragmentDirections
.actionObservacionesFragmentToRecetaDetailFragment(receta)
navController.navigate(action)
}

override fun onDestroy() {
super.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.preferences, rootKey)



// Obtener la referencia a la preferencia de edición de sugerencias
val editSuggestionPreference: Preference? = findPreference("edit_suggestion")

// Configurar el click listener para la preferencia de edición de sugerencias
editSuggestionPreference?.setOnPreferenceClickListener {
// Mostrar un cuadro de diálogo de edición de sugerencias
showSuggestionDialog()
true
}
}

private fun setDefaultValues() {
Expand All @@ -42,4 +52,29 @@ class SettingsFragment : PreferenceFragmentCompat() {
editor.apply()
}

// Función para mostrar un cuadro de diálogo de edición de sugerencias
private fun showSuggestionDialog() {
val builder = AlertDialog.Builder(requireContext())
builder.setTitle("Enviar Sugerencia")

// Configurar un EditText en el cuadro de diálogo para que los usuarios ingresen su sugerencia
val input = EditText(requireContext())
input.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
builder.setView(input)

// Configurar los botones del cuadro de diálogo
builder.setPositiveButton("Enviar") { _, _ ->
// Obtener la sugerencia ingresada por el usuario
val userSuggestion = input.text.toString()

// Aquí la lógica de la sugerencia

// Mostrar un mensaje de confirmación (esto es solo un ejemplo)
Toast.makeText(requireContext(), "Sugerencia enviada: $userSuggestion", Toast.LENGTH_SHORT).show()
}
builder.setNegativeButton("Cancelar") { dialog, _ -> dialog.cancel() }

// Mostrar el cuadro de diálogo
builder.show()
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_observaciones.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.home.ObservacionesFragment">
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit cd86ce7

Please sign in to comment.