Add status of particular user
This commit is contained in:
parent
49199ccc44
commit
1e281b3ea5
@ -56,5 +56,6 @@ dependencies {
|
|||||||
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
|
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
|
||||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||||
|
implementation 'com.annimon:stream:1.2.1'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.uam.wmi.findmytutor.activity;
|
package com.uam.wmi.findmytutor.activity;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.design.widget.CoordinatorLayout;
|
import android.support.design.widget.CoordinatorLayout;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
@ -12,6 +14,7 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
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;
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -54,6 +58,7 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
@BindView(R.id.txt_empty_notes_view)
|
@BindView(R.id.txt_empty_notes_view)
|
||||||
TextView noNotesView;
|
TextView noNotesView;
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -87,6 +92,7 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void fetchAllTutors() {
|
private void fetchAllTutors() {
|
||||||
disposable.add(
|
disposable.add(
|
||||||
apiService.apiUsersGet()
|
apiService.apiUsersGet()
|
||||||
@ -94,9 +100,23 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map(tutors -> {
|
.map(tutors -> {
|
||||||
List<User> tutorsList = new ArrayList<>(tutors.getTutors());
|
List<User> tutorsList = new ArrayList<>(tutors.getTutors());
|
||||||
Collections.sort(tutorsList, (t1, t2) -> t2.isIsOnline().compareTo(t1.isIsOnline()));
|
|
||||||
|
|
||||||
return tutorsList;
|
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();;
|
||||||
|
|
||||||
|
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()));
|
||||||
|
|
||||||
|
List<User> sortedUserList = new ArrayList<>(onlineTutors);
|
||||||
|
sortedUserList.addAll(activeNotOnlineTutors);
|
||||||
|
sortedUserList.addAll(notActiveTutors);
|
||||||
|
|
||||||
|
return sortedUserList;
|
||||||
})
|
})
|
||||||
.subscribeWith(new DisposableSingleObserver <List<User>>() {
|
.subscribeWith(new DisposableSingleObserver <List<User>>() {
|
||||||
@Override
|
@Override
|
||||||
@ -117,7 +137,7 @@ public class UsersListActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showError(Throwable e) {
|
private void showError(Throwable e) {
|
||||||
String message = "Something went wrong!";
|
String message = e.toString();
|
||||||
|
|
||||||
if (e instanceof HttpException) {
|
if (e instanceof HttpException) {
|
||||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||||
|
@ -94,17 +94,5 @@ public class TutorsAdapter extends RecyclerView.Adapter<TutorsAdapter.MyViewHold
|
|||||||
return tutorsList.size();
|
return tutorsList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRandomMaterialColor(String typeColor) {
|
|
||||||
int returnColor = Color.GRAY;
|
|
||||||
int arrayId = context.getResources().getIdentifier("mdcolor_" + typeColor, "array", context.getPackageName());
|
|
||||||
|
|
||||||
if (arrayId != 0) {
|
|
||||||
TypedArray colors = context.getResources().obtainTypedArray(arrayId);
|
|
||||||
int index = (int) (Math.random() * colors.length());
|
|
||||||
returnColor = colors.getColor(index, Color.GRAY);
|
|
||||||
colors.recycle();
|
|
||||||
}
|
|
||||||
return returnColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -23,24 +23,24 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/lastName"
|
android:id="@+id/lastName"
|
||||||
android:layout_width="269dp"
|
android:layout_width="270dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/firstName"
|
android:layout_below="@+id/firstName"
|
||||||
android:layout_alignEnd="@+id/firstName"
|
android:layout_alignEnd="@+id/firstName"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_marginEnd="1dp"
|
android:layout_marginEnd="0dp"
|
||||||
android:textColor="@color/note_list_text"
|
android:textColor="@color/note_list_text"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/isOnline"
|
android:id="@+id/isOnline"
|
||||||
android:layout_width="25dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="30dp"
|
||||||
android:layout_below="@+id/lastName"
|
android:layout_below="@+id/firstName"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_marginStart="10dp"
|
||||||
android:layout_marginTop="-42dp"
|
android:layout_marginTop="-10dp"
|
||||||
android:layout_marginEnd="33dp"
|
android:layout_toEndOf="@+id/firstName"
|
||||||
android:textColor="@color/note_list_text"
|
android:textColor="@color/note_list_text"
|
||||||
android:textSize="@dimen/note_list_text" />
|
android:textSize="@dimen/note_list_text" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user