Refactor & don't show user information when tutor tab does not exist
This commit is contained in:
parent
4701387d48
commit
d4aa5b5261
@ -1,7 +1,6 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -20,10 +19,8 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.facebook.shimmer.ShimmerFrameLayout;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
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;
|
||||
@ -47,8 +44,6 @@ import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class UsersListActivity extends BaseActivity {
|
||||
private static final String TAG = UsersListActivity.class.getSimpleName();
|
||||
@BindView(R.id.coordinator_layout)
|
||||
@ -67,7 +62,6 @@ public class UsersListActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.users_list);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
@ -95,29 +89,10 @@ public class UsersListActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
//showActionsDialog(position);
|
||||
|
||||
//showNoteDialog(true, tutorsList.get(position), position);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void showActionsDialog(final int position) {
|
||||
CharSequence colors[] = new CharSequence[]{"Edit", "Delete"};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Choose option");
|
||||
builder.setItems(colors, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
showNoteDialog(true, tutorsList.get(position), position);
|
||||
} else {
|
||||
//deleteNote(tutorsList.get(position).getId(), position);
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
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);
|
||||
@ -135,7 +110,7 @@ public class UsersListActivity extends BaseActivity {
|
||||
TextView userRoom = view.findViewById(R.id.userRoom);
|
||||
TextView userEmail = view.findViewById(R.id.userEmail);
|
||||
|
||||
userName.setText(user.getFirstName() + " " + user.getLastName());
|
||||
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
|
||||
|
||||
disposable.add(
|
||||
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
|
||||
@ -145,21 +120,19 @@ public class UsersListActivity extends BaseActivity {
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
|
||||
Log.e("TUTOR_TAB",tutorTabViewModel.toString());
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
|
||||
.map(DutyHourViewModel::getSummary).toList();
|
||||
|
||||
userRoom.setText(getString(R.string.userRoom) + ": " + tutorTabViewModel.getRoom());
|
||||
userEmail.setText(getString(R.string.userEmail) + ": " + tutorTabViewModel.getEmailTutorTab());
|
||||
userNote.setText(getString(R.string.userNote) + ": " + tutorTabViewModel.getNote());
|
||||
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
|
||||
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
|
||||
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(UsersListActivity.this,
|
||||
android.R.layout.simple_list_item_activated_1,dutyHoursList);
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(UsersListActivity.this,
|
||||
android.R.layout.simple_list_item_activated_1, dutyHoursList);
|
||||
|
||||
userDutyHours.setAdapter(arrayAdapter);
|
||||
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -167,11 +140,7 @@ public class UsersListActivity extends BaseActivity {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
alertDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void fetchAllTutors() {
|
||||
@ -180,7 +149,7 @@ public class UsersListActivity extends BaseActivity {
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(tutors -> {
|
||||
List<User> tutorsList = new ArrayList<>(tutors.getTutors());
|
||||
List<User> tutorsList = new ArrayList<>(tutors);
|
||||
|
||||
List<User> onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList();
|
||||
|
||||
@ -190,9 +159,9 @@ public class UsersListActivity extends BaseActivity {
|
||||
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()));
|
||||
Collections.sort(notActiveTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
|
||||
Collections.sort(onlineTutors, this::sortByUserName);
|
||||
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
|
||||
Collections.sort(notActiveTutors, this::sortByUserName);
|
||||
|
||||
List<User> sortedUserList = new ArrayList<>(onlineTutors);
|
||||
sortedUserList.addAll(activeNotOnlineTutors);
|
||||
@ -216,6 +185,11 @@ public class UsersListActivity extends BaseActivity {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private int sortByUserName(User t1, User t2) {
|
||||
return t1.getFirstName().compareTo(t2.getFirstName());
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message = e.toString();
|
||||
|
||||
@ -237,7 +211,6 @@ public class UsersListActivity extends BaseActivity {
|
||||
} else {
|
||||
noNotesView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,121 +1,108 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class ReturnedTutors {
|
||||
|
||||
/**
|
||||
* ReturnedTutors
|
||||
*/
|
||||
|
||||
public class ReturnedTutors extends User{
|
||||
@SerializedName("tutors")
|
||||
@SerializedName("id")
|
||||
@Expose
|
||||
private List<User> tutors = null;
|
||||
|
||||
@SerializedName("blacklistersTutors")
|
||||
private String id;
|
||||
@SerializedName("isOnline")
|
||||
@Expose
|
||||
private List<User> blacklistersTutors = null;
|
||||
private Boolean isOnline;
|
||||
@SerializedName("title")
|
||||
@Expose
|
||||
private String title;
|
||||
@SerializedName("firstName")
|
||||
@Expose
|
||||
private String firstName;
|
||||
@SerializedName("lastName")
|
||||
@Expose
|
||||
private String lastName;
|
||||
@SerializedName("department")
|
||||
@Expose
|
||||
private String department;
|
||||
@SerializedName("userName")
|
||||
@Expose
|
||||
private String userName;
|
||||
@SerializedName("email")
|
||||
@Expose
|
||||
private String email;
|
||||
@SerializedName("isActive")
|
||||
@Expose
|
||||
private Boolean isActive;
|
||||
|
||||
public ReturnedTutors tutors(List<User> tutors) {
|
||||
this.tutors = tutors;
|
||||
return this;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<User> getTutors() {
|
||||
return tutors;
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ReturnedTutors addTutorsItem(User tutorsItem) {
|
||||
if (this.tutors == null) {
|
||||
this.tutors = new ArrayList<User>();
|
||||
}
|
||||
this.tutors.add(tutorsItem);
|
||||
return this;
|
||||
public Boolean getIsOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tutors
|
||||
* @return tutors
|
||||
**/
|
||||
|
||||
|
||||
public void setTutors(List<User> tutors) {
|
||||
this.tutors = tutors;
|
||||
public void setIsOnline(Boolean isOnline) {
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
public ReturnedTutors blacklistersTutors(List<User> blacklistersTutors) {
|
||||
this.blacklistersTutors = blacklistersTutors;
|
||||
return this;
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public ReturnedTutors addBlacklistersTutorsItem(User blacklistersTutorsItem) {
|
||||
if (this.blacklistersTutors == null) {
|
||||
this.blacklistersTutors = new ArrayList<User>();
|
||||
}
|
||||
this.blacklistersTutors.add(blacklistersTutorsItem);
|
||||
return this;
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get blacklistersTutors
|
||||
* @return blacklistersTutors
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public List<User> getBlacklistersTutors() {
|
||||
return blacklistersTutors;
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setBlacklistersTutors(List<User> blacklistersTutors) {
|
||||
this.blacklistersTutors = blacklistersTutors;
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ReturnedTutors returnedTutors = (ReturnedTutors) o;
|
||||
return Objects.equals(this.tutors, returnedTutors.tutors) &&
|
||||
Objects.equals(this.blacklistersTutors, returnedTutors.blacklistersTutors);
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(tutors, blacklistersTutors);
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ReturnedTutors {\n");
|
||||
|
||||
sb.append(" tutors: ").append(toIndentedString(tutors)).append("\n");
|
||||
sb.append(" blacklistersTutors: ").append(toIndentedString(blacklistersTutors)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ");
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Boolean getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(Boolean isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public interface UserService {
|
||||
Single <List<User>> getAllUsers();
|
||||
|
||||
@GET("api/users")
|
||||
Single<ReturnedTutors> apiUsersGet();
|
||||
Single <List<User>> apiUsersGet();
|
||||
|
||||
@POST("api/users")
|
||||
Completable createUser(@Body User user);
|
||||
|
@ -8,7 +8,6 @@
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
|
||||
<TextView android:id="@+id/userName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -39,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/userDutyHoursHeader"
|
||||
android:textColor="@color/note_list_text"
|
||||
tools:text="Dyżury:" />
|
||||
tools:text="@string/dutyHours" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/userDutyHours"
|
||||
|
@ -203,4 +203,5 @@ functionality.</string>
|
||||
<string name="userEmail">Email</string>
|
||||
<string name="userNote">Notatka</string>
|
||||
<string name="userDutyHoursHeader">Dyżury:</string>
|
||||
<string name="dutyHours">Dyżury:</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user