diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 9bc36847..0262cd5a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -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_SELECTED_HOMEPAGE_API import com.lagradost.cloudstream3.utils.resources.ResourcePackManager -import com.lagradost.cloudstream3.utils.resources.ResourcePatchActivity import com.lagradost.nicehttp.Requests import com.lagradost.nicehttp.ResponseParser import kotlinx.android.synthetic.main.activity_main.* @@ -136,16 +135,11 @@ var app = Requests(responseParser = object : ResponseParser { defaultHeaders = mapOf("user-agent" to USER_AGENT) } -class MainActivity : AppCompatActivity(), ColorPickerDialogListener, ResourcePatchActivity { +class MainActivity : AppCompatActivity(), ColorPickerDialogListener { private var resourcePatch: ResourcePatch? = null - override fun getResources(): Resources = resourcePatch ?: super.getResources() - override fun reloadResourcePatch() { - resourcePatch = try { - ResourcePackManager.activePack?.invoke(super.getResources()) - } catch (e: Throwable) { - null - } + override fun getResources(): Resources { + return resourcePatch ?: super.getResources() } companion object { @@ -472,6 +466,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, ResourcePat override fun onCreate(savedInstanceState: Bundle?) { app.initClient(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) + resourcePatch = try { + ResourcePackManager.activePack?.invoke(super.getResources()) + } catch (e: Throwable) { + null + } val errorFile = filesDir.resolve("last_error") var lastError: String? = null diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt index 0d9c819c..5b55a3b3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt @@ -18,7 +18,7 @@ import com.lagradost.cloudstream3.utils.resources.ResourcePatchActivity const val DTAG = "PlayerActivity" -class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity { +class DownloadedPlayerActivity : AppCompatActivity() { override fun dispatchKeyEvent(event: KeyEvent?): Boolean { CommonActivity.dispatchKeyEvent(this, event)?.let { return it @@ -71,6 +71,11 @@ class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity { override fun onCreate(savedInstanceState: Bundle?) { Log.i(DTAG, "onCreate") + resourcePatch = try { + ResourcePackManager.activePack?.invoke(super.getResources()) + } catch (e: Throwable) { + null + } CommonActivity.loadThemes(this) super.onCreate(savedInstanceState) @@ -113,11 +118,4 @@ class DownloadedPlayerActivity : AppCompatActivity(), ResourcePatchActivity { private var resourcePatch: ResourcePatch? = null override fun getResources(): Resources = resourcePatch ?: super.getResources() - override fun reloadResourcePatch() { - resourcePatch = try { - ResourcePackManager.activePack?.invoke(super.getResources()) - } catch (e: Throwable) { - null - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt index b01d900e..61a5b130 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUI.kt @@ -146,7 +146,7 @@ class SettingsUI : PreferenceFragmentCompat() { true, {}) { try { - ResourcePackManager.selectPack(prefValues[it], activity as MainActivity) + ResourcePackManager.selectPack(prefValues[it]) activity?.recreate() } catch (e: Exception) { logError(e) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/resources/MapResourcePatch.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/resources/MapResourcePatch.kt index 732a95cc..e5e885cb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/resources/MapResourcePatch.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/resources/MapResourcePatch.kt @@ -22,7 +22,7 @@ open class MapResourcePatch(private val original: Resources): ResourcePatch(orig mapping.getMappingKA(id, null) ?: super.getLayout(id) override fun getDrawable(id: Int, theme: Theme?): Drawable = - mapping.getMappingKA(id, theme) ?: super.getDrawable(id, theme) + mapping.getMappingKA(id, theme) ?: super.getDrawable(id, theme) @RequiresApi(Build.VERSION_CODES.M) override fun getColorStateList(id: Int, theme: Theme?): ColorStateList = diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/resources/ResourcePackManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/resources/ResourcePackManager.kt index f9d8c31c..6aadfe10 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/resources/ResourcePackManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/resources/ResourcePackManager.kt @@ -7,7 +7,6 @@ import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent -import com.lagradost.cloudstream3.R typealias PatchFactory = (Resources) -> ResourcePatch @@ -38,20 +37,18 @@ object ResourcePackManager { pluginMapping[pluginId]?.forEach { packs.remove(it) 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) } - fun selectPack(packId: String?, activity: ResourcePatchActivity?) { - if (packId == null) activePackId = null - else if (packs.containsKey(packId)) activePackId = packId - else activePackId = null + fun selectPack(packId: String?) { + activePackId = if (packId == null) null + else if (packs.containsKey(packId)) packId + else null Log.d(KEY, "Selecting: ${activePackId ?: "none"}") setKey(SETTINGS_KEY, activePackId) - - activity?.reloadResourcePatch() } @@ -59,8 +56,6 @@ object ResourcePackManager { if (!successful) return activePackId = getKey(SETTINGS_KEY) Log.d(KEY, "Selecting saved: ${activePackId ?: "none"}") - val activity = AcraApplication.context?.getActivity() as? ResourcePatchActivity - activity?.reloadResourcePatch() } } \ No newline at end of file