Commit 082e9391 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#160: Done Account Update(still needs some warnings)

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent ac00646d
......@@ -845,20 +845,15 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
values.put("password_confirmation", et_password_confirmation.getText().toString());
}
//TODO: sometimes update with picture fails with 422 return.
if(isChangingPhoto) {
if(isPhotoDelete) {
//TODO: change photo removal according to back-end
values.put("photo_content", "");
values.put("photo_type", "image/png");
values.put("photo_type", "delete");
}else {
values.put("photo_content", Utils.getBase64FromFile(userPhotoHelper.getTempFilePath()));
values.put("photo_type", "image/png");
// TODO: 03/05/17 Change here to work with multi photo types
values.put("photo_name", userPhotoHelper.getUserUid() + ".png");
}
values.put("photo_name", userPhotoHelper.getUserUid() + ".png");
}
return values;
......
......@@ -24,7 +24,7 @@ import java.io.IOException;
*/
// TODO: 03/05/17 Add multi file extension usage.
public class UserPhotoHelper {
private String filePath;
......@@ -51,7 +51,7 @@ public class UserPhotoHelper {
private void createFile() {
this.userUid = osb.getString("uid", null);
this.photo = new File(filePath + userUid + ".bmp");
this.tempPhoto = new File(filePath + "_temp_" + userUid);
this.tempPhoto = new File(filePath + "temp_" + userUid);
this.photoFileUri = Uri.fromFile(photo);
this.tempPhotoFileUri = Uri.fromFile(tempPhoto);
}
......
......@@ -22,7 +22,7 @@ public class Utils {
public final static String DIR_PICTRS = "pictures";
public final static String USR_PICT_FILE_NAME = "usr_prof_pic";
public final static String USR_PICT_FILE_NAME = "usr_prof_pic_";
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
......@@ -40,6 +40,8 @@ public class Utils {
return options.outWidth != -1 && options.outHeight != -1;
}
/* Not used.
image is not received as base64.
public static Bitmap decodeBase64(String encodedImage){
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
......@@ -48,7 +50,7 @@ public class Utils {
return decodedByte;
}
*/
// Converting File to Base64.encode String type using Method
public static String getBase64FromFile(String absolutePath) {
InputStream inputStream = null;
......
......@@ -73,7 +73,7 @@ public class AccountPresenter extends BasePresenter<AccountView> {
UserUpdate user = new UserUpdate(body);
final AccountUpdate account;
if(body.get("photo_content") != null)
if(body.get("photo_type") != null)
user.setImage(body.get("photo_type"), body.get("photo_name"), body.get("photo_content"));
if (body.get("password") == null || body.get("password_confirmation") == null){
......
......@@ -3,13 +3,17 @@ package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.util.Log;
import java.io.File;
import java.io.FilenameFilter;
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.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.Account;
import br.ufpr.c3sl.agendador.agendador.models.AccountOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -85,7 +89,8 @@ public class LoginPresenter extends BasePresenter<LoginView> {
case 200:
onSuccessfulLogin(accountOutput, headers);
loginPresenter.requestImage();
searchPhoto();
//loginPresenter.requestImage();
break;
default:
break;
......@@ -149,4 +154,28 @@ public class LoginPresenter extends BasePresenter<LoginView> {
});
}
// TODO: 03/05/17 Adapt function to scenario with different file extensions, if needed.
private void searchPhoto(){
final String uid = osb.getString("uid", null);
File dir = new File(context.getExternalFilesDir(null) + File.separator + Utils.DIR_PICTRS + File.separator);
FilenameFilter filter = new FilenameFilter() {
public boolean accept (File dir, String name) {
return name.startsWith(Utils.USR_PICT_FILE_NAME + uid);
}
};
String[] children = dir.list(filter);
if (children == null || children.length == 0) {
Log.d("Error", "(Either dir does not exist or is not a directory) or ( File not Found).");
requestImage();
}else{
loginPresenter.view().setProgressBar(false);
loginPresenter.view().afterSuccessfulLogin();
}
}
}
\ 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