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 2f4cba0..5c2ff61 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 @@ -1,6 +1,7 @@ package com.uam.wmi.findmytutor.activity; import android.Manifest; +import android.annotation.SuppressLint; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; @@ -19,6 +20,7 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -29,10 +31,17 @@ import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; import com.uam.wmi.findmytutor.utils.ActiveFragment; import com.uam.wmi.findmytutor.utils.PrefUtils; +import com.uam.wmi.findmytutor.utils.RxSearchObservable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; + +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.schedulers.Schedulers; import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus; @@ -61,7 +70,9 @@ public abstract class BaseActivity private Fragment userListFragment; private ActiveFragment activeFragment = ActiveFragment.NONE; + private SearchView searchView; + @SuppressLint("CheckResult") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -121,6 +132,9 @@ public abstract class BaseActivity } + + + } @@ -241,41 +255,31 @@ public abstract class BaseActivity actionBarDrawerToggle.onConfigurationChanged(newConfig); } + @SuppressLint("CheckResult") @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem myActionMenuItem = menu.findItem(R.id.action_search); - final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String input) { - if (activeFragment.equals(ActiveFragment.USER_LIST)) { - executeUserListSearch(input); - } + searchView = (SearchView) myActionMenuItem.getActionView(); - return false; - } - - @Override - - public boolean onQueryTextChange(String input) { - if (activeFragment.equals(ActiveFragment.USER_LIST)) { - executeUserListSearch(input); - } - - return true; - } - - }); + RxSearchObservable.fromView(searchView) + .map(String::toLowerCase) + .debounce(300, TimeUnit.MILLISECONDS) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(this::executeSearch); return true; } - private void executeUserListSearch(String input) { - ((UsersListFragment) userListFragment).searchUser(input); + private void executeSearch(String input) { + if (activeFragment.equals(ActiveFragment.USER_LIST)) { + ((UsersListFragment) userListFragment).searchUser(input); + } } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (actionBarDrawerToggle.onOptionsItemSelected(item)) { 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 9880c1b..d9b67a6 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 @@ -349,8 +349,6 @@ public class MapActivity extends BaseActivity coordinateService.getOnlineCoordinates() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .map(tutors -> Stream.of(tutors). - filterNot(t -> t.getDisplayMode().equals(SharingLevel.PRESENCE.toString())).toList()) .subscribeWith(new DisposableSingleObserver>() { @Override @@ -362,12 +360,18 @@ public class MapActivity extends BaseActivity return; } - ArrayList tmp = new ArrayList<>(); + for (Coordinate coordinate : coordsList) { - tmp.add(coordinate.getUserId()); + Log.e(tag, coordinate.toString()); + if (coordinate.getDisplayMode().equals(SharingLevel.PRESENCE.toString())) { + Log.e(tag, "presence user omitted"); + } else { + tmp.add(coordinate.getUserId()); + } } + Set currentCoordsIds = new HashSet<>(tmp); if (previousCoordsIds.isEmpty()){ previousCoordsIds.addAll(currentCoordsIds); @@ -388,7 +392,6 @@ public class MapActivity extends BaseActivity - for (Coordinate element : coordsList) { String id = element.getUserId(); String newLabel = element.getLabel(); 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 82888b2..c2c8e53 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 @@ -9,6 +9,7 @@ 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.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/RxSearchObservable.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/RxSearchObservable.java new file mode 100644 index 0000000..6fc3b7a --- /dev/null +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/RxSearchObservable.java @@ -0,0 +1,36 @@ +package com.uam.wmi.findmytutor.utils; + + +import android.support.v7.widget.SearchView; + +import io.reactivex.Observable; +import io.reactivex.subjects.PublishSubject; + + +public class RxSearchObservable { + + private RxSearchObservable() { + // no instance + } + + public static Observable fromView(SearchView searchView) { + + final PublishSubject subject = PublishSubject.create(); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + subject.onComplete(); + return false; + } + + @Override + public boolean onQueryTextChange(String text) { + subject.onNext(text); + return false; + } + }); + + return subject; + } +}