Commit 9017d48b authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#196 Selection of Citizen is done in a different activity

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent d6aefeb9
......@@ -25,6 +25,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.code.gson:gson:2.7'
......
......@@ -23,15 +23,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"></activity>
<activity android:name=".HomeActivity"></activity>
<activity android:name=".CepActivity"></activity>
<activity android:name=".CepNotFoundActivity"></activity>
<activity android:name=".SignupActivity"></activity>
<activity android:name=".AccountActivity"></activity>
<activity android:name=".ForgotPasswordActivity"></activity>
<activity android:name=".TermActivity"></activity>
<activity android:name=".SchedulingActivity"></activity>
<activity android:name=".LoginActivity" />
<activity android:name=".HomeActivity" />
<activity android:name=".CepActivity" />
<activity android:name=".CepNotFoundActivity" />
<activity android:name=".SignupActivity" />
<activity android:name=".AccountActivity" />
<activity android:name=".ForgotPasswordActivity" />
<activity android:name=".TermActivity" />
<activity android:name=".SchedulingActivity" />
<activity android:name=".CitizenActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.CitizensArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.CitizensItemListener;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.CitizensPresenter;
import br.ufpr.c3sl.agendador.agendador.views.CitizenView;
/**
* Created by Lucas B. Cunha on 27/06/17.
*/
public class CitizenActivity extends AppCompatActivity implements CitizenView{
private RecyclerView rv_citizens;
private ProgressBar pb_citizen;
private CitizensPresenter citizensPresenter;
private List<UserOutput> citizens;
private ConnectionFailureDialog dg_connection_failure;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
citizensPresenter = new CitizensPresenter(this);
} else {
citizensPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
}
setContentView(R.layout.activity_citizen);
pb_citizen = (ProgressBar) findViewById(R.id.pb_citizenact);
rv_citizens = (RecyclerView) findViewById(R.id.rv_citizens_citizens);
RecyclerView.LayoutManager layout = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false);
rv_citizens.setLayoutManager(layout);
rv_citizens.setVisibility(View.INVISIBLE);
rv_citizens.addOnItemTouchListener(new CitizensItemListener(getApplicationContext(), rv_citizens,
new CitizensItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
Intent intent = new Intent(CitizenActivity.this, SchedulingActivity.class);
Bundle bundle = getIntent().getBundleExtra(Utils.SECTORS_BUNDLE);
bundle.putParcelable(Utils.CITIZEN, citizens.get(position));
intent.putExtra(Utils.SECTORS_CITIZENS_BUNDLE, bundle);
startActivity(intent);
}
public void onLongClickItem(View v, int position) {
//Log.d("AAAAAAaaaaa", "On long Click Item interface");
//do nothing.
}
}));
citizensPresenter.bindView(this);
citizensPresenter.requestCitizens();
}
@Override
protected void onResume() {
super.onResume();
citizensPresenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
citizensPresenter.unbindView();
}
public void showLayout(boolean enabled) {
rv_citizens.setAdapter(new CitizensArrayAdapter(this, citizens));
rv_citizens.setVisibility(View.VISIBLE);
}
public void successfulCitizens(List<UserOutput> citizens) {
this.citizens = citizens;
}
public void onRequestFailure(){
Bundle bundle = new Bundle();
if(dg_connection_failure == null){
dg_connection_failure = new ConnectionFailureDialog();
}
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE_KEY, getString(R.string.dialog_term_error));
dg_connection_failure.setArguments(bundle);
dg_connection_failure.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
public void setProgressBar(boolean enabled) {
if (enabled) {
pb_citizen.setVisibility(View.VISIBLE);
rv_citizens.setVisibility(View.INVISIBLE);
} else {
pb_citizen.setVisibility(View.INVISIBLE);
}
}
public static class ConnectionFailureDialog extends DialogFragment {
public static final String DIALOG_MESSAGE_KEY = "message";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getArguments().getString(DIALOG_MESSAGE_KEY))
.setTitle(getString(R.string.warningDialog_title))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Activity activity = getActivity();
activity.onBackPressed();
}
});
return builder.create();
}
}
}
......@@ -41,6 +41,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.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
......@@ -65,11 +66,13 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private ProgressBar pb_scheduling;
private Spinner spnr_citizen, spnr_sector, spnr_type, spnr_location;
private Spinner spnr_sector, spnr_type, spnr_location;
//private Spinner spnr_citizen;
private LinearLayout ll_fields;
private TextView tv_year, tv_day_month;
private TextView tv_year, tv_day_month, tv_citizen;
private MaterialCalendarView mcv;
......@@ -83,7 +86,9 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private SchedulingPresenter schedulingPresenter;
private List<UserOutput> dependents;
//private List<UserOutput> dependents;
private UserOutput citizen;
private List<SectorInput> sectors;
......@@ -97,9 +102,9 @@ 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);
Bundle bundle = getIntent().getBundleExtra(Utils.SECTORS_CITIZENS_BUNDLE);
sectors = bundle.getParcelableArrayList(Utils.SECTORS_LIST);
citizen = bundle.getParcelable(Utils.CITIZEN);
setContentView(R.layout.activity_scheduling);
......@@ -127,7 +132,11 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
ll_fields = (LinearLayout) findViewById(R.id.ll_scheduling_fields);
spnr_citizen = (Spinner) findViewById(R.id.spnr_scheduling_citizen);
//spnr_citizen = (Spinner) findViewById(R.id.spnr_scheduling_citizen);
tv_citizen = (TextView) findViewById(R.id.tv_scheduling_citizen);
tv_citizen.setText(getResources().getString(R.string.scheduling_citizen) + " " + citizen.getName());
spnr_sector = (Spinner) findViewById(R.id.spnr_scheduling_sector);
......@@ -174,9 +183,6 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
navigationView.setNavigationItemSelectedListener(this);
String[] sector = new String[sectors.size() + 1];
int i = 0;
for (; i < sectors.size(); i++)
......@@ -235,10 +241,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
ll_fields.setVisibility(View.INVISIBLE);
schedulingPresenter.bindView(this);
schedulingPresenter.getDependents();
spnr_location.setEnabled(false);
spnr_type.setEnabled(false);
}
@Override
......@@ -257,6 +261,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
@Override
protected void onStart(){
super.onStart();
/*
spnr_citizen.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
......@@ -268,11 +273,12 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// do nothing?
// do nothing
}
});
*/
}
@Override
......@@ -308,14 +314,14 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
public void setProgressBar(boolean enabled) {
if (enabled) {
pb_scheduling.setVisibility(View.VISIBLE);
spnr_citizen.setEnabled(false);
//spnr_citizen.setEnabled(false);
spnr_location.setEnabled(false);
spnr_sector.setEnabled(false);
spnr_type.setEnabled(false);
mcv.setEnabled(false);
} else {
pb_scheduling.setVisibility(View.INVISIBLE);
spnr_citizen.setEnabled(true);
//spnr_citizen.setEnabled(true);
spnr_location.setEnabled(true);
spnr_sector.setEnabled(true);
spnr_type.setEnabled(true);
......@@ -344,6 +350,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
}
}
/*
public void successfulDependents(List<UserOutput> dependents){
this.dependents = dependents;
String[] dependents_name = new String[dependents.size() + 1];
......@@ -358,6 +365,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
// show hint
spnr_citizen.setSelection(hintAdapterCitizen.getCount());
}
*/
/**
* Called when a user clicks on a day.
......
......@@ -21,6 +21,7 @@ import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.SectorArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.presenters.TermPresenter;
import br.ufpr.c3sl.agendador.agendador.views.TermView;
......@@ -39,9 +40,6 @@ 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
......@@ -70,10 +68,10 @@ public class TermActivity extends AppCompatActivity implements TermView {
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(TermActivity.this, SchedulingActivity.class);
Intent intent = new Intent(TermActivity.this, CitizenActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(SECTORS_LIST, (ArrayList<? extends Parcelable>) sectors);
intent.putExtra(SECTORS_BUNDLE, bundle);
bundle.putParcelableArrayList(Utils.SECTORS_LIST, (ArrayList<? extends Parcelable>) sectors);
intent.putExtra(Utils.SECTORS_BUNDLE, bundle);
startActivity(intent);
finish();
}
......
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.R;
/**
* Created by Lucas B. Cunha on 27/06/17.
*/
public class CitizenHolder extends RecyclerView.ViewHolder{
final TextView name;
CitizenHolder(View view) {
super(view);
name = (TextView) view.findViewById(R.id.list_citizen_name);
}
}
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
/**
* Created by Lucas B. Cunha on 27/06/17.
*/
public class CitizensArrayAdapter extends RecyclerView.Adapter {
private List<UserOutput> citizens;
private Context context;
public CitizensArrayAdapter(Context context, List<UserOutput> citizens){
super();
this.citizens = citizens;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context)
.inflate(R.layout.item_citizen_list, parent, false);
return new CitizenHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
CitizenHolder citizenHolder = (CitizenHolder) holder;
UserOutput citizen = citizens.get(position);
citizenHolder.name.setText(citizen.getName());
String s = citizen.getName() + "";
citizenHolder.name.setText(s);
}
/**
* Returns the total number of items in the data set held by the adapter.
*
* @return The total number of items in this adapter.
*/
@Override
public int getItemCount() {
return citizens.size();
}
}
......@@ -28,27 +28,6 @@ public class SectorArrayAdapter extends RecyclerView.Adapter{
this.context = context;
}
/**
* Called when RecyclerView needs a new {@link ViewHolder} of the given type to represent
* an item.
* <p>
* This new ViewHolder should be constructed with a new View that can represent the items
* of the given type. You can either create a new View manually or inflate it from an XML
* layout file.
* <p>
* The new ViewHolder will be used to display items of the adapter using
* {@link #onBindViewHolder(ViewHolder, int, List)}. Since it will be re-used to display
* different items in the data set, it is a good idea to cache references to sub views of
* the View to avoid unnecessary {@link View#findViewById(int)} calls.
*
* @param parent The ViewGroup into which the new View will be added after it is bound to
* an adapter position.
* @param viewType The view type of the new View.
* @return A new ViewHolder that holds a View of the given view type.
* @see #getItemViewType(int)
* @see #onBindViewHolder(ViewHolder, int)
*/
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context)
......@@ -57,26 +36,7 @@ public class SectorArrayAdapter extends RecyclerView.Adapter{
return new SectorHolder(view);
}
/**
* Called by RecyclerView to display the data at the specified position. This method should
* update the contents of the {@link ViewHolder#itemView} to reflect the item at the given
* position.
* <p>
* Note that unlike {@link ListView}, RecyclerView will not call this method
* again if the position of the item changes in the data set unless the item itself is
* invalidated or the new position cannot be determined. For this reason, you should only
* use the <code>position</code> parameter while acquiring the related data item inside
* this method and should not keep a copy of it. If you need the position of an item later
* on (e.g. in a click listener), use {@link ViewHolder#getAdapterPosition()} which will
* have the updated adapter position.
* <p>
* Override {@link #onBindViewHolder(ViewHolder, int, List)} instead if Adapter can
* handle efficient partial bind.
*
* @param holder The ViewHolder which should be updated to represent the contents of the
* item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
SectorHolder sectorHolder = (SectorHolder) holder;
......
......@@ -21,9 +21,18 @@ import java.io.InputStream;
public class Utils {
public static final String SECTORS_LIST = "sectors_list";
public static final String SECTORS_BUNDLE = "br.ufpr.c3sl.agendador.agendador.sectors_bundle";
public static final String SECTORS_CITIZENS_BUNDLE = "br.ufpr.c3sl.agendador.agendador.sectors_citizens_bundle";
public final static String DIR_PICTRS = "pictures";
public final static String USR_PICT_FILE_NAME = "usr_prof_pic";
public final static String CITIZEN = "citizen_object";
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
......
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by Lucas B. Cunha on 28/06/17.
*
* Based on: https://www.survivingwithandroid.com/2016/09/android-recyclerview-tutorial.html
*/
public class CitizensItemListener implements RecyclerView.OnItemTouchListener{
private RecyclerTouchListener listener;
private GestureDetector gd;
public interface RecyclerTouchListener {
void onClickItem(View v, int position) ;
void onLongClickItem(View v, int position);
}
public CitizensItemListener(Context ctx, final RecyclerView rv,
final RecyclerTouchListener listener) {
this.listener = listener;
gd = new GestureDetector(ctx,
new GestureDetector.SimpleOnGestureListener() {
@Override
public void onLongPress(MotionEvent e) {
// We find the view
View v = rv.findChildViewUnder(e.getX(), e.getY());
// Notify the even
listener.onLongClickItem(v, rv.getChildAdapterPosition(v));
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
View v = rv.findChildViewUnder(e.getX(), e.getY());
// Notify the even
listener.onClickItem(v, rv.getChildAdapterPosition(v));
return true;
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
return ( child != null && gd.onTouchEvent(e));
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import android.util.Log;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
......@@ -8,7 +9,7 @@ import com.google.gson.annotations.SerializedName;
* Created by Bruno Freitas Tissei on 2/10/17.
*/
public class Address {
public class Address implements Parcelable{
@SerializedName("id")
private int mId;
......@@ -46,6 +47,30 @@ public class Address {
this.mState_name = state_name;
}
/**reads back fields IN THE ORDER they were written */
public Address(Parcel pc){
mId = pc.readInt();
mZipcode = pc.readString();
mAddress = pc.readString();
mNeighborhood = pc.readString();
mComplement = pc.readString();
mComplement2 = pc.readString();
mCity_name = pc.readString();
mState_name = pc.readString();
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<Address> CREATOR = new Parcelable.Creator<Address>() {
public Address createFromParcel(Parcel pc) {
return new Address(pc);
}
public Address[] newArray(int size) {
return new Address[size];
}
};
public String getZipcode() {
return mZipcode;
}
......@@ -77,4 +102,24 @@ public class Address {
public String getState_name() {
return mState_name;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mId);
dest.writeString(mZipcode);
dest.writeString(mAddress);
dest.writeString(mNeighborhood);
dest.writeString(mComplement);
dest.writeString(mComplement2);
dest.writeString(mCity_name);
dest.writeString(mState_name);
}
@Override
public int describeContents() {
return 0;
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by Bruno Freitas Tissei on 2/10/17.
*/
public class City {
public class City implements Parcelable{
//package private because they're used on UserOutput.
@SerializedName("id")
int mId;
......@@ -22,4 +26,36 @@ public class City {
this.mIbge_code = ibge_code;
this.mName = name;
}
/**reads back fields IN THE ORDER they were written */
public City(Parcel pc){
mId = pc.readInt();