2021-04-30 17:20:15 +00:00
|
|
|
package com.lagradost.cloudstream3
|
|
|
|
|
2021-07-17 21:36:50 +00:00
|
|
|
import android.content.ComponentName
|
2021-07-04 00:59:51 +00:00
|
|
|
import android.content.Intent
|
2021-07-19 13:19:47 +00:00
|
|
|
import android.content.res.ColorStateList
|
2021-09-03 09:13:34 +00:00
|
|
|
import android.content.res.Configuration
|
2021-04-30 17:20:15 +00:00
|
|
|
import android.os.Bundle
|
2022-04-03 15:00:50 +00:00
|
|
|
import android.util.Log
|
2022-01-07 19:27:25 +00:00
|
|
|
import android.view.KeyEvent
|
2022-03-03 11:26:26 +00:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
2022-01-07 19:27:25 +00:00
|
|
|
import android.view.WindowManager
|
2022-09-01 12:13:54 +00:00
|
|
|
import android.widget.Toast
|
2022-03-03 11:26:26 +00:00
|
|
|
import androidx.annotation.IdRes
|
2022-09-01 12:13:54 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog
|
2021-04-30 17:20:15 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2021-09-20 21:11:36 +00:00
|
|
|
import androidx.core.view.isVisible
|
2022-09-17 11:03:41 +00:00
|
|
|
import androidx.fragment.app.FragmentActivity
|
2022-03-03 11:26:26 +00:00
|
|
|
import androidx.navigation.NavController
|
2021-12-12 02:33:17 +00:00
|
|
|
import androidx.navigation.NavDestination
|
2022-03-03 11:26:26 +00:00
|
|
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
|
|
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
|
|
import androidx.navigation.NavOptions
|
2022-04-22 18:53:58 +00:00
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
2021-09-20 21:11:36 +00:00
|
|
|
import androidx.navigation.ui.setupWithNavController
|
2021-08-30 21:42:58 +00:00
|
|
|
import androidx.preference.PreferenceManager
|
2022-07-30 15:43:37 +00:00
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
|
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
2021-09-23 18:08:57 +00:00
|
|
|
import com.google.android.gms.cast.framework.*
|
2021-11-25 22:36:35 +00:00
|
|
|
import com.google.android.material.navigationrail.NavigationRailView
|
2021-08-06 20:55:11 +00:00
|
|
|
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
2022-03-16 15:29:11 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.allProviders
|
2021-07-30 01:14:53 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.apis
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
|
2022-06-02 22:51:41 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.initAll
|
2022-06-17 20:43:42 +00:00
|
|
|
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.loadThemes
|
|
|
|
import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent
|
|
|
|
import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent
|
|
|
|
import com.lagradost.cloudstream3.CommonActivity.onUserLeaveHint
|
2022-04-03 15:00:50 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.CommonActivity.updateLocale
|
2021-09-12 15:57:07 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.logError
|
2022-05-02 16:58:27 +00:00
|
|
|
import com.lagradost.cloudstream3.network.initClient
|
2022-08-20 17:39:04 +00:00
|
|
|
import com.lagradost.cloudstream3.plugins.PluginManager
|
2022-08-21 01:44:49 +00:00
|
|
|
import com.lagradost.cloudstream3.plugins.PluginManager.loadSinglePlugin
|
2021-07-08 19:39:49 +00:00
|
|
|
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
2022-06-07 16:38:24 +00:00
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString
|
2022-08-20 17:39:04 +00:00
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
|
2022-06-07 16:38:24 +00:00
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.inAppAuths
|
2021-09-12 14:10:22 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.APIRepository
|
2021-07-30 01:14:53 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
2022-01-18 14:10:01 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.result.ResultFragment
|
2022-05-05 16:16:41 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
|
2022-02-18 19:54:55 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings
|
2021-10-30 18:14:12 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
2022-08-07 12:14:51 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.settings.SettingsGeneral
|
2022-07-30 01:24:07 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.setup.HAS_DONE_SETUP_KEY
|
2022-08-20 17:39:04 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.setup.SetupFragmentExtensions
|
2021-09-24 22:51:08 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
2022-01-07 19:27:25 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
2022-08-20 17:39:04 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.loadRepository
|
2021-07-30 01:14:53 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
2022-03-04 15:39:56 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup
|
2022-04-03 15:00:50 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
2021-07-17 15:56:26 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
2021-07-17 21:36:50 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.removeKey
|
2022-03-16 15:29:11 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
2022-05-02 21:32:28 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
|
2021-07-17 21:36:50 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setViewPos
|
2022-08-20 17:39:04 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.Event
|
2022-06-16 17:47:48 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.IOnBackPressed
|
2021-08-15 17:38:41 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate
|
2022-02-18 19:54:55 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.changeStatusBarState
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
|
2022-02-05 01:05:13 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.getResourceColor
|
2021-11-12 16:55:54 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
2021-09-23 10:50:10 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
2021-08-24 22:19:15 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
2022-08-07 12:14:51 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
|
2022-08-21 01:44:49 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
2022-05-02 16:58:27 +00:00
|
|
|
import com.lagradost.nicehttp.Requests
|
2022-07-30 15:43:37 +00:00
|
|
|
import com.lagradost.nicehttp.ResponseParser
|
2021-07-30 01:14:53 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_main.*
|
2022-02-04 20:49:35 +00:00
|
|
|
import kotlinx.android.synthetic.main.fragment_result_swipe.*
|
2022-08-23 19:28:42 +00:00
|
|
|
import kotlinx.coroutines.sync.Mutex
|
|
|
|
import kotlinx.coroutines.sync.withLock
|
2022-01-07 19:27:25 +00:00
|
|
|
import java.io.File
|
2022-08-16 22:17:50 +00:00
|
|
|
import java.net.URI
|
2022-09-01 12:13:54 +00:00
|
|
|
import java.nio.charset.Charset
|
2022-08-20 17:39:04 +00:00
|
|
|
import kotlin.reflect.KClass
|
2021-04-30 17:20:15 +00:00
|
|
|
|
2021-08-24 22:19:15 +00:00
|
|
|
|
2021-07-17 21:36:50 +00:00
|
|
|
const val VLC_PACKAGE = "org.videolan.vlc"
|
|
|
|
const val VLC_INTENT_ACTION_RESULT = "org.videolan.vlc.player.result"
|
|
|
|
val VLC_COMPONENT: ComponentName =
|
|
|
|
ComponentName(VLC_PACKAGE, "org.videolan.vlc.gui.video.VideoPlayerActivity")
|
|
|
|
const val VLC_REQUEST_CODE = 42
|
|
|
|
|
|
|
|
const val VLC_EXTRA_POSITION_OUT = "extra_position"
|
|
|
|
const val VLC_EXTRA_DURATION_OUT = "extra_duration"
|
|
|
|
const val VLC_LAST_ID_KEY = "vlc_last_open_id"
|
2022-01-07 19:27:25 +00:00
|
|
|
|
2022-10-08 15:48:46 +00:00
|
|
|
const val WEB_VIDEO_CAST_PACKAGE = "com.instantbits.cast.webvideo"
|
|
|
|
|
|
|
|
|
2021-12-05 16:22:30 +00:00
|
|
|
// Short name for requests client to make it nicer to use
|
2022-07-30 15:43:37 +00:00
|
|
|
|
|
|
|
var app = Requests(responseParser = object : ResponseParser {
|
|
|
|
val mapper: ObjectMapper = jacksonObjectMapper().configure(
|
|
|
|
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
|
|
|
|
override fun <T : Any> parse(text: String, kClass: KClass<T>): T {
|
|
|
|
return mapper.readValue(text, kClass.java)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun <T : Any> parseSafe(text: String, kClass: KClass<T>): T? {
|
|
|
|
return try {
|
|
|
|
mapper.readValue(text, kClass.java)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun writeValueAsString(obj: Any): String {
|
|
|
|
return mapper.writeValueAsString(obj)
|
|
|
|
}
|
|
|
|
}).apply {
|
2022-05-07 11:18:22 +00:00
|
|
|
defaultHeaders = mapOf("user-agent" to USER_AGENT)
|
|
|
|
}
|
2021-06-14 16:58:43 +00:00
|
|
|
|
2021-08-06 20:55:11 +00:00
|
|
|
class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
2022-04-03 15:00:50 +00:00
|
|
|
companion object {
|
|
|
|
const val TAG = "MAINACT"
|
2022-08-23 19:28:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires every time a new batch of plugins have been loaded, no guarantee about how often this is run and on which thread
|
|
|
|
* */
|
2022-08-14 21:34:47 +00:00
|
|
|
val afterPluginsLoadedEvent = Event<Boolean>()
|
2022-08-21 01:44:49 +00:00
|
|
|
val mainPluginsLoadedEvent =
|
|
|
|
Event<Boolean>() // homepage api, used to speed up time to load for homepage
|
2022-08-15 01:31:33 +00:00
|
|
|
val afterRepositoryLoadedEvent = Event<Boolean>()
|
2022-09-17 11:03:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the str has launched an app task (be it successful or not)
|
|
|
|
* @param isWebview does not handle providers and opening download page if true. Can still add repos and login.
|
|
|
|
* */
|
2022-09-22 15:20:26 +00:00
|
|
|
fun handleAppIntentUrl(
|
|
|
|
activity: FragmentActivity?,
|
|
|
|
str: String?,
|
|
|
|
isWebview: Boolean
|
|
|
|
): Boolean =
|
2022-09-17 11:03:41 +00:00
|
|
|
with(activity) {
|
|
|
|
if (str != null && this != null) {
|
|
|
|
if (str.startsWith("https://cs.repo")) {
|
|
|
|
val realUrl = "https://" + str.substringAfter("?")
|
|
|
|
println("Repository url: $realUrl")
|
|
|
|
loadRepository(realUrl)
|
|
|
|
return true
|
|
|
|
} else if (str.contains(appString)) {
|
|
|
|
for (api in OAuth2Apis) {
|
|
|
|
if (str.contains("/${api.redirectUrl}")) {
|
|
|
|
ioSafe {
|
|
|
|
Log.i(TAG, "handleAppIntent $str")
|
|
|
|
val isSuccessful = api.handleRedirect(str)
|
|
|
|
|
|
|
|
if (isSuccessful) {
|
|
|
|
Log.i(TAG, "authenticated ${api.name}")
|
|
|
|
} else {
|
|
|
|
Log.i(TAG, "failed to authenticate ${api.name}")
|
|
|
|
}
|
|
|
|
|
|
|
|
this@with.runOnUiThread {
|
|
|
|
try {
|
|
|
|
showToast(
|
|
|
|
this@with,
|
|
|
|
getString(if (isSuccessful) R.string.authenticated_user else R.string.authenticated_user_fail).format(
|
|
|
|
api.name
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e) // format might fail
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (URI(str).scheme == appStringRepo) {
|
|
|
|
val url = str.replaceFirst(appStringRepo, "https")
|
|
|
|
loadRepository(url)
|
|
|
|
return true
|
2022-09-22 15:20:26 +00:00
|
|
|
} else if (!isWebview) {
|
2022-09-17 11:03:41 +00:00
|
|
|
if (str.startsWith(DOWNLOAD_NAVIGATE_TO)) {
|
|
|
|
this.navigate(R.id.navigation_downloads)
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
for (api in apis) {
|
|
|
|
if (str.startsWith(api.mainUrl)) {
|
|
|
|
loadResult(str, api.name)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-04-03 15:00:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-06 20:55:11 +00:00
|
|
|
override fun onColorSelected(dialogId: Int, color: Int) {
|
|
|
|
onColorSelectedEvent.invoke(Pair(dialogId, color))
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDialogDismissed(dialogId: Int) {
|
|
|
|
onDialogDismissedEvent.invoke(dialogId)
|
|
|
|
}
|
2021-06-10 23:00:22 +00:00
|
|
|
|
2021-09-03 09:13:34 +00:00
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
super.onConfigurationChanged(newConfig)
|
|
|
|
updateLocale() // android fucks me by chaining lang when rotating the phone
|
2022-04-22 18:53:58 +00:00
|
|
|
|
2022-05-05 16:16:41 +00:00
|
|
|
val navHostFragment =
|
|
|
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
2022-04-22 18:53:58 +00:00
|
|
|
navHostFragment.navController.currentDestination?.let { updateNavBar(it) }
|
2021-12-12 02:33:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
private fun updateNavBar(destination: NavDestination) {
|
2021-12-12 02:33:17 +00:00
|
|
|
this.hideKeyboard()
|
|
|
|
|
|
|
|
// Fucks up anime info layout since that has its own layout
|
|
|
|
cast_mini_controller_holder?.isVisible =
|
2022-08-04 22:26:33 +00:00
|
|
|
!listOf(
|
|
|
|
R.id.navigation_results_phone,
|
|
|
|
R.id.navigation_results_tv,
|
|
|
|
R.id.navigation_player
|
|
|
|
).contains(destination.id)
|
2021-12-12 02:33:17 +00:00
|
|
|
|
|
|
|
val isNavVisible = listOf(
|
|
|
|
R.id.navigation_home,
|
|
|
|
R.id.navigation_search,
|
|
|
|
R.id.navigation_downloads,
|
|
|
|
R.id.navigation_settings,
|
2022-05-15 18:38:32 +00:00
|
|
|
R.id.navigation_download_child,
|
|
|
|
R.id.navigation_subtitles,
|
|
|
|
R.id.navigation_chrome_subtitles,
|
|
|
|
R.id.navigation_settings_player,
|
|
|
|
R.id.navigation_settings_updates,
|
|
|
|
R.id.navigation_settings_ui,
|
|
|
|
R.id.navigation_settings_account,
|
2022-08-29 21:20:03 +00:00
|
|
|
R.id.navigation_settings_providers,
|
2022-06-09 13:50:55 +00:00
|
|
|
R.id.navigation_settings_general,
|
2022-08-07 21:11:13 +00:00
|
|
|
R.id.navigation_settings_extensions,
|
|
|
|
R.id.navigation_settings_plugins,
|
2021-12-12 02:33:17 +00:00
|
|
|
).contains(destination.id)
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
val landscape = when (resources.configuration.orientation) {
|
2021-12-12 02:33:17 +00:00
|
|
|
Configuration.ORIENTATION_LANDSCAPE -> {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nav_view?.isVisible = isNavVisible && !landscape
|
|
|
|
nav_rail_view?.isVisible = isNavVisible && landscape
|
2021-09-03 09:13:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 22:36:35 +00:00
|
|
|
//private var mCastSession: CastSession? = null
|
2021-09-30 12:16:23 +00:00
|
|
|
lateinit var mSessionManager: SessionManager
|
|
|
|
private val mSessionManagerListener: SessionManagerListener<Session> by lazy { SessionManagerListenerImpl() }
|
2021-09-23 18:08:57 +00:00
|
|
|
|
|
|
|
private inner class SessionManagerListenerImpl : SessionManagerListener<Session> {
|
|
|
|
override fun onSessionStarting(session: Session) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionStarted(session: Session, sessionId: String) {
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionStartFailed(session: Session, i: Int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionEnding(session: Session) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionResumed(session: Session, wasSuspended: Boolean) {
|
|
|
|
invalidateOptionsMenu()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionResumeFailed(session: Session, i: Int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionSuspended(session: Session, i: Int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionEnded(session: Session, error: Int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSessionResuming(session: Session, s: String) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
2022-08-23 19:28:42 +00:00
|
|
|
afterPluginsLoadedEvent += ::onAllPluginsLoaded
|
2021-09-24 22:51:08 +00:00
|
|
|
try {
|
2021-09-30 12:16:23 +00:00
|
|
|
if (isCastApiAvailable()) {
|
2021-11-25 22:36:35 +00:00
|
|
|
//mCastSession = mSessionManager.currentCastSession
|
2021-09-24 22:51:08 +00:00
|
|
|
mSessionManager.addSessionManagerListener(mSessionManagerListener)
|
|
|
|
}
|
2021-09-30 12:16:23 +00:00
|
|
|
} catch (e: Exception) {
|
2021-09-24 22:51:08 +00:00
|
|
|
logError(e)
|
|
|
|
}
|
2021-09-23 18:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
2021-09-24 22:51:08 +00:00
|
|
|
try {
|
2021-09-30 12:16:23 +00:00
|
|
|
if (isCastApiAvailable()) {
|
2021-09-24 22:51:08 +00:00
|
|
|
mSessionManager.removeSessionManagerListener(mSessionManagerListener)
|
2021-11-25 22:36:35 +00:00
|
|
|
//mCastSession = null
|
2021-09-24 22:51:08 +00:00
|
|
|
}
|
2021-09-30 12:16:23 +00:00
|
|
|
} catch (e: Exception) {
|
2021-09-24 22:51:08 +00:00
|
|
|
logError(e)
|
|
|
|
}
|
2021-09-23 18:08:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 12:18:01 +00:00
|
|
|
|
2021-11-26 23:19:17 +00:00
|
|
|
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
|
2022-01-07 19:27:25 +00:00
|
|
|
CommonActivity.dispatchKeyEvent(this, event)?.let {
|
|
|
|
return it
|
2021-11-27 18:49:51 +00:00
|
|
|
}
|
2021-11-26 23:19:17 +00:00
|
|
|
return super.dispatchKeyEvent(event)
|
|
|
|
}
|
|
|
|
|
2021-10-27 14:54:57 +00:00
|
|
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
2022-01-07 19:27:25 +00:00
|
|
|
CommonActivity.onKeyDown(this, keyCode, event)
|
2021-10-30 18:14:12 +00:00
|
|
|
|
2021-10-27 14:54:57 +00:00
|
|
|
return super.onKeyDown(keyCode, event)
|
|
|
|
}
|
|
|
|
|
2021-05-22 22:25:56 +00:00
|
|
|
|
2021-06-10 23:00:22 +00:00
|
|
|
override fun onUserLeaveHint() {
|
|
|
|
super.onUserLeaveHint()
|
2022-01-07 19:27:25 +00:00
|
|
|
onUserLeaveHint(this)
|
2021-06-10 23:00:22 +00:00
|
|
|
}
|
2021-05-22 22:25:56 +00:00
|
|
|
|
2022-06-16 17:47:48 +00:00
|
|
|
private fun backPressed() {
|
2022-02-05 01:05:13 +00:00
|
|
|
this.window?.navigationBarColor =
|
|
|
|
this.colorFromAttribute(R.attr.primaryGrayBackground)
|
2021-09-02 16:51:13 +00:00
|
|
|
this.updateLocale()
|
2021-05-18 13:43:32 +00:00
|
|
|
super.onBackPressed()
|
2021-09-03 09:13:34 +00:00
|
|
|
this.updateLocale()
|
2021-05-18 13:43:32 +00:00
|
|
|
}
|
2021-04-30 17:20:15 +00:00
|
|
|
|
2022-06-16 17:47:48 +00:00
|
|
|
override fun onBackPressed() {
|
|
|
|
((supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment?)?.childFragmentManager?.primaryNavigationFragment as? IOnBackPressed)?.onBackPressed()
|
|
|
|
?.let { runNormal ->
|
|
|
|
if (runNormal) backPressed()
|
|
|
|
} ?: run {
|
|
|
|
backPressed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-04 00:59:51 +00:00
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
2022-08-16 19:07:49 +00:00
|
|
|
if (requestCode == VLC_REQUEST_CODE) {
|
2021-07-17 21:36:50 +00:00
|
|
|
if (resultCode == RESULT_OK && data != null) {
|
|
|
|
val pos: Long =
|
2022-01-07 19:27:25 +00:00
|
|
|
data.getLongExtra(
|
|
|
|
VLC_EXTRA_POSITION_OUT,
|
|
|
|
-1
|
|
|
|
) //Last position in media when player exited
|
2021-07-17 21:36:50 +00:00
|
|
|
val dur: Long =
|
2022-01-07 19:27:25 +00:00
|
|
|
data.getLongExtra(
|
|
|
|
VLC_EXTRA_DURATION_OUT,
|
|
|
|
-1
|
|
|
|
) //Last position in media when player exited
|
2021-07-17 21:36:50 +00:00
|
|
|
val id = getKey<Int>(VLC_LAST_ID_KEY)
|
2021-07-18 13:02:30 +00:00
|
|
|
println("SET KEY $id at $pos / $dur")
|
2021-07-17 21:36:50 +00:00
|
|
|
if (dur > 0 && pos > 0) {
|
|
|
|
setViewPos(id, pos, dur)
|
|
|
|
}
|
|
|
|
removeKey(VLC_LAST_ID_KEY)
|
2022-01-18 14:10:01 +00:00
|
|
|
ResultFragment.updateUI()
|
2021-07-17 21:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-04 00:59:51 +00:00
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
}
|
|
|
|
|
2021-07-08 17:46:47 +00:00
|
|
|
override fun onDestroy() {
|
|
|
|
val broadcastIntent = Intent()
|
|
|
|
broadcastIntent.action = "restart_service"
|
|
|
|
broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java)
|
|
|
|
this.sendBroadcast(broadcastIntent)
|
2022-08-23 19:28:42 +00:00
|
|
|
afterPluginsLoadedEvent -= ::onAllPluginsLoaded
|
2021-07-08 17:46:47 +00:00
|
|
|
super.onDestroy()
|
|
|
|
}
|
|
|
|
|
2021-07-30 01:14:53 +00:00
|
|
|
override fun onNewIntent(intent: Intent?) {
|
|
|
|
handleAppIntent(intent)
|
|
|
|
super.onNewIntent(intent)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun handleAppIntent(intent: Intent?) {
|
|
|
|
if (intent == null) return
|
|
|
|
val str = intent.dataString
|
2022-01-07 19:27:25 +00:00
|
|
|
loadCache()
|
2022-09-17 11:03:41 +00:00
|
|
|
handleAppIntentUrl(this, str, false)
|
2021-07-30 01:14:53 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 11:26:26 +00:00
|
|
|
private fun NavDestination.matchDestination(@IdRes destId: Int): Boolean =
|
|
|
|
hierarchy.any { it.id == destId }
|
|
|
|
|
|
|
|
private fun onNavDestinationSelected(item: MenuItem, navController: NavController): Boolean {
|
|
|
|
val builder = NavOptions.Builder().setLaunchSingleTop(true).setRestoreState(true)
|
|
|
|
.setEnterAnim(R.anim.enter_anim)
|
|
|
|
.setExitAnim(R.anim.exit_anim)
|
|
|
|
.setPopEnterAnim(R.anim.pop_enter)
|
|
|
|
.setPopExitAnim(R.anim.pop_exit)
|
|
|
|
if (item.order and Menu.CATEGORY_SECONDARY == 0) {
|
|
|
|
builder.setPopUpTo(
|
|
|
|
navController.graph.findStartDestination().id,
|
|
|
|
inclusive = false,
|
|
|
|
saveState = true
|
|
|
|
)
|
|
|
|
}
|
|
|
|
val options = builder.build()
|
|
|
|
return try {
|
|
|
|
navController.navigate(item.itemId, null, options)
|
|
|
|
navController.currentDestination?.matchDestination(item.itemId) == true
|
|
|
|
} catch (e: IllegalArgumentException) {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-23 19:28:42 +00:00
|
|
|
private val pluginsLock = Mutex()
|
|
|
|
private fun onAllPluginsLoaded(success: Boolean = false) {
|
|
|
|
ioSafe {
|
|
|
|
pluginsLock.withLock {
|
|
|
|
// Load cloned sites after plugins have been loaded since clones depend on plugins.
|
|
|
|
try {
|
|
|
|
getKey<Array<SettingsGeneral.CustomSite>>(USER_PROVIDER_API)?.let { list ->
|
|
|
|
list.forEach { custom ->
|
|
|
|
allProviders.firstOrNull { it.javaClass.simpleName == custom.parentJavaClass }
|
|
|
|
?.let {
|
|
|
|
allProviders.add(it.javaClass.newInstance().apply {
|
|
|
|
name = custom.name
|
|
|
|
lang = custom.lang
|
|
|
|
mainUrl = custom.url.trimEnd('/')
|
|
|
|
canBeOverridden = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// it.hashCode() is not enough to make sure they are distinct
|
2022-09-17 11:03:41 +00:00
|
|
|
apis =
|
|
|
|
allProviders.distinctBy { it.lang + it.name + it.mainUrl + it.javaClass.name }
|
2022-08-23 19:28:42 +00:00
|
|
|
APIHolder.apiMap = null
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-30 17:20:15 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2022-08-06 18:27:56 +00:00
|
|
|
app.initClient(this)
|
2022-08-11 17:12:27 +00:00
|
|
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
2022-09-01 12:13:54 +00:00
|
|
|
|
|
|
|
val errorFile = filesDir.resolve("last_error")
|
|
|
|
var lastError: String? = null
|
|
|
|
if (errorFile.exists() && errorFile.isFile) {
|
|
|
|
lastError = errorFile.readText(Charset.defaultCharset())
|
|
|
|
errorFile.delete()
|
|
|
|
}
|
2022-09-17 11:03:41 +00:00
|
|
|
|
2022-08-28 18:32:17 +00:00
|
|
|
val settingsForProvider = SettingsJson()
|
2022-09-17 11:03:41 +00:00
|
|
|
settingsForProvider.enableAdult =
|
|
|
|
settingsManager.getBoolean(getString(R.string.enable_nsfw_on_providers_key), false)
|
2022-08-28 18:32:17 +00:00
|
|
|
|
|
|
|
MainAPI.settingsForProvider = settingsForProvider
|
2022-08-11 17:12:27 +00:00
|
|
|
|
2022-08-14 11:23:06 +00:00
|
|
|
loadThemes(this)
|
|
|
|
updateLocale()
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
try {
|
|
|
|
if (isCastApiAvailable()) {
|
|
|
|
mSessionManager = CastContext.getSharedInstance(this).sessionManager
|
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
|
|
|
|
|
|
|
if (isTvSettings()) {
|
|
|
|
setContentView(R.layout.activity_main_tv)
|
|
|
|
} else {
|
|
|
|
setContentView(R.layout.activity_main)
|
|
|
|
}
|
|
|
|
|
|
|
|
changeStatusBarState(isEmulatorSettings())
|
|
|
|
|
2022-09-01 12:13:54 +00:00
|
|
|
if (lastError == null) {
|
2022-08-23 19:28:42 +00:00
|
|
|
ioSafe {
|
2022-09-01 12:13:54 +00:00
|
|
|
getKey<String>(USER_SELECTED_HOMEPAGE_API)?.let { homeApi ->
|
|
|
|
mainPluginsLoadedEvent.invoke(loadSinglePlugin(this@MainActivity, homeApi))
|
|
|
|
} ?: run {
|
|
|
|
mainPluginsLoadedEvent.invoke(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
ioSafe {
|
2022-09-17 11:03:41 +00:00
|
|
|
if (settingsManager.getBoolean(
|
|
|
|
getString(R.string.auto_update_plugins_key),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
) {
|
2022-09-01 12:13:54 +00:00
|
|
|
PluginManager.updateAllOnlinePluginsAndLoadThem(this@MainActivity)
|
|
|
|
} else {
|
|
|
|
PluginManager.loadAllOnlinePlugins(this@MainActivity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ioSafe {
|
|
|
|
PluginManager.loadAllLocalPlugins(this@MainActivity)
|
2022-08-17 12:26:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-01 12:13:54 +00:00
|
|
|
} else {
|
|
|
|
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
|
|
|
|
builder.setTitle(R.string.safe_mode_title)
|
|
|
|
builder.setMessage(R.string.safe_mode_description)
|
|
|
|
builder.apply {
|
|
|
|
setPositiveButton(R.string.safe_mode_crash_info) { _, _ ->
|
|
|
|
val tbBuilder: AlertDialog.Builder = AlertDialog.Builder(context)
|
|
|
|
tbBuilder.setTitle(R.string.safe_mode_title)
|
|
|
|
tbBuilder.setMessage(lastError)
|
|
|
|
tbBuilder.show()
|
|
|
|
}
|
2022-08-17 12:26:36 +00:00
|
|
|
|
2022-09-01 12:13:54 +00:00
|
|
|
setNegativeButton("Ok") { _, _ -> }
|
2022-08-23 19:28:42 +00:00
|
|
|
}
|
2022-09-01 12:13:54 +00:00
|
|
|
builder.show()
|
2022-08-14 16:13:44 +00:00
|
|
|
}
|
2022-06-16 01:04:24 +00:00
|
|
|
|
2022-09-01 12:13:54 +00:00
|
|
|
|
2022-08-06 18:27:56 +00:00
|
|
|
// ioSafe {
|
|
|
|
// val plugins =
|
|
|
|
// RepositoryParser.getRepoPlugins("https://raw.githubusercontent.com/recloudstream/TestPlugin/master/repo.json")
|
|
|
|
// ?: emptyList()
|
|
|
|
// plugins.map {
|
|
|
|
// println("Load plugin: ${it.name} ${it.url}")
|
|
|
|
// RepositoryParser.loadSiteTemp(applicationContext, it.url, it.name)
|
|
|
|
// }
|
|
|
|
// }
|
2022-05-26 17:04:39 +00:00
|
|
|
|
2021-11-08 18:13:39 +00:00
|
|
|
// init accounts
|
2022-08-14 16:13:44 +00:00
|
|
|
ioSafe {
|
|
|
|
for (api in accountManagers) {
|
|
|
|
api.init()
|
|
|
|
}
|
2022-03-16 15:29:11 +00:00
|
|
|
|
2022-06-07 16:38:24 +00:00
|
|
|
inAppAuths.apmap { api ->
|
|
|
|
try {
|
|
|
|
api.initialize()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-05 16:16:41 +00:00
|
|
|
SearchResultBuilder.updateCache(this)
|
|
|
|
|
2022-08-14 16:13:44 +00:00
|
|
|
ioSafe {
|
|
|
|
initAll()
|
2022-08-14 21:34:47 +00:00
|
|
|
// No duplicates (which can happen by registerMainAPI)
|
|
|
|
apis = allProviders.distinctBy { it }
|
2022-08-07 12:14:51 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 01:14:53 +00:00
|
|
|
// val navView: BottomNavigationView = findViewById(R.id.nav_view)
|
2022-03-04 15:39:56 +00:00
|
|
|
setUpBackup()
|
2022-01-07 19:27:25 +00:00
|
|
|
|
|
|
|
CommonActivity.init(this)
|
2022-05-05 16:16:41 +00:00
|
|
|
val navHostFragment =
|
|
|
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
|
2022-04-22 18:53:58 +00:00
|
|
|
val navController = navHostFragment.navController
|
|
|
|
//val navController = findNavController(R.id.nav_host_fragment)
|
2021-07-19 13:19:47 +00:00
|
|
|
|
2021-09-20 21:11:36 +00:00
|
|
|
/*navOptions = NavOptions.Builder()
|
2021-07-19 13:19:47 +00:00
|
|
|
.setLaunchSingleTop(true)
|
|
|
|
.setEnterAnim(R.anim.nav_enter_anim)
|
|
|
|
.setExitAnim(R.anim.nav_exit_anim)
|
|
|
|
.setPopEnterAnim(R.anim.nav_pop_enter)
|
|
|
|
.setPopExitAnim(R.anim.nav_pop_exit)
|
|
|
|
.setPopUpTo(navController.graph.startDestination, false)
|
2021-09-20 21:11:36 +00:00
|
|
|
.build()*/
|
2021-11-25 17:26:14 +00:00
|
|
|
nav_view?.setupWithNavController(navController)
|
2022-04-18 18:24:29 +00:00
|
|
|
val nav_rail = findViewById<NavigationRailView?>(R.id.nav_rail_view)
|
|
|
|
nav_rail?.setupWithNavController(navController)
|
2022-03-03 11:26:26 +00:00
|
|
|
|
2022-04-18 18:24:29 +00:00
|
|
|
nav_rail?.setOnItemSelectedListener { item ->
|
2022-03-03 11:26:26 +00:00
|
|
|
onNavDestinationSelected(
|
|
|
|
item,
|
|
|
|
navController
|
|
|
|
)
|
|
|
|
}
|
|
|
|
nav_view?.setOnItemSelectedListener { item ->
|
|
|
|
onNavDestinationSelected(
|
|
|
|
item,
|
|
|
|
navController
|
|
|
|
)
|
|
|
|
}
|
2021-09-20 21:11:36 +00:00
|
|
|
navController.addOnDestinationChangedListener { _, destination, _ ->
|
2021-12-12 02:33:17 +00:00
|
|
|
updateNavBar(destination)
|
2021-09-20 21:11:36 +00:00
|
|
|
}
|
2022-03-03 11:26:26 +00:00
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
loadCache()
|
2022-06-17 20:43:42 +00:00
|
|
|
updateHasTrailers()
|
2021-09-20 21:11:36 +00:00
|
|
|
/*nav_view.setOnNavigationItemSelectedListener { item ->
|
2021-07-19 13:19:47 +00:00
|
|
|
when (item.itemId) {
|
2021-07-28 01:04:32 +00:00
|
|
|
R.id.navigation_home -> {
|
|
|
|
navController.navigate(R.id.navigation_home, null, navOptions)
|
|
|
|
}
|
2021-07-19 13:19:47 +00:00
|
|
|
R.id.navigation_search -> {
|
|
|
|
navController.navigate(R.id.navigation_search, null, navOptions)
|
|
|
|
}
|
|
|
|
R.id.navigation_downloads -> {
|
|
|
|
navController.navigate(R.id.navigation_downloads, null, navOptions)
|
|
|
|
}
|
|
|
|
R.id.navigation_settings -> {
|
|
|
|
navController.navigate(R.id.navigation_settings, null, navOptions)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
2021-09-20 21:11:36 +00:00
|
|
|
}*/
|
2021-07-19 13:19:47 +00:00
|
|
|
|
2021-11-26 23:19:17 +00:00
|
|
|
val rippleColor = ColorStateList.valueOf(getResourceColor(R.attr.colorPrimary, 0.1f))
|
2021-11-25 17:26:14 +00:00
|
|
|
nav_view?.itemRippleColor = rippleColor
|
2022-04-18 18:24:29 +00:00
|
|
|
nav_rail?.itemRippleColor = rippleColor
|
|
|
|
nav_rail?.itemActiveIndicatorColor = rippleColor
|
|
|
|
nav_view?.itemActiveIndicatorColor = rippleColor
|
2021-05-20 21:25:41 +00:00
|
|
|
|
|
|
|
if (!checkWrite()) {
|
|
|
|
requestRW()
|
|
|
|
if (checkWrite()) return
|
|
|
|
}
|
2021-06-14 00:00:29 +00:00
|
|
|
CastButtonFactory.setUpMediaRouteButton(this, media_route_button)
|
2021-06-14 16:58:43 +00:00
|
|
|
|
2021-07-15 16:45:25 +00:00
|
|
|
// THIS IS CURRENTLY REMOVED BECAUSE HIGHER VERS OF ANDROID NEEDS A NOTIFICATION
|
|
|
|
//if (!VideoDownloadManager.isMyServiceRunning(this, VideoDownloadKeepAliveService::class.java)) {
|
|
|
|
// val mYourService = VideoDownloadKeepAliveService()
|
|
|
|
// val mServiceIntent = Intent(this, mYourService::class.java).putExtra(START_VALUE_KEY, RESTART_ALL_DOWNLOADS_AND_QUEUE)
|
|
|
|
// this.startService(mServiceIntent)
|
|
|
|
//}
|
2021-07-17 15:56:26 +00:00
|
|
|
//settingsManager.getBoolean("disable_automatic_data_downloads", true) &&
|
2021-07-25 14:25:09 +00:00
|
|
|
|
|
|
|
// TODO RETURN TO TRUE
|
|
|
|
/*
|
2021-07-17 21:36:50 +00:00
|
|
|
if (isUsingMobileData()) {
|
2021-07-17 15:56:26 +00:00
|
|
|
Toast.makeText(this, "Downloads not resumed on mobile data", Toast.LENGTH_LONG).show()
|
|
|
|
} else {
|
|
|
|
val keys = getKeys(VideoDownloadManager.KEY_RESUME_PACKAGES)
|
|
|
|
val resumePkg = keys.mapNotNull { k -> getKey<VideoDownloadManager.DownloadResumePackage>(k) }
|
|
|
|
|
|
|
|
// To remove a bug where this is permanent
|
|
|
|
removeKeys(VideoDownloadManager.KEY_RESUME_PACKAGES)
|
|
|
|
|
|
|
|
for (pkg in resumePkg) { // ADD ALL CURRENT DOWNLOADS
|
|
|
|
VideoDownloadManager.downloadFromResume(this, pkg, false)
|
|
|
|
}
|
2021-07-08 17:46:47 +00:00
|
|
|
|
2021-07-17 15:56:26 +00:00
|
|
|
// ADD QUEUE
|
|
|
|
// array needed because List gets cast exception to linkedList for some unknown reason
|
|
|
|
val resumeQueue =
|
|
|
|
getKey<Array<VideoDownloadManager.DownloadQueueResumePackage>>(VideoDownloadManager.KEY_RESUME_QUEUE_PACKAGES)
|
|
|
|
|
|
|
|
resumeQueue?.sortedBy { it.index }?.forEach {
|
|
|
|
VideoDownloadManager.downloadFromResume(this, it.pkg)
|
|
|
|
}
|
2021-07-25 14:25:09 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
2021-06-14 00:00:29 +00:00
|
|
|
/*
|
|
|
|
val castContext = CastContext.getSharedInstance(applicationContext)
|
|
|
|
fun buildMediaQueueItem(video: String): MediaQueueItem {
|
|
|
|
// val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_PHOTO)
|
|
|
|
//movieMetadata.putString(MediaMetadata.KEY_TITLE, "CloudStream")
|
|
|
|
val mediaInfo = MediaInfo.Builder(Uri.parse(video).toString())
|
|
|
|
.setStreamType(MediaInfo.STREAM_TYPE_NONE)
|
|
|
|
.setContentType(MimeTypes.IMAGE_JPEG)
|
|
|
|
// .setMetadata(movieMetadata).build()
|
|
|
|
.build()
|
|
|
|
return MediaQueueItem.Builder(mediaInfo).build()
|
|
|
|
}*/
|
|
|
|
/*
|
|
|
|
castContext.addCastStateListener { state ->
|
|
|
|
if (state == CastState.CONNECTED) {
|
|
|
|
println("TESTING")
|
|
|
|
val isCasting = castContext?.sessionManager?.currentCastSession?.remoteMediaClient?.currentItem != null
|
|
|
|
if(!isCasting) {
|
|
|
|
val castPlayer = CastPlayer(castContext)
|
|
|
|
println("LOAD ITEM")
|
|
|
|
|
|
|
|
castPlayer.loadItem(buildMediaQueueItem("https://cdn.discordapp.com/attachments/551382684560261121/730169809408622702/ChromecastLogo6.png"),0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
2021-07-31 22:11:56 +00:00
|
|
|
/*thread {
|
|
|
|
createISO()
|
|
|
|
}*/
|
2021-08-19 20:05:18 +00:00
|
|
|
|
2022-04-10 22:00:03 +00:00
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
var providersAndroidManifestString = "Current androidmanifest should be:\n"
|
|
|
|
for (api in allProviders) {
|
|
|
|
providersAndroidManifestString += "<data android:scheme=\"https\" android:host=\"${
|
|
|
|
api.mainUrl.removePrefix(
|
|
|
|
"https://"
|
|
|
|
)
|
|
|
|
}\" android:pathPrefix=\"/\"/>\n"
|
|
|
|
}
|
2021-09-30 12:16:23 +00:00
|
|
|
|
2022-04-10 22:00:03 +00:00
|
|
|
println(providersAndroidManifestString)
|
|
|
|
}
|
2021-09-30 12:16:23 +00:00
|
|
|
|
2021-07-30 01:14:53 +00:00
|
|
|
handleAppIntent(intent)
|
2021-08-15 17:38:41 +00:00
|
|
|
|
2022-08-20 17:39:04 +00:00
|
|
|
ioSafe {
|
2021-08-15 17:38:41 +00:00
|
|
|
runAutoUpdate()
|
|
|
|
}
|
2021-08-30 21:42:58 +00:00
|
|
|
|
2021-09-12 14:10:22 +00:00
|
|
|
APIRepository.dubStatusActive = getApiDubstatusSettings()
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
try {
|
|
|
|
// this ensures that no unnecessary space is taken
|
|
|
|
loadCache()
|
|
|
|
File(filesDir, "exoplayer").deleteRecursively() // old cache
|
|
|
|
File(cacheDir, "exoplayer").deleteOnExit() // current cache
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
}
|
2022-03-16 15:29:11 +00:00
|
|
|
println("Loaded everything")
|
2022-05-02 21:32:28 +00:00
|
|
|
|
|
|
|
ioSafe {
|
|
|
|
migrateResumeWatching()
|
|
|
|
}
|
2022-07-30 01:24:07 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (getKey(HAS_DONE_SETUP_KEY, false) != true) {
|
|
|
|
navController.navigate(R.id.navigation_setup_language)
|
2022-08-09 02:53:24 +00:00
|
|
|
// If no plugins bring up extensions screen
|
|
|
|
} else if (PluginManager.getPluginsOnline().isEmpty()
|
|
|
|
&& PluginManager.getPluginsLocal().isEmpty()
|
2022-08-15 01:31:33 +00:00
|
|
|
// && PREBUILT_REPOSITORIES.isNotEmpty()
|
2022-08-09 02:53:24 +00:00
|
|
|
) {
|
2022-08-16 19:07:49 +00:00
|
|
|
navController.navigate(
|
|
|
|
R.id.navigation_setup_extensions,
|
|
|
|
SetupFragmentExtensions.newInstance(false)
|
|
|
|
)
|
2022-07-30 01:24:07 +00:00
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
|
|
|
logError(e)
|
|
|
|
} finally {
|
|
|
|
setKey(HAS_DONE_SETUP_KEY, true)
|
|
|
|
}
|
2022-08-16 19:07:49 +00:00
|
|
|
|
|
|
|
// Used to check current focus for TV
|
|
|
|
// main {
|
|
|
|
// while (true) {
|
|
|
|
// delay(1000)
|
|
|
|
// println("Current focus: $currentFocus")
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2021-04-30 17:20:15 +00:00
|
|
|
}
|
2022-04-11 20:17:34 +00:00
|
|
|
}
|