Fix tutors list

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-12 16:38:28 +01:00
parent a27c18b468
commit b126cbfe31
7 changed files with 89 additions and 114 deletions

View File

@ -68,6 +68,7 @@ import io.reactivex.Observable;
import io.reactivex.ObservableSource; import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function; import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver;
import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.observers.DisposableSingleObserver;
@ -153,7 +154,6 @@ public class BlackList extends AppCompatActivity {
})); }));
addToBlackListFab.setOnClickListener(this::showFabDialog); addToBlackListFab.setOnClickListener(this::showFabDialog);
handleSwitch(); handleSwitch();
} }
@ -173,34 +173,29 @@ public class BlackList extends AppCompatActivity {
} }
private void fetchBlackListedUsers() { private void fetchBlackListedUsers() {
prevSize = blacklistedUsers.size();
blacklistedUsers.clear();
disposable.add(getListOfBlacklistedUsers(tutorId) disposable.add(getListOfBlacklistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false) .doOnSubscribe(this::handleDoOnSubscribe)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .flatMap(Observable::fromIterable)
.flatMap((Function<String, ObservableSource<User>>) this::getUserObservable) .flatMap(this::getUserObservable)
.subscribeWith(new DisposableObserver<User>() { .subscribe(user -> blacklistedUsers.add(user), this::handleError,this::handleComplete));
@Override }
public void onNext(User user) {
blacklistedUsers.add(user);
}
@Override private void handleDoOnSubscribe(Disposable disposable) {
public void onError(Throwable e) { prevSize = blacklistedUsers.size();
showError(e); blacklistedUsers.clear();
didFetched = false; didFetched = false;
} }
@Override private void handleComplete() {
public void onComplete() { Collections.sort(blacklistedUsers, this::sortByUserName);
Collections.sort(blacklistedUsers, (a, b) -> sortByUserName(a,b)); didFetched = true;
didFetched = true; refreshUI();
refreshUI(); }
} private void handleError(Throwable e){
})); showError(e);
didFetched = false;
} }
private void refreshUI(){ private void refreshUI(){
@ -262,10 +257,8 @@ public class BlackList extends AppCompatActivity {
); );
} }
private void handleAddUser(User user) { private void handleAddUser(User user) {
Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show(); Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show();
blacklistedUsers.clear(); blacklistedUsers.clear();
fetchBlackListedUsers(); fetchBlackListedUsers();
} }

View File

@ -157,9 +157,9 @@ LoginActivity extends AppCompatActivity {
private void loginProcess(String email, String password) { private void loginProcess(String email, String password) {
ValidateUser user = new ValidateUser(email, 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.validate(user)
//disposable.add(ldapService.fakeValidate(fakeUser) //disposable.add(ldapService.fakeValidate(fakeUser)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));

View File

@ -63,6 +63,7 @@ import io.reactivex.Observable;
import io.reactivex.ObservableSource; import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function; import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver;
import io.reactivex.observers.DisposableSingleObserver; 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 @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -447,54 +478,4 @@ public class UsersListFragment extends Fragment {
super.onStop(); 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;
}
} }

View File

@ -58,6 +58,7 @@ import io.reactivex.Observable;
import io.reactivex.ObservableSource; import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function; import io.reactivex.functions.Function;
import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -162,34 +163,29 @@ public class WhiteList extends AppCompatActivity {
} }
private void fetchWhiteListedUsers() { private void fetchWhiteListedUsers() {
prevSize = whitelistedUsers.size();
whitelistedUsers.clear();
disposable.add(getListOfWhitelistedUsers(tutorId) disposable.add(getListOfWhitelistedUsers(tutorId)
.doOnSubscribe(t -> didFetched = false) .doOnSubscribe(this::handleDoOnSubscribe)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.flatMap((Function<List<String>, Observable<String>>) Observable::fromIterable) .flatMap(Observable::fromIterable)
.flatMap((Function<String, ObservableSource<User>>) this::getUserObservable) .flatMap(this::getUserObservable)
.subscribeWith(new DisposableObserver<User>() { .subscribe(user -> whitelistedUsers.add(user), this::handleError,this::handleComplete));
@Override }
public void onNext(User user) {
whitelistedUsers.add(user);
}
@Override private void handleDoOnSubscribe(Disposable disposable) {
public void onError(Throwable e) { prevSize = whitelistedUsers.size();
showError(e); whitelistedUsers.clear();
didFetched = false; didFetched = false;
} }
@Override private void handleComplete() {
public void onComplete() { Collections.sort(whitelistedUsers, this::sortByUserName);
Collections.sort(whitelistedUsers, (a, b) -> sortByUserName(a, b)); didFetched = true;
didFetched = true; refreshUI();
refreshUI(); }
} private void handleError(Throwable e){
})); showError(e);
didFetched = false;
} }
private void refreshUI() { private void refreshUI() {

View File

@ -46,6 +46,7 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
User tutor = tutorsList.get(position); User tutor = tutorsList.get(position);
holder.firstName.setText(String.format("%s %s", tutor.getFirstName(), tutor.getLastName())); holder.firstName.setText(String.format("%s %s", tutor.getFirstName(), tutor.getLastName()));
String ts = tutorsTimeStamps.get(tutor.getId());
if (tutor.isIsOnline()) { if (tutor.isIsOnline()) {
image = context.getResources().getDrawable(R.drawable.user_list_online); 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); holder.loader.setVisibility(View.GONE);
} else { } else {
image = context.getResources().getDrawable(R.drawable.user_list_offline); image = context.getResources().getDrawable(R.drawable.user_list_offline);
String ts = tutorsTimeStamps.get(tutor.getId());
if (ts != null){ if (ts != null){
holder.lastSeen.setText(R.string.last_sign); holder.lastSeen.setText(R.string.last_sign);
@ -64,7 +64,12 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
if (!tutor.isIsActive()) { if (!tutor.isIsActive()) {
image = context.getResources().getDrawable(R.drawable.user_list_off); 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); holder.loader.setVisibility(View.GONE);
} }

View File

@ -77,6 +77,7 @@
android:layout_alignStart="@+id/userRoomLayout" android:layout_alignStart="@+id/userRoomLayout"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:layout_marginStart="5dp"
android:text="@string/personalInfoTitle" android:text="@string/personalInfoTitle"
android:textColor="@color/mapboxRedDark" android:textColor="@color/mapboxRedDark"
android:textSize="18sp" android:textSize="18sp"
@ -113,7 +114,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/userRoomLayout" android:layout_below="@+id/userRoomLayout"
android:layout_alignStart="@+id/userRoomLayout" android:layout_alignStart="@+id/userRoomLayout"
android:layout_marginStart="0dp" android:layout_marginStart="5dp"
android:layout_marginEnd="30dp" android:layout_marginEnd="30dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:gravity="center" android:gravity="center"
@ -125,18 +126,18 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/dutyHourView" android:id="@+id/dutyHourView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="120dp"
android:layout_below="@+id/addDuty" android:layout_below="@+id/addDuty"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_marginStart="30dp" android:layout_marginStart="30dp"
android:layout_marginTop="0dp" android:layout_marginTop="15dp"
android:layout_marginEnd="30dp" android:layout_marginEnd="50dp"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
<TextView <TextView
android:id="@+id/userNoteTitle" android:id="@+id/userNoteTitle"
android:textStyle="bold" android:textStyle="bold"
android:layout_marginStart="5dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/dutyHourView" android:layout_below="@+id/dutyHourView"
@ -163,12 +164,11 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_marginStart="30dp" android:layout_marginStart="30dp"
android:layout_marginEnd="30dp" android:layout_marginEnd="30dp"
android:layout_marginTop="0dp" android:layout_marginTop="15dp"
app:counterEnabled="true" app:counterEnabled="true"
app:counterMaxLength="1000"> app:counterMaxLength="1000">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/userNote" android:id="@+id/userNote"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
@ -178,7 +178,7 @@
android:lineSpacingExtra="8sp" android:lineSpacingExtra="8sp"
android:maxLength="1000" android:maxLength="1000"
android:maxLines="7" android:maxLines="7"
android:paddingTop="5dp" android:paddingTop="15dp"
android:requiresFadingEdge="vertical" android:requiresFadingEdge="vertical"
android:scrollbars="vertical" android:scrollbars="vertical"
android:textColor="@color/note_list_text" /> android:textColor="@color/note_list_text" />
@ -196,14 +196,15 @@
<android.support.v7.widget.AppCompatButton <android.support.v7.widget.AppCompatButton
android:id="@+id/saveButton" android:id="@+id/saveButton"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="-25dp"
android:layout_below="@+id/userNoteLayout" android:layout_below="@+id/userNoteLayout"
android:layout_alignEnd="@+id/dutyHourView" android:layout_alignEnd="@+id/dutyHourView"
android:textColor="@color/white" android:textColor="@color/white"
app:backgroundTint="@color/colorPrimary" app:backgroundTint="@color/colorPrimary"
android:text="@string/saveButton" /> android:text="@string/saveButton" />
</RelativeLayout> </RelativeLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>

View File

@ -8,7 +8,6 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files