Skip to content

Commit

Permalink
fix #965
Browse files Browse the repository at this point in the history
preference file bugfix
'search by plot' bugfix now correctly uses unique name/id
  • Loading branch information
chaneylc committed May 10, 2024
1 parent f99bf47 commit 50b9f20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2703,11 +2703,11 @@ public ObservationModel[] getRepeatedValues(String studyId, String plotId, Strin
return ObservationDao.Companion.getAllRepeatedValues(studyId, plotId, traitDbId);
}

public String getObservationUnitPropertyByPlotId(String column, String plot_id) {
public String getObservationUnitPropertyByPlotId(String uniqueName, String column, String uniqueId) {

open();

return ObservationUnitPropertyDao.Companion.getObservationUnitPropertyByPlotId(column, plot_id);
return ObservationUnitPropertyDao.Companion.getObservationUnitPropertyByUniqueId(uniqueName, column, uniqueId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import android.util.Log
import androidx.preference.PreferenceManager
import com.fieldbook.tracker.database.DataHelper
import com.fieldbook.tracker.database.Migrator.Companion.sObservationUnitPropertyViewName
import com.fieldbook.tracker.database.Migrator.Observation
import com.fieldbook.tracker.database.Migrator.ObservationUnit
import com.fieldbook.tracker.database.Migrator.ObservationUnitAttribute
import com.fieldbook.tracker.database.Migrator.ObservationUnitValue
import com.fieldbook.tracker.database.Migrator.ObservationVariable
import com.fieldbook.tracker.database.Migrator.Study
import com.fieldbook.tracker.database.query
import com.fieldbook.tracker.database.toFirst
Expand All @@ -30,8 +28,8 @@ class ObservationUnitPropertyDao {
// db.query(sObservationUnitPropertyViewName).toTable().toTypedArray()
// }

fun getObservationUnitPropertyByPlotId(column: String, plot_id: String): String = withDatabase { db ->
db.query("ObservationUnitProperty", select = arrayOf(column), where = "plot_id = ?", whereArgs = arrayOf(plot_id))
fun getObservationUnitPropertyByUniqueId(uniqueName: String, column: String, uniqueId: String): String = withDatabase { db ->
db.query(sObservationUnitPropertyViewName, select = arrayOf(column), where = "`${uniqueName}` = ?", whereArgs = arrayOf(uniqueId))
.toFirst()[column].toString()
}?: ""

Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/com/fieldbook/tracker/dialogs/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class SearchDialog extends DialogFragment implements AttributeChooserDialog.OnAttributeSelectedListener, OperatorDialog.OnOperatorClickedListener, SearchAdapter.onEditTextChangedListener, SearchAdapter.onDeleteClickedListener {

@Inject
SharedPreferences ep;

private static final String TAG = "SearchDialog";
private static CollectActivity originActivity;
private SearchAdapter searchAdapter;
private SharedPreferences ep;
private static List<SearchDialogDataModel> dataSet;
public static boolean openResults;
private final onSearchResultsClickedListener onSearchResultsClickedListener;
Expand All @@ -56,8 +63,6 @@ public SearchDialog(CollectActivity activity, onSearchResultsClickedListener onS
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

ep = requireContext().getSharedPreferences(GeneralKeys.SHARED_PREF_FILE_NAME, 0);

AlertDialog.Builder builder = new AlertDialog.Builder(originActivity, R.style.AppAlertDialog);

View customView = getLayoutInflater().inflate(R.layout.dialog_search, null);
Expand Down Expand Up @@ -164,6 +169,8 @@ public void createSearchResultsDialog () {

if (data != null) {

String uniqueName = ep.getString(GeneralKeys.UNIQUE_NAME, "");

//Array to store all the columns to be displayed in the search results dialog
ArrayList<String> columnsList = new ArrayList<>();
columnsList.add(ep.getString(GeneralKeys.PRIMARY_NAME, getString(R.string.search_results_dialog_range)));
Expand Down Expand Up @@ -208,7 +215,7 @@ public void createSearchResultsDialog () {
}
// If column is an attribute
else {
temp.add(originActivity.getDatabase().getObservationUnitPropertyByPlotId(column, searchdata.unique));
temp.add(originActivity.getDatabase().getObservationUnitPropertyByPlotId(uniqueName, column, searchdata.unique));
}
}
traitData.add(temp);
Expand Down

0 comments on commit 50b9f20

Please sign in to comment.