105 lines
3.8 KiB
Kotlin
105 lines
3.8 KiB
Kotlin
package com.lagradost.cloudstream3.ui.settings.testing
|
|
|
|
import android.os.Bundle
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.activityViewModels
|
|
import com.lagradost.cloudstream3.R
|
|
import com.lagradost.cloudstream3.databinding.FragmentTestingBinding
|
|
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
|
import com.lagradost.cloudstream3.mvvm.observe
|
|
import com.lagradost.cloudstream3.mvvm.observeNullable
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
|
|
|
|
|
class TestFragment : Fragment() {
|
|
|
|
private val testViewModel: TestViewModel by activityViewModels()
|
|
var binding: FragmentTestingBinding? = null
|
|
|
|
override fun onDestroyView() {
|
|
binding = null
|
|
super.onDestroyView()
|
|
}
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
setUpToolbar(R.string.category_provider_test)
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
binding?.apply {
|
|
providerTestRecyclerView.adapter = TestResultAdapter(
|
|
mutableListOf()
|
|
)
|
|
|
|
testViewModel.init()
|
|
if (testViewModel.isRunningTest) {
|
|
providerTest.setState(TestView.TestState.Running)
|
|
}
|
|
|
|
observe(testViewModel.providerProgress) { (passed, failed, total) ->
|
|
providerTest.setProgress(passed, failed, total)
|
|
}
|
|
|
|
observeNullable(testViewModel.providerResults) {
|
|
normalSafeApiCall {
|
|
val newItems = it.sortedBy { api -> api.first.name }
|
|
(providerTestRecyclerView.adapter as? TestResultAdapter)?.updateList(
|
|
newItems
|
|
)
|
|
}
|
|
}
|
|
|
|
providerTest.setOnPlayButtonListener { state ->
|
|
when (state) {
|
|
TestView.TestState.Stopped -> testViewModel.stopTest()
|
|
TestView.TestState.Running -> testViewModel.startTest()
|
|
TestView.TestState.None -> testViewModel.startTest()
|
|
}
|
|
}
|
|
|
|
if (isTrueTvSettings()) {
|
|
providerTest.playPauseButton?.isFocusableInTouchMode = true
|
|
providerTest.playPauseButton?.requestFocus()
|
|
}
|
|
|
|
providerTest.playPauseButton?.setOnFocusChangeListener { _, hasFocus ->
|
|
if (hasFocus) {
|
|
providerTestAppbar.setExpanded(true, true)
|
|
}
|
|
}
|
|
|
|
fun focusRecyclerView() {
|
|
// Hack to make it possible to focus the recyclerview.
|
|
if (isTrueTvSettings()) {
|
|
providerTestRecyclerView.requestFocus()
|
|
providerTestAppbar.setExpanded(false, true)
|
|
}
|
|
}
|
|
|
|
providerTest.setOnMainClick {
|
|
testViewModel.setFilterMethod(TestViewModel.ProviderFilter.All)
|
|
focusRecyclerView()
|
|
}
|
|
providerTest.setOnFailedClick {
|
|
testViewModel.setFilterMethod(TestViewModel.ProviderFilter.Failed)
|
|
focusRecyclerView()
|
|
}
|
|
providerTest.setOnPassedClick {
|
|
testViewModel.setFilterMethod(TestViewModel.ProviderFilter.Passed)
|
|
focusRecyclerView()
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onCreateView(
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
savedInstanceState: Bundle?
|
|
): View {
|
|
val localBinding = FragmentTestingBinding.inflate(inflater, container, false)
|
|
binding = localBinding
|
|
return localBinding.root//inflater.inflate(R.layout.fragment_testing, container, false)
|
|
}
|
|
} |