-
-
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 pull request #18 from CodericLatam/data_preferences
Flujo de Datos Completado
- Loading branch information
Showing
9 changed files
with
185 additions
and
69 deletions.
There are no files selected for viewing
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
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
38 changes: 33 additions & 5 deletions
38
app/src/main/java/org/coderic/protective/mobile/presentation/pet/PetViewModel.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 |
---|---|---|
@@ -1,16 +1,44 @@ | ||
package org.coderic.protective.mobile.presentation.pet | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.navigation.NavHostController | ||
import org.coderic.protective.mobile.domain.CasosUsoMascota | ||
import org.coderic.protective.mobile.model.datos.Gender | ||
import org.coderic.protective.mobile.model.Routes | ||
import org.coderic.protective.mobile.model.datos.Pet | ||
|
||
class PetViewModel( context: Context) : ViewModel() { | ||
val casosUsoMascota = CasosUsoMascota( context ) | ||
val myPet = casosUsoMascota.getMascota( 1231 ) | ||
class PetViewModel( context: Context, val navController: NavHostController ) : ViewModel() { | ||
private val casosUsoMascota = CasosUsoMascota( context ) | ||
|
||
fun btnAddPet() { | ||
private val _myPet = MutableLiveData<Pet?>( casosUsoMascota.getMascota() ) | ||
private val _arePet = MutableLiveData<Boolean>() | ||
|
||
val myPet = _myPet | ||
val arePet = _arePet | ||
fun btnToAddPet() { | ||
navController.navigate( Routes.MyUpdatePetScreen.route ) | ||
} | ||
fun btnAddPet( pet: Pet ) { | ||
casosUsoMascota.guardarMascota( pet ) | ||
|
||
_myPet.value = pet | ||
arePet.value = true | ||
|
||
navController.navigate( Routes.MyPetScreen.route ) | ||
} | ||
fun getPet() { | ||
_myPet.value = casosUsoMascota.getMascota() | ||
if( _myPet.value == null ) { | ||
_arePet.value = false | ||
} else { | ||
_arePet.value = true | ||
} | ||
} | ||
fun deletePet( pet: Pet ) { | ||
_arePet.value = false | ||
_myPet.value = null | ||
casosUsoMascota.deleteMascota( pet = pet ) | ||
} | ||
} |
Oops, something went wrong.