Working search in both map and list view
This commit is contained in:
parent
d74462a66c
commit
28258d8c15
@ -1,37 +1,24 @@
|
||||
package it.danieleverducci.nextcloudmaps.fragments;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CATEGORY;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_CREATED;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_DISTANCE;
|
||||
import static it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter.SORT_BY_TITLE;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -47,7 +34,6 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
|
||||
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private GeofavoriteAdapter geofavoriteAdapter;
|
||||
private List<Geofavorite> geofavorites = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -99,13 +85,6 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
|
||||
}
|
||||
}
|
||||
});
|
||||
mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer<List<Geofavorite>>() {
|
||||
@Override
|
||||
public void onChanged(List<Geofavorite> geofavorites) {
|
||||
GeofavoriteListFragment.this.geofavorites = geofavorites;
|
||||
geofavoriteAdapter.setGeofavoriteList(geofavorites);
|
||||
}
|
||||
});
|
||||
|
||||
// Setup view listeners
|
||||
swipeRefresh = v.findViewById(R.id.swipe_refresh);
|
||||
@ -130,10 +109,10 @@ public class GeofavoriteListFragment extends GeofavoritesFragment implements Sor
|
||||
updateSortingIcon(sortRule);
|
||||
}
|
||||
|
||||
public void onSearch(String query) {
|
||||
geofavoriteAdapter.setGeofavoriteList(
|
||||
(new GeofavoritesFilter(geofavorites)).byText(query)
|
||||
);
|
||||
@Override
|
||||
public void onDatasetChange(List<Geofavorite> items) {
|
||||
// Called when the items are loaded or a filtering happens
|
||||
geofavoriteAdapter.setGeofavoriteList(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -106,15 +106,6 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
|
||||
}
|
||||
}
|
||||
});
|
||||
mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer<List<Geofavorite>>() {
|
||||
@Override
|
||||
public void onChanged(List<Geofavorite> geofavorites) {
|
||||
clearAllMarkers();
|
||||
for(Geofavorite gf : geofavorites)
|
||||
addMarker(gf);
|
||||
map.invalidate();
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
@ -126,6 +117,14 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
|
||||
((MainActivity)requireActivity()).addOnGpsPermissionGrantedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDatasetChange(List<Geofavorite> items) {
|
||||
clearAllMarkers();
|
||||
for(Geofavorite gf : items)
|
||||
addMarker(gf);
|
||||
map.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
@ -139,11 +138,6 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearch(String query) {
|
||||
// TODO: filter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpsPermissionGranted() {
|
||||
showUserPosition();
|
||||
|
@ -31,12 +31,15 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.R;
|
||||
import it.danieleverducci.nextcloudmaps.activity.detail.GeofavoriteDetailActivity;
|
||||
import it.danieleverducci.nextcloudmaps.activity.main.GeofavoritesFragmentViewModel;
|
||||
import it.danieleverducci.nextcloudmaps.activity.main.MainActivity;
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
import it.danieleverducci.nextcloudmaps.utils.GeofavoritesFilter;
|
||||
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
|
||||
|
||||
/**
|
||||
@ -50,6 +53,7 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
private View toolbar;
|
||||
private View homeToolbar;
|
||||
private SearchView searchView;
|
||||
private List<Geofavorite> geofavorites = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -93,11 +97,21 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String query) {
|
||||
onSearch(query);
|
||||
onDatasetChange(
|
||||
(new GeofavoritesFilter(geofavorites)).byText(query)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer<List<Geofavorite>>() {
|
||||
@Override
|
||||
public void onChanged(List<Geofavorite> geofavorites) {
|
||||
GeofavoritesFragment.this.geofavorites = geofavorites;
|
||||
onDatasetChange(geofavorites);
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnCloseListener(() -> {
|
||||
if (toolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(searchView.getQuery())) {
|
||||
updateToolbars(true);
|
||||
@ -131,7 +145,7 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
}
|
||||
|
||||
|
||||
abstract public void onSearch(String query);
|
||||
abstract public void onDatasetChange(List<Geofavorite> items);
|
||||
|
||||
|
||||
protected void openGeofavorite(Geofavorite item) {
|
||||
|
Loading…
Reference in New Issue
Block a user