-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #577 from willowtreeapps/bugfix/edit_phrase_should…
…_not_vertical_scroll #566: Replaces RecyclerView with GridView on edit phrases screen
- Loading branch information
Showing
3 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...m/willowtree/vocable/settings/customcategories/adapter/CustomCategoryPhraseGridAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.willowtree.vocable.settings.customcategories.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import androidx.core.view.isInvisible | ||
import com.willowtree.vocable.R | ||
import com.willowtree.vocable.databinding.EditCustomCategoryPhraseItemBinding | ||
import com.willowtree.vocable.presets.Phrase | ||
import org.koin.core.component.KoinComponent | ||
|
||
class CustomCategoryPhraseGridAdapter( | ||
context: Context, | ||
private var phrases: List<Phrase>, | ||
private val onPhraseEdit: (Phrase) -> Unit, | ||
private val onPhraseDelete: (Phrase) -> Unit | ||
) : | ||
ArrayAdapter<Phrase>( | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters