Skip to content

Commit

Permalink
Fixed profile restore issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brodeurlv committed Jul 10, 2020
1 parent 8d3b738 commit 888cdb5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/src/main/java/com/easyfitness/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ public void onCreate(Bundle savedInstanceState) {

loadPreferences();

profileViMo = new ViewModelProvider(this).get(ProfileViMo.class);
profileViMo.getProfile().observe(this, profile -> {
// Update UI
setDrawerTitle(profile.getName());
setPhotoProfile(profile.getPhoto());
mCurrentProfilID = profile.getId();
savePreferences();
});

DatabaseHelper.renameOldDatabase(this);

if (DatabaseHelper.DATABASE_VERSION >= 15 && !mMigrationBD15done) {
Expand Down Expand Up @@ -344,13 +353,7 @@ public void onCreate(Bundle savedInstanceState) {
startActivityForResult(intent, REQUEST_CODE_INTRO);
}

profileViMo = new ViewModelProvider(this).get(ProfileViMo.class);
profileViMo.getProfile().observe(this, profile -> {
// Update UI
setDrawerTitle(profile.getName());
setPhotoProfile(profile.getPhoto());
savePreferences();
});

}

@Override
Expand Down Expand Up @@ -756,7 +759,6 @@ public void setCurrentProfil(String newProfilName) {

public void setCurrentProfil(Profile newProfil) {
profileViMo.setProfile(newProfil);

}

private void setPhotoProfile(String path) {
Expand Down Expand Up @@ -807,7 +809,7 @@ private void savePreferences() {
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
if (profileViMo!=null && profileViMo.getProfile().getValue()!=null) editor.putLong("currentProfil", profileViMo.getProfile().getValue().getId());
editor.putLong("currentProfil", mCurrentProfilID);
editor.putBoolean("intro014Launched", mIntro014Launched);
editor.putBoolean("migrationBD15done", mMigrationBD15done);
editor.apply();
Expand Down

0 comments on commit 888cdb5

Please sign in to comment.