removed crash stuff

This commit is contained in:
LagradOst 2021-09-01 14:02:32 +02:00
parent 3e3e1b6a9d
commit 3ab3986e22
9 changed files with 37 additions and 136 deletions

View file

@ -37,7 +37,6 @@ android {
resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}"
buildConfigField("String", "BUILDDATE", "new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm\").format(new java.util.Date(" + System.currentTimeMillis() + "L));")
buildConfigField("String", "PRIVATE_BENENE_KEY", "\"${(System.getenv("PRIVATE_BENENE_KEY") ?: "")}\"")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -641,15 +641,15 @@ class PlayerFragment : Fragment() {
data.isAnimeBased()//(data is AnimeLoadResponse && (data.type == TvType.Anime || data.type == TvType.ONA))
skip_op?.setVis(isAnime && !nextEp)
skip_episode.setVis((!isAnime || nextEp) && hasNext)
skip_episode?.setVis((!isAnime || nextEp) && hasNext)
} else {
val isAnime = data.isAnimeBased()
if (isAnime) {
skip_op?.setVis(true)
skip_episode.setVis(false)
skip_episode?.setVis(false)
} else {
skip_episode.setVis(data.isEpisodeBased())
skip_episode?.setVis(data.isEpisodeBased())
skip_op?.setVis(false)
}
}
@ -795,7 +795,7 @@ class PlayerFragment : Fragment() {
//next_episode_btt.isClickable = isClick
playback_speed_btt.isClickable = isClick
skip_op?.isClickable = isClick
skip_episode.isClickable = isClick
skip_episode?.isClickable = isClick
resize_player.isClickable = isClick
exo_progress.isEnabled = isClick
player_media_route_button.isEnabled = isClick
@ -1409,7 +1409,7 @@ class PlayerFragment : Fragment() {
skipOP()
}
skip_episode.setOnClickListener {
skip_episode?.setOnClickListener {
if (hasNextEpisode()) {
skipToNextEpisode()
}

View file

@ -962,12 +962,12 @@ class ResultFragment : Fragment() {
lateFixDownloadButton(true)
result_play_movie.setOnClickListener {
val card = currentEpisodes?.first() ?: return@setOnClickListener
val card = currentEpisodes?.firstOrNull() ?: return@setOnClickListener
handleAction(EpisodeClickEvent(ACTION_CLICK_DEFAULT, card))
}
result_play_movie.setOnLongClickListener {
val card = currentEpisodes?.first() ?: return@setOnLongClickListener true
val card = currentEpisodes?.firstOrNull() ?: return@setOnLongClickListener true
handleAction(EpisodeClickEvent(ACTION_SHOW_OPTIONS, card))
return@setOnLongClickListener true
}
@ -1004,7 +1004,7 @@ class ResultFragment : Fragment() {
)
) { downloadClickEvent ->
if (downloadClickEvent.action == DOWNLOAD_ACTION_DOWNLOAD) {
currentEpisodes?.first()?.let { episode ->
currentEpisodes?.firstOrNull()?.let { episode ->
handleAction(
EpisodeClickEvent(
ACTION_DOWNLOAD_EPISODE,

View file

@ -1,43 +0,0 @@
package com.lagradost.cloudstream3.ui.settings
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.mapper
object ScoreManager {
private const val mainUrl = "http://dreamlo.com"
private const val publicCode = "612d3dcf8f40bb6e98bece15"
var privateCode: String? = BuildConfig.PRIVATE_BENENE_KEY // plz keep it a bit fair
data class DreamloMain(
@JsonProperty("dreamlo") var dreamlo: Dreamlo
)
data class Dreamlo(
@JsonProperty("leaderboard") var leaderboard: Leaderboard
)
data class Leaderboard(
@JsonProperty("entry") var entry: List<DreamloEntry>
)
data class DreamloEntry(
@JsonProperty("name") var name: String,
@JsonProperty("score") var score: String,
//@JsonProperty("seconds") var seconds: String,
//@JsonProperty("text") var text: String,
// @JsonProperty("date") var date: String
)
fun getScore(): List<DreamloEntry> {
val response = khttp.get("$mainUrl/lb/$publicCode/json")
return mapper.readValue<DreamloMain>(response.text).dreamlo.leaderboard.entry
}
fun addScore(name: String, score: Int) { // plz dont cheat
if (score < 0 || score > 100000 || privateCode.isNullOrBlank()) return
khttp.get("$mainUrl/lb/$privateCode/add/$name/$score")
}
}

View file

@ -20,50 +20,6 @@ import kotlin.concurrent.thread
class SettingsFragment : PreferenceFragmentCompat() {
var count = 0
private var scoreboard: List<ScoreManager.DreamloEntry>? = null
private var usernameUUID: String? = null
var ongoingJob: Job? = null
private fun saveAfterTime() {
ongoingJob?.cancel()
ongoingJob = main {
delay(10000) // dont ddos the scoreboard
saveAndUpload()
}
}
private fun saveAndUpload() {
if (ScoreManager.privateCode.isNullOrBlank()) return
try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
val uuid = usernameUUID
if (uuid != null) {
settingsManager.edit()
.putString(getString(R.string.benene_count_uuid), uuid)
.putInt(getString(R.string.benene_count), count)
.apply()
thread {
normalSafeApiCall {
ScoreManager.addScore(uuid, count)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun onPause() {
saveAndUpload()
super.onPause()
}
override fun onDestroy() {
saveAndUpload()
super.onDestroy()
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
@ -76,15 +32,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
count = settingsManager.getInt(getString(R.string.benene_count), 0)
usernameUUID =
settingsManager.getString(getString(R.string.benene_count_uuid), UUID.randomUUID().toString())
if (count > 20) {
if (!ScoreManager.privateCode.isNullOrBlank()) {
thread {
scoreboard = normalSafeApiCall { ScoreManager.getScore() }
}
}
}
benenePref.summary =
if (count <= 0) getString(R.string.benene_count_text_none) else getString(R.string.benene_count_text).format(
count
@ -93,18 +41,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
try {
count++
settingsManager.edit().putInt(getString(R.string.benene_count), count).apply()
var add = ""
val localScoreBoard = scoreboard
if (localScoreBoard != null) {
for ((index, score) in localScoreBoard.withIndex()) {
if (count > (score.score.toIntOrNull() ?: 0)) {
add = " (${index + 1}/${localScoreBoard.size})"
break
}
}
}
it.summary = getString(R.string.benene_count_text).format(count) + add
saveAfterTime()
it.summary = getString(R.string.benene_count_text).format(count)
} catch (e: Exception) {
e.printStackTrace()
}

View file

@ -21,6 +21,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import java.io.File
import kotlin.concurrent.thread
@ -235,7 +236,8 @@ class InAppUpdater {
setPositiveButton("Update") { _, _ ->
showToast(context, "Download started", Toast.LENGTH_LONG)
thread {
val downloadStatus = context.downloadUpdate(update.updateURL)
val downloadStatus =
normalSafeApiCall { context.downloadUpdate(update.updateURL) } ?: false
if (!downloadStatus) {
runOnUiThread {
showToast(

View file

@ -141,6 +141,7 @@ object VideoDownloadManager {
private const val SUCCESS_STOPPED = 2
private const val ERROR_DELETING_FILE = 3 // will not download the next one, but is still classified as an error
private const val ERROR_CREATE_FILE = -2
private const val ERROR_UNKNOWN = -10
private const val ERROR_OPEN_FILE = -3
private const val ERROR_TOO_SMALL_CONNECTION = -4
private const val ERROR_WRONG_CONTENT = -5
@ -756,7 +757,7 @@ object VideoDownloadManager {
createNotificationCallback: (CreateNotificationMetadata) -> Unit
): Int {
if (link.url.startsWith("magnet") || link.url.endsWith(".torrent")) {
return downloadTorrent(context, link.url, name, folder, extension, parentId, createNotificationCallback)
return normalSafeApiCall { downloadTorrent(context, link.url, name, folder, extension, parentId, createNotificationCallback) } ?: ERROR_UNKNOWN
}
val relativePath = (Environment.DIRECTORY_DOWNLOADS + '/' + folder + '/').replace('/', File.separatorChar)
@ -880,10 +881,15 @@ object VideoDownloadManager {
// ON CONNECTION
connection.connect()
val contentLength = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // fuck android
connection.contentLengthLong
val contentLength = try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // fuck android
connection.contentLengthLong ?: 0L
} else {
connection.getHeaderField("content-length").toLongOrNull() ?: connection.contentLength.toLong()
connection.getHeaderField("content-length").toLongOrNull() ?: connection.contentLength?.toLong() ?: 0L
}
} catch (e: Exception) {
e.printStackTrace()
0L
}
val bytesTotal = contentLength + resumeLength
@ -1050,7 +1056,8 @@ object VideoDownloadManager {
): Int {
val name = sanitizeFilename(ep.name ?: "Episode ${ep.episode}")
return downloadThing(context, link, name, folder, "mp4", tryResume, ep.id) { meta ->
return normalSafeApiCall {
downloadThing(context, link, name, folder, "mp4", tryResume, ep.id) { meta ->
createNotification(
context,
source,
@ -1061,6 +1068,7 @@ object VideoDownloadManager {
meta.bytesTotal
)
}
} ?: ERROR_UNKNOWN
}
private fun downloadCheck(context: Context) {

View file

@ -21,7 +21,6 @@
android:layout_marginEnd="30dp"
android:layout_height="30dp">
<androidx.appcompat.widget.SearchView
android:animateLayoutChanges="true"
android:id="@+id/main_search"
app:queryBackground="@color/transparent"
app:searchIcon="@drawable/search_icon"

View file

@ -89,7 +89,6 @@
<string name="prerelease_update_key">prerelease_update</string>
<string name="manual_check_update_key">manual_check_update</string>
<string name="benene_count">benene_count</string>
<string name="benene_count_uuid">benene_count_uuid</string>
<string name="benene_count_text">%d Benenes given to devs</string>
<string name="benene_count_text_none">No Benenes given</string>