Commit 8f423cac authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#166: Receives image from back-end

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 19c1960b
package br.ufpr.c3sl.agendador.agendador;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
......@@ -194,6 +195,12 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
finish();
}
@Override
public void afterSuccessfulPhoto(Bitmap bitmap){
// TODO: 17/04/17 handle photo saving
afterSuccessfulLogin();
}
private class LoginChangeListener implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
......
......@@ -7,11 +7,15 @@ import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput;
import br.ufpr.c3sl.agendador.agendador.models.User;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
/**
* Created by Bruno Freitas Tissei on 2/3/17.
......@@ -32,4 +36,7 @@ public interface ApiEndpoints {
@POST("validate_cep")
Call<Address> validateCep(@Body CepInput cepInput);
@GET("citizens/{id}/picture")
Call<ResponseBody> requestPhoto(@Path("id") int id, @Query("size") String size);
}
\ No newline at end of file
......@@ -2,20 +2,21 @@ package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import java.util.HashMap;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.CepActivity;
import br.ufpr.c3sl.agendador.agendador.ForgotPasswordActivity;
import br.ufpr.c3sl.agendador.agendador.HomeActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.Account;
import br.ufpr.c3sl.agendador.agendador.models.AccountOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import br.ufpr.c3sl.agendador.agendador.models.Account;
import br.ufpr.c3sl.agendador.agendador.views.LoginView;
import okhttp3.Headers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -82,20 +83,67 @@ public class LoginPresenter extends BasePresenter<LoginView> {
loginPresenter.view().setProgressBar(false);
break;
case 200:
onSuccessfulLogin(accountOutput, headers);
loginPresenter.requestImage();
break;
default:
break;
}
}
@Override
public void onFailure(Call<AccountOutput> call, Throwable t) {
loginPresenter.view().setNoConnection(true);
loginPresenter.view().setProgressBar(false);
}
});
}
private void requestImage() {
Map<String, String> header = new HashMap<>();
String uid = osb.getString("uid", null);
header.put("Content-Type", "application/json");
header.put("access-token", osb.getString("access-token", null));
header.put("client", osb.getString("client", null));
header.put("uid", uid);
loginPresenter.view().setProgressBar(true);
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(osb.getInt("id", 0), "large");
loginPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
int status = response.code();
switch (status) {
case 500:
//image not found
loginPresenter.view().setProgressBar(false);
loginPresenter.view().afterSuccessfulLogin();
break;
case 200:
loginPresenter.view().afterSuccessfulPhoto(BitmapFactory.decodeStream(response.body().byteStream()));
loginPresenter.view().setProgressBar(false);
break;
default:
break;
}
}
@Override
public void onFailure(Call<AccountOutput> call, Throwable t) {
public void onFailure(Call<ResponseBody> call, Throwable t) {
// TODO: 17/04/17 what to do if request fails to get image?
loginPresenter.view().setNoConnection(true);
loginPresenter.view().setProgressBar(false);
}
});
}
}
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador.views;
import android.graphics.Bitmap;
/**
* Created by Bruno Freitas Tissei on 2/2/17.
*/
......@@ -14,4 +16,6 @@ public interface LoginView {
void setNoConnection(boolean enabled);
void afterSuccessfulLogin();
void afterSuccessfulPhoto(Bitmap bitmap);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment