mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
37e7e1ffdc
3 changed files with 82 additions and 2 deletions
|
@ -1,13 +1,19 @@
|
||||||
package com.lagradost.cloudstream3.plugins
|
package com.lagradost.cloudstream3.plugins
|
||||||
|
|
||||||
|
import android.app.*
|
||||||
import dalvik.system.PathClassLoader
|
import dalvik.system.PathClassLoader
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import android.content.res.AssetManager
|
import android.content.res.AssetManager
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import android.app.Activity
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
|
@ -25,7 +31,9 @@ import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
|
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorApi
|
import com.lagradost.cloudstream3.utils.ExtractorApi
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||||
import com.lagradost.cloudstream3.utils.extractorApis
|
import com.lagradost.cloudstream3.utils.extractorApis
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
@ -38,6 +46,9 @@ import java.util.*
|
||||||
const val PLUGINS_KEY = "PLUGINS_KEY"
|
const val PLUGINS_KEY = "PLUGINS_KEY"
|
||||||
const val PLUGINS_KEY_LOCAL = "PLUGINS_KEY_LOCAL"
|
const val PLUGINS_KEY_LOCAL = "PLUGINS_KEY_LOCAL"
|
||||||
|
|
||||||
|
const val EXTENSIONS_CHANNEL_ID = "cloudstream3.extensions"
|
||||||
|
const val EXTENSIONS_CHANNEL_NAME = "Extensions"
|
||||||
|
const val EXTENSIONS_CHANNEL_DESCRIPT = "Extension notification channel"
|
||||||
|
|
||||||
// Data class for internal storage
|
// Data class for internal storage
|
||||||
data class PluginData(
|
data class PluginData(
|
||||||
|
@ -78,6 +89,8 @@ object PluginManager {
|
||||||
|
|
||||||
const val TAG = "PluginManager"
|
const val TAG = "PluginManager"
|
||||||
|
|
||||||
|
private var hasCreatedNotChanel = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store data about the plugin for fetching later
|
* Store data about the plugin for fetching later
|
||||||
* */
|
* */
|
||||||
|
@ -220,8 +233,11 @@ object PluginManager {
|
||||||
"Outdated plugins: ${outdatedPlugins.filter { it.isOutdated }}"
|
"Outdated plugins: ${outdatedPlugins.filter { it.isOutdated }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val updatedPlugins = mutableListOf<String>()
|
||||||
|
|
||||||
outdatedPlugins.apmap { pluginData ->
|
outdatedPlugins.apmap { pluginData ->
|
||||||
if (pluginData.isDisabled) {
|
if (pluginData.isDisabled) {
|
||||||
|
//updatedPlugins.add(activity.getString(R.string.single_plugin_disabled, pluginData.onlineData.second.name))
|
||||||
unloadPlugin(pluginData.savedData.filePath)
|
unloadPlugin(pluginData.savedData.filePath)
|
||||||
} else if (pluginData.isOutdated) {
|
} else if (pluginData.isOutdated) {
|
||||||
downloadAndLoadPlugin(
|
downloadAndLoadPlugin(
|
||||||
|
@ -229,10 +245,17 @@ object PluginManager {
|
||||||
pluginData.onlineData.second.url,
|
pluginData.onlineData.second.url,
|
||||||
pluginData.savedData.internalName,
|
pluginData.savedData.internalName,
|
||||||
pluginData.onlineData.first
|
pluginData.onlineData.first
|
||||||
)
|
).let { success ->
|
||||||
|
if (success)
|
||||||
|
updatedPlugins.add(pluginData.onlineData.second.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
createNotification(activity, updatedPlugins)
|
||||||
|
}
|
||||||
|
|
||||||
ioSafe {
|
ioSafe {
|
||||||
afterPluginsLoadedEvent.invoke(true)
|
afterPluginsLoadedEvent.invoke(true)
|
||||||
}
|
}
|
||||||
|
@ -438,4 +461,59 @@ object PluginManager {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Context.createNotificationChannel() {
|
||||||
|
hasCreatedNotChanel = true
|
||||||
|
// Create the NotificationChannel, but only on API 26+ because
|
||||||
|
// the NotificationChannel class is new and not in the support library
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val name = EXTENSIONS_CHANNEL_NAME //getString(R.string.channel_name)
|
||||||
|
val descriptionText = EXTENSIONS_CHANNEL_DESCRIPT//getString(R.string.channel_description)
|
||||||
|
val importance = NotificationManager.IMPORTANCE_LOW
|
||||||
|
val channel = NotificationChannel(EXTENSIONS_CHANNEL_ID, name, importance).apply {
|
||||||
|
description = descriptionText
|
||||||
|
}
|
||||||
|
// Register the channel with the system
|
||||||
|
val notificationManager: NotificationManager =
|
||||||
|
this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
notificationManager.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private fun createNotification(
|
||||||
|
context: Context,
|
||||||
|
extensionNames: List<String>
|
||||||
|
): Notification? {
|
||||||
|
try {
|
||||||
|
if (extensionNames.isEmpty()) return null
|
||||||
|
|
||||||
|
val content = extensionNames.joinToString(", ")
|
||||||
|
// main { // DON'T WANT TO SLOW IT DOWN
|
||||||
|
val builder = NotificationCompat.Builder(context, EXTENSIONS_CHANNEL_ID)
|
||||||
|
.setAutoCancel(false)
|
||||||
|
.setColorized(true)
|
||||||
|
.setOnlyAlertOnce(true)
|
||||||
|
.setSilent(true)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||||
|
.setColor(context.colorFromAttribute(R.attr.colorPrimary))
|
||||||
|
.setContentTitle(context.getString(R.string.plugins_updated, extensionNames.size))
|
||||||
|
.setSmallIcon(R.drawable.ic_baseline_extension_24)
|
||||||
|
.setStyle(NotificationCompat.BigTextStyle()
|
||||||
|
.bigText(content))
|
||||||
|
.setContentText(content)
|
||||||
|
|
||||||
|
if (!hasCreatedNotChanel) {
|
||||||
|
context.createNotificationChannel()
|
||||||
|
}
|
||||||
|
|
||||||
|
val notification = builder.build()
|
||||||
|
with(NotificationManagerCompat.from(context)) {
|
||||||
|
// notificationId is a unique int for each notification that you must define
|
||||||
|
notify((System.currentTimeMillis()/1000).toInt(), notification)
|
||||||
|
}
|
||||||
|
return notification
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError(e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -455,4 +455,5 @@
|
||||||
<string name="extension_types">Wspierane</string>
|
<string name="extension_types">Wspierane</string>
|
||||||
<string name="extension_language">Język</string>
|
<string name="extension_language">Język</string>
|
||||||
<string name="extension_install_first">Najpierw zainstaluj rozszerzenie</string>
|
<string name="extension_install_first">Najpierw zainstaluj rozszerzenie</string>
|
||||||
|
<string name="plugins_updated">Zaaktualizowano %d rozszerzeń</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -600,6 +600,7 @@
|
||||||
<string name="plugins_downloaded" formatted="true">Downloaded: %d</string>
|
<string name="plugins_downloaded" formatted="true">Downloaded: %d</string>
|
||||||
<string name="plugins_disabled" formatted="true">Disabled: %d</string>
|
<string name="plugins_disabled" formatted="true">Disabled: %d</string>
|
||||||
<string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string>
|
<string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string>
|
||||||
|
<string name="plugins_updated" formatted="true">Updated %d plugins</string>
|
||||||
<string name="blank_repo_message">Add a repository to install site extensions</string>
|
<string name="blank_repo_message">Add a repository to install site extensions</string>
|
||||||
<string name="view_public_repositories_button">View community repositories</string>
|
<string name="view_public_repositories_button">View community repositories</string>
|
||||||
<string name="view_public_repositories_button_short">Public list</string>
|
<string name="view_public_repositories_button_short">Public list</string>
|
||||||
|
|
Loading…
Reference in a new issue