mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
improve extension ui, add setting button for plugins
This commit is contained in:
parent
bb18433e93
commit
416d2b67b9
6 changed files with 95 additions and 11 deletions
|
@ -56,6 +56,14 @@ abstract class Plugin {
|
||||||
@JsonProperty("requiresResources") var requiresResources: Boolean = false
|
@JsonProperty("requiresResources") var requiresResources: Boolean = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will contain your resources if you specified requiresResources in gradle
|
||||||
|
*/
|
||||||
var resources: Resources? = null
|
var resources: Resources? = null
|
||||||
var __filename: String? = null
|
var __filename: String? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will add a button in the settings allowing you to add custom settings
|
||||||
|
*/
|
||||||
|
var openSettings: (() -> Unit)? = null
|
||||||
}
|
}
|
|
@ -101,6 +101,10 @@ object PluginManager {
|
||||||
private val plugins: MutableMap<String, Plugin> =
|
private val plugins: MutableMap<String, Plugin> =
|
||||||
LinkedHashMap<String, Plugin>()
|
LinkedHashMap<String, Plugin>()
|
||||||
|
|
||||||
|
// Maps urls to plugin
|
||||||
|
val urlPlugins: MutableMap<String, Plugin> =
|
||||||
|
LinkedHashMap<String, Plugin>()
|
||||||
|
|
||||||
private val classLoaders: MutableMap<PathClassLoader, Plugin> =
|
private val classLoaders: MutableMap<PathClassLoader, Plugin> =
|
||||||
HashMap<PathClassLoader, Plugin>()
|
HashMap<PathClassLoader, Plugin>()
|
||||||
|
|
||||||
|
@ -266,6 +270,9 @@ object PluginManager {
|
||||||
}
|
}
|
||||||
plugins[filePath] = pluginInstance
|
plugins[filePath] = pluginInstance
|
||||||
classLoaders[loader] = pluginInstance
|
classLoaders[loader] = pluginInstance
|
||||||
|
if (data.url != null) { // TODO: make this cleaner
|
||||||
|
urlPlugins[data.url] = pluginInstance
|
||||||
|
}
|
||||||
pluginInstance.load(activity)
|
pluginInstance.load(activity)
|
||||||
Log.i(TAG, "Loaded plugin ${data.internalName} successfully")
|
Log.i(TAG, "Loaded plugin ${data.internalName} successfully")
|
||||||
true
|
true
|
||||||
|
@ -280,9 +287,9 @@ object PluginManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun unloadPlugin(absolutePath: String) {
|
private fun unloadPlugin(absolutePath: String) {
|
||||||
Log.i(TAG, "Unloading plugin: $absolutePath")
|
Log.i(TAG, "Unloading plugin: $absolutePath")
|
||||||
var plugin = plugins.get(absolutePath)
|
val plugin = plugins[absolutePath]
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
Log.w(TAG, "Couldn't find plugin $absolutePath")
|
Log.w(TAG, "Couldn't find plugin $absolutePath")
|
||||||
return
|
return
|
||||||
|
|
|
@ -63,8 +63,8 @@ data class SitePlugin(
|
||||||
@JsonProperty("repositoryUrl") val repositoryUrl: String?,
|
@JsonProperty("repositoryUrl") val repositoryUrl: String?,
|
||||||
// These types are yet to be mapped and used, ignore for now
|
// These types are yet to be mapped and used, ignore for now
|
||||||
// @JsonProperty("tvTypes") val tvTypes: List<String>?,
|
// @JsonProperty("tvTypes") val tvTypes: List<String>?,
|
||||||
// @JsonProperty("language") val language: String?,
|
@JsonProperty("language") val language: String?,
|
||||||
// @JsonProperty("iconUrl") val iconUrl: String?,
|
@JsonProperty("iconUrl") val iconUrl: String?,
|
||||||
// Set to true to get an 18+ symbol next to the plugin
|
// Set to true to get an 18+ symbol next to the plugin
|
||||||
@JsonProperty("adult") val adult: Boolean?,
|
@JsonProperty("adult") val adult: Boolean?,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.lagradost.cloudstream3.ui.settings.extensions
|
package com.lagradost.cloudstream3.ui.settings.extensions
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -8,6 +9,8 @@ import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
|
import com.lagradost.cloudstream3.PROVIDER_STATUS_DOWN
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.plugins.PluginManager
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||||
import kotlinx.android.synthetic.main.repository_item.view.*
|
import kotlinx.android.synthetic.main.repository_item.view.*
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,6 +83,29 @@ class PluginAdapter(
|
||||||
iconClickCallback.invoke(data.plugin)
|
iconClickCallback.invoke(data.plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.isDownloaded) {
|
||||||
|
val plugin = PluginManager.urlPlugins[metadata.url]
|
||||||
|
if (plugin?.openSettings != null) {
|
||||||
|
itemView.action_settings?.isVisible = true
|
||||||
|
itemView.action_settings.setOnClickListener {
|
||||||
|
try {
|
||||||
|
plugin.openSettings!!.invoke()
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
Log.e("PluginAdapter", "Failed to open ${metadata.name} settings: ${Log.getStackTraceString(e)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata.iconUrl == null ||
|
||||||
|
itemView.entry_icon?.setImage(metadata.iconUrl, null) != true) {
|
||||||
|
itemView.entry_icon?.setImageResource(R.drawable.ic_baseline_extension_24)
|
||||||
|
}
|
||||||
|
|
||||||
|
itemView.ext_version?.isVisible = true
|
||||||
|
itemView.ext_version?.text = "v${metadata.version}"
|
||||||
|
|
||||||
itemView.main_text?.text = metadata.name
|
itemView.main_text?.text = metadata.name
|
||||||
itemView.sub_text?.text = metadata.description
|
itemView.sub_text?.text = metadata.description
|
||||||
}
|
}
|
||||||
|
|
5
app/src/main/res/drawable/ic_baseline_extension_24.xml
Normal file
5
app/src/main/res/drawable/ic_baseline_extension_24.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M20.5,11H19V7c0,-1.1 -0.9,-2 -2,-2h-4V3.5C13,2.12 11.88,1 10.5,1S8,2.12 8,3.5V5H4c-1.1,0 -1.99,0.9 -1.99,2v3.8H3.5c1.49,0 2.7,1.21 2.7,2.7s-1.21,2.7 -2.7,2.7H2V20c0,1.1 0.9,2 2,2h3.8v-1.5c0,-1.49 1.21,-2.7 2.7,-2.7 1.49,0 2.7,1.21 2.7,2.7V22H17c1.1,0 2,-0.9 2,-2v-4h1.5c1.38,0 2.5,-1.12 2.5,-2.5S21.88,11 20.5,11z"/>
|
||||||
|
</vector>
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/repository_item_root"
|
android:id="@+id/repository_item_root"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -7,12 +8,26 @@
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="20dp">
|
android:padding="20dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/entry_icon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
app:srcCompat="@drawable/ic_github_logo" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/main_text"
|
android:id="@+id/main_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -20,6 +35,19 @@
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
tools:text="Test repository" />
|
tools:text="Test repository" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ext_version"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:text="v1"
|
||||||
|
android:textColor="@color/colorPrimaryGrey"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/sub_text"
|
android:id="@+id/sub_text"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -39,11 +67,21 @@
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/action_button"
|
android:id="@+id/action_settings"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:srcCompat="@drawable/ic_baseline_tune_24"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/action_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical|end"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
tools:src="@drawable/ic_baseline_add_24" />
|
tools:src="@drawable/ic_baseline_add_24" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in a new issue