Skip to content

Commit

Permalink
Merge pull request #5543 from Isira-Seneviratne/parcelableArray
Browse files Browse the repository at this point in the history
refactor: Add parcelableArrayList extension
  • Loading branch information
Isira-Seneviratne authored Jan 24, 2024
2 parents f18be5b + 588ef35 commit 75cdfae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/github/libretube/extensions/Bundle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inline fun <reified T : Parcelable> Bundle.parcelable(key: String?): T? {
return BundleCompat.getParcelable(this, key, T::class.java)
}

inline fun <reified T : Parcelable> Bundle.parcelableArrayList(key: String?): ArrayList<T>? {
return BundleCompat.getParcelableArrayList(this, key, T::class.java)
}

inline fun <reified T : Serializable> Bundle.serializable(key: String?): T? {
return getSerializable(this, key, T::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,11 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
}
}

private fun fetchSortOptions(): Array<SelectableOption> {
return resources
.getStringArray(R.array.sortOptions)
private fun fetchSortOptions(): List<SelectableOption> {
return resources.getStringArray(R.array.sortOptions)
.mapIndexed { index, option ->
SelectableOption(isSelected = index == selectedSortOrder, name = option)
}
.toTypedArray()
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.libretube.ui.sheets

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -11,26 +10,22 @@ import androidx.fragment.app.setFragmentResult
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FilterSortSheetBinding
import com.github.libretube.enums.ContentFilter
import com.github.libretube.extensions.parcelableArrayList
import com.github.libretube.obj.SelectableOption

class FilterSortBottomSheet: ExpandedBottomSheet() {

private var _binding: FilterSortSheetBinding? = null
private val binding get() = _binding!!

private lateinit var sortOptions: Array<SelectableOption>
private lateinit var sortOptions: List<SelectableOption>

private var selectedIndex = 0
private var hideWatched = false

override fun onCreate(savedInstanceState: Bundle?) {
sortOptions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
requireArguments().getParcelableArray(IntentData.sortOptions, SelectableOption::class.java)!!
} else {
@Suppress("DEPRECATION")
requireArguments().getParcelableArray(IntentData.sortOptions) as Array<SelectableOption>
}
hideWatched = requireArguments().getBoolean(IntentData.hideWatched)
val arguments = requireArguments()
sortOptions = arguments.parcelableArrayList(IntentData.sortOptions)!!
hideWatched = arguments.getBoolean(IntentData.hideWatched)
super.onCreate(savedInstanceState)
}

Expand All @@ -52,8 +47,7 @@ class FilterSortBottomSheet: ExpandedBottomSheet() {
}

private fun addSortOptions() {
for (i in sortOptions.indices) {
val option = sortOptions.elementAt(i)
sortOptions.forEachIndexed { i, option ->
val rb = createRadioButton(i, option.name)

binding.sortRadioGroup.addView(rb)
Expand Down

0 comments on commit 75cdfae

Please sign in to comment.