-
-
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 #14 from CodericLatam/data_preferences
Guardado de datos usando SharedPreferences.
- Loading branch information
Showing
114 changed files
with
565 additions
and
46 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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.
Empty file.
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified
0
app/src/androidTest/java/org/coderic/protective/mobile/ExampleInstrumentedTest.kt
100644 → 100755
Empty file.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/StartActivity.kt
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/coderic/protective/mobile/data/Almacenamiento.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,11 @@ | ||
package org.coderic.protective.mobile.data | ||
|
||
import org.coderic.protective.mobile.model.datos.Device | ||
import org.coderic.protective.mobile.model.datos.Pet | ||
|
||
interface Almacenamiento { | ||
fun savePet( pet: Pet ) | ||
fun saveDevice( device: Device ) | ||
fun getPet( id: Long ) : Pet? | ||
fun getDevice() : Device | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/org/coderic/protective/mobile/data/MacronutrientPreferences.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,61 @@ | ||
package org.coderic.protective.mobile.data | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import org.coderic.protective.mobile.model.datos.Device | ||
import org.coderic.protective.mobile.model.datos.Gender | ||
import org.coderic.protective.mobile.model.datos.Pet | ||
import org.json.JSONObject | ||
|
||
const val ARCHIVE_PREFERENCE = "almacenamiento" | ||
class MacronutrientPreferences (context: Context ) : Almacenamiento { | ||
|
||
private val preferences: SharedPreferences = context.getSharedPreferences( ARCHIVE_PREFERENCE, Context.MODE_PRIVATE ) | ||
override fun savePet( pet: Pet ) { | ||
val editor = preferences.edit() | ||
val petJson = JSONObject() | ||
.put("name", pet.name) | ||
.put("typePet", pet.typePet ) | ||
.put("age", pet.age ) | ||
.put("weight", pet.weight ) | ||
.put("height", pet.height ) | ||
.put("color", pet.color ) | ||
.put("description", pet.description ) | ||
.put("image", pet.image ) | ||
.put("id", pet.id ) | ||
.put("gender", pet.gender.type ) | ||
editor.putString("pet${pet.id}", petJson.toString() ) | ||
editor.apply() | ||
} | ||
|
||
override fun saveDevice( device: Device ) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getPet(id: Long): Pet? { | ||
val petString = preferences.getString("pet$id", "") | ||
if (petString.equals("")) return null; | ||
val petJSON = JSONObject(petString) | ||
|
||
return Pet( | ||
name = petJSON.getString("name"), | ||
gender = if (petJSON.getInt("gender") == 0) Gender.MAN else Gender.FEMALE, | ||
typePet = petJSON.getString("typePet"), | ||
age = petJSON.getInt("age"), | ||
weight = petJSON.getDouble("weight"), | ||
height = petJSON.getInt("height"), | ||
color = petJSON.getString("color"), | ||
description = petJSON.getString("description"), | ||
image = petJSON.getString("image"), | ||
id = petJSON.getLong("id") | ||
) | ||
} | ||
|
||
override fun getDevice(): Device { | ||
return Device( | ||
preferences.getString("device_name", "")!!, | ||
false, | ||
0 | ||
) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/org/coderic/protective/mobile/domain/CasosUsoMascota.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,34 @@ | ||
package org.coderic.protective.mobile.domain | ||
|
||
import android.content.Context | ||
import org.coderic.protective.mobile.data.Almacenamiento | ||
import org.coderic.protective.mobile.data.MacronutrientPreferences | ||
import org.coderic.protective.mobile.model.datos.Gender | ||
import org.coderic.protective.mobile.model.datos.Pet | ||
|
||
class CasosUsoMascota( context: Context ) { | ||
val almacenamiento : Almacenamiento = MacronutrientPreferences( context ) | ||
fun guardarMascota( pet: Pet ) { | ||
almacenamiento.savePet( pet ) | ||
} | ||
fun getMascota( id: Long ) : Pet? { | ||
val pet = almacenamiento.getPet( id ) | ||
return pet | ||
/*if( pet == null ) { | ||
return Pet( | ||
name = "Bella", | ||
typePet = "Border Collie", | ||
gender = Gender.MAN, | ||
age = 11, | ||
weight = 7.5, | ||
height = 54, | ||
color = "Black", | ||
description = "My first dog which was gifted by my mother for my 20th birthday." | ||
) | ||
} | ||
else { | ||
return pet | ||
}*/ | ||
} | ||
|
||
} |
17 changes: 9 additions & 8 deletions
17
app/src/main/java/org/coderic/protective/mobile/model/Routes.kt
100644 → 100755
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,12 +1,13 @@ | ||
package org.coderic.protective.mobile.model | ||
|
||
sealed class Routes( val route : String ) { | ||
// Rutas de Start Activity | ||
object InicioSesion: Routes("inicio/inicio_sesion") | ||
object GetStarted: Routes("inicio/get_started") | ||
// Rutas de MainActivity | ||
object MainScreen: Routes("main/home") | ||
object MyPetScreen: Routes("main/profile") | ||
object ExploreScreen: Routes("main/explore") | ||
object ManageScreen: Routes("main/manage") | ||
// Ruts de Start Activity | ||
data object InicioSesion: Routes("inicio/inicio_sesion") | ||
data object GetStarted: Routes("inicio/get_started") | ||
// Ruts de MainActivity | ||
data object MainScreen: Routes("main/home") | ||
data object MyPetScreen: Routes("main/profile") | ||
data object MyUpdatePetScreen : Routes("main/profile/update") | ||
data object ExploreScreen: Routes("main/explore") | ||
data object ManageScreen: Routes("main/manage") | ||
} |
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/model/datos/Device.kt
100644 → 100755
Empty file.
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/model/datos/GeoPunto.kt
100644 → 100755
Empty file.
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
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/presentation/DashBoardScreen.kt
100644 → 100755
Empty file.
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/presentation/DeviceScreen.kt
100644 → 100755
Empty file.
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/presentation/HomeScreen.kt
100644 → 100755
Empty file.
Empty file modified
0
app/src/main/java/org/coderic/protective/mobile/presentation/LoadingScreen.kt
100644 → 100755
Empty file.
Oops, something went wrong.