Skip to content

Commit

Permalink
Merge pull request #10 from WillNilges/will
Browse files Browse the repository at this point in the history
Add the ability to chose how events are filtered
  • Loading branch information
WillNilges authored Mar 15, 2019
2 parents 7974dd4 + 4e1e87f commit ac3e7b5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 25 deletions.
29 changes: 9 additions & 20 deletions app/src/main/java/edu/rit/csh/bettervent/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,33 +348,22 @@ public void run() {
infoPrint("*** Events found. *** " + dataEvents.toString());
String eventKeyword = appSettings.getString("edu.rit.csh.bettervent.filterkeywords", "");
APIOutList = new ArrayList<>();
String eventFieldToCheck;
for (Event event : dataEvents){
infoPrint(event.getSummary());
if (eventKeyword.length() > 0 && event.getSummary() != null){
if (event.getSummary().contains(eventKeyword)){
// infoPrint("Found an invalid event: " + event.getSummary());
if (appSettings.getBoolean("edu.rit.csh.bettervent.filterbytitle", false)){
eventFieldToCheck = event.getSummary();
}else{
eventFieldToCheck = event.getLocation();
}
infoPrint(eventFieldToCheck);
if (eventKeyword.length() > 0 && eventFieldToCheck != null){
if (eventFieldToCheck.contains(eventKeyword)){
APIOutList.add(event);
}
}else if(eventKeyword.length() < 1){
APIOutList.add(event);
}
}
// for (int i = 0; i < dataEvents.size(); i++){
// Event event = dataEvents.get(i);
// infoPrint("Found event: " + event.getSummary());
// String eventKeyword = appSettings.getString("edu.rit.csh.bettervent.filterkeywords", "");
// // Good good this is messy.
// if (eventKeyword.length() > 0 && event.getSummary() != null){
// if (!event.getSummary().contains(eventKeyword)){
//// infoPrint("Found an invalid event: " + event.getSummary());
// dataEvents.remove(event);
// }
// }
// }
// APIOutList = dataEvents;
// Check if a desired keyword is set.
// If it is, Check if a desired keyword is present in an event's title or location.
//If it is not, remove it from the returned events.
isFree();
}
}
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/edu/rit/csh/bettervent/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class SettingsFragment extends Fragment {

Expand All @@ -18,6 +20,11 @@ public class SettingsFragment extends Fragment {

EditText filterKeywords;
String filterKeywordsString = "edu.rit.csh.bettervent.filterkeywords";
RadioGroup filterOptions;
RadioButton filterByTitle;
String filterByTitleString = "edu.rit.csh.bettervent.filterbytitle";
RadioButton filterByLocation;
String filterByLocationString = "edu.rit.csh.bettervent.filterbylocation";
EditText freeColor;
String freeColorString = "edu.rit.csh.bettervent.freecolor";
EditText reservedColor;
Expand All @@ -35,18 +42,30 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
getString(R.string.preference_file_key), Context.MODE_PRIVATE);

filterKeywords = view.findViewById(R.id.filtering_keywords_prompt);
filterOptions = view.findViewById(R.id.filter_options_group);
filterByTitle = view.findViewById(R.id.title_filter_option);
filterByLocation = view.findViewById(R.id.location_filter_option);
freeColor = view.findViewById(R.id.free_color);
reservedColor = view.findViewById(R.id.reserved_color);
password = view.findViewById(R.id.password_prompt);

// Log the current settings and load them into the settings fields.
infoPrint("Keywords: " + appSettings.getString(filterKeywordsString, "") + "\n" +
"Filtering by Title/Location " + appSettings.getBoolean(filterByTitleString, false) + " / " + appSettings.getBoolean(filterByLocationString, false) + "\n" +
"ColorFree: " + appSettings.getString(freeColorString, "") + "\n" +
"ColorReserved: " + appSettings.getString(reservedColorString, "") + "\n" +
"Password: [REDACTED]"
);

filterKeywords.setText(appSettings.getString(filterKeywordsString, ""));
//TODO: Set which radio button is clicked
if (appSettings.getBoolean(filterByTitleString, false)){
filterByTitle.setChecked(true);
filterByLocation.setChecked(false);
}else if (appSettings.getBoolean(filterByLocationString, false)){
filterByTitle.setChecked(false);
filterByLocation.setChecked(true);
}
freeColor.setText(appSettings.getString(freeColorString, ""));
reservedColor.setText(appSettings.getString(reservedColorString, ""));
password.setText(appSettings.getString(passwordString, ""));
Expand All @@ -63,6 +82,23 @@ public void onFocusChange(View v, boolean hasFocus) {
}
});

//TODO: Put radio button code here
filterByTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
appSettings.edit().putBoolean(filterByTitleString, true).apply();
appSettings.edit().putBoolean(filterByLocationString, false).apply();
}
});

filterByLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
appSettings.edit().putBoolean(filterByTitleString, false).apply();
appSettings.edit().putBoolean(filterByLocationString, true).apply();
}
});

(view.findViewById(R.id.free_color)).setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Expand Down
43 changes: 38 additions & 5 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,22 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="@string/enter_keywords_to_only_display_events_that_contain_those_words"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/filtering_keywords_prompt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filter_label" />

<TextView
android:id="@+id/filter_desc3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Filter events based on..."
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filtering_keywords_prompt" />

<TextView
android:id="@+id/escape_square_password_desc"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -111,7 +120,7 @@
android:textColor="@color/black"
android:textSize="40sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filtering_keywords_prompt" />
app:layout_constraintTop_toBottomOf="@+id/filter_options_group" />

<EditText
android:id="@+id/free_color"
Expand Down Expand Up @@ -166,12 +175,12 @@
android:layout_width="556dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="52dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="@string/separate_keywords_with_commas"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/filter_label" />
app:layout_constraintTop_toBottomOf="@+id/filter_desc" />

<EditText
android:id="@+id/password_prompt"
Expand All @@ -184,6 +193,30 @@
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/escape_square_password_desc" />

<RadioGroup
android:id="@+id/filter_options_group"
android:layout_width="319dp"
android:layout_height="61dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/filter_desc3"
tools:layout_editor_absoluteX="9dp">

<RadioButton
android:id="@+id/title_filter_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Title"
android:textSize="16sp" />

<RadioButton
android:id="@+id/location_filter_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Location" />
</RadioGroup>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</ScrollView>
Expand Down

0 comments on commit ac3e7b5

Please sign in to comment.