Skip to content

Commit

Permalink
Merge pull request #208 from angrezichatterbox/bugfix/keyboard-langua…
Browse files Browse the repository at this point in the history
…ge-recycler-view-size-increase

bugfix/Auto increase size of the select keyboard recycler view on page change
  • Loading branch information
andrewtavis authored Oct 18, 2024
2 parents 43ec2d7 + 955e547 commit 09a169b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private var englishKeyboardIME: EnglishKeyboardIME? = null

fun getEnglishKeyboardIME(): EnglishKeyboardIME? = englishKeyboardIME

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.displayOptions = androidx.appcompat.app.ActionBar.DISPLAY_SHOW_CUSTOM
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/be/scri/fragments/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ class AboutFragment : Fragment() {
),
)

private fun getSecondRecyclerViewData(): List<Any> {
val context = requireContext()
return listOf(
private fun getSecondRecyclerViewData(): List<Any> =
listOf(
ItemsViewModel(
image = R.drawable.star,
text = ItemsViewModel.Text(R.string.app_about_feedback_rate_scribe),
Expand Down Expand Up @@ -177,7 +176,6 @@ class AboutFragment : Fragment() {
action = ::resetHints,
),
)
}

private fun getThirdRecyclerViewData(): List<ItemsViewModel> =
listOf(
Expand Down
29 changes: 19 additions & 10 deletions app/src/main/java/be/scri/fragments/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import be.scri.R
import be.scri.activities.MainActivity
import be.scri.databinding.FragmentSettingsBinding
Expand All @@ -30,6 +31,7 @@ import be.scri.models.TextItem

class SettingsFragment : Fragment() {
private lateinit var binding: FragmentSettingsBinding
private var isDecorationSet: Boolean = false

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -141,24 +143,31 @@ class SettingsFragment : Fragment() {
setupItemVisibility()
}
}

val recyclerView = binding.recyclerView2
val adapter = CustomAdapter(getRecyclerViewElements(), requireContext())
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.adapter = adapter
recyclerView.suppressLayout(true)
recyclerView.apply {
val itemDecoration =
CustomDividerItemDecoration(
drawable = getDrawable(requireContext(), R.drawable.rv_divider)!!,
width = 1,
marginLeft = 50,
marginRight = 50,
)
addItemDecoration(itemDecoration)

if (!isDecorationSet) {
isDecorationSet = true
recyclerView.apply {
addCustomItemDecoration()
}
}
}

private fun RecyclerView.addCustomItemDecoration() {
val itemDecoration =
CustomDividerItemDecoration(
drawable = getDrawable(requireContext(), R.drawable.rv_divider)!!,
width = 1,
marginLeft = 50,
marginRight = 50,
)
addItemDecoration(itemDecoration)
}

private fun getRecyclerViewElements(): MutableList<TextItem> {
val languages = setupKeyboardLanguage()
val list = mutableListOf<TextItem>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CustomDividerItemDecoration(
val right = parent.width - parent.paddingRight - marginRight

val childCount = parent.childCount
for (i in 0 until childCount - 1) { // Exclude the last item
for (i in 0 until childCount - 1) {
val child = parent.getChildAt(i)
val params = child.layoutParams as RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/res/drawable/rv_divider.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="1dp" />
<corners android:radius="10dp" />
<solid android:color="@color/rv_divider" />
</shape>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1023dp"
android:height="1dp"
android:viewportWidth="1023"
android:viewportHeight="1">
<path
android:pathData="M0,0h1023v1h-1023z"
android:fillColor="@color/rv_divider"
android:fillAlpha="0.5"/>
</vector>

0 comments on commit 09a169b

Please sign in to comment.