Skip to content

Commit

Permalink
Saving before merging new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio2uofa committed Nov 9, 2023
1 parent 1ef3b11 commit ab0e686
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.househomey.filter.model;

import com.example.househomey.Item;
import com.google.android.material.chip.Chip;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;

/**
Expand All @@ -17,7 +19,12 @@ public class KeywordFilter extends Filter{
*
* @param keyWords The keywords to filter by.
*/
public KeywordFilter(ArrayList<String> keyWords) {this.keyWords = keyWords;}
public KeywordFilter(ArrayList<String> keyWords) {
this.keyWords = new ArrayList<>();
for (String keyword : keyWords) {
this.keyWords.add(keyword.toLowerCase(Locale.ENGLISH));
}
}

/**
* Filters the passed in list of items, retaining only those items that match the
Expand All @@ -29,7 +36,7 @@ public class KeywordFilter extends Filter{
@Override
public ArrayList<Item> filterList(ArrayList<Item> itemList) {
return itemList.stream()
.filter(item -> Arrays.stream(item.getDescription()
.filter(item -> Arrays.stream(item.getDescription().toLowerCase(Locale.ENGLISH)
.split(" ")).anyMatch(keyWords::contains))
.collect(Collectors.toCollection(ArrayList::new));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.example.househomey.filter.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.househomey.R;
import com.example.househomey.filter.model.FilterCallback;
import com.example.househomey.filter.model.KeywordFilter;
import com.example.househomey.filter.model.MakeFilter;
import com.google.android.material.chip.Chip;
import com.google.android.material.chip.ChipGroup;

Expand All @@ -18,8 +18,25 @@
* Fragment for applying "Keyword" filter criteria.
*/
public class KeywordFilterFragment extends FilterFragment {
private ChipGroup chipGroup = contentView.findViewById(R.id.chip_group_labels);
private ArrayList<String> chipTextVals;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.err.println("Created");
if (savedInstanceState != null) {
chipTextVals = savedInstanceState.getStringArrayList("chipTextValues");
} else {
chipTextVals = new ArrayList<>();
}
}

ArrayList<String> chipValues = new ArrayList<>();
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
System.err.println("Saved");
savedInstanceState.putStringArrayList("chipTextValues", chipTextVals);
}

/**
* Constructs a new KeywordFilterFragment.
Expand All @@ -29,24 +46,40 @@ public class KeywordFilterFragment extends FilterFragment {
*/
public KeywordFilterFragment(String title, View contentView, FilterCallback filterCallback) {
super(title, contentView, filterCallback);
Button addButton = contentView.findViewById(R.id.add_keyword_button);
EditText keyWords = contentView.findViewById(R.id.keyword_edit_text);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] keyWordArray = keyWords.getText().toString().split(" ");
if (keyWordArray.length != 0) {
for (String label : keyWordArray) {
Chip chip = new Chip(contentView.getContext());
chip.setText(label);
chipGroup.addView(chip);
chipTextVals.add(chip.getText().toString());
}
}

}
});
}

/**
* Extracts the "Keyword" filter edit text input and applies the filter.
* Extracts the "Keyword" filter values from the chip group.
*/
@Override
public void getFilterInput() {
// TODO: get the filter properties from fragment inputs
ChipGroup chipGroup = contentView.findViewById(R.id.chip_group_labels);
// TODO: get the filter properties from fragment input
for (int i = 0; i < chipGroup.getChildCount(); i++) {
View view = chipGroup.getChildAt(i);
if (view instanceof Chip) {
Chip chip = (Chip) view;
chipValues.add(chip.getText().toString());
chipTextVals.add(chip.getText().toString());
}
}

KeywordFilter keywordFilter = new KeywordFilter(chipValues);
KeywordFilter keywordFilter = new KeywordFilter(chipTextVals);
filterCallback.onFilterApplied(keywordFilter);

dismiss();
Expand Down
19 changes: 1 addition & 18 deletions app/src/main/res/layout/fragment_filter_by_keywords.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/filter_dropdown_button"
android:id="@+id/add_keyword_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="30dp"
android:layout_height="30dp"
Expand All @@ -44,23 +44,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleLine="false">

<!-- Example chips, these should be added dynamically based on user input -->
<com.google.android.material.chip.Chip
android:id="@+id/keyword_filter_one"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keyword 1"
app:closeIconVisible="true"/>

<com.google.android.material.chip.Chip
android:id="@+id/keyword_filter_two"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keyword 2"
app:closeIconVisible="true"/>
</com.google.android.material.chip.ChipGroup>

</LinearLayout>

0 comments on commit ab0e686

Please sign in to comment.