Commit 64ba9bd1 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#151: Done - transfer sectors between activities & signout on scheduling activity

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 6fd86c77
......@@ -15,7 +15,6 @@ 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;
......@@ -41,6 +40,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.EventDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.HintAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
......@@ -80,10 +80,9 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private SchedulingPresenter schedulingPresenter;
private List dependents;
private String[] dependents_name;
private List<UserOutput> dependents;
private List<SectorInput> sectors;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -95,16 +94,18 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
schedulingPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}
Bundle bundle = getIntent().getBundleExtra(TermActivity.SECTORS_BUNDLE);
sectors = bundle.getParcelableArrayList(TermActivity.SECTORS_LIST);
setContentView(R.layout.activity_scheduling);
Toolbar toolbar = (Toolbar) findViewById(R.id.agendador_toolbar);
toolbar.setTitle(null);
setSupportActionBar(toolbar);
//getSupportActionBar().setTitle(null);
pb_scheduling = (ProgressBar) findViewById(R.id.pb_scheduling);
Log.d("Aaaaaaa", pb_scheduling == null ? "Progress bar Vazio" : "Progress bar Não vazio");
actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
......@@ -123,10 +124,6 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
ll_fields = (LinearLayout) findViewById(R.id.ll_scheduling_fields);
//pb_scheduling.setVisibility(View.VISIBLE);
//ll_fields.setVisibility(View.INVISIBLE);
spnr_citizen = (Spinner) findViewById(R.id.spnr_scheduling_citizen);
spnr_sector = (Spinner) findViewById(R.id.spnr_scheduling_sector);
......@@ -175,14 +172,20 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
navigationView.setNavigationItemSelectedListener(this);
// TODO: 17/04/17 example on how to set hint to spinner
String[] sector = {"Saúde", "Selecione um setor"};
String[] sector = new String[sectors.size() + 1];
int i = 0;
for (; i < sectors.size(); i++)
sector[i] = sectors.get(i).getName();
sector[i] = getResources().getString(R.string.scheduling_sector_hint);
HintAdapter hintAdapterSector = new HintAdapter(this, android.R.layout.simple_list_item_1, sector);
spnr_sector.setAdapter(hintAdapterSector);
spnr_sector.setSelection(hintAdapterSector.getCount());
// TODO: 17/04/17 example on how to set hint to spinner
String[] types = {"Texto1", "Selecione o tipo"};
HintAdapter hintAdapterType = new HintAdapter(this, android.R.layout.simple_list_item_1, types);
spnr_type.setAdapter(hintAdapterType);
......@@ -340,7 +343,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
public void successfulDependents(List<UserOutput> dependents){
this.dependents = dependents;
dependents_name = new String[dependents.size()+1];
String[] dependents_name = new String[dependents.size() + 1];
int i = 0;
for (; i < dependents.size(); i++)
dependents_name[i] = dependents.get(i).getName();
......@@ -387,8 +390,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
builder.setMessage(R.string.signout_confirmation)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//SchedulingActivity activity = (SchedulingActivity) getActivity();
//activity.schedulingPresenter.onSignOutClicked();
SchedulingActivity activity = (SchedulingActivity) getActivity();
activity.schedulingPresenter.onSignOutClicked();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
......
......@@ -7,6 +7,7 @@ import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -15,6 +16,7 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import java.util.ArrayList;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
......@@ -37,6 +39,11 @@ public class TermActivity extends AppCompatActivity implements TermView {
private ConnectionFailureDialog dg_connection_failure;
public static final String SECTORS_LIST = "sectors";
public static final String SECTORS_BUNDLE = "br.ufpr.c3sl.agendador.agendador.sectors_bundle";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -64,6 +71,9 @@ public class TermActivity extends AppCompatActivity implements TermView {
@Override
public void onClick(View v) {
Intent intent = new Intent(TermActivity.this, SchedulingActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(SECTORS_LIST, (ArrayList<? extends Parcelable>) sectors);
intent.putExtra(SECTORS_BUNDLE, bundle);
startActivity(intent);
finish();
}
......@@ -101,19 +111,14 @@ public class TermActivity extends AppCompatActivity implements TermView {
}
// TODO: 02/06/17
//after sectors request, dependents request receives 401 - Não está acontecendo(?) Checar novamente
// TODO: 06/06/17 tratar casoss em que a requisição falhe!
@Override
@Override
public void showLayout(boolean enabled) {
rv_sectors.setAdapter(new SectorArrayAdapter(this, sectors));
sv_term.setVisibility(View.VISIBLE);
}
// TODO: 06/06/17 usar o set progressBar para deixar o layout escondido ou mudar?
@Override
public void setProgressBar(boolean enabled) {
if (enabled) {
......
......@@ -81,8 +81,8 @@ public class SectorArrayAdapter extends RecyclerView.Adapter{
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
SectorHolder sectorHolder = (SectorHolder) holder;
SectorInput sector = sectors.get(position);
sectorHolder.name.setText(sector.getmName());
String s = sector.getmAbsenceMax() + "";
sectorHolder.name.setText(sector.getName());
String s = sector.getAbsenceMax() + "";
sectorHolder.absences.setText(s);
}
......
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by Lucas B. Cunha on 02/06/17.
*/
public class SectorInput {
public class SectorInput implements Parcelable {
@SerializedName("id")
private int mId;
......@@ -46,12 +49,51 @@ public class SectorInput {
}
public String getmName(){
protected SectorInput(Parcel in) {
mId = in.readInt();
mName = in.readString();
mAbsenceMax = in.readInt();
isActive = in.readByte() != 0;
mBlockingDays = in.readInt();
mCancelLimit = in.readInt();
description = in.readString();
mSchedules = in.readInt();
}
public static final Creator<SectorInput> CREATOR = new Creator<SectorInput>() {
@Override
public SectorInput createFromParcel(Parcel in) {
return new SectorInput(in);
}
@Override
public SectorInput[] newArray(int size) {
return new SectorInput[size];
}
};
public String getName(){
return this.mName;
}
public int getmAbsenceMax(){return this.mAbsenceMax;}
public int getAbsenceMax(){return this.mAbsenceMax;}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mId);
dest.writeString(mName);
dest.writeInt(mAbsenceMax);
dest.writeByte((byte) (isActive ? 1 : 0));
dest.writeInt(mBlockingDays);
dest.writeInt(mCancelLimit);
dest.writeString(description);
dest.writeInt(mSchedules);
}
}
......@@ -24,6 +24,7 @@ import retrofit2.http.PUT;
*/
public interface ApiEndpoints {
@POST("auth/sign_in")
Call<AccountOutput> signIn(@Body Account account);
......
......@@ -48,16 +48,18 @@ public class AccountPresenter extends BasePresenter<AccountView> {
}
private void updateToken(Headers headers) {
osb.edit().putString("access-token", headers.get("access-token")).apply();
osb.edit().putString("client", headers.get("client")).apply();
if(headers.get("access-token") != null)
osb.edit().putString("access-token", headers.get("access-token")).apply();
if(headers.get("client") != null)
osb.edit().putString("client", headers.get("client")).apply();
}
@Override
protected void updateView() {
}
// TODO: 01/06/17 Review: Check if the token update is done correctly
public void onUpdateClicked(){
Map<String, String> header = new HashMap<>();
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -41,9 +42,22 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
}
public void onSignOutClicked(){
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);
schedulingPresenter.view().finish();
}
private void updateToken(Headers headers) {
osb.edit().putString("access-token", headers.get("access-token")).apply();
osb.edit().putString("client", headers.get("client")).apply();
if(headers.get("access-token") != null)
osb.edit().putString("access-token", headers.get("access-token")).apply();
if(headers.get("client") != null)
osb.edit().putString("client", headers.get("client")).apply();
}
......
......@@ -38,8 +38,12 @@ public class TermPresenter extends BasePresenter<TermActivity>{
private void updateToken(Headers headers) {
osb.edit().putString("access-token", headers.get("access-token")).apply();
osb.edit().putString("client", headers.get("client")).apply();
if(headers.get("access-token") != null)
osb.edit().putString("access-token", headers.get("access-token")).apply();
if(headers.get("client") != null)
osb.edit().putString("client", headers.get("client")).apply();
}
@Override
......
......@@ -16,4 +16,7 @@ public interface SchedulingView {
void successfulDependents(List<UserOutput> dependents);
void finish();
}
......@@ -80,11 +80,12 @@
android:typeface="normal"/>
<Spinner
android:id="@+id/spnr_scheduling_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="35dp"
android:layout_marginStart="14dp"
android:layout_marginBottom="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
/>
<TextView
android:layout_width="match_parent"
......
......@@ -147,6 +147,7 @@
<string name="scheduling_date">Datas disponíveis</string>
<string name="highlight_date_accessibility">Círculo ao redor de uma data demonstra que ela está disponível para agendamento</string>
<string name="scheduling_dependent_hint">Selecione um cidadão</string>
<string name="scheduling_sector_hint">Selecione um setor</string>
<string name="list_item_absences">Limite de faltas: </string>
<string name="dialog_term_error">Ocorreu um erro ao carregar, por favor:
* Verifique sua conexão com a internet;
......
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