Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add parcelableArrayList extension #5543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading