code cleanup

This commit is contained in:
LagradOst 2021-08-29 20:42:44 +02:00
parent 7b62788f0b
commit 96dd822fa1
35 changed files with 72 additions and 110 deletions

View file

@ -8,7 +8,6 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
import org.acra.ReportField
import org.acra.config.CoreConfiguration
import org.acra.config.toast
import org.acra.data.CrashReportData
import org.acra.data.StringFormat
import org.acra.ktx.initAcra

View file

@ -3,7 +3,6 @@ package com.lagradost.cloudstream3
import android.app.Activity
import android.app.PictureInPictureParams
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
@ -76,6 +75,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
lateinit var navOptions: NavOptions
var currentToast: Toast? = null
fun showToast(act: Activity?, @StringRes message: Int, duration: Int) {
if (act == null) return
showToast(act, act.getString(message), duration)

View file

@ -40,7 +40,7 @@ class GogoanimeProvider : MainAPI() {
TvType.ONA
)
override fun getMainPage(): HomePageResponse? {
override fun getMainPage(): HomePageResponse {
val headers = mapOf(
"authority" to "ajax.gogo-load.com",
"sec-ch-ua" to "\"Google Chrome\";v=\"89\", \"Chromium\";v=\"89\", \";Not A Brand\";v=\"99\"",

View file

@ -15,7 +15,7 @@ class WcoStream : ExtractorApi() {
val html = khttp.get(url, headers = mapOf("Referer" to "https://wcostream.cc/")).text
val (Id) = "/e/(.*?)?domain".toRegex().find(url)!!.destructured
val (skey) = """skey\s=\s['\"](.*?)['\"];""".toRegex().find(html)!!.destructured
val (skey) = """skey\s=\s['"](.*?)['"];""".toRegex().find(html)!!.destructured
val apiLink = "$baseUrl/info/$Id?domain=wcostream.cc&skey=$skey"
val referrer = "$baseUrl/e/$Id?domain=wcostream.cc"

View file

@ -37,7 +37,7 @@ class XStreamCdn : ExtractorApi() {
}
}
override fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
override fun getUrl(url: String, referer: String?): List<ExtractorLink> {
val headers = mapOf(
"Referer" to url,
"User-Agent" to "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",

View file

@ -3,7 +3,6 @@ package com.lagradost.cloudstream3.mvvm
import android.util.Log
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.bumptech.glide.load.HttpException
import com.lagradost.cloudstream3.ErrorLoadingException
import kotlinx.coroutines.Dispatchers
@ -12,11 +11,11 @@ import java.net.SocketTimeoutException
import java.net.UnknownHostException
fun <T> LifecycleOwner.observe(liveData: LiveData<T>, action: (t: T) -> Unit) {
liveData.observe(this, Observer { it?.let { t -> action(t) } })
liveData.observe(this) { it?.let { t -> action(t) } }
}
fun <T> LifecycleOwner.observeDirectly(liveData: LiveData<T>, action: (t: T) -> Unit) {
liveData.observe(this, Observer { it?.let { t -> action(t) } })
liveData.observe(this) { it?.let { t -> action(t) } }
val currentValue = liveData.value
if (currentValue != null)
action(currentValue)
@ -64,7 +63,7 @@ suspend fun <T> safeApiCall(
Resource.Failure(true, null, null, "Please try again later.")
}
is HttpException -> {
Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage)
Resource.Failure(false, throwable.statusCode, null, throwable.localizedMessage ?: "")
}
is UnknownHostException -> {
Resource.Failure(true, null, null, "Cannot connect to server, try again later.")
@ -76,7 +75,7 @@ suspend fun <T> safeApiCall(
Resource.Failure(false, null, null, "This operation is not implemented.")
}
else -> {
val stackTraceMsg = throwable.localizedMessage + "\n\n" + throwable.stackTrace.joinToString(
val stackTraceMsg = (throwable.localizedMessage ?: "") + "\n\n" + throwable.stackTrace.joinToString(
separator = "\n"
) {
"${it.fileName} ${it.lineNumber}"

View file

@ -3,7 +3,6 @@ package com.lagradost.cloudstream3.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log

View file

@ -23,7 +23,7 @@ class MyMiniControllerFragment : MiniControllerFragment() {
if (obtainStyledAttributes.hasValue(R.styleable.CustomCast_customCastBackgroundColor)) {
currentColor = obtainStyledAttributes.getColor(R.styleable.CustomCast_customCastBackgroundColor, 0)
}
obtainStyledAttributes.recycle()
super.onInflate(context, attributeSet, bundle)
}

View file

@ -7,7 +7,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.isMovieType
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
import com.lagradost.cloudstream3.utils.DOWNLOAD_HEADER_CACHE

View file

@ -9,10 +9,9 @@ import android.widget.TextView
import androidx.core.widget.ContentLoadingProgressBar
import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
import com.lagradost.cloudstream3.utils.Coroutines
import com.lagradost.cloudstream3.utils.IDisposable
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
import com.lagradost.cloudstream3.utils.VideoDownloadManager
class EasyDownloadButton : IDisposable {

View file

@ -3,19 +3,11 @@ package com.lagradost.cloudstream3.ui.home
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
import com.lagradost.cloudstream3.utils.UIHelper.setImage
import kotlinx.android.synthetic.main.home_result_grid.view.*
class HomeChildItemAdapter(
var cardList: List<SearchResponse>,

View file

@ -8,7 +8,6 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.HomePageList
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
import kotlinx.android.synthetic.main.homepage_parent.view.*

View file

@ -853,7 +853,7 @@ class PlayerFragment : Fragment() {
if (realLang.length == 2) SubtitleHelper.fromTwoLettersToLanguage(realLang) ?: realLang else realLang
if (!this::exoPlayer.isInitialized) return
(exoPlayer?.trackSelector as DefaultTrackSelector?)?.let { trackSelector ->
(exoPlayer.trackSelector as DefaultTrackSelector?)?.let { trackSelector ->
if (lang.isNullOrBlank()) {
trackSelector.setParameters(
trackSelector.buildUponParameters()
@ -1028,11 +1028,11 @@ class PlayerFragment : Fragment() {
observeDirectly(viewModel.episodes) { _episodes ->
episodes = _episodes
if (isLoading) {
if (playerData.episodeIndex > 0 && playerData.episodeIndex < episodes.size) {
/*if (playerData.episodeIndex > 0 && playerData.episodeIndex < episodes.size) {
} else {
// WHAT THE FUCK DID YOU DO
}
}*/
}
}
@ -1304,11 +1304,11 @@ class PlayerFragment : Fragment() {
playbackPosition = if (this::exoPlayer.isInitialized) exoPlayer.currentPosition else 0
setMirrorId(sources[sourceIndex].getId())
initPlayer(getCurrentUrl())
} else {
} /*else {
if (isPlaying) {
// exoPlayer.play()
}
}
}*/
if (subtitleIndex != startIndexFromMap) {
setPreferredSubLanguage(if (subtitleIndex <= 0) null else currentSubtitles[subtitleIndex - 1])

View file

@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.LayoutRes
import androidx.core.widget.ContentLoadingProgressBar
import androidx.recyclerview.widget.RecyclerView

View file

@ -1,29 +1,17 @@
package com.lagradost.cloudstream3.ui.search
import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl
import com.lagradost.cloudstream3.AnimeSearchResponse
import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
import com.lagradost.cloudstream3.utils.UIHelper.getGridFormatId
import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
import com.lagradost.cloudstream3.utils.UIHelper.setImage
import kotlinx.android.synthetic.main.search_result_compact.view.backgroundCard
import kotlinx.android.synthetic.main.search_result_compact.view.imageText
import kotlinx.android.synthetic.main.search_result_compact.view.imageView
import kotlinx.android.synthetic.main.search_result_grid.view.*
import kotlinx.android.synthetic.main.search_result_compact.view.*
import kotlin.math.roundToInt
const val SEARCH_ACTION_LOAD = 0

View file

@ -7,7 +7,6 @@ import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_PLAY_FILE
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
import com.lagradost.cloudstream3.ui.result.START_ACTION_LOAD_EP
import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.VideoDownloadHelper

View file

@ -12,9 +12,7 @@ import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import com.google.android.gms.cast.framework.CastContext
import com.google.android.gms.cast.framework.CastState
import com.google.android.gms.common.ConnectionResult

View file

@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.utils
import android.content.Context
import com.google.android.gms.cast.CastMediaControlIntent
import com.google.android.gms.cast.LaunchOptions
import com.google.android.gms.cast.framework.CastOptions
import com.google.android.gms.cast.framework.OptionsProvider
import com.google.android.gms.cast.framework.SessionProvider

View file

@ -1,6 +1,5 @@
package com.lagradost.cloudstream3.utils
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.extractors.*
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall

View file

@ -104,12 +104,15 @@ class InAppUpdater {
}).toList().lastOrNull()
val foundAsset = found?.assets?.getOrNull(0)
val currentVersion = packageName?.let {
packageManager.getPackageInfo(it,
0)
packageManager.getPackageInfo(
it,
0
)
}
val foundVersion = foundAsset?.name?.let { versionRegex.find(it) }
val shouldUpdate = if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
val shouldUpdate =
if (found != null && foundAsset?.browser_download_url != "" && foundVersion != null) currentVersion?.versionName?.compareTo(
foundVersion.groupValues[2]
)!! < 0 else false
return if (foundVersion != null) {
@ -161,6 +164,7 @@ class InAppUpdater {
val localContext = this
val id = downloadManager.enqueue(request)
registerReceiver(
object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
@ -173,8 +177,7 @@ class InAppUpdater {
val c = downloadManager.query(query)
if (c.moveToFirst()) {
val columnIndex = c
.getColumnIndex(DownloadManager.COLUMN_STATUS)
val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS)
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)
) {
@ -217,8 +220,10 @@ class InAppUpdater {
if (update.shouldUpdate && update.updateURL != null) {
runOnUiThread {
val currentVersion = packageName?.let {
packageManager.getPackageInfo(it,
0)
packageManager.getPackageInfo(
it,
0
)
}
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
@ -233,23 +238,19 @@ class InAppUpdater {
val downloadStatus = context.downloadUpdate(update.updateURL)
if (!downloadStatus) {
runOnUiThread {
showToast(context,
showToast(
context,
"Download Failed",
Toast.LENGTH_LONG)
Toast.LENGTH_LONG
)
}
} /*else {
activity.runOnUiThread {
Toast.makeText(localContext,
"Downloaded APK",
Toast.LENGTH_LONG).show()
}
}*/
}
}
setNegativeButton("Cancel") { _, _ -> }
if(checkAutoUpdate) {
if (checkAutoUpdate) {
setNeutralButton("Don't show again") { _, _ ->
settingsManager.edit().putBoolean("auto_update", false).apply()
}

View file

@ -31,7 +31,7 @@ class JsUnpacker(packedJS: String?) {
val js = packedJS
try {
var p =
Pattern.compile("""\}\s*\('(.*)',\s*(.*?),\s*(\d+),\s*'(.*?)'\.split\('\|'\)""", Pattern.DOTALL)
Pattern.compile("""}\s*\('(.*)',\s*(.*?),\s*(\d+),\s*'(.*?)'\.split\('\|'\)""", Pattern.DOTALL)
var m = p.matcher(js)
if (m.find() && m.groupCount() == 4) {
val payload = m.group(1).replace("\\'", "'")

View file

@ -5,7 +5,6 @@ import android.content.Context
import android.view.View
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.core.util.forEach
import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop

View file

@ -1,6 +1,5 @@
package com.lagradost.cloudstream3.utils
import com.lagradost.cloudstream3.SearchResponse
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton

View file

@ -7,7 +7,6 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.webkit.MimeTypeMap
import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
@ -26,7 +25,6 @@ import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.removeKey
import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getExistingDownloadUriOrNullQ
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
@ -35,7 +33,6 @@ import java.lang.Thread.sleep
import java.net.URL
import java.net.URLConnection
import java.util.*
import kotlin.collections.ArrayList
const val DOWNLOAD_CHANNEL_ID = "cloudstream3.general"
const val DOWNLOAD_CHANNEL_NAME = "Downloads"
@ -91,7 +88,7 @@ object VideoDownloadManager {
val referer: String
}
fun VideoDownloadManager.IDownloadableMinimum.getId(): Int {
fun IDownloadableMinimum.getId(): Int {
return url.hashCode()
}
@ -146,9 +143,9 @@ object VideoDownloadManager {
private const val ERROR_CONTENT_RESOLVER_CANT_OPEN_STREAM = -8
private const val ERROR_CONTENT_RESOLVER_NOT_FOUND = -9
const val KEY_RESUME_PACKAGES = "download_resume"
private const val KEY_RESUME_PACKAGES = "download_resume"
const val KEY_DOWNLOAD_INFO = "download_info"
const val KEY_RESUME_QUEUE_PACKAGES = "download_q_resume"
private const val KEY_RESUME_QUEUE_PACKAGES = "download_q_resume"
val downloadStatus = HashMap<Int, DownloadType>()
val downloadStatusEvent = Event<Pair<Int, DownloadType>>()
@ -428,7 +425,7 @@ object VideoDownloadManager {
)
val folder = File(normalPath)
if (folder.isDirectory) {
return folder.listFiles().map { Pair(it.name, it.toUri()) }
return folder.listFiles()?.map { Pair(it.name, it.toUri()) }
}
return null
}
@ -934,7 +931,7 @@ object VideoDownloadManager {
context.setKey(KEY_RESUME_QUEUE_PACKAGES, dQueue)
}
fun isMyServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
/*fun isMyServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager?
for (service in manager!!.getRunningServices(Int.MAX_VALUE)) {
if (serviceClass.name == service.service.className) {
@ -942,7 +939,7 @@ object VideoDownloadManager {
}
}
return false
}
}*/
fun downloadEpisode(
context: Activity?,

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
<font-family
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="?attr/bitDarkerGrayBackground"

View file

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:orientation="horizontal"
android:keepScreenOn="true"
app:backgroundTint="@android:color/black"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="?attr/darkBackground"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@null"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@null"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="?attr/bitDarkerGrayBackground"

View file

@ -3,7 +3,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:focusable="true"

View file

@ -9,7 +9,6 @@
>
<androidx.cardview.widget.CardView
android:foreground="?android:attr/selectableItemBackgroundBorderless"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/backgroundCard"
android:layout_margin="2dp"
android:layout_width="match_parent"

View file

@ -5,7 +5,6 @@
android:layout_height="match_parent"
android:id="@+id/subs_root"
android:background="?attr/bitDarkerGrayBackground"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:orientation="vertical"

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<paths>
<external-path
name="external"
path="." />