Fix tutors list
This commit is contained in:
parent
a27c18b468
commit
b126cbfe31
@ -68,6 +68,7 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
@ -153,7 +154,6 @@ public class BlackList extends AppCompatActivity {
|
||||
}));
|
||||
|
||||
addToBlackListFab.setOnClickListener(this::showFabDialog);
|
||||
|
||||
handleSwitch();
|
||||
}
|
||||
|
||||
@ -173,34 +173,29 @@ public class BlackList extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void fetchBlackListedUsers() {
|
||||
prevSize = blacklistedUsers.size();
|
||||
blacklistedUsers.clear();
|
||||
|
||||
disposable.add(getListOfBlacklistedUsers(tutorId)
|
||||
.doOnSubscribe(t -> didFetched = false)
|
||||
.doOnSubscribe(this::handleDoOnSubscribe)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
|
||||
.flatMap((Function<String, ObservableSource<User>>) this::getUserObservable)
|
||||
.subscribeWith(new DisposableObserver<User>() {
|
||||
@Override
|
||||
public void onNext(User user) {
|
||||
blacklistedUsers.add(user);
|
||||
.flatMap(Observable::fromIterable)
|
||||
.flatMap(this::getUserObservable)
|
||||
.subscribe(user -> blacklistedUsers.add(user), this::handleError,this::handleComplete));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
private void handleDoOnSubscribe(Disposable disposable) {
|
||||
prevSize = blacklistedUsers.size();
|
||||
blacklistedUsers.clear();
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b));
|
||||
private void handleComplete() {
|
||||
Collections.sort(blacklistedUsers, this::sortByUserName);
|
||||
didFetched = true;
|
||||
refreshUI();
|
||||
}
|
||||
}));
|
||||
private void handleError(Throwable e){
|
||||
showError(e);
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void refreshUI(){
|
||||
@ -262,10 +257,8 @@ public class BlackList extends AppCompatActivity {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private void handleAddUser(User user) {
|
||||
Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show();
|
||||
|
||||
blacklistedUsers.clear();
|
||||
fetchBlackListedUsers();
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ LoginActivity extends AppCompatActivity {
|
||||
|
||||
private void loginProcess(String email, String password) {
|
||||
ValidateUser user = new ValidateUser(email, password);
|
||||
// LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email);
|
||||
//LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email);
|
||||
disposable.add(ldapService.validate(user)
|
||||
//disposable.add(ldapService.fakeValidate(fakeUser)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -63,6 +63,7 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
@ -425,6 +426,36 @@ public class UsersListFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void fetchTopCords(){
|
||||
disposable.add(
|
||||
coordinateService.getTopCoordinates()
|
||||
.doOnSubscribe(t -> tutorsTimeStamps.clear())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::addTimestamps,this::showError));
|
||||
}
|
||||
|
||||
private void addTimestamps(List<Coordinate> coordinates) {
|
||||
for (Coordinate crd :
|
||||
coordinates) {
|
||||
Long ts = crd.getTimeStamp();
|
||||
tutorsTimeStamps.put(crd.getUserId(), getDate(ts));
|
||||
}
|
||||
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private String getDate(long time) {
|
||||
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
|
||||
cal.setTimeInMillis(time);
|
||||
return DateFormat.format("HH:mm dd/MM", cal).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -447,54 +478,4 @@ public class UsersListFragment extends Fragment {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private Observable<List<User>> getListOfActiveUsers() {
|
||||
return userService.getAllActiveTutors()
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private Observable<Coordinate> getCoordinateObservable(User user) {
|
||||
return coordinateService
|
||||
.getTopCoordinateByUserId(user.getId())
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private void fetchTopCords(){
|
||||
tutorsTimeStamps.clear();
|
||||
disposable.add(getListOfActiveUsers()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap((Function<List<User>, Observable<User>>) Observable::fromIterable)
|
||||
.flatMap((Function<User, ObservableSource<Coordinate>>) this::getCoordinateObservable)
|
||||
.subscribeWith(new DisposableObserver<Coordinate>() {
|
||||
@Override
|
||||
public void onNext(Coordinate coordinate) {
|
||||
Long ts = coordinate.getTimeStamp();
|
||||
tutorsTimeStamps.put(coordinate.getUserId(), getDate(ts));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {showError(e);}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("USERS", String.valueOf(tutorsTimeStamps));
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private String getDate(long time) {
|
||||
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
|
||||
cal.setTimeInMillis(time);
|
||||
String date = DateFormat.format("HH:mm dd/MM", cal).toString();
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
@ -162,34 +163,29 @@ public class WhiteList extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void fetchWhiteListedUsers() {
|
||||
prevSize = whitelistedUsers.size();
|
||||
whitelistedUsers.clear();
|
||||
|
||||
disposable.add(getListOfWhitelistedUsers(tutorId)
|
||||
.doOnSubscribe(t -> didFetched = false)
|
||||
.doOnSubscribe(this::handleDoOnSubscribe)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable)
|
||||
.flatMap((Function<String, ObservableSource<User>>) this::getUserObservable)
|
||||
.subscribeWith(new DisposableObserver<User>() {
|
||||
@Override
|
||||
public void onNext(User user) {
|
||||
whitelistedUsers.add(user);
|
||||
.flatMap(Observable::fromIterable)
|
||||
.flatMap(this::getUserObservable)
|
||||
.subscribe(user -> whitelistedUsers.add(user), this::handleError,this::handleComplete));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
private void handleDoOnSubscribe(Disposable disposable) {
|
||||
prevSize = whitelistedUsers.size();
|
||||
whitelistedUsers.clear();
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b));
|
||||
private void handleComplete() {
|
||||
Collections.sort(whitelistedUsers, this::sortByUserName);
|
||||
didFetched = true;
|
||||
refreshUI();
|
||||
}
|
||||
}));
|
||||
private void handleError(Throwable e){
|
||||
showError(e);
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void refreshUI() {
|
||||
|
@ -46,6 +46,7 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(String.format("%s %s", tutor.getFirstName(), tutor.getLastName()));
|
||||
String ts = tutorsTimeStamps.get(tutor.getId());
|
||||
|
||||
if (tutor.isIsOnline()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_online);
|
||||
@ -53,7 +54,6 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
} else {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_offline);
|
||||
String ts = tutorsTimeStamps.get(tutor.getId());
|
||||
|
||||
if (ts != null){
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
@ -64,7 +64,12 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
|
||||
if (!tutor.isIsActive()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_off);
|
||||
holder.lastSeen.setText("");
|
||||
if(ts != null){
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
holder.lastSeen.append(String.format(": %s", ts));
|
||||
}else{
|
||||
holder.lastSeen.setVisibility(View.GONE);
|
||||
}
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@
|
||||
android:layout_alignStart="@+id/userRoomLayout"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="@string/personalInfoTitle"
|
||||
android:textColor="@color/mapboxRedDark"
|
||||
android:textSize="18sp"
|
||||
@ -113,7 +114,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/userRoomLayout"
|
||||
android:layout_alignStart="@+id/userRoomLayout"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center"
|
||||
@ -125,18 +126,18 @@
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/dutyHourView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_below="@+id/addDuty"
|
||||
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginEnd="50dp"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/userNoteTitle"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/dutyHourView"
|
||||
@ -163,12 +164,11 @@
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginTop="15dp"
|
||||
app:counterEnabled="true"
|
||||
app:counterMaxLength="1000">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
|
||||
android:id="@+id/userNote"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
@ -178,7 +178,7 @@
|
||||
android:lineSpacingExtra="8sp"
|
||||
android:maxLength="1000"
|
||||
android:maxLines="7"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingTop="15dp"
|
||||
android:requiresFadingEdge="vertical"
|
||||
android:scrollbars="vertical"
|
||||
android:textColor="@color/note_list_text" />
|
||||
@ -196,14 +196,15 @@
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
android:id="@+id/saveButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_marginEnd="-25dp"
|
||||
android:layout_below="@+id/userNoteLayout"
|
||||
android:layout_alignEnd="@+id/dutyHourView"
|
||||
android:textColor="@color/white"
|
||||
app:backgroundTint="@color/colorPrimary"
|
||||
android:text="@string/saveButton" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
@ -9,7 +9,6 @@ buildscript {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user