Browse Source

Add filter options

master
Apostolos Fanakis 6 years ago
parent
commit
fde2f6df1b
  1. 103
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java
  2. 16
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/dialog_filter_by_calories.xml
  3. 16
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/dialog_filter_by_distance.xml
  4. 27
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/menu/main_filters_popup_menu.xml
  5. 0
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/restaurant_types.xml
  6. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

103
UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/main/MainActivity.java

@ -1,15 +1,22 @@
package gr.auth.databases.flavours.activities.main;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -28,6 +35,8 @@ public class MainActivity extends BaseActivity {
private ViewPager viewPager;
private MenuItem menuMapItem;
private FloatingActionButton FAB;
private ArrayList<Integer> mSelectedRestaurantTypes;
private int maxDistance = -1, maxCalories = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -104,6 +113,100 @@ public class MainActivity extends BaseActivity {
int id = item.getItemId();
if (id == R.id.main_toolbar_menu_filter) {
View menuItemView = findViewById(R.id.main_toolbar_menu_filter);
PopupMenu popupMenu = new PopupMenu(this, menuItemView);
popupMenu.inflate(R.menu.main_filters_popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(getThemedContext());
LayoutInflater inflater = getLayoutInflater();
switch (item.getItemId()) {
case R.id.main_filters_type:
mSelectedRestaurantTypes = new ArrayList<>();
builder.setTitle(R.string.main_filters_menu_type)
.setMultiChoiceItems(R.array.restaurant_type, null,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
mSelectedRestaurantTypes.add(which);
} else if (mSelectedRestaurantTypes.contains(which)) {
// Else, if the item is already in the array, remove it
mSelectedRestaurantTypes.remove(Integer.valueOf(which));
}
}
})
.setPositiveButton(R.string.main_filters_dialog_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//TODO
}
})
.setNegativeButton(R.string.main_filters_dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mSelectedRestaurantTypes.clear();
}
});
builder.create().show();
break;
case R.id.main_filters_distance:
maxDistance = -1;
final View customDistanceDialogView = inflater.inflate(R.layout.dialog_filter_by_distance, null);
builder.setView(customDistanceDialogView)
.setTitle(R.string.main_filters_menu_distance)
.setPositiveButton(R.string.main_filters_dialog_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
String distanceString = ((EditText) customDistanceDialogView
.findViewById(R.id.dialog_filter_distance)).getText().toString();
if (!distanceString.isEmpty()) {
maxDistance = Integer.parseInt(distanceString);
}
}
})
.setNegativeButton(R.string.main_filters_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
maxDistance = -1;
}
});
builder.create().show();
break;
case R.id.main_filters_calories:
maxCalories = -1;
final View customCaloriesDialogView = inflater.inflate(R.layout.dialog_filter_by_calories, null);
builder.setView(customCaloriesDialogView)
.setTitle(R.string.main_filters_menu_calories)
.setPositiveButton(R.string.main_filters_dialog_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
String caloriesString = ((EditText) customCaloriesDialogView
.findViewById(R.id.dialog_filter_calories)).getText().toString();
if (!caloriesString.isEmpty()) {
maxCalories = Integer.parseInt(caloriesString);
}
}
})
.setNegativeButton(R.string.main_filters_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
maxCalories = -1;
}
});
builder.create().show();
break;
case R.id.main_filters_clear:
//TODO
break;
}
return false;
}
});
popupMenu.show();
return true;
} else if (id == R.id.main_toolbar_menu_map) {
if (viewPager.getCurrentItem() == 0) {

16
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/dialog_filter_by_calories.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp">
<EditText
android:id="@+id/dialog_filter_calories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/main_filters_dialog_distance"
android:importantForAutofill="no"
android:inputType="number"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>

16
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/dialog_filter_by_distance.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp">
<EditText
android:id="@+id/dialog_filter_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/main_filters_dialog_distance"
android:importantForAutofill="no"
android:inputType="number"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>

27
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/menu/main_filters_popup_menu.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/main_filters_type"
android:orderInCategory="100"
android:title="@string/main_filters_menu_type"
app:showAsAction="always" />
<item
android:id="@+id/main_filters_distance"
android:orderInCategory="100"
android:title="@string/main_filters_menu_distance"
app:showAsAction="always" />
<item
android:id="@+id/main_filters_calories"
android:orderInCategory="100"
android:title="@string/main_filters_menu_calories"
app:showAsAction="always" />
<item
android:id="@+id/main_filters_clear"
android:orderInCategory="100"
android:title="@string/main_filters_menu_clear"
app:showAsAction="always" />
</menu>

0
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_add_restaurant_spinner_type.xml → UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/restaurant_types.xml

8
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

@ -30,6 +30,14 @@
<string name="main_toolbar_title">Restaurants</string>
<string name="main_toolbar_menu_filter">Filter results</string>
<string name="main_toolbar_menu_map">Show in map</string>
<string name="main_filters_menu_type">Filter by type</string>
<string name="main_filters_menu_distance">Filter by distance</string>
<string name="main_filters_menu_calories">Filter by calories</string>
<string name="main_filters_menu_clear">Clear filters</string>
<string name="main_filters_dialog_positive">Filter</string>
<string name="main_filters_dialog_cancel">Cancel</string>
<string name="main_filters_dialog_distance">Max distance</string>
<string name="main_restaurant_type">Restaurant</string>
<string name="main_bar_type">Bar</string>
<string name="main_cafeteria_type">Cafeteria</string>

Loading…
Cancel
Save