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;
|
package com.uam.wmi.findmytutor.activity;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -20,10 +19,8 @@ import android.widget.ListView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
import com.facebook.shimmer.ShimmerFrameLayout;
|
|
||||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||||
import com.uam.wmi.findmytutor.R;
|
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.DutyHourViewModel;
|
||||||
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||||
import com.uam.wmi.findmytutor.model.User;
|
import com.uam.wmi.findmytutor.model.User;
|
||||||
@ -47,8 +44,6 @@ import io.reactivex.observers.DisposableSingleObserver;
|
|||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
public class UsersListActivity extends BaseActivity {
|
public class UsersListActivity extends BaseActivity {
|
||||||
private static final String TAG = UsersListActivity.class.getSimpleName();
|
private static final String TAG = UsersListActivity.class.getSimpleName();
|
||||||
@BindView(R.id.coordinator_layout)
|
@BindView(R.id.coordinator_layout)
|
||||||
@ -67,7 +62,6 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.users_list);
|
setContentView(R.layout.users_list);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
@ -95,29 +89,10 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongClick(View view, int position) {
|
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) {
|
private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) {
|
||||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||||
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null);
|
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 userRoom = view.findViewById(R.id.userRoom);
|
||||||
TextView userEmail = view.findViewById(R.id.userEmail);
|
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(
|
disposable.add(
|
||||||
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
|
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
|
||||||
@ -145,21 +120,19 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
|
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
|
||||||
Log.e("TUTOR_TAB",tutorTabViewModel.toString());
|
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||||
|
|
||||||
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
|
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
|
||||||
.map(DutyHourViewModel::getSummary).toList();
|
.map(DutyHourViewModel::getSummary).toList();
|
||||||
|
|
||||||
userRoom.setText(getString(R.string.userRoom) + ": " + tutorTabViewModel.getRoom());
|
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
|
||||||
userEmail.setText(getString(R.string.userEmail) + ": " + tutorTabViewModel.getEmailTutorTab());
|
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
|
||||||
userNote.setText(getString(R.string.userNote) + ": " + tutorTabViewModel.getNote());
|
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
|
||||||
|
|
||||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(UsersListActivity.this,
|
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(UsersListActivity.this,
|
||||||
android.R.layout.simple_list_item_activated_1, dutyHoursList);
|
android.R.layout.simple_list_item_activated_1, dutyHoursList);
|
||||||
|
|
||||||
userDutyHours.setAdapter(arrayAdapter);
|
userDutyHours.setAdapter(arrayAdapter);
|
||||||
|
alertDialog.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -167,10 +140,6 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
showError(e);
|
showError(e);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
|
||||||
alertDialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,7 +149,7 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map(tutors -> {
|
.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();
|
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)
|
List<User> notActiveTutors = Stream.of(tutorsList)
|
||||||
.filterNot(User::isIsActive).toList();
|
.filterNot(User::isIsActive).toList();
|
||||||
|
|
||||||
Collections.sort(onlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
|
Collections.sort(onlineTutors, this::sortByUserName);
|
||||||
Collections.sort(activeNotOnlineTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
|
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
|
||||||
Collections.sort(notActiveTutors, (t1, t2) -> t1.getFirstName().compareTo(t2.getFirstName()));
|
Collections.sort(notActiveTutors, this::sortByUserName);
|
||||||
|
|
||||||
List<User> sortedUserList = new ArrayList<>(onlineTutors);
|
List<User> sortedUserList = new ArrayList<>(onlineTutors);
|
||||||
sortedUserList.addAll(activeNotOnlineTutors);
|
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) {
|
private void showError(Throwable e) {
|
||||||
String message = e.toString();
|
String message = e.toString();
|
||||||
|
|
||||||
@ -237,7 +211,6 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
} else {
|
} else {
|
||||||
noNotesView.setVisibility(View.VISIBLE);
|
noNotesView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,121 +1,108 @@
|
|||||||
package com.uam.wmi.findmytutor.model;
|
package com.uam.wmi.findmytutor.model;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
public class ReturnedTutors {
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
@SerializedName("id")
|
||||||
* ReturnedTutors
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ReturnedTutors extends User{
|
|
||||||
@SerializedName("tutors")
|
|
||||||
@Expose
|
@Expose
|
||||||
private List<User> tutors = null;
|
private String id;
|
||||||
|
@SerializedName("isOnline")
|
||||||
@SerializedName("blacklistersTutors")
|
|
||||||
@Expose
|
@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) {
|
public String getId() {
|
||||||
this.tutors = tutors;
|
return id;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getTutors() {
|
public void setId(String id) {
|
||||||
return tutors;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnedTutors addTutorsItem(User tutorsItem) {
|
public Boolean getIsOnline() {
|
||||||
if (this.tutors == null) {
|
return isOnline;
|
||||||
this.tutors = new ArrayList<User>();
|
|
||||||
}
|
|
||||||
this.tutors.add(tutorsItem);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setIsOnline(Boolean isOnline) {
|
||||||
* Get tutors
|
this.isOnline = isOnline;
|
||||||
* @return tutors
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
public void setTutors(List<User> tutors) {
|
|
||||||
this.tutors = tutors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnedTutors blacklistersTutors(List<User> blacklistersTutors) {
|
public String getTitle() {
|
||||||
this.blacklistersTutors = blacklistersTutors;
|
return title;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnedTutors addBlacklistersTutorsItem(User blacklistersTutorsItem) {
|
public void setTitle(String title) {
|
||||||
if (this.blacklistersTutors == null) {
|
this.title = title;
|
||||||
this.blacklistersTutors = new ArrayList<User>();
|
|
||||||
}
|
|
||||||
this.blacklistersTutors.add(blacklistersTutorsItem);
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getFirstName() {
|
||||||
* Get blacklistersTutors
|
return firstName;
|
||||||
* @return blacklistersTutors
|
|
||||||
**/
|
|
||||||
@ApiModelProperty(value = "")
|
|
||||||
public List<User> getBlacklistersTutors() {
|
|
||||||
return blacklistersTutors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlacklistersTutors(List<User> blacklistersTutors) {
|
public void setFirstName(String firstName) {
|
||||||
this.blacklistersTutors = blacklistersTutors;
|
this.firstName = firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
@Override
|
return lastName;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setLastName(String lastName) {
|
||||||
public int hashCode() {
|
this.lastName = lastName;
|
||||||
return Objects.hash(tutors, blacklistersTutors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDepartment() {
|
||||||
@Override
|
return department;
|
||||||
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 void setDepartment(String department) {
|
||||||
* Convert the given object to string with each line indented by 4 spaces
|
this.department = department;
|
||||||
* (except the first line).
|
|
||||||
*/
|
|
||||||
private String toIndentedString(java.lang.Object o) {
|
|
||||||
if (o == null) {
|
|
||||||
return "null";
|
|
||||||
}
|
}
|
||||||
return o.toString().replace("\n", "\n ");
|
|
||||||
|
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();
|
Single <List<User>> getAllUsers();
|
||||||
|
|
||||||
@GET("api/users")
|
@GET("api/users")
|
||||||
Single<ReturnedTutors> apiUsersGet();
|
Single <List<User>> apiUsersGet();
|
||||||
|
|
||||||
@POST("api/users")
|
@POST("api/users")
|
||||||
Completable createUser(@Body User user);
|
Completable createUser(@Body User user);
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
android:paddingTop="@dimen/activity_margin">
|
android:paddingTop="@dimen/activity_margin">
|
||||||
|
|
||||||
|
|
||||||
<TextView android:id="@+id/userName"
|
<TextView android:id="@+id/userName"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -39,7 +38,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/userDutyHoursHeader"
|
android:text="@string/userDutyHoursHeader"
|
||||||
android:textColor="@color/note_list_text"
|
android:textColor="@color/note_list_text"
|
||||||
tools:text="Dyżury:" />
|
tools:text="@string/dutyHours" />
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/userDutyHours"
|
android:id="@+id/userDutyHours"
|
||||||
|
@ -203,4 +203,5 @@ functionality.</string>
|
|||||||
<string name="userEmail">Email</string>
|
<string name="userEmail">Email</string>
|
||||||
<string name="userNote">Notatka</string>
|
<string name="userNote">Notatka</string>
|
||||||
<string name="userDutyHoursHeader">Dyżury:</string>
|
<string name="userDutyHoursHeader">Dyżury:</string>
|
||||||
|
<string name="dutyHours">Dyżury:</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user