-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into CU07
# 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
Showing
15 changed files
with
684 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/es/unex/giis/asee/gepeto/view/RestorePopUpFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.