From ec291913428483faaf80c17110e22f284ac3b215 Mon Sep 17 00:00:00 2001 From: Domagalski Date: Fri, 4 Jan 2019 13:58:04 +0100 Subject: [PATCH] tutor tap show on map and status indicator --- .../findmytutor/activity/BaseActivity.java | 5 +- .../wmi/findmytutor/activity/MapActivity.java | 4 +- .../activity/UsersListFragment.java | 74 +++++++++++++++---- app/src/main/res/drawable/trip_orgin.xml | 15 ++++ app/src/main/res/layout/user_list_modal.xml | 60 +++++++-------- app/src/main/res/values-pl/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + 7 files changed, 118 insertions(+), 48 deletions(-) create mode 100644 app/src/main/res/drawable/trip_orgin.xml diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java index 5792051..31d11e0 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/BaseActivity.java @@ -389,11 +389,14 @@ public abstract class BaseActivity if (itemId == R.id.nav_map) { removeFragment(sharingFragment); removeFragment(userListFragment); - activeFragment = ActiveFragment.NONE; + activeFragment = ActiveFragment.NONE; + findViewById(R.id.action_search).setVisibility(View.VISIBLE); } else if (itemId == R.id.nav_profile) { loadUserSettingsFragment(); + findViewById(R.id.action_search).setVisibility(View.GONE); } else if (itemId == R.id.nav_user_list) { loadUserListFragment(); + findViewById(R.id.action_search).setVisibility(View.VISIBLE); } selectBottomNavigationBarItem(itemId); }, 300); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java index e0d4309..1db07e8 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/MapActivity.java @@ -91,7 +91,7 @@ public class MapActivity extends BaseActivity private Coordinate droppedMarkercoordinate; private HashMap coordsMap = new HashMap<>(); private HashMap markerHash = new HashMap<>(); - private HashMap markerUserHash = new HashMap<>(); + public HashMap markerUserHash = new HashMap<>(); private Set previousCoordsIds = new HashSet<>(); private ManualLocationUtils manualLocationUtils; // Camera Animation params @@ -708,7 +708,7 @@ public class MapActivity extends BaseActivity })); } - private void filterMarkers(List users) { + public void filterMarkers(List users) { restoreMapMarkers(); Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.search_marker); diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java index 47e63a3..0abf829 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/UsersListFragment.java @@ -1,6 +1,8 @@ package com.uam.wmi.findmytutor.activity; import android.app.Fragment; +import android.app.FragmentTransaction; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.CoordinatorLayout; @@ -9,6 +11,10 @@ import android.support.v7.app.AlertDialog; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.ImageSpan; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -18,6 +24,8 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -25,7 +33,6 @@ import com.annimon.stream.Stream; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.adapters.TutorsListAdapter; - import com.uam.wmi.findmytutor.model.DutyHourViewModel; import com.uam.wmi.findmytutor.model.TutorTabViewModel; import com.uam.wmi.findmytutor.model.User; @@ -63,6 +70,7 @@ public class UsersListFragment extends Fragment { @BindView(R.id.txt_empty_notes_view) TextView noNotesView; + private SearchView searchView; private UserService userService; private TutorTabApi tutorTabService; private CompositeDisposable disposable = new CompositeDisposable(); @@ -120,14 +128,12 @@ public class UsersListFragment extends Fragment { } - @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); try { menu.findItem(R.id.showOnlineUsersOnly).setChecked(fetchOnlyOnlineUsers); - } - catch(Exception e) { + } catch (Exception e) { Log.e(TAG, "onPrepareOptionsMenu error"); } } @@ -135,13 +141,13 @@ public class UsersListFragment extends Fragment { @Override public boolean onOptionsItemSelected(MenuItem item) { //item.setChecked(fetchOnlyOnlineUsers); - switch (item.getItemId()){ + switch (item.getItemId()) { case R.id.showOnlineUsersOnly: - if(item.isChecked()) { + if (item.isChecked()) { fetchOnlyOnlineUsers = false; item.setChecked(false); - }else{ + } else { item.setChecked(true); fetchOnlyOnlineUsers = true; } @@ -158,7 +164,11 @@ public class UsersListFragment extends Fragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.users_list_menu, menu); menu.getItem(0).setChecked(fetchOnlyOnlineUsers); - super.onCreateOptionsMenu(menu,inflater); + + MenuItem myActionMenuItem = menu.findItem(R.id.action_search); + searchView = (SearchView) myActionMenuItem.getActionView(); + + super.onCreateOptionsMenu(menu, inflater); } public void searchUser(String textToSearch) { @@ -176,6 +186,7 @@ public class UsersListFragment extends Fragment { // User cancelled the dialog }); + TextView userName = view.findViewById(R.id.userName); ListView userDutyHours = view.findViewById(R.id.userDutyHours); TextView userDutyHoursTitle = view.findViewById(R.id.userDutyHoursTitle); @@ -184,8 +195,26 @@ public class UsersListFragment extends Fragment { TextView userEmail = view.findViewById(R.id.userEmail); TextView department = view.findViewById(R.id.userDepartment); - userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); + userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName())); + Drawable image; + if (user.isIsOnline()) { + image = this.getResources().getDrawable(R.drawable.user_list_online); + } else { + image = this.getResources().getDrawable(R.drawable.user_list_offline); + } + + if (!user.isIsActive()) { + image = this.getResources().getDrawable(R.drawable.user_list_off); + } + + Spannable span = new SpannableString(" " + userName.getText()); // or set your text manually + image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); + ImageSpan imageSpan = new ImageSpan(image); + span.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + userName.setText(span); + + UsersListFragment usersListFragment = this; disposable.add( tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId()) .subscribeOn(Schedulers.io()) @@ -193,7 +222,20 @@ public class UsersListFragment extends Fragment { .subscribeWith(new DisposableSingleObserver() { @Override public void onSuccess(TutorTabViewModel tutorTabViewModel) { - final AlertDialog alertDialog = alertDialogBuilderUserInput.create(); + final AlertDialog alertDialog; + if (((MapActivity) getActivity()).markerUserHash.containsValue(user.getId())) { + alertDialogBuilderUserInput.setPositiveButton(R.string.show_on_map, (dialog, id) -> { + // User cancelled the dialog + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.hide(usersListFragment); + fragmentTransaction.commit(); + List list = new ArrayList(); + list.add(user); + ((MapActivity) getActivity()).filterMarkers(list); + }); + } + alertDialog = alertDialogBuilderUserInput.create(); + String userNoteText = tutorTabViewModel.getNote(); List dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours()) .map(DutyHourViewModel::getSummary).toList(); @@ -276,7 +318,7 @@ public class UsersListFragment extends Fragment { private void searchTutorInBackend(String searchString) { disposable.add( - userService.searchUser(searchString) + userService.searchUser(searchString) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableSingleObserver>() { @@ -295,7 +337,7 @@ public class UsersListFragment extends Fragment { } - public void restoreUsersList(){ + public void restoreUsersList() { fetchAllTutors(); } @@ -331,10 +373,10 @@ public class UsersListFragment extends Fragment { createSnackbar(message); } - private void createSnackbar(String msg){ + private void createSnackbar(String msg) { Snackbar snackbar = Snackbar.make(coordinatorLayout, msg, Snackbar.LENGTH_LONG); View view = snackbar.getView(); - CoordinatorLayout.LayoutParams params=(CoordinatorLayout.LayoutParams)view.getLayoutParams(); + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams(); params.gravity = Gravity.TOP; view.setLayoutParams(params); snackbar.show(); @@ -345,9 +387,9 @@ public class UsersListFragment extends Fragment { noNotesView.setVisibility(View.GONE); } else { noNotesView.setVisibility(View.VISIBLE); - if(fetchOnlyOnlineUsers) + if (fetchOnlyOnlineUsers) noNotesView.setText(R.string.no_online_users); - else{ + else { noNotesView.setText(R.string.no_offline_users); } } diff --git a/app/src/main/res/drawable/trip_orgin.xml b/app/src/main/res/drawable/trip_orgin.xml new file mode 100644 index 0000000..110d9dc --- /dev/null +++ b/app/src/main/res/drawable/trip_orgin.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/user_list_modal.xml b/app/src/main/res/layout/user_list_modal.xml index c95e45e..b92f8eb 100644 --- a/app/src/main/res/layout/user_list_modal.xml +++ b/app/src/main/res/layout/user_list_modal.xml @@ -27,17 +27,19 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - + + @@ -158,25 +160,25 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="5dp" + android:orientation="horizontal" + android:paddingLeft="20dp"> - - - + + + diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 4e66421..57c3d0b 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -265,6 +265,10 @@ Błąd sieci! Brak wyników! Nadaj nazwę tej lokalizacji. + Dostępny + Niedostępny + Nieaktywny + POKAŻ NA MAPIE diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5fc583..804cc57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -436,5 +436,9 @@ Network Error ! Search response is empty! Insert a name for this localization. + Online + Offline + Inactive + SHOW ON MAP -- 2.20.1