Skip to content

Instantly share code, notes, and snippets.

@adrielAd
Created November 21, 2018 08:14
Show Gist options
  • Save adrielAd/b1fbc4f8665183eb195871d21cd415eb to your computer and use it in GitHub Desktop.
Save adrielAd/b1fbc4f8665183eb195871d21cd415eb to your computer and use it in GitHub Desktop.
// make listEmails global and also initialise this in onCreate so you get already saved emails when you come to this screen
ArrayList<String> listEmails;
public void getDataForId() {
SharedPreferences authToken = getSharedPreferences("authToken", Context.MODE_PRIVATE);
String token = authToken.getString("token", "");
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<UserResponse> call = apiInterface.getData("Bearer " + token);
call.enqueue(new Callback<UserResponse>() {
@Override
public void onResponse(Call<UserResponse> call, Response<UserResponse> response) {
if (response.isSuccessful()) {
String emp_email = response.body().getUser().getEmail();
listEmails = getFromPrefs(this);
if(listEmails == null){
listEmails = new ArrayList<>();
listEmails.add(emp_email);
}else{
if(!listEmails.contains(emp_email)){
listEmails.add(emp_email);
}
}
saveToPrefs(this, listEmails);
/*Log.i("MainActivity", "onCreate: " + getFromPrefs(this).toString());
if(!listEmails.contains(emp_email)){
listEmails.add("b@b.b");
}
saveToPrefs(this, listEmails);
Log.i("MainActivity", "onCreate: " + getFromPrefs(this).toString());*/
} else {
}
}
@Override
public void onFailure(Call<UserResponse> call, Throwable t) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment