Commit 606ff045 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Signout working


Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent 8d6593a9
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintValidFragment" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
......@@ -28,12 +35,15 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
private HomePresenter presenter;
private ObscuredSharedPreferences osb;
private MenuBuilder menuBuilder;
private ActionMenuView actionMenuView;
private ImageView drawerHamburger;
private TextView drawerCitizenName, drawerCityName, homeCitizenWelcome;
private String citizenName, citizenCity;
private DialogFragment confirmationDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -54,6 +64,43 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
citizenCity = osb.getString("city.name", null);
actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
menuBuilder.setCallback(new MenuBuilder.Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
return onOptionsItemSelected(item);
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
}
});
// confirmationDialog = new ConfirmationDialog();
confirmationDialog = new DialogFragment() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.signout_confirmation)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
presenter.onSignOutClicked();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// Create the AlertDialog object and return it
return builder.create();
}
};
drawerHamburger = (ImageView) toolbar.findViewById(R.id.img_toolbar_hamburger);
homeCitizenWelcome = (TextView) findViewById(R.id.tv_homeact_welcome);
homeCitizenWelcome.setText(String.format(getString(R.string.welcome), citizenName));
......@@ -108,10 +155,23 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, actionMenuView.getMenu());
getMenuInflater().inflate(R.menu.main_menu, menuBuilder);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logout_actionbtn:
FragmentManager manager = getFragmentManager();
confirmationDialog.show(manager, "Error");
// presenter.onSignOutClicked();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return false;
......
......@@ -20,6 +20,7 @@ public class MainActivity extends AppCompatActivity implements MainView {
}
setContentView(R.layout.activity_main);
onLoaded();
}
@Override
......
package br.ufpr.c3sl.agendador.agendador.models;
import com.google.gson.annotations.SerializedName;
/**
* Created by Bruno Freitas Tissei on 3/2/17.
*/
public class SignOutOutput {
@SerializedName("success")
private boolean mSuccess;
public SignOutOutput(boolean success) {
this.mSuccess = success;
}
}
package br.ufpr.c3sl.agendador.agendador.network;
import android.content.Context;
import br.ufpr.c3sl.agendador.agendador.models.Account;
import br.ufpr.c3sl.agendador.agendador.models.AccountOutput;
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 retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.POST;
/**
......@@ -19,9 +19,12 @@ public interface ApiEndpoints {
@POST("auth/sign_in")
Call<AccountOutput> signIn(@Body Account account);
@POST("validate_cep")
Call<Address> validateCep(@Body CepInput cepInput);
@POST ("auth")
Call<AccountOutput> signUp(@Body User user);
@DELETE ("auth/sign_out")
Call<SignOutOutput> signOut();
@POST("validate_cep")
Call<Address> validateCep(@Body CepInput cepInput);
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ package br.ufpr.c3sl.agendador.agendador.network;
import java.io.IOException;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.MainActivity;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import java.util.HashMap;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.LoginActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import br.ufpr.c3sl.agendador.agendador.views.HomeView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Bruno Freitas Tissei on 2/7/17.
......@@ -10,13 +22,65 @@ import br.ufpr.c3sl.agendador.agendador.views.HomeView;
public class HomePresenter extends BasePresenter<HomeView> {
private Context context;
private HomePresenter homePresenter;
private ObscuredSharedPreferences osb;
public HomePresenter(Context context) {
this.context = context;
this.homePresenter = this;
}
@Override
protected void updateView() {
}
public void onSuccessfulSignOut() {
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", context.MODE_PRIVATE);
osb.edit().clear().apply();
Intent intent = new Intent(context, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public void onSignOutClicked() {
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", context.MODE_PRIVATE);
Map<String, String> header = new HashMap<>();
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", osb.getString("uid", null));
ApiEndpoints service = ApiUtils.request(header);
Call<SignOutOutput> listCall = service.signOut();
// loginPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<SignOutOutput>() {
@Override
public void onResponse(Call<SignOutOutput> call, Response<SignOutOutput> response) {
int status = response.code();
switch (status) {
case 401:
// homePresenter.view().setProgressBar(false);
break;
case 200:
onSuccessfulSignOut();
// homePresenter.view().setProgressBar(false);
break;
default:
break;
}
}
@Override
public void onFailure(Call<SignOutOutput> call, Throwable t) {
// homePresenter.view().setNoConnection(true);
// homePresenter.view().setProgressBar(false);
}
});
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import android.content.Context;
import android.os.AsyncTask;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.util.Log;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.views.MainView;
......@@ -44,6 +45,7 @@ public class MainPresenter extends BasePresenter<MainView>{
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(context,
"Agendador", context.MODE_PRIVATE);
String expiry = osb.getString("expiry", null);
//Log.v("aaaa", osb.getString("access-token", null));
if (expiry == null) {
return -1;
......
......@@ -63,4 +63,7 @@
<string name="schedules_more_information">Para mais informações sobre como usar o Sistema Agendador de Serviços Públicos visite o Manual de Utilização ou a Seção de Perguntar Frequentes.</string>
<string name="signup_errorDialog_title">Erro</string>
<string name="signup_erroDialog_message">CPF já cadastrado</string>
<string name="signout_confirmation">Você tem certeza que deseja sair?</string>
<string name="yes">Sim</string>
<string name="no">Não</string>
</resources>
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