last seen working just fine
This commit is contained in:
parent
4300c33d65
commit
f98e4289fb
@ -14,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.format.DateFormat;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@ -38,6 +39,7 @@ import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.TutorTabApi;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||
@ -48,7 +50,9 @@ import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -75,9 +79,12 @@ public class UsersListFragment extends Fragment {
|
||||
private SearchView searchView;
|
||||
private UserService userService;
|
||||
private TutorTabApi tutorTabService;
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private TutorsListAdapter mAdapter;
|
||||
private List<User> tutorsList = new ArrayList<>();
|
||||
private HashMap<String, String> tutorsTimeStamps = new HashMap<>();
|
||||
|
||||
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
||||
private Boolean fetchOnlyOnlineUsers = PrefUtils.getShowOnlyOnlineUsers(getApplicationContext());
|
||||
|
||||
@ -89,7 +96,8 @@ public class UsersListFragment extends Fragment {
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsList);
|
||||
|
||||
mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsList, tutorsTimeStamps);
|
||||
View view = inflater.inflate(R.layout.users_list, container, false);
|
||||
view.setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
setHasOptionsMenu(true);
|
||||
@ -101,9 +109,10 @@ public class UsersListFragment extends Fragment {
|
||||
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
tutorTabService = ApiClient.getClient(getActivity().getApplicationContext())
|
||||
.create(TutorTabApi.class);
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(mLayoutManager);
|
||||
@ -113,6 +122,7 @@ public class UsersListFragment extends Fragment {
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
fetchAllTutors();
|
||||
fetchTopCords();
|
||||
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity().getApplicationContext(),
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@ -431,4 +441,60 @@ public class UsersListFragment extends Fragment {
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void fetchTopCords(){
|
||||
disposable.add(
|
||||
coordinateService.getTopCoordinates()
|
||||
// coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> newCords) {
|
||||
for (Coordinate crd :
|
||||
newCords) {
|
||||
Long ts = crd.getTimeStamp();
|
||||
if (ts != 0){
|
||||
tutorsTimeStamps.put(crd.getUserId(), getDate(ts));
|
||||
}
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
Log.e("PATRZ", tutorsTimeStamps.toString());
|
||||
Log.e("length", tutorsTimeStamps.size() +"");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("adapter",e +"");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void fetchTopCords(String id){
|
||||
Log.e("MORDO2", id);
|
||||
|
||||
disposable.add(
|
||||
coordinateService.getTopCoordinatesByUserId(id)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@Override
|
||||
public void onSuccess(Coordinate newCords) {
|
||||
Log.e("MORDO", newCords.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("adapter",e +"");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -3,29 +3,56 @@ package com.uam.wmi.findmytutor.adapters;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static android.support.constraint.Constraints.TAG;
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
|
||||
public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.MyViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<User> tutorsList;
|
||||
private HashMap<String, String> tutorsTimeStamps;
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
public TutorsListAdapter(Context context, List<User> tutors) {
|
||||
|
||||
|
||||
public TutorsListAdapter(Context context, List<User> tutors, HashMap<String,String> tutorsTimeStamps) {
|
||||
this.context = context;
|
||||
this.tutorsList = tutors;
|
||||
this.tutorsTimeStamps = tutorsTimeStamps;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
@ -33,6 +60,7 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.tutor_list_row, parent, false);
|
||||
|
||||
// fetchTopCords();
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@ -41,17 +69,26 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
Drawable image = null;
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(tutor.getFirstName());
|
||||
holder.lastName.setText(tutor.getLastName());
|
||||
holder.firstName.setText(tutor.getFirstName() + " " + tutor.getLastName());
|
||||
|
||||
|
||||
|
||||
if (tutor.isIsOnline()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_online);
|
||||
holder.lastSeen.setText("Available now");
|
||||
} else {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_offline);
|
||||
String tmp = tutorsTimeStamps.get(tutor.getId());
|
||||
if (tmp != null){
|
||||
holder.lastSeen.setText("Last seen: " + tmp);
|
||||
}else {
|
||||
holder.lastSeen.setText("no timestamp");
|
||||
}
|
||||
}
|
||||
|
||||
if (!tutor.isIsActive()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_off);
|
||||
holder.lastSeen.setText("Ages ago");
|
||||
}
|
||||
|
||||
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
|
||||
@ -68,17 +105,20 @@ public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.My
|
||||
@BindView(R.id.firstName)
|
||||
TextView firstName;
|
||||
|
||||
@BindView(R.id.lastName)
|
||||
TextView lastName;
|
||||
@BindView(R.id.lastSeen)
|
||||
TextView lastSeen;
|
||||
|
||||
@BindView(R.id.isOnline)
|
||||
TextView isOnline;
|
||||
|
||||
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ public interface CoordinateService {
|
||||
Single<List<Coordinate>> getCoordinatesByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/userTop/{userId}")
|
||||
Single<List<Coordinate>> getTopCoordinatesByUserId(@Path("userId") String userId);
|
||||
Single<Coordinate> getTopCoordinatesByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/top")
|
||||
Single<List<Coordinate>> getTopCoordinates();
|
||||
|
@ -23,7 +23,7 @@
|
||||
android:textSize="15sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lastName"
|
||||
android:id="@+id/lastSeen"
|
||||
android:layout_width="270dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginStart="12dp"
|
||||
@ -32,8 +32,8 @@
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginEnd="0dp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:textColor="@color/note_list_text"
|
||||
android:textSize="15sp" />
|
||||
android:textColor="#979797"
|
||||
android:textSize="11sp" />
|
||||
|
||||
|
||||
<TextView
|
||||
|
Loading…
Reference in New Issue
Block a user