Improve user search
This commit is contained in:
parent
d5114a8587
commit
50a427313f
@ -1,6 +1,7 @@
|
|||||||
package com.uam.wmi.findmytutor.activity;
|
package com.uam.wmi.findmytutor.activity;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -19,6 +20,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
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.service.BackgroundLocalizationService;
|
||||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
|
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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;
|
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||||
|
|
||||||
@ -61,7 +70,9 @@ public abstract class BaseActivity
|
|||||||
|
|
||||||
private Fragment userListFragment;
|
private Fragment userListFragment;
|
||||||
private ActiveFragment activeFragment = ActiveFragment.NONE;
|
private ActiveFragment activeFragment = ActiveFragment.NONE;
|
||||||
|
private SearchView searchView;
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -121,6 +132,9 @@ public abstract class BaseActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -241,41 +255,31 @@ public abstract class BaseActivity
|
|||||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
|
|
||||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||||
final SearchView searchView = (SearchView) myActionMenuItem.getActionView();
|
searchView = (SearchView) myActionMenuItem.getActionView();
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String input) {
|
|
||||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
|
||||||
executeUserListSearch(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
RxSearchObservable.fromView(searchView)
|
||||||
}
|
.map(String::toLowerCase)
|
||||||
|
.debounce(300, TimeUnit.MILLISECONDS)
|
||||||
@Override
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
public boolean onQueryTextChange(String input) {
|
.subscribe(this::executeSearch);
|
||||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
|
||||||
executeUserListSearch(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeUserListSearch(String input) {
|
private void executeSearch(String input) {
|
||||||
((UsersListFragment) userListFragment).searchUser(input);
|
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||||
|
((UsersListFragment) userListFragment).searchUser(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||||
|
@ -349,8 +349,6 @@ public class MapActivity extends BaseActivity
|
|||||||
coordinateService.getOnlineCoordinates()
|
coordinateService.getOnlineCoordinates()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.map(tutors -> Stream.of(tutors).
|
|
||||||
filterNot(t -> t.getDisplayMode().equals(SharingLevel.PRESENCE.toString())).toList())
|
|
||||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -362,12 +360,18 @@ public class MapActivity extends BaseActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ArrayList<String> tmp = new ArrayList<>();
|
ArrayList<String> tmp = new ArrayList<>();
|
||||||
|
|
||||||
for (Coordinate coordinate : coordsList) {
|
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<String> currentCoordsIds = new HashSet<>(tmp);
|
Set<String> currentCoordsIds = new HashSet<>(tmp);
|
||||||
if (previousCoordsIds.isEmpty()){
|
if (previousCoordsIds.isEmpty()){
|
||||||
previousCoordsIds.addAll(currentCoordsIds);
|
previousCoordsIds.addAll(currentCoordsIds);
|
||||||
@ -388,7 +392,6 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (Coordinate element : coordsList) {
|
for (Coordinate element : coordsList) {
|
||||||
String id = element.getUserId();
|
String id = element.getUserId();
|
||||||
String newLabel = element.getLabel();
|
String newLabel = element.getLabel();
|
||||||
|
@ -9,6 +9,7 @@ import android.support.v7.app.AlertDialog;
|
|||||||
import android.support.v7.widget.DefaultItemAnimator;
|
import android.support.v7.widget.DefaultItemAnimator;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -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<String> fromView(SearchView searchView) {
|
||||||
|
|
||||||
|
final PublishSubject<String> 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user