Commit 3b03eaec authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#198 [WIP] Layout and simple behavior completed

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent d9ffa6a6
......@@ -394,9 +394,10 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
else
imv_profile.setImageBitmap(null);
} else {
Intent intent = new Intent(AccountActivity.this, HomeActivity.class);
/*Intent intent = new Intent(AccountActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
startActivity(intent);*/
super.onBackPressed();
finish();
}
}
......
......@@ -37,6 +37,7 @@ 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.presenters.HomePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.ScheduleConfirmationPresenter;
import br.ufpr.c3sl.agendador.agendador.services.ImageUpdateService;
import br.ufpr.c3sl.agendador.agendador.views.HomeView;
......@@ -52,21 +53,13 @@ import br.ufpr.c3sl.agendador.agendador.views.HomeView;
public class HomeActivity extends AppCompatActivity implements HomeView,
NavigationView.OnNavigationItemSelectedListener {
private HomePresenter presenter;
private ObscuredSharedPreferences osb;
private MenuBuilder menuBuilder;
private ActionMenuView actionMenuView;
private ImageView drawerHamburger, drawerProfilePicture;
private DrawerLayout drawer;
private NavigationView navigationView;
private TextView drawerCitizenName, drawerCityName, homeCitizenWelcome, tv_presentation;
private UserPhotoHelper userPhotoHelper;
private TextView tv_presentation;
private ConfirmationDialog confirmationDialog;
private Button btn_schedule;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -82,11 +75,11 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
toolbar.setTitle(null);
setSupportActionBar(toolbar);
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
String citizenCity = osb.getString("city.name", null);
actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
ActionMenuView actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
//noinspection RestrictedApi
menuBuilder.setCallback(new Callback() {
......@@ -103,8 +96,8 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
confirmationDialog = new ConfirmationDialog();
drawerHamburger = (ImageView) toolbar.findViewById(R.id.img_toolbar_hamburger);
homeCitizenWelcome = (TextView) findViewById(R.id.tv_homeact_welcome);
ImageView drawerHamburger = (ImageView) toolbar.findViewById(R.id.img_toolbar_hamburger);
TextView homeCitizenWelcome = (TextView) findViewById(R.id.tv_homeact_welcome);
homeCitizenWelcome.setText(String.format(getString(R.string.welcome), citizenName));
tv_presentation = (TextView) findViewById(R.id.tv_homeact_moreinfo);
......@@ -114,13 +107,13 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
View headerView = navigationView.getHeaderView(0);
drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
ImageView drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
userPhotoHelper = new UserPhotoHelper(getBaseContext());
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext());
drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
TextView drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
drawerCityName = (TextView) headerView.findViewById(R.id.tv_drawerheader_city_name);
TextView drawerCityName = (TextView) headerView.findViewById(R.id.tv_drawerheader_city_name);
drawerCitizenName.setText(citizenName);
drawerCityName.setText(citizenCity);
......@@ -133,14 +126,14 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
drawerHamburger.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer(Gravity.LEFT);
drawer.openDrawer(Gravity.START);
}
});
navigationView.setNavigationItemSelectedListener(this);
btn_schedule = (Button) findViewById(R.id.btn_homeact_schedule);
Button btn_schedule = (Button) findViewById(R.id.btn_homeact_schedule);
btn_schedule.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -35,12 +35,22 @@ public class Utils {
public static final String SECTORS_CITIZENS_BUNDLE = "br.ufpr.c3sl.agendador.agendador.sectors_citizens_bundle";
public static final String SCHEDULE_BUNDLE = "br.ufpr.c3sl.agendador.agendador.schedule_confirmation";
public static final String DIR_PICTRS = "pictures";
public static final String USR_PICT_FILE_NAME = "usr_prof_pic";
public static final String CITIZEN = "citizen_object";
public static final String SECTOR = "selected_sector";
public static final String LOCATION = "selected_location";
public static final String TYPE = "selected_type";
public static final String SCHEDULE = "selected_schedule";
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
......
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Lucas B. Cunha on 05/07/17.
*/
public class ServiceLocation {
public class ServiceLocation implements Parcelable{
@SerializedName("id")
private long mId;
......@@ -22,6 +27,42 @@ public class ServiceLocation {
@SerializedName("schedules")
private List<ServiceSchedule> schedules;
/**reads back fields IN THE ORDER they were written */
private ServiceLocation(Parcel pc){
mId = pc.readLong();
mName = pc.readString();
mPeriod = pc.readInt();
schedules = new ArrayList<>();
pc.readList(schedules, ServiceLocation.class.getClassLoader());
Log.d("TAMANHO DA LISTA", "tamanho:" + getSchedules().size());
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<ServiceLocation> CREATOR = new Parcelable.Creator<ServiceLocation>() {
public ServiceLocation createFromParcel(Parcel pc) {
return new ServiceLocation(pc);
}
public ServiceLocation[] newArray(int size) {
return new ServiceLocation[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeString(mName);
dest.writeInt(mPeriod);
dest.writeList(schedules);
}
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
......
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
......@@ -8,7 +11,7 @@ import java.util.Date;
* Created by Lucas B. Cunha on 05/07/17.
*/
public class ServiceSchedule{
public class ServiceSchedule implements Parcelable{
@SerializedName("id")
private long mId;
......@@ -20,6 +23,38 @@ public class ServiceSchedule{
private Date end;
/**reads back fields IN THE ORDER they were written */
private ServiceSchedule(Parcel pc){
mId = pc.readLong();
start = new Date(pc.readLong());
end = new Date(pc.readLong());
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<ServiceSchedule> CREATOR = new Parcelable.Creator<ServiceSchedule>() {
public ServiceSchedule createFromParcel(Parcel pc) {
return new ServiceSchedule(pc);
}
public ServiceSchedule[] newArray(int size) {
return new ServiceSchedule[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeLong(start.getTime());
dest.writeLong(end.getTime());
}
@Override
public int describeContents() {
return 0;
}
public long getmId() {
return mId;
......
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 30/06/17.
*/
public class ServiceType {
public class ServiceType implements Parcelable{
@SerializedName("id")
private long mId;
......@@ -28,8 +31,39 @@ public class ServiceType {
this.schedules = schedules;
}
public boolean isActive() {
return isActive;
/**reads back fields IN THE ORDER they were written */
ServiceType(Parcel pc){
mId = pc.readLong();
mDescription = pc.readString();
isActive = pc.readByte()!= 0;
schedules = pc.readInt();
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<ServiceType> CREATOR = new Parcelable.Creator<ServiceType>() {
public ServiceType createFromParcel(Parcel pc) {
return new ServiceType(pc);
}
public ServiceType[] newArray(int size) {
return new ServiceType[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeString(mDescription);
dest.writeByte((byte) (isActive ? 1 : 0));
dest.writeInt(schedules);
}
@Override
public int describeContents() {
return 0;
}
public String getmDescription() {
......
......@@ -16,7 +16,6 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
public class UserOutput implements Parcelable {
@SerializedName("id")
private long mId;
......@@ -27,7 +26,7 @@ public class UserOutput implements Parcelable {
private String mUpdated_At;
@SerializedName("avatar_updated_at")
String mPhoto_Update_At;
private String mPhoto_Update_At;
@SerializedName("photo_content_type")
private String mPhoto_Content_Type;
......@@ -150,7 +149,7 @@ public class UserOutput implements Parcelable {
};
/**reads back fields IN THE ORDER they were written */
public UserOutput(Parcel pc){
UserOutput(Parcel pc){
mId = pc.readLong();
mAddress_Number = pc.readString();
mUpdated_At = pc.readString();
......@@ -258,6 +257,9 @@ public class UserOutput implements Parcelable {
return 0;
}
public long getmId() {
return mId;
}
}
......@@ -9,6 +9,7 @@ import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput;
import br.ufpr.c3sl.agendador.agendador.models.User;
......@@ -38,8 +39,8 @@ public interface ApiEndpoints {
@PUT("auth")
Call<AccountOutput> update(@Body AccountUpdate accountUpdate);
@DELETE ("auth/sign_out")
Call<SignOutOutput> signOut();
//@DELETE ("auth/sign_out")
//Call<SignOutOutput> signOut();
@POST("validate_cep")
Call<Address> validateCep(@Body CepInput cepInput);
......@@ -62,4 +63,6 @@ public interface ApiEndpoints {
@GET("service_places")
Call<List<ServiceLocation>> requestServicePlaces(@Query("service_type_id") long typeId, @Query("schedule") boolean needSchedule);
@PUT("schedules/{id_schedule}/confirm?permission=citizen")
Call<ServiceSchedule> requestConfirmSchedule(@Path("id_schedule") long scheduleId, @Query("citizen_id") long citizenId);
}
\ No newline at end of file
......@@ -51,5 +51,6 @@ public class HomePresenter extends BasePresenter<HomeView> {
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);
}
}
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
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.ScheduleConfirmationActivity;
import br.ufpr.c3sl.agendador.agendador.SchedulingActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import okhttp3.Headers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Lucas B. Cunha on 25/07/17.
......@@ -8,6 +32,80 @@ import br.ufpr.c3sl.agendador.agendador.ScheduleConfirmationActivity;
public class ScheduleConfirmationPresenter extends BasePresenter<ScheduleConfirmationActivity> {
private ObscuredSharedPreferences osb;
private Context context;
private ScheduleConfirmationPresenter scheduleConfirmationPresenter;
public ScheduleConfirmationPresenter(Context context){
this.context = context;
this.scheduleConfirmationPresenter = this;
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
}
private void updateToken(Headers headers) {
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();
}
public void onSignOutClicked() {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
dispatcher.cancel(Utils.SERVICE_UPDATE_IMAGE);
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 onScheduleClicked(final ServiceSchedule schedule, UserOutput citizen){
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));
final ApiEndpoints service = ApiUtils.request(header);
Call<ServiceSchedule> listCall = service.requestConfirmSchedule(schedule.getmId(), citizen.getmId());
scheduleConfirmationPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ServiceSchedule>() {
@Override
public void onResponse(Call<ServiceSchedule> call, Response<ServiceSchedule> response) {
Headers headers = response.headers();
int status = response.code();
ServiceSchedule confirmation = response.body();
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
updateToken(headers);
scheduleConfirmationPresenter.view().setProgressBar(false);
break;
default:
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
break;
}
}
@Override
public void onFailure(Call<ServiceSchedule> call, Throwable t) {
Log.e("Server response", "REQUEST FAIL");
scheduleConfirmationPresenter.view().setNoConnection(true);
scheduleConfirmationPresenter.view().setProgressBar(false);
}
});
}
@Override
protected void updateView() {
......
......@@ -4,6 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
import com.firebase.jobdispatcher.GooglePlayDriver;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -11,6 +14,7 @@ import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.LoginActivity;
import br.ufpr.c3sl.agendador.agendador.SchedulingActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -43,13 +47,19 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
}
public void onSignOutClicked(){
public void onSignOutClicked() {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
dispatcher.cancel(Utils.SERVICE_UPDATE_IMAGE);
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) {
......@@ -60,6 +70,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
osb.edit().putString("client", headers.get("client")).apply();
}
public void requestServiceTypes(long sectorId){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
......
......@@ -5,4 +5,9 @@ package br.ufpr.c3sl.agendador.agendador.views;
*/
public interface ScheduleConfirmationView {
void setNoConnection(boolean enabled);
void setProgressBar(boolean enabled);
}
......@@ -15,8 +15,6 @@ public interface SchedulingView {
void setNoConnection(boolean enabled);
void finish();
void setServiceTypesList(List<ServiceType> serviceTypes);
void setServiceLocationList(List<ServiceLocation> serviceLocations);
......
......@@ -21,6 +21,6 @@
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_drawer_header"
app:menu="@menu/activity_home_drawer" />
app:menu="@menu/activitys_menu_drawer" />
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="br.ufpr.c3sl.agendador.agendador.ScheduleConfirmationActivity"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
android:fitsSystemWindows="true"
tools:openDrawer="start">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Olá"
tools:layout_editor_absoluteX="151dp"
tools:layout_editor_absoluteY="227dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<include
layout="@layout/appbar_schedule_confirmation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/schedule_confirmation_navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_drawer_header"
app:menu="@menu/activitys_menu_drawer" />
</android.support.v4.widget.DrawerLayout>
......@@ -15,13 +15,13 @@
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/home_navigation_view"
android:id="@+id/scheduling_navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_drawer_header"
app:menu="@menu/activity_home_drawer" />
app:menu="@menu/activitys_menu_drawer" />
......
......@@ -31,7 +31,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:text="@string/terms_title"
android:text="@string/terms_description"
android:textSize="18sp"
android:textColor="@color/colorBlack"
android:textStyle="bold" />
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/toolbar"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_schedule_confirmation" />
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="59dp"
android:background="@color/colorGray"
android:orientation="vertical">
<TextView
android:id="@+id/tv_scheduling_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:text="@string/schedule"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="14sp"
android:textStyle="normal|bold"
android:typeface="normal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tv_scheduling_welcome"
android:orientation="vertical"