2022-08-06 23:43:39 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.settings.extensions
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2022-08-07 23:03:54 +00:00
|
|
|
import android.view.*
|
|
|
|
import androidx.appcompat.view.menu.MenuBuilder
|
2022-08-06 23:43:39 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
import com.lagradost.cloudstream3.R
|
2022-08-07 21:11:13 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.observe
|
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
2022-08-07 23:03:54 +00:00
|
|
|
import kotlinx.android.synthetic.main.fragment_plugins.*
|
2022-08-06 23:43:39 +00:00
|
|
|
|
|
|
|
const val PLUGINS_BUNDLE_NAME = "name"
|
|
|
|
const val PLUGINS_BUNDLE_URL = "url"
|
|
|
|
|
|
|
|
class PluginsFragment : Fragment() {
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?,
|
|
|
|
): View? {
|
2022-08-07 23:03:54 +00:00
|
|
|
return inflater.inflate(R.layout.fragment_plugins, container, false)
|
2022-08-06 23:43:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-07 21:11:13 +00:00
|
|
|
private val pluginViewModel: PluginsViewModel by activityViewModels()
|
2022-08-06 23:43:39 +00:00
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
|
|
val name = arguments?.getString(PLUGINS_BUNDLE_NAME)
|
|
|
|
val url = arguments?.getString(PLUGINS_BUNDLE_URL)
|
2022-08-07 21:11:13 +00:00
|
|
|
|
2022-08-07 23:03:54 +00:00
|
|
|
if (url == null || name == null) {
|
2022-08-06 23:43:39 +00:00
|
|
|
activity?.onBackPressed()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-07 23:03:54 +00:00
|
|
|
setUpToolbar(name)
|
2022-08-06 23:43:39 +00:00
|
|
|
|
2022-08-07 23:03:54 +00:00
|
|
|
settings_toolbar?.setOnMenuItemClickListener { menuItem ->
|
|
|
|
when (menuItem?.itemId) {
|
|
|
|
R.id.download_all -> {
|
2022-08-09 02:53:24 +00:00
|
|
|
PluginsViewModel.downloadAll(activity, url, pluginViewModel)
|
2022-08-07 23:03:54 +00:00
|
|
|
}
|
|
|
|
else -> {}
|
|
|
|
}
|
|
|
|
return@setOnMenuItemClickListener true
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin_recycler_view?.adapter =
|
2022-08-07 21:11:13 +00:00
|
|
|
PluginAdapter {
|
|
|
|
pluginViewModel.handlePluginAction(activity, url, it)
|
2022-08-06 23:43:39 +00:00
|
|
|
}
|
2022-08-07 21:11:13 +00:00
|
|
|
|
|
|
|
observe(pluginViewModel.plugins) {
|
2022-08-07 23:03:54 +00:00
|
|
|
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(it)
|
2022-08-06 23:43:39 +00:00
|
|
|
}
|
2022-08-07 21:11:13 +00:00
|
|
|
|
|
|
|
pluginViewModel.updatePluginList(url)
|
2022-08-06 23:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
fun newInstance(name: String, url: String): Bundle {
|
|
|
|
return Bundle().apply {
|
|
|
|
putString(PLUGINS_BUNDLE_NAME, name)
|
|
|
|
putString(PLUGINS_BUNDLE_URL, url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|