Skip to content

Commit

Permalink
Merge pull request #154 from PhenoApps/toggle-exclusion-state
Browse files Browse the repository at this point in the history
Add preference for toggle exclusion state
  • Loading branch information
trife authored Oct 24, 2024
2 parents e37d73c + 3880efd commit b5860b1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,33 @@ public DisplayModel getDisplayModel() {

@Override
public void toggle(@Nullable final ElementModel elementModel) {
if (this.joinedGridModelIsLoaded()) {
final EntriesTable entriesTable =
this.entriesTable();
if (null != entriesTable) {
final EntryModel entryModel =
(EntryModel) elementModel;
if (this.joinedGridModel instanceof
CurrentGridUniqueJoinedGridModel) {
final CurrentGridUniqueJoinedGridModel
currentGridUniqueJoinedGridModel =
(CurrentGridUniqueJoinedGridModel)
this.joinedGridModel;
try {
currentGridUniqueJoinedGridModel.checkThenSetEntryModel(entryModel);//throws
} catch (final
CheckedIncludedEntryModel.CheckException e) {
return;
}
} else this.joinedGridModel.setEntryModel(entryModel);
entriesTable.insertOrUpdate(entryModel);
if (entryModel instanceof ExcludedEntryModel)
if (this.joinedGridModel.getActiveEntryModel() == entryModel)
this.goToNext(entryModel);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
boolean togglePreference = prefs.getBoolean(GeneralKeys.TOGGLE_EXCLUSION_STATE, false);
if (togglePreference) {
if (this.joinedGridModelIsLoaded()) {
final EntriesTable entriesTable =
this.entriesTable();
if (null != entriesTable) {
final EntryModel entryModel =
(EntryModel) elementModel;
if (this.joinedGridModel instanceof
CurrentGridUniqueJoinedGridModel) {
final CurrentGridUniqueJoinedGridModel
currentGridUniqueJoinedGridModel =
(CurrentGridUniqueJoinedGridModel)
this.joinedGridModel;
try {
currentGridUniqueJoinedGridModel.checkThenSetEntryModel(entryModel);//throws
} catch (final
CheckedIncludedEntryModel.CheckException e) {
return;
}
} else this.joinedGridModel.setEntryModel(entryModel);
entriesTable.insertOrUpdate(entryModel);
if (entryModel instanceof ExcludedEntryModel)
if (this.joinedGridModel.getActiveEntryModel() == entryModel)
this.goToNext(entryModel);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.wheatgenetics.coordinate.display.adapter;

import android.content.SharedPreferences;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.preference.PreferenceManager;

import org.wheatgenetics.coordinate.model.ElementModel;
import org.wheatgenetics.coordinate.preference.GeneralKeys;

public abstract class DataViewHolder extends ViewHolder {
// region Fields
Expand Down Expand Up @@ -66,8 +69,12 @@ protected void setElementModelAndImage(@Nullable final ElementModel elementModel

@RestrictTo(RestrictTo.Scope.SUBCLASSES)
protected void toggle() {
this.handler.toggle(this.elementModel);
this.setImage();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itemView.getContext());
boolean togglePreference = prefs.getBoolean(GeneralKeys.TOGGLE_EXCLUSION_STATE, false);
if (togglePreference) {
this.handler.toggle(this.elementModel);
this.setImage();
}
}

// region onClickListener Protected Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GeneralKeys private constructor() {
*/
// Collection Preferences
const val DIRECTION = COORDINATE_PREFIX + "DIRECTION"
const val TOGGLE_EXCLUSION_STATE = COORDINATE_PREFIX + "TOGGLE_EXCLUSION_STATE"
const val UNIQUE_VALUES = COORDINATE_PREFIX + "UNIQUE_VALUES"
const val UNIQUE_OPTIONS = COORDINATE_PREFIX + "UNIQUE_OPTIONS"
// sounds
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/drawable/ic_exclude_cell.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- drawable/close_box_outline.xml --><vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="#000000" android:pathData="M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3M19,19H5V5H19V19M17,8.4L13.4,12L17,15.6L15.6,17L12,13.4L8.4,17L7,15.6L10.6,12L7,8.4L8.4,7L12,10.6L15.6,7L17,8.4Z" /></vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@

<string name="preferences_direction_default">@string/preferences_direction_down_then_across_entry_value</string>

<string name="preferences_toggle_exclusion_state_title">Toggle Exclusion State</string>
<string name="preferences_toggle_exclusion_state_summary">Toggle exclusion state of a cell on long press</string>

<!-- Sounds -->
<string name="preferences_sound_title">Sounds</string>
<string name="preferences_sound_filled_row_or_column_title">Navigation sound</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences_collection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
android:title="@string/preferences_direction_title"
app:useSimpleSummaryProvider="false" />

<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_exclude_cell"
android:key="org.wheatgenetics.coordinate.TOGGLE_EXCLUSION_STATE"
android:title="@string/preferences_toggle_exclusion_state_title"
android:summary="@string/preferences_toggle_exclusion_state_summary"/>

<PreferenceCategory
android:key="category_collection_unique"
android:title="@string/preferences_unique_title"
Expand Down

0 comments on commit b5860b1

Please sign in to comment.