Commit 075e0b36 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#174: Done update on account activity

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 84611818
......@@ -59,7 +59,7 @@ import br.ufpr.c3sl.agendador.agendador.views.AccountView;
* Created by Horstmann on 02/03/17.
*/
// TODO: 23/05/17 test "connection failure" dialogs
public class AccountActivity extends AppCompatActivity implements AccountView {
......@@ -132,7 +132,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
String citizenName = osb.getString("name", "");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
setSupportActionBar(toolbar);
......@@ -254,19 +254,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
public void afterTextChanged(Editable s) {}
});
} else {
if(ConnectionChecker.hasConnection(getBaseContext())) {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
}
else{
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_cep_connection_error));
if(dg_connection_error == null){
dg_connection_error = new ConnectionErrorDialog();
}
dg_connection_error.setArguments(bundle);
dg_connection_error.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
}
}
});
......@@ -285,16 +273,8 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
}
}
else{
if( dg_connection_error == null){
dg_connection_error = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_no_connection_message));
dg_connection_error.setArguments(bundle);
dg_connection_error.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
scrollUp();
setNoConnection(true);
}
}
else{
scrollUp();
......@@ -552,7 +532,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
enableButtonEdit(true);
enableAllFields(false);
loadData();
Log.d(this.getClass().getName(),"Atualizou com sucesso");
}
private void cancelUpdate(){
......@@ -892,7 +871,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
}
@Override
public void setNoConnection(boolean enabled){
public void setConnectionError(boolean enabled){
if(enabled){
if(dg_connection_error == null){
dg_connection_error = new ConnectionErrorDialog();
......@@ -905,8 +884,9 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
}
@Override
public void setNoConnectionCep(boolean enabled){
public void setConnectionCepError(boolean enabled){
if(enabled){
Log.d("Aaaa","aaaaaaaa");
if(dg_connection_error == null){
dg_connection_error = new ConnectionErrorDialog();
}
......@@ -918,6 +898,19 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
}
}
public void setNoConnection(boolean enabled){
if(enabled) {
scrollUp();
if (dg_connection_error == null) {
dg_connection_error = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_no_connection_message));
dg_connection_error.setArguments(bundle);
dg_connection_error.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
private void checkBuildVersion(){
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M )
......
......@@ -54,10 +54,9 @@ public class AccountPresenter extends BasePresenter<AccountView> {
accountOutput.getCitizen().save(context);
}
// TODO: 18/05/17 Testar a funcao
public void updateCheck(){
//get user data from back-end to keep App updated.
//similar to login
accountPresenter.view().setProgressBar(true);
Map<String, String> header = new HashMap<>();
......@@ -67,7 +66,6 @@ public class AccountPresenter extends BasePresenter<AccountView> {
header.put("uid", osb.getString("uid", null));
Log.d("SELF Request", "Token enviado:" + osb.getString("access-token", null) + "\n\n");
ApiEndpoints service = ApiUtils.request(header);
Call<AccountOutput> listCall = service.requestSelf();
listCall.enqueue(new Callback<AccountOutput>() {
......@@ -77,17 +75,9 @@ public class AccountPresenter extends BasePresenter<AccountView> {
Headers headers = response.headers();
int status = response.code();
AccountOutput accountOutput = response.body();
Log.d("SELF Request", "Token recebido:" + headers.get("access-token") + "\n\n");
Log.d("SELF Request", "Client recebido:" + headers.get("client") + "\n\n");
Log.d("SELF Request", headers.names().toString());
Log.d("SELF Request", response.raw().toString());
if(headers.get("access-token") == null || headers.get("access-token").equals(""))
Toast.makeText(context,"Token Null ou Vazio!!",Toast.LENGTH_SHORT).show();
Log.d("SELF Request", "Got " + status + " from server on self request!!!");
switch (status) {
case 200:
Log.d("SELF Request", "Voltou 200!!!");
//info downloaded
accountPresenter.view().setUpdated(true);
onSuccessfulCheck(accountOutput, headers);
......@@ -97,29 +87,24 @@ public class AccountPresenter extends BasePresenter<AccountView> {
accountPresenter.view().enableButtonSync(true);
break;
default:
Log.d("SELF Request", "Voltou " + status + "!!!");
//error!! block edit and wait for user to try synchronization again.
//notify user
Toast.makeText(context,"Ocorreu um problema com o servidor, tente novamente mais tarde.",Toast.LENGTH_SHORT).show();
accountPresenter.view().setUpdated(false);
accountPresenter.view().setProgressBar(false);
accountPresenter.view().enableAllFields(false);
accountPresenter.view().enableButtonEdit(false);
accountPresenter.view().enableButtonSync(true);
accountPresenter.view().setConnectionError(true);
break;
}
}
@Override
public void onFailure(Call<AccountOutput> call, Throwable t) {
Log.d("SELF Request", "Falhou!!!");
//disable edit on UI & notify user & wait for user to try sync again
accountPresenter.view().setUpdated(false);
accountPresenter.view().setProgressBar(false);
accountPresenter.view().enableAllFields(false);
accountPresenter.view().setNoConnection(true);
accountPresenter.view().enableButtonEdit(false);
accountPresenter.view().enableButtonSync(true);
accountPresenter.view().setNoConnection(true);
}
});
}
......@@ -186,6 +171,7 @@ public class AccountPresenter extends BasePresenter<AccountView> {
case 404:
Log.d("Server response", "404 - Falha!");
accountPresenter.view().setProgressBar(false);
accountPresenter.view().setConnectionError(true);
break;
case 422:
Log.d("Server response", "422 - Erro na requisição!");
......@@ -275,7 +261,8 @@ public class AccountPresenter extends BasePresenter<AccountView> {
@Override
public void onFailure(Call<Address> call, Throwable t) {
accountPresenter.view().setProgressBar(false);
accountPresenter.view().setNoConnectionCep(true);
accountPresenter.view().setConnectionCepError(true);
Log.d("Aaaa","aaaaaaaa2222222");
}
});
}
......
......@@ -19,9 +19,11 @@ public interface AccountView {
void showPasswordWarning();
void setNoConnection(boolean enabled);
void setConnectionError(boolean enabled);
void setConnectionCepError(boolean enabled);
void setNoConnectionCep(boolean enabled);
void setNoConnection(boolean enabled);
void setUpdated(boolean updated);
......
......@@ -333,7 +333,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_account_disability"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:checked="true"
android:text="@string/no" />
......@@ -366,9 +366,9 @@
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="7dp"
android:layout_marginStart="7dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/tv_account_disability_what" />
android:layout_toEndOf="@id/tv_account_disability_what" />
</RelativeLayout>
......
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