Add primitive modal about user

This commit is contained in:
Mieszko Wrzeszczyński 2018-10-27 23:58:51 +02:00
parent edd5fb76a3
commit 299e25d0f9
6 changed files with 475 additions and 56 deletions

View File

@ -1,6 +1,5 @@
package com.uam.wmi.findmytutor.activity;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
@ -8,25 +7,25 @@ import android.support.annotation.RequiresApi;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.annimon.stream.Stream;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.ReturnedTutors;
import com.uam.wmi.findmytutor.model.DutyHour;
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.TutorTabApi;
import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
@ -35,34 +34,29 @@ import com.uam.wmi.findmytutor.view.TutorsAdapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
public class UsersListActivity extends BaseActivity {
public class UsersListActivity extends BaseActivity {
private static final String TAG = UsersListActivity.class.getSimpleName();
private UserService apiService;
@BindView(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.txt_empty_notes_view)
TextView noNotesView;
private UserService userService;
private TutorTabApi tutorTabService;
private CompositeDisposable disposable = new CompositeDisposable();
private TutorsAdapter mAdapter;
private List<User> tutorsList = new ArrayList<>();
@BindView(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.recycler_view)
RecyclerView recyclerView;
@BindView(R.id.txt_empty_notes_view)
TextView noNotesView;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
@ -72,9 +66,12 @@ public class UsersListActivity extends BaseActivity {
setContentView(R.layout.users_list);
ButterKnife.bind(this);
apiService = ApiClient.getClient(getApplicationContext())
userService = ApiClient.getClient(getApplicationContext())
.create(UserService.class);
tutorTabService = ApiClient.getClient(getApplicationContext())
.create(TutorTabApi.class);
mAdapter = new TutorsAdapter(this, tutorsList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
@ -94,7 +91,8 @@ public class UsersListActivity extends BaseActivity {
@Override
public void onLongClick(View view, int position) {
//showActionsDialog(position);
showNoteDialog(true, tutorsList.get(position), position);
//showNoteDialog(true, tutorsList.get(position), position);
}
}));
}
@ -115,43 +113,70 @@ public class UsersListActivity extends BaseActivity {
builder.show();
}
private void showNoteDialog(final boolean shouldUpdate, final User note, final int position) {
private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this);
alertDialogBuilderUserInput.setView(view);
final TextView inputNote = view.findViewById(R.id.note);
TextView dialogTitle = view.findViewById(R.id.dialog_title);
dialogTitle.setText(note.getNormalizedUserName());
TextView userName = view.findViewById(R.id.userName);
TextView userDutyHours = view.findViewById(R.id.userDutyHours);
TextView userNote = view.findViewById(R.id.userNote);
TextView userRoom = view.findViewById(R.id.userRoom);
TextView userEmail = view.findViewById(R.id.userEmail);
userName.setText(user.getFirstName() + " " + user.getLastName());
disposable.add(
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
@Override
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
Log.e("TUTOR_TAB",tutorTabViewModel.toString());
List<String> dutyHourslist = Stream.of(tutorTabViewModel.getDutyHours())
.map(DutyHourViewModel::toString).toList();
userRoom.setText(tutorTabViewModel.getRoom());
userEmail.setText(tutorTabViewModel.getEmailTutorTab());
userNote.setText(tutorTabViewModel.getNote());
if(dutyHourslist.size() > 0)
userDutyHours.setText(dutyHourslist.get(0));
inputNote.setText(note.getNormalizedUserName() + note.getTitle() + note.getDepartment());
}
@Override
public void onError(Throwable e) {
showError(e);
}
}));
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.show();
}
private void fetchAllTutors() {
disposable.add(
apiService.apiUsersGet()
userService.apiUsersGet()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(tutors -> {
List<User> tutorsList = new ArrayList<>(tutors.getTutors());
List<User> onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList();
List<User> activeNotOnlineTutors = Stream.of(tutorsList)
.filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();;
List<User> notActiveTutors = Stream.of(tutorsList)
.filterNot(User::isIsActive).toList();;
List<User> activeNotOnlineTutors = Stream.of(tutorsList)
.filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();
List<User> notActiveTutors = Stream.of(tutorsList)
.filterNot(User::isIsActive).toList();
Collections.sort(onlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
Collections.sort(activeNotOnlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
@ -163,7 +188,7 @@ public class UsersListActivity extends BaseActivity {
return sortedUserList;
})
.subscribeWith(new DisposableSingleObserver <List<User>>() {
.subscribeWith(new DisposableSingleObserver<List<User>>() {
@Override
public void onSuccess(List<User> users) {
tutorsList.clear();

View File

@ -0,0 +1,122 @@
package com.uam.wmi.findmytutor.model;
import java.util.Objects;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
/**
* DutyHourViewModel
*/
public class DutyHourViewModel {
@SerializedName("day")
private String day = null;
@SerializedName("start")
private String start = null;
@SerializedName("end")
private String end = null;
public DutyHourViewModel day(String day) {
this.day = day;
return this;
}
/**
* Get day
* @return day
**/
@ApiModelProperty(value = "")
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
public DutyHourViewModel start(String start) {
this.start = start;
return this;
}
/**
* Get start
* @return start
**/
@ApiModelProperty(value = "")
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public DutyHourViewModel end(String end) {
this.end = end;
return this;
}
/**
* Get end
* @return end
**/
@ApiModelProperty(value = "")
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DutyHourViewModel dutyHourViewModel = (DutyHourViewModel) o;
return Objects.equals(this.day, dutyHourViewModel.day) &&
Objects.equals(this.start, dutyHourViewModel.start) &&
Objects.equals(this.end, dutyHourViewModel.end);
}
@Override
public int hashCode() {
return Objects.hash(day, start, end);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class DutyHourViewModel {\n");
sb.append(" day: ").append(toIndentedString(day)).append("\n");
sb.append(" start: ").append(toIndentedString(start)).append("\n");
sb.append(" end: ").append(toIndentedString(end)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -0,0 +1,199 @@
package com.uam.wmi.findmytutor.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import java.util.UUID;
/**
* TutorTabViewModel
*/
public class TutorTabViewModel {
@SerializedName("tutorTabId")
private UUID tutorTabId = null;
@SerializedName("userId")
private String userId = null;
@SerializedName("room")
private String room = null;
@SerializedName("emailTutorTab")
private String emailTutorTab = null;
@SerializedName("note")
private String note = null;
@SerializedName("dutyHours")
private List<DutyHourViewModel> dutyHours = null;
public TutorTabViewModel tutorTabId(UUID tutorTabId) {
this.tutorTabId = tutorTabId;
return this;
}
/**
* Get tutorTabId
* @return tutorTabId
**/
@ApiModelProperty(value = "")
public UUID getTutorTabId() {
return tutorTabId;
}
public void setTutorTabId(UUID tutorTabId) {
this.tutorTabId = tutorTabId;
}
public TutorTabViewModel userId(String userId) {
this.userId = userId;
return this;
}
/**
* Get userId
* @return userId
**/
@ApiModelProperty(value = "")
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public TutorTabViewModel room(String room) {
this.room = room;
return this;
}
/**
* Get room
* @return room
**/
@ApiModelProperty(value = "")
public String getRoom() {
return room;
}
public void setRoom(String room) {
this.room = room;
}
public TutorTabViewModel emailTutorTab(String emailTutorTab) {
this.emailTutorTab = emailTutorTab;
return this;
}
/**
* Get emailTutorTab
* @return emailTutorTab
**/
@ApiModelProperty(value = "")
public String getEmailTutorTab() {
return emailTutorTab;
}
public void setEmailTutorTab(String emailTutorTab) {
this.emailTutorTab = emailTutorTab;
}
public TutorTabViewModel note(String note) {
this.note = note;
return this;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public TutorTabViewModel dutyHours(List<DutyHourViewModel> dutyHours) {
this.dutyHours = dutyHours;
return this;
}
public TutorTabViewModel addDutyHoursItem(DutyHourViewModel dutyHoursItem) {
if (this.dutyHours == null) {
this.dutyHours = new ArrayList<DutyHourViewModel>();
}
this.dutyHours.add(dutyHoursItem);
return this;
}
/**
* Get dutyHours
* @return dutyHours
**/
@ApiModelProperty(value = "")
public List<DutyHourViewModel> getDutyHours() {
return dutyHours;
}
public void setDutyHours(List<DutyHourViewModel> dutyHours) {
this.dutyHours = dutyHours;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TutorTabViewModel tutorTabViewModel = (TutorTabViewModel) o;
return Objects.equals(this.tutorTabId, tutorTabViewModel.tutorTabId) &&
Objects.equals(this.userId, tutorTabViewModel.userId) &&
Objects.equals(this.room, tutorTabViewModel.room) &&
Objects.equals(this.emailTutorTab, tutorTabViewModel.emailTutorTab) &&
Objects.equals(this.note, tutorTabViewModel.note) &&
Objects.equals(this.dutyHours, tutorTabViewModel.dutyHours);
}
@Override
public int hashCode() {
return Objects.hash(tutorTabId, userId, room, emailTutorTab, note, dutyHours);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class TutorTabViewModel {\n");
sb.append(" tutorTabId: ").append(toIndentedString(tutorTabId)).append("\n");
sb.append(" userId: ").append(toIndentedString(userId)).append("\n");
sb.append(" room: ").append(toIndentedString(room)).append("\n");
sb.append(" emailTutorTab: ").append(toIndentedString(emailTutorTab)).append("\n");
sb.append(" note: ").append(toIndentedString(note)).append("\n");
sb.append(" dutyHours: ").append(toIndentedString(dutyHours)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}

View File

@ -0,0 +1,58 @@
package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.http.*;
public interface TutorTabApi {
/**
* Scrap all tutor tabs
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
* @param tutorId (required)
* @return Call&lt;Void&gt;
*/
@POST("api/users/scrapTutorTab/{tutorId}")
Observable<Void> apiUsersScrapTutorTabByTutorIdPost(
@retrofit2.http.Path("tutorId") String tutorId
);
/**
* Scrap all tutor tabs
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
* @return Call&lt;Void&gt;
*/
@POST("api/users/scrapTutorTab")
Observable<Void> apiUsersScrapTutorTabPost();
/**
*
*
* @param tutorId (required)
* @return Call&lt;TutorTabViewModel&gt;
*/
@GET("api/users/tutorTab/{tutorId}")
Single<TutorTabViewModel> apiUsersTutorTabByTutorIdGet(
@retrofit2.http.Path("tutorId") String tutorId
);
/**
*
*
* @param tutorId (required)
* @param tutorTab (optional)
* @return Call&lt;Void&gt;
*/
@Headers({
"Content-Type:application/json"
})
@PUT("api/users/tutorTab/{tutorId}")
Observable<Void> apiUsersTutorTabByTutorIdPut(
@retrofit2.http.Path("tutorId") String tutorId, @retrofit2.http.Body TutorTabViewModel tutorTab
);
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -7,27 +8,41 @@
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<TextView android:id="@+id/dialog_title"
<TextView android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="@string/lbl_new_note_title"
android:textColor="@color/colorAccent"
android:textColor="@color/note_list_text"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<EditText
android:id="@+id/note"
<TextView
android:id="@+id/userRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="top"
android:hint="@string/hint_enter_note"
android:inputType="textCapSentences|textMultiLine"
android:lines="4"
android:textColorHint="@color/hint_enter_note"
android:textSize="@dimen/input_new_note" />
android:textColor="@color/note_list_text"
/>
<TextView
android:id="@+id/userEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
<TextView
android:id="@+id/userDutyHours"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
<TextView
android:id="@+id/userNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/note_list_text" />
</LinearLayout>

View File

@ -1,7 +1,7 @@
<?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="100dp"
android:layout_height="90dp"
android:clickable="true"
android:focusable="true"
android:paddingLeft="@dimen/activity_margin"
@ -13,24 +13,24 @@
<TextView
android:id="@+id/firstName"
android:layout_width="271dp"
android:layout_height="30dp"
android:layout_height="22dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:textColor="@color/note_list_text"
android:textSize="20sp" />
android:textSize="15sp" />
<TextView
android:id="@+id/lastName"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_height="22dp"
android:layout_below="@+id/firstName"
android:layout_alignEnd="@+id/firstName"
android:layout_marginTop="10dp"
android:layout_marginEnd="0dp"
android:textColor="@color/note_list_text"
android:textSize="20sp" />
android:textSize="15sp" />
<TextView
@ -38,7 +38,7 @@
android:layout_width="48dp"
android:layout_height="30dp"
android:layout_below="@+id/firstName"
android:layout_marginStart="10dp"
android:layout_marginStart="7dp"
android:layout_marginTop="-10dp"
android:layout_toEndOf="@+id/firstName"
android:textColor="@color/note_list_text"