From 79517d5031156659fbd1ff8dd2887b919838f961 Mon Sep 17 00:00:00 2001 From: nickreeve Date: Mon, 29 Jul 2024 11:33:09 -0400 Subject: [PATCH] Editing phrases screen: replaces RecyclerView with GridView (working on preventing vertical scrolling) --- .../CustomCategoryPhraseListFragment.kt | 25 ++++---- .../CustomCategoryPhraseGridAdapter.kt | 62 +++++++++++++++++++ .../fragment_custom_category_phrase_list.xml | 2 +- 3 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/com/willowtree/vocable/settings/customcategories/adapter/CustomCategoryPhraseGridAdapter.kt diff --git a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt index 6ea8d4b1..8f5a4bc9 100644 --- a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt +++ b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt @@ -1,11 +1,11 @@ package com.willowtree.vocable.settings.customcategories +import android.os.Build import android.os.Bundle import android.view.View import androidx.core.os.bundleOf import androidx.core.view.isVisible import androidx.navigation.fragment.findNavController -import androidx.recyclerview.widget.GridLayoutManager import com.willowtree.vocable.BaseFragment import com.willowtree.vocable.BindingInflater import com.willowtree.vocable.R @@ -13,8 +13,7 @@ import com.willowtree.vocable.databinding.FragmentCustomCategoryPhraseListBindin import com.willowtree.vocable.presets.Category import com.willowtree.vocable.presets.Phrase import com.willowtree.vocable.settings.EditCategoryPhrasesFragmentDirections -import com.willowtree.vocable.settings.customcategories.adapter.CustomCategoryPhraseAdapter -import com.willowtree.vocable.utils.ItemOffsetDecoration +import com.willowtree.vocable.settings.customcategories.adapter.CustomCategoryPhraseGridAdapter import org.koin.androidx.viewmodel.ext.android.viewModel class CustomCategoryPhraseListFragment : BaseFragment() { @@ -37,7 +36,10 @@ class CustomCategoryPhraseListFragment : BaseFragment - val action = EditCategoryPhrasesFragmentDirections.actionEditCategoryPhrasesFragmentToEditPhrasesKeyboardFragment(phrase) + val action = + EditCategoryPhrasesFragmentDirections.actionEditCategoryPhrasesFragmentToEditPhrasesKeyboardFragment( + phrase + ) if (findNavController().currentDestination?.id == R.id.editCategoryPhrasesFragment) { findNavController().navigate(action) } @@ -63,16 +65,13 @@ class CustomCategoryPhraseListFragment : BaseFragment, + private val onPhraseEdit: (Phrase) -> Unit, + private val onPhraseDelete: (Phrase) -> Unit +) : + ArrayAdapter( + context, + R.layout.edit_custom_category_phrase_item + ), + KoinComponent { + + private lateinit var binding: EditCustomCategoryPhraseItemBinding + + init { + addAll(phrases) + } + + // Linter warns about using ViewHolder for smoother scrolling, but we shouldn't be scrolling here anyway + @SuppressLint("ViewHolder") + override fun getView(position: Int, itemView: View?, parent: ViewGroup): View { + binding = + EditCustomCategoryPhraseItemBinding.inflate(LayoutInflater.from(context), parent, false) + + val listItemView: View = binding.root + + listItemView.isInvisible = true + binding.removeCategoryButton.action = { + onPhraseDelete(phrases[position]) + } + binding.phraseTextButton.action = { + onPhraseEdit(phrases[position]) + } + binding.root.setPaddingRelative( + 0, + context.resources.getDimensionPixelSize(R.dimen.edit_category_phrase_button_margin), + 0, + 0 + ) + binding.phraseTextButton.text = phrases[position].text(context) + parent.post { + with(listItemView) { + isInvisible = false + } + } + return listItemView + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_custom_category_phrase_list.xml b/app/src/main/res/layout/fragment_custom_category_phrase_list.xml index 6ea36e19..f31edb48 100644 --- a/app/src/main/res/layout/fragment_custom_category_phrase_list.xml +++ b/app/src/main/res/layout/fragment_custom_category_phrase_list.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> -