-
Notifications
You must be signed in to change notification settings - Fork 22
Import and export data #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
odweta
wants to merge
27
commits into
LibreFitOrg:main
Choose a base branch
from
odweta:feat/import-and-export-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
760813f
add: import & export buttons in SettingsScreen
mnjxclone c17da6d
update: add import and export functionality
mnjxclone daed80b
progress on a migration from raw SQL backup/restore to a JSON arch.
mnjxclone 1d61653
update: JSON data export/import
mnjxclone e8bb260
fix: remove temporary logging
mnjxclone 8e2aed6
fix: remove to-be-deprecated content
mnjxclone 3bc0c36
fix: proper use of ioDispatcher
mnjxclone a6b6f97
fix: remove unused imports
mnjxclone eb46859
fix: remove redundant lib in libs.versions.toml
mnjxclone f1ee9b5
fix: repair build.gradle.kts
mnjxclone 70c7dc0
fix: use standard naming conventions
mnjxclone cab0cc9
fix: use correct serializer for LocalDateTime
mnjxclone aab175e
fix: remove unused variables
mnjxclone 703cfb7
fix: revert prev commit
mnjxclone 3d0f7aa
fix: remove unnecessary upsert methods
mnjxclone 3ecf5e0
fix: correct export/import pipeline (but allows duplicates)
mnjxclone e7f57bc
fix: convert toasts to snackbars
mnjxclone 0d1f0c6
resolve merge conflicts with upstream
mnjxclone 7d6d1cf
add: missing generic savePreferences function
mnjxclone 3988156
add: datastore dependency
mnjxclone 2240b70
fix: correct jvm version
mnjxclone 67efb57
update: use dialogs instead of snackbars
mnjxclone d7000c9
fix: fix linted errors
mnjxclone 29d6a42
fix: add proper migration logic
mnjxclone 01a3c42
fix: fix typo and add animations to loading
mnjxclone edb8a62
fix: separated concerns regarding SettingsEvents
mnjxclone 48d9855
fix: remove redundant datastore dependency
mnjxclone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/librefit/db/importExport/dto/ExportData.kt
This file contains hidden or 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,10 @@ | ||
| package org.librefit.db.importExport.dto | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.librefit.db.entity.Measurement | ||
|
|
||
| @Serializable | ||
| data class ExportData( | ||
| val workouts: List<ExportWorkout>, | ||
| val measurements: List<Measurement>, | ||
| ) |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/librefit/db/importExport/dto/ExportExercise.kt
This file contains hidden or 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,16 @@ | ||
| package org.librefit.db.importExport.dto | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.librefit.enums.SetMode | ||
|
|
||
| @Serializable | ||
| data class ExportExercise( | ||
| val id: Long, | ||
| val idExerciseDC: String, | ||
| val notes: String, | ||
| val setMode: SetMode, | ||
| val restTime: Int, | ||
| val position: Int, | ||
| val workoutId: Long, | ||
| val sets: List<ExportSet> | ||
| ) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/librefit/db/importExport/dto/ExportPayload.kt
This file contains hidden or 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,9 @@ | ||
| package org.librefit.db.importExport.dto | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class ExportPayload( | ||
| val schemaVersion: Int, | ||
| val data: ExportData | ||
| ) |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/librefit/db/importExport/dto/ExportSet.kt
This file contains hidden or 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,13 @@ | ||
| package org.librefit.db.importExport.dto | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class ExportSet( | ||
| val id: Long, | ||
| val load: Double, | ||
| val reps: Int, | ||
| val elapsedTime: Int, | ||
| val completed: Boolean, | ||
| val exerciseId: Long | ||
| ) |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/librefit/db/importExport/dto/ExportWorkout.kt
This file contains hidden or 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,21 @@ | ||
| package org.librefit.db.importExport.dto | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
| import org.librefit.db.entity.LocalDateTimeSerializer | ||
| import org.librefit.enums.WorkoutState | ||
| import java.time.LocalDateTime | ||
|
|
||
| @Serializable | ||
| data class ExportWorkout( | ||
| val id: Long, | ||
| val routineId: Long, | ||
| val notes: String, | ||
| val title: String, | ||
| val state: WorkoutState, | ||
| val timeElapsed: Int, | ||
| @Serializable(with = LocalDateTimeSerializer::class) | ||
| val created: LocalDateTime, | ||
| @Serializable(with = LocalDateTimeSerializer::class) | ||
| val completed: LocalDateTime, | ||
| val exercises: List<ExportExercise> | ||
| ) |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/org/librefit/db/importExport/mapper/ExportMapper.kt
This file contains hidden or 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,40 @@ | ||
| package org.librefit.db.importExport.mapper | ||
|
|
||
| import org.librefit.db.importExport.dto.ExportExercise | ||
| import org.librefit.db.importExport.dto.ExportSet | ||
| import org.librefit.db.importExport.dto.ExportWorkout | ||
| import org.librefit.db.relations.WorkoutWithExercisesAndSets | ||
|
|
||
| fun WorkoutWithExercisesAndSets.toExport(): ExportWorkout { | ||
| return ExportWorkout( | ||
| id = workout.id, | ||
| routineId = workout.routineId, | ||
| notes = workout.notes, | ||
| title = workout.title, | ||
| state = workout.state, | ||
| timeElapsed = workout.timeElapsed, | ||
| created = workout.created, | ||
| completed = workout.completed, | ||
| exercises = exercisesWithSets.map { ex -> | ||
| ExportExercise( | ||
| id = ex.exercise.id, | ||
| idExerciseDC = ex.exercise.idExerciseDC, | ||
| notes = ex.exercise.notes, | ||
| setMode = ex.exercise.setMode, | ||
| restTime = ex.exercise.restTime, | ||
| position = ex.exercise.position, | ||
| workoutId = ex.exercise.workoutId, | ||
| sets = ex.sets.map { s -> | ||
| ExportSet( | ||
| id = s.id, | ||
| load = s.load, | ||
| reps = s.reps, | ||
| elapsedTime = s.elapsedTime, | ||
| completed = s.completed, | ||
| exerciseId = s.exerciseId | ||
| ) | ||
| } | ||
| ) | ||
| } | ||
| ) | ||
| } |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/org/librefit/db/importExport/mapper/ImportMapper.kt
This file contains hidden or 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,54 @@ | ||
| package org.librefit.db.importExport.mapper | ||
|
|
||
| import org.librefit.db.entity.Exercise | ||
| import org.librefit.db.entity.Workout | ||
| import org.librefit.db.entity.Set | ||
| import org.librefit.db.importExport.dto.ExportWorkout | ||
| import org.librefit.db.relations.ExerciseWithSets | ||
| import org.librefit.db.relations.WorkoutWithExercisesAndSets | ||
|
|
||
| fun ExportWorkout.toRelation(): WorkoutWithExercisesAndSets { | ||
| val workoutEntity = Workout( | ||
| id = 0, // 0 -> then new unique ID assigned by ROOM | ||
| routineId = routineId, | ||
| notes = notes, | ||
| title = title, | ||
| state = state, | ||
| timeElapsed = timeElapsed, | ||
| created = created, | ||
| completed = completed | ||
| ) | ||
|
|
||
| val exerciseRelations = exercises.map { ex -> | ||
| val exerciseEntity = Exercise( | ||
| id = 0, // 0 -> then new unique ID assigned by ROOM | ||
| idExerciseDC = ex.idExerciseDC, | ||
| notes = ex.notes, | ||
| setMode = ex.setMode, | ||
| restTime = ex.restTime, | ||
| position = ex.position, | ||
| workoutId = id | ||
| ) | ||
|
|
||
| val sets = ex.sets.map { s -> | ||
| Set( | ||
| id = 0, // 0 -> then new unique ID assigned by ROOM | ||
| load = s.load, | ||
| reps = s.reps, | ||
| elapsedTime = s.elapsedTime, | ||
| completed = s.completed, | ||
| exerciseId = ex.id | ||
| ) | ||
| } | ||
|
|
||
| ExerciseWithSets( | ||
| exercise = exerciseEntity, | ||
| sets = sets | ||
| ) | ||
| } | ||
|
|
||
| return WorkoutWithExercisesAndSets( | ||
| workout = workoutEntity, | ||
| exercisesWithSets = exerciseRelations | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate object in other files