Merge branch 'change-user-list' of s416084/find-my-tutor-android into develop

This commit is contained in:
Mieszko Wrzeszczyński 2019-01-08 21:29:40 +00:00 committed by Gogs
commit c188ce38a8
7 changed files with 109 additions and 90 deletions

View File

@ -10,7 +10,7 @@ android {
applicationId "com.uam.wmi.findmytutor" applicationId "com.uam.wmi.findmytutor"
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 27 targetSdkVersion 27
versionCode 52 versionCode 53
versionName "1.0.0" versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true

View File

@ -80,9 +80,9 @@ public abstract class BaseActivity
private SharingFragment sharingFragment; private SharingFragment sharingFragment;
private Fragment userListFragment; private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE; public ActiveFragment activeFragment = ActiveFragment.NONE;
private Fragment activeBottomMenu = null; private Fragment activeBottomMenu = null;
private SearchView searchView; public SearchView searchView;
public MenuItem infoMenuItem; public MenuItem infoMenuItem;
@SuppressLint("CheckResult") @SuppressLint("CheckResult")

View File

@ -45,12 +45,10 @@ import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.CoordinateService; import com.uam.wmi.findmytutor.service.CoordinateService;
import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService; import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
import com.uam.wmi.findmytutor.utils.EnableSharingDialog; import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
import com.uam.wmi.findmytutor.utils.LocaleUtils;
import com.uam.wmi.findmytutor.utils.ManualLocationUtils; import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
import com.uam.wmi.findmytutor.utils.MapMarker; import com.uam.wmi.findmytutor.utils.MapMarker;
import com.uam.wmi.findmytutor.utils.MapUtils; import com.uam.wmi.findmytutor.utils.MapUtils;
@ -76,12 +74,12 @@ import static com.uam.wmi.findmytutor.utils.Const.mapRefreshInterval;
public class MapActivity extends BaseActivity public class MapActivity extends BaseActivity
implements PermissionsListener, OnMapReadyCallback { implements PermissionsListener, OnMapReadyCallback {
public HashMap<Long, String> markerUserHash = new HashMap<>();
private String tag = getClass().getName(); private String tag = getClass().getName();
private PermissionsManager permissionsManager; private PermissionsManager permissionsManager;
private LocationComponent locationComponent; private LocationComponent locationComponent;
private CoordinateService coordinateService; private CoordinateService coordinateService;
private UserService userService; private UserService userService;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private int mInterval = mapRefreshInterval; private int mInterval = mapRefreshInterval;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
@ -94,7 +92,6 @@ public class MapActivity extends BaseActivity
private Coordinate droppedMarkercoordinate; private Coordinate droppedMarkercoordinate;
private HashMap<String, Coordinate> coordsMap = new HashMap<>(); private HashMap<String, Coordinate> coordsMap = new HashMap<>();
private HashMap<String, MapMarker> markerHash = new HashMap<>(); private HashMap<String, MapMarker> markerHash = new HashMap<>();
public HashMap<Long, String> markerUserHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>(); private Set<String> previousCoordsIds = new HashSet<>();
private ManualLocationUtils manualLocationUtils; private ManualLocationUtils manualLocationUtils;
// Camera Animation params // Camera Animation params
@ -204,13 +201,25 @@ public class MapActivity extends BaseActivity
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
if(cordStatus.equals("")){ if (cordStatus.equals("")) {
status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), getString(R.string.lack_of_status))); status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), getString(R.string.lack_of_status)));
}else{ } else {
status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), cordStatus)); status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), cordStatus));
} }
sharingLevelView.setText(String.format("%s: %s", getResources().getString(R.string.settings_location_level), sharingLevel)); String sharingLevelToRender = sharingLevel;
if (PrefUtils.getLocale(getApplicationContext()).equals("pl")) {
if (sharingLevel.equals(SharingLevel.MANUAL.toString())) {
sharingLevelToRender = getString(R.string.manual_mode);
} else if (sharingLevel.equals(SharingLevel.EXACT.toString())) {
sharingLevelToRender = getString(R.string.exact_mode);
} else if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
sharingLevelToRender = getString(R.string.approx_mode);
}
}
sharingLevelView.setText(String.format("%s: %s", getResources().getString(R.string.settings_location_level), sharingLevelToRender));
final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
alertDialog.show(); alertDialog.show();
@ -238,6 +247,7 @@ public class MapActivity extends BaseActivity
mapboxMap.addOnMapClickListener(e -> { mapboxMap.addOnMapClickListener(e -> {
removeLocationButton.setVisibility(View.GONE); removeLocationButton.setVisibility(View.GONE);
selectLocationButton.setVisibility(View.GONE); selectLocationButton.setVisibility(View.GONE);
restoreMapMarkers();
}); });
} }
@ -595,47 +605,6 @@ public class MapActivity extends BaseActivity
} }
} }
@Override
public void onResume() {
super.onResume();
mapView.onResume();
shouldFetchNewCoords = true;
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
shouldFetchNewCoords = true;
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
shouldFetchNewCoords = false;
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
shouldFetchNewCoords = false;
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
@ -678,11 +647,13 @@ public class MapActivity extends BaseActivity
@Override @Override
public void searchUser(String textToSearch) { public void searchUser(String textToSearch) {
getUserFromApi(textToSearch); getUserFromApi(textToSearch);
Log.e("LOCALE",LocaleUtils.getCurrentLocale());
} }
private void getUserFromApi(String userNameToSearch) { private void getUserFromApi(String userNameToSearch) {
disposable.add( disposable.add(
userService.getAllTutors() userService.getAllOnlineTutors()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.map(tutors -> Stream.of(tutors).filter(t -> .map(tutors -> Stream.of(tutors).filter(t ->
@ -690,6 +661,7 @@ public class MapActivity extends BaseActivity
.subscribeWith(new DisposableSingleObserver<List<User>>() { .subscribeWith(new DisposableSingleObserver<List<User>>() {
@Override @Override
public void onSuccess(List<User> users) { public void onSuccess(List<User> users) {
Log.e("USERS", String.valueOf(users));
filterMarkers(users); filterMarkers(users);
} }
@ -721,7 +693,7 @@ public class MapActivity extends BaseActivity
} }
public void restoreMapMarkers() { public void restoreMapMarkers() {
try {
for (Marker marker : mapboxMap.getMarkers()) { for (Marker marker : mapboxMap.getMarkers()) {
MapMarker markerMap = markerHash.get(markerUserHash.get(marker.getId())); MapMarker markerMap = markerHash.get(markerUserHash.get(marker.getId()));
@ -730,10 +702,56 @@ public class MapActivity extends BaseActivity
} }
mapboxMap.getMarkerViewManager().update(); mapboxMap.getMarkerViewManager().update();
} catch (Exception e) {
Log.e("MAP", String.valueOf(e));
}
} }
public void adjustMapToSearch(Integer zoom) { public void adjustMapToSearch(Integer zoom) {
MapUtils.setZoom(mapboxMap, zoom); MapUtils.setZoom(mapboxMap, zoom);
} }
@Override
public void onResume() {
super.onResume();
mapView.onResume();
shouldFetchNewCoords = true;
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
shouldFetchNewCoords = true;
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
shouldFetchNewCoords = false;
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
shouldFetchNewCoords = false;
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
} }

View File

@ -1,4 +1,5 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
@ -11,11 +12,13 @@ import com.uam.wmi.findmytutor.model.DutyHourViewModel;
import java.util.Calendar; import java.util.Calendar;
@SuppressLint("ValidFragment")
public class TimePickerFragment extends DialogFragment public class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener { implements TimePickerDialog.OnTimeSetListener {
private TextView textView; private TextView textView;
private String field; private String field;
private DutyHourViewModel duty; private DutyHourViewModel duty;
@SuppressLint("ValidFragment")
public TimePickerFragment(TextView view, DutyHourViewModel duty, String field){ public TimePickerFragment(TextView view, DutyHourViewModel duty, String field){
this.textView = view; this.textView = view;
this.duty=duty; this.duty=duty;

View File

@ -24,8 +24,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
@ -39,6 +37,7 @@ import com.uam.wmi.findmytutor.model.User;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.TutorTabApi; import com.uam.wmi.findmytutor.service.TutorTabApi;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.ActiveFragment;
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration; import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener; import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
@ -225,13 +224,16 @@ public class UsersListFragment extends Fragment {
if (((MapActivity) getActivity()).markerUserHash.containsValue(user.getId())) { if (((MapActivity) getActivity()).markerUserHash.containsValue(user.getId())) {
alertDialogBuilderUserInput.setPositiveButton(R.string.show_on_map, (dialog, id) -> { alertDialogBuilderUserInput.setPositiveButton(R.string.show_on_map, (dialog, id) -> {
// User cancelled the dialog // User cancelled the dialog
((MapActivity) getActivity()).activeFragment = ActiveFragment.NONE;
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.hide(usersListFragment); fragmentTransaction.hide(usersListFragment);
fragmentTransaction.commit(); fragmentTransaction.commit();
List<User> list = new ArrayList<User>(); ((MapActivity) getActivity()).searchUser(user.getFirstName());
/* List<User> list = new ArrayList<User>();
list.add(user); list.add(user);
((MapActivity) getActivity()).filterMarkers(list); ((MapActivity) getActivity()).filterMarkers(list);
((MapActivity) getActivity()).updateNavigationBarState(); ((MapActivity) getActivity()).updateNavigationBarState();*/
}); });
} }
alertDialog = alertDialogBuilderUserInput.create(); alertDialog = alertDialogBuilderUserInput.create();
@ -273,27 +275,10 @@ public class UsersListFragment extends Fragment {
disposable.add( disposable.add(
(fetchOnlyOnlineUsers ? (fetchOnlyOnlineUsers ?
userService.getAllActiveTutors() : userService.getAllActiveTutors() :
userService.getAllOfflineTutors()) userService.getAllTutors())
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.map(tutors -> { .map(this::mapUsersToSortedList)
List<User> tutorsList = new ArrayList<>(tutors);
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, this::sortByUserName);
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
Collections.sort(notActiveTutors, this::sortByUserName);
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
public void onSuccess(List<User> users) { public void onSuccess(List<User> users) {
@ -310,6 +295,24 @@ public class UsersListFragment extends Fragment {
})); }));
} }
private List<User> mapUsersToSortedList(List<User> tutors) {
List<User> tutorsList = new ArrayList<>(tutors);
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, this::sortByUserName);
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
Collections.sort(notActiveTutors, this::sortByUserName);
List<User> sortedUserList = new ArrayList<>(onlineTutors);
sortedUserList.addAll(activeNotOnlineTutors);
sortedUserList.addAll(notActiveTutors);
return sortedUserList;
}
private void searchTutorInBackend(String searchString) { private void searchTutorInBackend(String searchString) {
disposable.add( disposable.add(

View File

@ -1,16 +1,13 @@
package com.uam.wmi.findmytutor.utils; package com.uam.wmi.findmytutor.utils;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.PublishSubject;
public class RxSearchObservable { public class RxSearchObservable {
private RxSearchObservable() { private RxSearchObservable() {
// no instance
} }
public static Observable<String> fromView(SearchView searchView) { public static Observable<String> fromView(SearchView searchView) {
@ -30,13 +27,8 @@ public class RxSearchObservable {
subject.onNext(text); subject.onNext(text);
return false; return false;
} }
}); });
return subject; return subject;
} }
} }

View File

@ -441,6 +441,9 @@
"For example, position the FAB to one side of stream of a cards so the FAB wont interfere " "For example, position the FAB to one side of stream of a cards so the FAB wont interfere "
"when a user tries to pick up one of cards.\n\n" "when a user tries to pick up one of cards.\n\n"
</string> </string>
<string name="manual_mode">manualny</string>
<string name="exact_mode">dokładny</string>
<string name="approx_mode">przybliżony</string>
</resources> </resources>