|
|
|
|
@ -7,12 +7,14 @@ import android.view.ViewGroup |
|
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import com.google.android.material.chip.ChipGroup |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_custom_view.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.realm.CustomField |
|
|
|
|
import net.pokeranalytics.android.model.realm.CustomFieldEntry |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.ChipGroupExtension |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.px |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetFragment |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
@ -22,6 +24,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow |
|
|
|
|
import net.pokeranalytics.android.util.NULL_TEXT |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Custom EditableDataFragment to manage the Transaction data |
|
|
|
|
@ -35,7 +38,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val oldRows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
|
|
private val currentEntriesOrder: ArrayList<CustomFieldEntry> = ArrayList() |
|
|
|
|
|
|
|
|
|
private val itemTouchHelper = ItemTouchHelper(object : ItemTouchHelper.Callback() { |
|
|
|
|
|
|
|
|
|
@ -54,6 +57,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { |
|
|
|
|
|
|
|
|
|
if (target.adapterPosition <= 2) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
@ -147,7 +151,7 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
is CustomFieldEntry -> { |
|
|
|
|
val data = customField.editDescriptors(row) |
|
|
|
|
Timber.d("data: $data") |
|
|
|
|
BottomSheetFragment.create(fragmentManager, row, this, data, false) |
|
|
|
|
BottomSheetFragment.create(fragmentManager, row, this, data, isClearable = false, isDeletable = true) |
|
|
|
|
} |
|
|
|
|
else -> super.onRowSelected(position, row, fromAction) |
|
|
|
|
} |
|
|
|
|
@ -158,16 +162,26 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
when (row) { |
|
|
|
|
is CustomFieldEntry -> { |
|
|
|
|
row.value = value as String? ?: "" |
|
|
|
|
rowRepresentableAdapter.refreshRow(row) |
|
|
|
|
customField.updateRowRepresentation() |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
CustomFieldRow.TYPE -> { |
|
|
|
|
customField.updateValue(value, row) |
|
|
|
|
updateUI() |
|
|
|
|
updateAdapterUI() |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
else -> super.onRowValueChanged(value, row) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowDeleted(row: RowRepresentable) { |
|
|
|
|
super.onRowDeleted(row) |
|
|
|
|
when (row) { |
|
|
|
|
is CustomFieldEntry -> { |
|
|
|
|
customField.deleteEntry(row) |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -178,15 +192,50 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
bottomBar.translationY = 72f.px |
|
|
|
|
bottomBar.visibility = View.VISIBLE |
|
|
|
|
|
|
|
|
|
if (customField.sortCondition == CustomField.Sort.DEFAULT.uniqueIdentifier) { |
|
|
|
|
itemTouchHelper.attachToRecyclerView(recyclerView) |
|
|
|
|
} else { |
|
|
|
|
itemTouchHelper.attachToRecyclerView(null) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
when(customField.sortCondition) { |
|
|
|
|
CustomField.Sort.DEFAULT.uniqueIdentifier -> sortDefault.isChecked = true |
|
|
|
|
CustomField.Sort.ASCENDING.uniqueIdentifier -> sortAscending.isChecked = true |
|
|
|
|
CustomField.Sort.DESCENDING.uniqueIdentifier -> sortDescending.isChecked = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
addItem.setOnClickListener { |
|
|
|
|
customField.addEntry() |
|
|
|
|
updateAdapterUI() |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sortChoices.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
|
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) { |
|
|
|
|
super.onCheckedChanged(group, checkedId) |
|
|
|
|
|
|
|
|
|
@SuppressWarnings |
|
|
|
|
if (checkedId < 0) { // when unchecked, checkedId returns -1, causing a crash |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
when(checkedId) { |
|
|
|
|
R.id.sortDefault -> customField.sortCondition = CustomField.Sort.DEFAULT.uniqueIdentifier |
|
|
|
|
R.id.sortAscending -> customField.sortCondition = CustomField.Sort.ASCENDING.uniqueIdentifier |
|
|
|
|
R.id.sortDescending -> customField.sortCondition = CustomField.Sort.DESCENDING.uniqueIdentifier |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (customField.sortCondition == CustomField.Sort.DEFAULT.uniqueIdentifier) { |
|
|
|
|
itemTouchHelper.attachToRecyclerView(recyclerView) |
|
|
|
|
} else { |
|
|
|
|
itemTouchHelper.attachToRecyclerView(null) |
|
|
|
|
} |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
updateUI() |
|
|
|
|
updateAdapterUI() |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -204,27 +253,4 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update adapter UI |
|
|
|
|
*/ |
|
|
|
|
private fun updateAdapterUI() { |
|
|
|
|
rowRepresentableAdapter.notifyDataSetChanged() |
|
|
|
|
/* |
|
|
|
|
//TODO: Code to animate changes |
|
|
|
|
|
|
|
|
|
// Test: |
|
|
|
|
// not really, i agree with your part about performance but notifyDataSetChanged() does not kill animations, |
|
|
|
|
// to animate using notifyDataSetChanged(), a) call setHasStableIds(true) on your RecyclerView.Adapter object and b) |
|
|
|
|
// override getItemId inside your Adapter to return a unique long value for each row and check it out, the animations do work |
|
|
|
|
|
|
|
|
|
customField.adapterRows()?.let { |
|
|
|
|
val diffResult = DiffUtil.calculateDiff(RowRepresentableDiffCallback(it, oldRows)) |
|
|
|
|
rowRepresentableAdapter.updateRows(diffResult) |
|
|
|
|
|
|
|
|
|
oldRows.clear() |
|
|
|
|
oldRows.addAll(it) |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |