mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-29 10:41:03 +00:00
feat: extension testing
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package ani.dantotsu.parsers
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import ani.dantotsu.BottomSheetDialogFragment
|
||||
import ani.dantotsu.databinding.BottomSheetExtensionTestSettingsBinding
|
||||
import ani.dantotsu.parsers.novel.NovelExtensionManager
|
||||
import com.xwray.groupie.GroupieAdapter
|
||||
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
|
||||
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class ExtensionTestSettingsBottomDialog : BottomSheetDialogFragment() {
|
||||
private var _binding: BottomSheetExtensionTestSettingsBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
private val adapter: GroupieAdapter = GroupieAdapter()
|
||||
private val animeExtension: AnimeExtensionManager = Injekt.get()
|
||||
private val mangaExtensions: MangaExtensionManager = Injekt.get()
|
||||
private val novelExtensions: NovelExtensionManager = Injekt.get()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = BottomSheetExtensionTestSettingsBinding.inflate(inflater, container, false)
|
||||
return _binding?.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.extensionSelectionRecyclerView.adapter = adapter
|
||||
binding.extensionSelectionRecyclerView.layoutManager = LinearLayoutManager(
|
||||
context,
|
||||
LinearLayoutManager.VERTICAL,
|
||||
false
|
||||
)
|
||||
binding.animeRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
extensionType = "anime"
|
||||
extensionsToTest.clear()
|
||||
setupAdapter()
|
||||
}
|
||||
}
|
||||
binding.mangaRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
extensionType = "manga"
|
||||
extensionsToTest.clear()
|
||||
setupAdapter()
|
||||
}
|
||||
}
|
||||
binding.novelsRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
extensionType = "novel"
|
||||
extensionsToTest.clear()
|
||||
setupAdapter()
|
||||
}
|
||||
}
|
||||
binding.pingRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
testType = "ping"
|
||||
}
|
||||
}
|
||||
binding.basicRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
testType = "basic"
|
||||
}
|
||||
}
|
||||
binding.fullRadioButton.setOnCheckedChangeListener { _, b ->
|
||||
if (b) {
|
||||
testType = "full"
|
||||
}
|
||||
}
|
||||
setupAdapter()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
_binding = null
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
private fun setupAdapter() {
|
||||
val namesAndUrls: Map<String,Drawable?> = when (extensionType) {
|
||||
"anime" -> animeExtension.installedExtensionsFlow.value.associate { it.name to it.icon }
|
||||
"manga" -> mangaExtensions.installedExtensionsFlow.value.associate { it.name to it.icon }
|
||||
"novel" -> novelExtensions.installedExtensionsFlow.value.associate { it.name to it.icon }
|
||||
else -> emptyMap()
|
||||
}
|
||||
adapter.clear()
|
||||
namesAndUrls.forEach { (name, icon) ->
|
||||
val isSelected = extensionsToTest.contains(name)
|
||||
adapter.add(ExtensionSelectItem(name, icon, isSelected, ::selectedCallback))
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectedCallback(name: String, isSelected: Boolean) {
|
||||
if (isSelected) {
|
||||
extensionsToTest.add(name)
|
||||
} else {
|
||||
extensionsToTest.remove(name)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(): ExtensionTestSettingsBottomDialog {
|
||||
return ExtensionTestSettingsBottomDialog()
|
||||
}
|
||||
|
||||
var extensionType = "anime"
|
||||
var testType = "ping"
|
||||
var extensionsToTest: MutableList<String> = mutableListOf()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user