Skip to content

Commit

Permalink
Merge pull request #1121 from PhenoApps/add_trial_chip_to_study_list_…
Browse files Browse the repository at this point in the history
…items

add_trial_chip_to_study_list_items
  • Loading branch information
trife authored Dec 13, 2024
2 parents c5be51d + cac82c0 commit 54f1b13
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FieldDetailFragment : Fragment(), FieldSyncController {
private lateinit var sortOrderChip: Chip
private lateinit var traitCountChip: Chip
private lateinit var observationCountChip: Chip
private lateinit var trialNameChip: Chip
private lateinit var detailRecyclerView: RecyclerView
private var adapter: FieldDetailAdapter? = null

Expand All @@ -99,6 +100,7 @@ class FieldDetailFragment : Fragment(), FieldSyncController {
traitCountChip = rootView.findViewById(R.id.traitCountChip)
observationCountChip = rootView.findViewById(R.id.observationCountChip)
detailRecyclerView = rootView.findViewById(R.id.fieldDetailRecyclerView)
trialNameChip = rootView.findViewById(R.id.trialNameChip)

fieldId = arguments?.getInt("fieldId")
loadFieldDetails()
Expand Down Expand Up @@ -278,6 +280,12 @@ class FieldDetailFragment : Fragment(), FieldSyncController {
}
}
entryCount = "${entryCount} ${field.observation_level}"

trialNameChip.visibility = View.GONE
trialNameChip.text = field.trial_name
if (trialNameChip.text.isNotBlank()) {
trialNameChip.visibility = View.VISIBLE
}
}

// val sortOrder = field.exp_sort.takeIf { !it.isNullOrBlank() } ?: getString(R.string.field_default_sort_order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ class BrapiStudyImportActivity : ThemedActivity(), CoroutineScope by MainScope()
override fun getLocation(id: String): String {
return cacheModels.studies.firstOrNull { it.study.studyDbId == id }?.study?.locationName ?: ""
}

override fun getTrialName(id: String): String {
return cacheModels.studies.firstOrNull { it.study.studyDbId == id }?.study?.trialName ?: ""
}
})

(studyList.adapter as StudyAdapter).submitList(studyModels)
Expand Down Expand Up @@ -647,6 +651,7 @@ class BrapiStudyImportActivity : ThemedActivity(), CoroutineScope by MainScope()
details.studyName = study.studyName
details.commonCropName = study.commonCropName
details.numberOfPlots = units.size
details.trialName = study.trialName

details.traits = observationVariables[study.studyDbId]?.toList()
?.map { it.toTraitObject(this@BrapiStudyImportActivity) } ?: listOf()
Expand Down Expand Up @@ -679,7 +684,7 @@ class BrapiStudyImportActivity : ThemedActivity(), CoroutineScope by MainScope()
level,
primaryId,
secondaryId,
sortOrder
sortOrder,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class StudyAdapter(private val studyLoader: StudyLoader) :
fun getObservationUnits(id: String, position: Int): HashSet<BrAPIObservationUnit>?
fun getGermplasm(id: String, position: Int): HashSet<BrAPIGermplasm>?
fun getLocation(id: String): String
fun getTrialName(id: String): String
}

data class Model(
Expand All @@ -47,11 +48,17 @@ class StudyAdapter(private val studyLoader: StudyLoader) :
holder.traitCountChip.text = studyLoader.getObservationVariables(id, position)?.size?.toString() ?: "0"
holder.unitCountChip.text = studyLoader.getObservationUnits(id, position)?.size?.toString() ?: ""
holder.locationChip.text = studyLoader.getLocation(id)

holder.trialChip.text = studyLoader.getTrialName(id)
if (holder.traitCountChip.text.isNotBlank()
&& holder.unitCountChip.text.isNotBlank()) {
holder.progressBar.visibility = View.GONE
}

if (holder.trialChip.text.isNotBlank()) {
holder.trialChip.visibility = View.VISIBLE
} else {
holder.trialChip.visibility = View.GONE
}
}
}

Expand All @@ -65,6 +72,7 @@ class StudyAdapter(private val studyLoader: StudyLoader) :
var traitCountChip: Chip = v.findViewById(R.id.list_item_study_traits_chip)
var locationChip: Chip = v.findViewById(R.id.list_item_study_location_chip)
var progressBar: ProgressBar = v.findViewById(R.id.list_item_study_pb)
var trialChip: Chip = v.findViewById(R.id.list_item_trial_chip)
}

class DiffCallback : DiffUtil.ItemCallback<Model>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class BrapiStudyDetails {
private List<List<String>> values;
private List<TraitObject> traits;
private List<Observation> observations;
private String trialName;

public static void merge(BrapiStudyDetails sd1, BrapiStudyDetails sd2) {
if (sd2.getStudyDbId() != null)
Expand All @@ -37,6 +38,8 @@ public static void merge(BrapiStudyDetails sd1, BrapiStudyDetails sd2) {
sd1.setTraits(sd2.getTraits());
if (sd2.getObservations() != null)
sd1.setObservations(sd2.getObservations());
if (sd2.getTrialName() != null)
sd1.setTrialName(sd2.getTrialName());
}

public String getCommonCropName() {
Expand Down Expand Up @@ -115,4 +118,11 @@ public void setValues(List<List<String>> values) {

public void setObservations(List<Observation> observations) { this.observations = observations; }

public String getTrialName() {
return trialName;
}

public void setTrialName(String trialName) {
this.trialName = trialName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ public BrapiControllerResponse saveStudyDetails(BrapiStudyDetails studyDetails,
field.setCount(studyDetails.getNumberOfPlots().toString());
field.setObservation_level(observationLevel);
field.setImport_format(ImportFormat.BRAPI);

field.setTrial_name(studyDetails.getTrialName());
// Get our host url
if (BrAPIService.getHostUrl(context) != null) {
field.setExp_source(BrAPIService.getHostUrl(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class StudyDao {
it.attribute_count = this["attribute_count"]?.toString()
it.trait_count = this["trait_count"]?.toString()
it.observation_count = this["observation_count"]?.toString()
it.trial_name = this["trial_name"]?.toString()
}

fun getAllFieldObjects(sortOrder: String): ArrayList<FieldObject> = withDatabase { db ->
Expand Down Expand Up @@ -235,6 +236,7 @@ class StudyDao {
import_format,
study_source,
study_sort_name,
trial_name,
count,
(SELECT COUNT(*) FROM observation_units_attributes WHERE study_id = Studies.${Study.PK}) AS attribute_count,
(SELECT COUNT(DISTINCT observation_variable_name) FROM observations WHERE study_id = Studies.${Study.PK} AND observation_variable_db_id > 0) AS trait_count,
Expand Down Expand Up @@ -359,6 +361,7 @@ class StudyDao {
put("study_source", e.exp_source)
put("count", e.count)
put("observation_levels", e.observation_level)
put("trial_name", e.trial_name)
}).toInt()

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public class FieldObject {
private String attribute_count;
private String trait_count;
private String observation_count;
private String trial_name;

public String getTrial_name() {
return trial_name;
}

public void setTrial_name(String trial_name) {
this.trial_name = trial_name;
}

public static class TraitDetail {
private final String traitName;
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_trial.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M12 2C11.5 2 11 2.19 10.59 2.59L7.29 5.88L12 10.58L16.71 5.88L13.41 2.59C13 2.19 12.5 2 12 2M5.88 7.29L2.59 10.59C1.8 11.37 1.8 12.63 2.59 13.41L5.88 16.71L10.58 12L5.88 7.29M18.12 7.29L13.42 12L18.12 16.71L21.41 13.41C22.2 12.63 22.2 11.37 21.41 10.59L18.12 7.29M12 13.42L7.29 18.12L10.59 21.41C11.37 22.2 12.63 22.2 13.41 21.41L16.71 18.12L12 13.42Z" />
</vector>
15 changes: 15 additions & 0 deletions app/src/main/res/layout/fragment_field_detail.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/WHITE"
Expand Down Expand Up @@ -141,6 +142,20 @@
app:closeIconVisible="false"
app:chipBackgroundColor="?attr/defaultChipBackground" />

<com.google.android.material.chip.Chip
tools:visibility="visible"
android:visibility="gone"
android:id="@+id/trialNameChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
app:chipIcon="@drawable/ic_trial"
app:chipIconSize="24dp"
app:ensureMinTouchTargetSize="false"
app:closeIconVisible="false"
app:chipBackgroundColor="?attr/defaultChipBackground" />

<com.google.android.material.chip.Chip
android:id="@+id/originalNameChip"
android:layout_width="wrap_content"
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/res/layout/list_item_study.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
android:layout_margin="16dp"
app:chipIcon="@drawable/ic_dots_grid"
android:checkable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/list_item_study_title_tv"
Expand All @@ -58,7 +57,6 @@
android:layout_margin="16dp"
app:chipIcon="@drawable/ic_ruler"
android:checkable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/list_item_study_units_chip"
app:layout_constraintTop_toBottomOf="@id/list_item_study_title_tv"
Expand All @@ -72,12 +70,25 @@
android:layout_margin="16dp"
app:chipIcon="@drawable/map_marker_outline"
android:checkable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/list_item_study_traits_chip"
app:layout_constraintTop_toBottomOf="@id/list_item_study_title_tv"
app:layout_constraintEnd_toStartOf="@id/list_item_study_pb"
tools:text="Manhattan, KS" />

<com.google.android.material.chip.Chip
android:id="@+id/list_item_trial_chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:chipIcon="@drawable/ic_trial"
android:checkable="false"
android:ellipsize="end"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/list_item_study_units_chip"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="PeeDee Otter Trial"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>
Expand Down

0 comments on commit 54f1b13

Please sign in to comment.