some fixes

This commit is contained in:
Cloudburst 2022-09-16 20:16:32 +02:00
parent 6baeadf55e
commit c80a8e863e
5 changed files with 21 additions and 29 deletions

View file

@ -84,7 +84,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
import com.lagradost.cloudstream3.utils.resources.ResourcePackManager import com.lagradost.cloudstream3.utils.resources.ResourcePackManager
import com.lagradost.cloudstream3.utils.resources.ResourcePatchActivity
import com.lagradost.nicehttp.Requests import com.lagradost.nicehttp.Requests
import com.lagradost.nicehttp.ResponseParser import com.lagradost.nicehttp.ResponseParser
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -136,16 +135,11 @@ var app = Requests(responseParser = object : ResponseParser {
defaultHeaders = mapOf("user-agent" to USER_AGENT) defaultHeaders = mapOf("user-agent" to USER_AGENT)
} }
class MainActivity : AppCompatActivity(), ColorPickerDialogListener, ResourcePatchActivity { class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
private var resourcePatch: ResourcePatch? = null private var resourcePatch: ResourcePatch? = null
override fun getResources(): Resources = resourcePatch ?: super.getResources() override fun getResources(): Resources {
override fun reloadResourcePatch() { return resourcePatch ?: super.getResources()
resourcePatch = try {
ResourcePackManager.activePack?.invoke(super.getResources())
} catch (e: Throwable) {
null
}
} }
companion object { companion object {
@ -472,6 +466,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, ResourcePat
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
app.initClient(this) app.initClient(this)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
resourcePatch = try {
ResourcePackManager.activePack?.invoke(super.getResources())
} catch (e: Throwable) {
null
}
val errorFile = filesDir.resolve("last_error") val errorFile = filesDir.resolve("last_error")
var lastError: String? = null var lastError: String? = null

View file

@ -18,7 +18,7 @@ import com.lagradost.cloudstream3.utils.resources.ResourcePatchActivity
const val DTAG = "PlayerActivity" const val DTAG = "PlayerActivity"
class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity { class DownloadedPlayerActivity : AppCompatActivity() {
override fun dispatchKeyEvent(event: KeyEvent?): Boolean { override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
CommonActivity.dispatchKeyEvent(this, event)?.let { CommonActivity.dispatchKeyEvent(this, event)?.let {
return it return it
@ -71,6 +71,11 @@ class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
Log.i(DTAG, "onCreate") Log.i(DTAG, "onCreate")
resourcePatch = try {
ResourcePackManager.activePack?.invoke(super.getResources())
} catch (e: Throwable) {
null
}
CommonActivity.loadThemes(this) CommonActivity.loadThemes(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -113,11 +118,4 @@ class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity {
private var resourcePatch: ResourcePatch? = null private var resourcePatch: ResourcePatch? = null
override fun getResources(): Resources = resourcePatch ?: super.getResources() override fun getResources(): Resources = resourcePatch ?: super.getResources()
override fun reloadResourcePatch() {
resourcePatch = try {
ResourcePackManager.activePack?.invoke(super.getResources())
} catch (e: Throwable) {
null
}
}
} }

View file

@ -146,7 +146,7 @@ class SettingsUI : PreferenceFragmentCompat() {
true, true,
{}) { {}) {
try { try {
ResourcePackManager.selectPack(prefValues[it], activity as MainActivity) ResourcePackManager.selectPack(prefValues[it])
activity?.recreate() activity?.recreate()
} catch (e: Exception) { } catch (e: Exception) {
logError(e) logError(e)

View file

@ -22,7 +22,7 @@ open class MapResourcePatch(private val original: Resources): ResourcePatch(orig
mapping.getMappingKA(id, null) ?: super.getLayout(id) mapping.getMappingKA(id, null) ?: super.getLayout(id)
override fun getDrawable(id: Int, theme: Theme?): Drawable = override fun getDrawable(id: Int, theme: Theme?): Drawable =
mapping.getMappingKA(id, theme) ?: super.getDrawable(id, theme) mapping.getMappingKA<Int, Drawable>(id, theme) ?: super.getDrawable(id, theme)
@RequiresApi(Build.VERSION_CODES.M) @RequiresApi(Build.VERSION_CODES.M)
override fun getColorStateList(id: Int, theme: Theme?): ColorStateList = override fun getColorStateList(id: Int, theme: Theme?): ColorStateList =

View file

@ -7,7 +7,6 @@ import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent
import com.lagradost.cloudstream3.R
typealias PatchFactory = (Resources) -> ResourcePatch typealias PatchFactory = (Resources) -> ResourcePatch
@ -38,20 +37,18 @@ object ResourcePackManager {
pluginMapping[pluginId]?.forEach { pluginMapping[pluginId]?.forEach {
packs.remove(it) packs.remove(it)
if (activePackId == it) // if pack is being removed make sure its not set if (activePackId == it) // if pack is being removed make sure its not set
selectPack(null, AcraApplication.context?.getActivity() as? ResourcePatchActivity) selectPack(null)
} }
pluginMapping.remove(pluginId) pluginMapping.remove(pluginId)
} }
fun selectPack(packId: String?, activity: ResourcePatchActivity?) { fun selectPack(packId: String?) {
if (packId == null) activePackId = null activePackId = if (packId == null) null
else if (packs.containsKey(packId)) activePackId = packId else if (packs.containsKey(packId)) packId
else activePackId = null else null
Log.d(KEY, "Selecting: ${activePackId ?: "none"}") Log.d(KEY, "Selecting: ${activePackId ?: "none"}")
setKey(SETTINGS_KEY, activePackId) setKey(SETTINGS_KEY, activePackId)
activity?.reloadResourcePatch()
} }
@ -59,8 +56,6 @@ object ResourcePackManager {
if (!successful) return if (!successful) return
activePackId = getKey(SETTINGS_KEY) activePackId = getKey(SETTINGS_KEY)
Log.d(KEY, "Selecting saved: ${activePackId ?: "none"}") Log.d(KEY, "Selecting saved: ${activePackId ?: "none"}")
val activity = AcraApplication.context?.getActivity() as? ResourcePatchActivity
activity?.reloadResourcePatch()
} }
} }