Skip to content

Commit

Permalink
Get user settings and safe it on login
Browse files Browse the repository at this point in the history
  • Loading branch information
StefMa committed Jun 17, 2016
1 parent 022b545 commit fb3df41
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import guru.stefma.restapi.ApiHelper;
import guru.stefma.restapi.objects.Token;
import guru.stefma.restapi.objects.user.CreateUser;
import guru.stefma.restapi.objects.user.Settings;
import guru.stefma.restapi.objects.user.UserResult;
import guru.stefma.timetracking.R;
import guru.stefma.timetracking.main.MainActivity;
Expand Down Expand Up @@ -109,6 +110,7 @@ public void onResponse(Call<UserResult> call,
if (result.getResult().equals(UserResult.RESULT_OK)) {
SettingsManager.saveUserToken(context, result.getToken());
context.startActivity(MainActivity.newInstance(context));
getSettingsAndSafe(result.getToken(), context);
} else {
Snackbar.make(view, context.getString(R.string.default_error),
Snackbar.LENGTH_LONG).show();
Expand All @@ -128,4 +130,22 @@ public void onFailure(Call<UserResult> call, Throwable t) {
.create().show();
}

private void getSettingsAndSafe(String token, final Context context) {
final Context appContext = context.getApplicationContext();
new ApiHelper().getSettings(new Token(token), new Callback<Settings>() {
@Override
public void onResponse(Call<Settings> call, Response<Settings> response) {
if (response.isSuccessful()) {
Settings settings = response.body();
SettingsManager.saveDefaultWorkingHours(appContext, settings.getDefaultWorktime());
}
}

@Override
public void onFailure(Call<Settings> call, Throwable t) {

}
});
}

}

0 comments on commit fb3df41

Please sign in to comment.