Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into CU07
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/IngredientesFragment.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
  • Loading branch information
COLOSO70 committed Nov 23, 2023
2 parents 1a82db4 + cd86ce7 commit 402fcd4
Show file tree
Hide file tree
Showing 15 changed files with 684 additions and 14 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.

79 changes: 79 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,85 @@ class LoginActivity : AppCompatActivity() {
}
}

private fun setUpListeners() {
with(binding) {

btLogin.setOnClickListener {
correctLogin()
}

}
}

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 @@ -122,6 +122,76 @@ 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 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IngredientesFragment : Fragment() {

private fun getIngredientes () : TreeSet<String> {
val ingredientes = Session.getValue("ingredientesSeleccionados") as TreeSet<*>? ?: TreeSet<String>()
val ingredientesFiltrados = TreeSet<String>()
val ingredientesFiltrados = TreeSet<String>(todosLosIngredientes)

if (ingredientes.isEmpty()) {
return ingredientesFiltrados
Expand All @@ -54,7 +54,7 @@ class IngredientesFragment : Fragment() {
}

// Esta lista almacenará todos los cambios que se hagan en la lista de todos los ingredientes
private var listaIngredientes : TreeSet<String> = TreeSet()
private var listaIngredientes : TreeSet<String> = getIngredientes()
// Utilizo un treeset porque no admite duplicados y los elementos están ordenados automaticamente

override fun onCreateView(
Expand Down Expand Up @@ -95,14 +95,20 @@ class IngredientesFragment : Fragment() {
private fun setUpButtonListener() {
with(binding) {
btnCrearReceta.setOnClickListener() {

val ingredientes = ingredientesSeleccionadosAdapter.getSet()

if (ingredientes.isEmpty()) {
advertenciaLabel.visibility = View.VISIBLE
} else {
listener.onCrearRecetaClick(ingredientesSeleccionadosAdapter.getSet())
}
}
}
}

private fun setUpAllRecyclerView () {
todosIngredientesAdapter = ItemSwapAdapter(
itemSet = TreeSet<String>(),
itemSet = TreeSet<String>(todosLosIngredientes),
onClick = {

with(binding.advertenciaLabel) {
Expand Down
Loading

0 comments on commit 402fcd4

Please sign in to comment.