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,32 +560,35 @@ class GeneratorPlayer : FullScreenPlayer() {
} }
//Generate video title //Generate video title
var playerVideoTitle = if (headerName != null) { context?.let { ctx ->
(headerName + var playerVideoTitle = if (headerName != null) {
if (tvType.isEpisodeBased() && episode != null) (headerName +
if (season == null) if (tvType.isEpisodeBased() && episode != null)
" - ${getString(R.string.episode)} $episode" if (season == null)
else " - ${ctx.getString(R.string.episode)} $episode"
" \"${getString(R.string.season_short)}${season}:${getString(R.string.episode_short)}${episode}\"" else
else "") + if (subName.isNullOrBlank() || subName == headerName) "" else " - $subName" " \"${ctx.getString(R.string.season_short)}${season}:${ctx.getString(R.string.episode_short)}${episode}\""
} else { else "") + if (subName.isNullOrBlank() || subName == headerName) "" else " - $subName"
"" } else {
} ""
//Hide title, if set in setting
if (limitTitle < 0) {
player_video_title?.visibility = View.GONE
} else {
//Truncate video title if it exceeds limit
val differenceInLength = playerVideoTitle.length - limitTitle
val margin = 3 //If the difference is smaller than or equal to this value, ignore it
if (limitTitle > 0 && differenceInLength > margin) {
playerVideoTitle = playerVideoTitle.substring(0, limitTitle - 1) + "..."
} }
//Hide title, if set in setting
if (limitTitle < 0) {
player_video_title?.visibility = View.GONE
} else {
//Truncate video title if it exceeds limit
val differenceInLength = playerVideoTitle.length - limitTitle
val margin = 3 //If the difference is smaller than or equal to this value, ignore it
if (limitTitle > 0 && differenceInLength > margin) {
playerVideoTitle = playerVideoTitle.substring(0, limitTitle - 1) + "..."
}
}
player_episode_filler_holder?.isVisible = isFiller ?: false
player_video_title?.text = playerVideoTitle
} }
player_episode_filler_holder?.isVisible = isFiller ?: false
player_video_title?.text = playerVideoTitle
} }
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")

View file

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

View file

@ -6,6 +6,7 @@ import androidx.preference.PreferenceManager
import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.lagradost.cloudstream3.mvvm.logError
const val DOWNLOAD_HEADER_CACHE = "download_header_cache" 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 DOWNLOAD_EPISODE_CACHE = "download_episode_cache"
const val VIDEO_PLAYER_BRIGHTNESS = "video_player_alpha_key" const val VIDEO_PLAYER_BRIGHTNESS = "video_player_alpha_key"
const val HOMEPAGE_API = "home_api_used" 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 { object DataStore {
val mapper: JsonMapper = JsonMapper.builder().addModule(KotlinModule()) val mapper: JsonMapper = JsonMapper.builder().addModule(KotlinModule())
@ -34,17 +34,21 @@ object DataStore {
} }
fun <T> Context.setKeyRaw(path: String, value: T, isEditingAppSettings: Boolean = false) { fun <T> Context.setKeyRaw(path: String, value: T, isEditingAppSettings: Boolean = false) {
val editor: SharedPreferences.Editor = try {
if (isEditingAppSettings) getDefaultSharedPrefs().edit() else getSharedPrefs().edit() val editor: SharedPreferences.Editor =
when (value) { if (isEditingAppSettings) getDefaultSharedPrefs().edit() else getSharedPrefs().edit()
is Boolean -> editor.putBoolean(path, value) when (value) {
is Int -> editor.putInt(path, value) is Boolean -> editor.putBoolean(path, value)
is String -> editor.putString(path, value) is Int -> editor.putInt(path, value)
is Float -> editor.putFloat(path, value) is String -> editor.putString(path, value)
is Long -> editor.putLong(path, value) is Float -> editor.putFloat(path, value)
(value as? Set<String> != null) -> editor.putStringSet(path, value as Set<String>) is Long -> editor.putLong(path, value)
(value as? Set<String> != null) -> editor.putStringSet(path, value as Set<String>)
}
editor.apply()
} catch (e: Exception) {
logError(e)
} }
editor.apply()
} }
fun Context.getDefaultSharedPrefs(): SharedPreferences { fun Context.getDefaultSharedPrefs(): SharedPreferences {
@ -69,11 +73,15 @@ object DataStore {
} }
fun Context.removeKey(path: String) { fun Context.removeKey(path: String) {
val prefs = getSharedPrefs() try {
if (prefs.contains(path)) { val prefs = getSharedPrefs()
val editor: SharedPreferences.Editor = prefs.edit() if (prefs.contains(path)) {
editor.remove(path) val editor: SharedPreferences.Editor = prefs.edit()
editor.apply() editor.remove(path)
editor.apply()
}
} catch (e: Exception) {
logError(e)
} }
} }
@ -86,9 +94,13 @@ object DataStore {
} }
fun <T> Context.setKey(path: String, value: T) { fun <T> Context.setKey(path: String, value: T) {
val editor: SharedPreferences.Editor = getSharedPrefs().edit() try {
editor.putString(path, mapper.writeValueAsString(value)) val editor: SharedPreferences.Editor = getSharedPrefs().edit()
editor.apply() editor.putString(path, mapper.writeValueAsString(value))
editor.apply()
} catch (e: Exception) {
logError(e)
}
} }
fun <T> Context.setKey(folder: String, path: String, value: T) { 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 if (parentId == null) return
removeKey("$currentAccount/$RESULT_RESUME_WATCHING_OLD", parentId.toString()) 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="resolution_and_title">Resolution and title</string>
<string name="title">Title</string> <string name="title">Title</string>
<string name="resolution">Resolution</string> <string name="resolution">Resolution</string>
<string name="error_invalid_id">Invalid id</string>
</resources> </resources>