WIP implementing filtering by category
This commit is contained in:
parent
443e954c66
commit
25f7b05fd0
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||
@ -26,6 +27,10 @@ public class GeofavoritesFragmentViewModel extends ViewModel {
|
||||
mRepo.updateGeofavorites();
|
||||
}
|
||||
|
||||
public LiveData<HashSet<String>> getCategories(){
|
||||
return mRepo.getCategories();
|
||||
}
|
||||
|
||||
public void deleteGeofavorite(Geofavorite geofav) {
|
||||
mRepo.deleteGeofavorite(geofav);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -32,6 +33,8 @@ import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import it.danieleverducci.nextcloudmaps.R;
|
||||
@ -53,7 +56,9 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
private View toolbar;
|
||||
private View homeToolbar;
|
||||
private SearchView searchView;
|
||||
private ImageButton filterButton;
|
||||
private List<Geofavorite> geofavorites = new ArrayList<>();
|
||||
private HashSet<String> categories = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -87,6 +92,8 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
// Setup toolbar/searchbar
|
||||
toolbar = view.findViewById(R.id.toolbar);
|
||||
homeToolbar = view.findViewById(R.id.home_toolbar);
|
||||
filterButton = view.findViewById(R.id.search_filter);
|
||||
filterButton.setOnClickListener(v -> showCategoryFilterDialog());
|
||||
|
||||
searchView = view.findViewById(R.id.search_view);
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@ -111,6 +118,12 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
onDatasetChange(geofavorites);
|
||||
}
|
||||
});
|
||||
mGeofavoritesFragmentViewModel.getCategories().observe(getViewLifecycleOwner(), new Observer<HashSet<String>>() {
|
||||
@Override
|
||||
public void onChanged(HashSet<String> categories) {
|
||||
GeofavoritesFragment.this.categories = categories;
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnCloseListener(() -> {
|
||||
if (toolbar.getVisibility() == VISIBLE && TextUtils.isEmpty(searchView.getQuery())) {
|
||||
@ -205,6 +218,26 @@ public abstract class GeofavoritesFragment extends Fragment {
|
||||
ad.show();
|
||||
}
|
||||
|
||||
private void showCategoryFilterDialog() {
|
||||
if (categories.isEmpty()) {
|
||||
Toast.makeText(requireContext(), R.string.filtering_unavailable, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle(R.string.filtering_dialog_title);
|
||||
String[] categoryNames = categories.toArray(new String[categories.size()]);
|
||||
builder.setItems(categoryNames, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String category = categoryNames[which];
|
||||
Log.d(TAG, "Selected category " + category);
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void updateToolbars(boolean disableSearch) {
|
||||
homeToolbar.setVisibility(disableSearch ? VISIBLE : GONE);
|
||||
toolbar.setVisibility(disableSearch ? GONE : VISIBLE);
|
||||
|
5
app/src/main/res/drawable/ic_filter.xml
Normal file
5
app/src/main/res/drawable/ic_filter.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
|
||||
</vector>
|
6
app/src/main/res/drawable/ic_filter_off.xml
Normal file
6
app/src/main/res/drawable/ic_filter_off.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19.79,5.61C20.3,4.95 19.83,4 19,4H6.83l7.97,7.97L19.79,5.61z"/>
|
||||
<path android:fillColor="@android:color/white" android:pathData="M2.81,2.81L1.39,4.22L10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-2.17l5.78,5.78l1.41,-1.41L2.81,2.81z"/>
|
||||
</vector>
|
@ -71,6 +71,15 @@
|
||||
android:textSize="16sp"
|
||||
android:text="@string/search_in_all"/>
|
||||
|
||||
<!-- Filter button -->
|
||||
<ImageButton
|
||||
android:id="@+id/search_filter"
|
||||
android:layout_width="?android:attr/actionBarSize"
|
||||
android:layout_height="?android:attr/actionBarSize"
|
||||
android:src="@drawable/ic_filter_off"
|
||||
app:tint="@color/inactive"
|
||||
android:background="@color/transparent"/>
|
||||
|
||||
<!-- User badge -->
|
||||
<FrameLayout
|
||||
android:id="@+id/user_badge_container"
|
||||
|
@ -43,6 +43,8 @@
|
||||
<string name="dialog_logout_message">Vuoi cambiare account?</string>
|
||||
<string name="list_geofavorite_deleted">Geosegnalibro eliminato</string>
|
||||
<string name="list_geofavorite_connection_error">Impossibile ottenere la lista dei geosegnalibri</string>
|
||||
<string name="filtering_unavailable">Il filtro per categoria non è disponibile al momento</string>
|
||||
<string name="filtering_dialog_title">Filtra per categoria</string>
|
||||
|
||||
<!-- Sort dialog -->
|
||||
<string name="sort_by">Ordina per</string>
|
||||
|
@ -42,6 +42,8 @@
|
||||
<string name="dialog_logout_message">Do you want to switch account?</string>
|
||||
<string name="list_geofavorite_deleted">Geofavorite deleted</string>
|
||||
<string name="list_geofavorite_connection_error">Unable to obtain geofavorites list</string>
|
||||
<string name="filtering_unavailable">Category filtering is unavailable at the moment</string>
|
||||
<string name="filtering_dialog_title">Filter by category</string>
|
||||
|
||||
<!-- Sort dialog -->
|
||||
<string name="sort_by">Sort by</string>
|
||||
|
Loading…
Reference in New Issue
Block a user