Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grid name saving when editing template optional fields #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import org.wheatgenetics.coordinate.optionalField.NonNullOptionalFields
class FieldsAdapter(private val listener: RequiredFieldsCompleteListener, private val requiredName: String, private val fields: NonNullOptionalFields) :
ListAdapter<BaseOptionalField, RecyclerView.ViewHolder>(DiffCallback()) {

private val values = hashMapOf<String, String>()
// linkedMapOf to preserve the order when doing 'get'
private val values = linkedMapOf<String, String>()

init {
fields.forEach {
Expand Down Expand Up @@ -83,6 +84,8 @@ class FieldsAdapter(private val listener: RequiredFieldsCompleteListener, privat
}
}

fun getAllFieldValues(): Map<String, String> = values.toMap()

class DiffCallback : DiffUtil.ItemCallback<BaseOptionalField>() {

override fun areItemsTheSame(oldItem: BaseOptionalField, newItem: BaseOptionalField): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.widget.*
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.core.view.children
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -38,6 +40,8 @@ class GridCreatorTemplateFields : Fragment(R.layout.fragment_grid_creator_fields
private var mProjectsTable: ProjectsTable? = null
private var mEntriesTable: EntriesTable? = null

private lateinit var fieldsAdapter: FieldsAdapter

private val mTemplate: TemplateModel? by lazy {
mTemplatesTable?.load()?.find { it.title == args.title }
}
Expand Down Expand Up @@ -169,12 +173,16 @@ class GridCreatorTemplateFields : Fragment(R.layout.fragment_grid_creator_fields

val fields = NonNullOptionalFields(this)

val listView = view?.findViewById<RecyclerView>(R.id.frag_grid_creator_fields_lv)
// val listView = view?.findViewById<RecyclerView>(R.id.frag_grid_creator_fields_lv)

listView?.children?.forEach {
val nameTextView = it.findViewById<TextView>(R.id.list_item_field_tv)
val valueEditText = it.findViewById<EditText>(R.id.list_item_field_et)
fields.add(nameTextView.text.toString(), valueEditText.text.toString(), null)
// listView?.children?.forEach {
// val nameTextView = it.findViewById<TextView>(R.id.list_item_field_tv)
// val valueEditText = it.findViewById<EditText>(R.id.list_item_field_et)
// fields.add(nameTextView.text.toString(), valueEditText.text.toString(), null)
// }

fieldsAdapter.getAllFieldValues().forEach { (name, value) ->
fields.add(name, value, null)
}

return fields
Expand Down Expand Up @@ -233,7 +241,7 @@ class GridCreatorTemplateFields : Fragment(R.layout.fragment_grid_creator_fields
}
}

val adapter = FieldsAdapter(this, requiredName, fields)
fieldsAdapter = FieldsAdapter(this, requiredName, fields)

val listView = view?.findViewById<RecyclerView>(R.id.frag_grid_creator_fields_lv)

Expand All @@ -243,7 +251,7 @@ class GridCreatorTemplateFields : Fragment(R.layout.fragment_grid_creator_fields

listView?.layoutManager = LinearLayoutManager(act)

listView?.adapter = adapter
listView?.adapter = fieldsAdapter

(listView?.adapter as FieldsAdapter).submitList(fields.map { it })

Expand Down