fixed small crash issue

This commit is contained in:
LagradOst 2022-05-27 00:34:09 +02:00
parent 1d7a74324b
commit 9b94853199
5 changed files with 84 additions and 61 deletions

View file

@ -560,13 +560,14 @@ class GeneratorPlayer : FullScreenPlayer() {
}
//Generate video title
context?.let { ctx ->
var playerVideoTitle = if (headerName != null) {
(headerName +
if (tvType.isEpisodeBased() && episode != null)
if (season == null)
" - ${getString(R.string.episode)} $episode"
" - ${ctx.getString(R.string.episode)} $episode"
else
" \"${getString(R.string.season_short)}${season}:${getString(R.string.episode_short)}${episode}\""
" \"${ctx.getString(R.string.season_short)}${season}:${ctx.getString(R.string.episode_short)}${episode}\""
else "") + if (subName.isNullOrBlank() || subName == headerName) "" else " - $subName"
} else {
""
@ -588,6 +589,8 @@ class GeneratorPlayer : FullScreenPlayer() {
player_video_title?.text = playerVideoTitle
}
}
@SuppressLint("SetTextI18n")
fun setPlayerDimen(widthHeight: Pair<Int, Int>?) {
val extra = if (widthHeight != null) {

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.search
import android.app.Activity
import android.widget.Toast
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
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
@ -20,6 +21,10 @@ object SearchHelper {
}
SEARCH_ACTION_PLAY_FILE -> {
if (card is DataStoreHelper.ResumeWatchingResult) {
val id = card.id
if(id == null) {
showToast(activity, R.string.error_invalid_id, Toast.LENGTH_SHORT)
} else {
if (card.isFromDownload) {
handleDownloadClick(
activity, card.name, DownloadClickEvent(
@ -29,7 +34,7 @@ object SearchHelper {
card.posterUrl,
card.episode ?: 0,
card.season,
card.id!!,
id,
card.parentId ?: return,
null,
null,
@ -38,8 +43,10 @@ object SearchHelper {
)
)
} else {
activity.loadSearchResult(card, START_ACTION_LOAD_EP, card.id)
activity.loadSearchResult(card, START_ACTION_LOAD_EP, id)
}
}
} else {
handleSearchClickCallback(
activity,

View file

@ -6,6 +6,7 @@ import androidx.preference.PreferenceManager
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.lagradost.cloudstream3.mvvm.logError
const val DOWNLOAD_HEADER_CACHE = "download_header_cache"
@ -13,9 +14,8 @@ const val DOWNLOAD_HEADER_CACHE = "download_header_cache"
const val DOWNLOAD_EPISODE_CACHE = "download_episode_cache"
const val VIDEO_PLAYER_BRIGHTNESS = "video_player_alpha_key"
const val HOMEPAGE_API = "home_api_used"
const val SEARCH_PROVIDER_TOGGLE = "settings_providers_toggle"
const val PREFERENCES_NAME: String = "rebuild_preference"
const val PREFERENCES_NAME = "rebuild_preference"
object DataStore {
val mapper: JsonMapper = JsonMapper.builder().addModule(KotlinModule())
@ -34,6 +34,7 @@ object DataStore {
}
fun <T> Context.setKeyRaw(path: String, value: T, isEditingAppSettings: Boolean = false) {
try {
val editor: SharedPreferences.Editor =
if (isEditingAppSettings) getDefaultSharedPrefs().edit() else getSharedPrefs().edit()
when (value) {
@ -45,6 +46,9 @@ object DataStore {
(value as? Set<String> != null) -> editor.putStringSet(path, value as Set<String>)
}
editor.apply()
} catch (e: Exception) {
logError(e)
}
}
fun Context.getDefaultSharedPrefs(): SharedPreferences {
@ -69,12 +73,16 @@ object DataStore {
}
fun Context.removeKey(path: String) {
try {
val prefs = getSharedPrefs()
if (prefs.contains(path)) {
val editor: SharedPreferences.Editor = prefs.edit()
editor.remove(path)
editor.apply()
}
} catch (e: Exception) {
logError(e)
}
}
fun Context.removeKeys(folder: String): Int {
@ -86,9 +94,13 @@ object DataStore {
}
fun <T> Context.setKey(path: String, value: T) {
try {
val editor: SharedPreferences.Editor = getSharedPrefs().edit()
editor.putString(path, mapper.writeValueAsString(value))
editor.apply()
} catch (e: Exception) {
logError(e)
}
}
fun <T> Context.setKey(folder: String, path: String, value: T) {

View file

@ -132,7 +132,7 @@ object DataStoreHelper {
)
}
fun removeLastWatchedOld(parentId: Int?) {
private fun removeLastWatchedOld(parentId: Int?) {
if (parentId == null) return
removeKey("$currentAccount/$RESULT_RESUME_WATCHING_OLD", parentId.toString())
}

View file

@ -520,4 +520,5 @@
<string name="resolution_and_title">Resolution and title</string>
<string name="title">Title</string>
<string name="resolution">Resolution</string>
<string name="error_invalid_id">Invalid id</string>
</resources>