mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	fixed small crash issue
This commit is contained in:
		
							parent
							
								
									1d7a74324b
								
							
						
					
					
						commit
						9b94853199
					
				
					 5 changed files with 84 additions and 61 deletions
				
			
		| 
						 | 
				
			
			@ -560,32 +560,35 @@ class GeneratorPlayer : FullScreenPlayer() {
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        //Generate video title
 | 
			
		||||
        var playerVideoTitle = if (headerName != null) {
 | 
			
		||||
            (headerName +
 | 
			
		||||
                    if (tvType.isEpisodeBased() && episode != null)
 | 
			
		||||
                        if (season == null)
 | 
			
		||||
                            " - ${getString(R.string.episode)} $episode"
 | 
			
		||||
                        else
 | 
			
		||||
                            " \"${getString(R.string.season_short)}${season}:${getString(R.string.episode_short)}${episode}\""
 | 
			
		||||
                    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) + "..."
 | 
			
		||||
        context?.let { ctx ->
 | 
			
		||||
            var playerVideoTitle = if (headerName != null) {
 | 
			
		||||
                (headerName +
 | 
			
		||||
                        if (tvType.isEpisodeBased() && episode != null)
 | 
			
		||||
                            if (season == null)
 | 
			
		||||
                                " - ${ctx.getString(R.string.episode)} $episode"
 | 
			
		||||
                            else
 | 
			
		||||
                                " \"${ctx.getString(R.string.season_short)}${season}:${ctx.getString(R.string.episode_short)}${episode}\""
 | 
			
		||||
                        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) + "..."
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            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")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,26 +21,32 @@ object SearchHelper {
 | 
			
		|||
            }
 | 
			
		||||
            SEARCH_ACTION_PLAY_FILE -> {
 | 
			
		||||
                if (card is DataStoreHelper.ResumeWatchingResult) {
 | 
			
		||||
                    if (card.isFromDownload) {
 | 
			
		||||
                        handleDownloadClick(
 | 
			
		||||
                            activity, card.name, DownloadClickEvent(
 | 
			
		||||
                                DOWNLOAD_ACTION_PLAY_FILE,
 | 
			
		||||
                                VideoDownloadHelper.DownloadEpisodeCached(
 | 
			
		||||
                                    card.name,
 | 
			
		||||
                                    card.posterUrl,
 | 
			
		||||
                                    card.episode ?: 0,
 | 
			
		||||
                                    card.season,
 | 
			
		||||
                                    card.id!!,
 | 
			
		||||
                                    card.parentId ?: return,
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    null,
 | 
			
		||||
                                    System.currentTimeMillis()
 | 
			
		||||
                    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(
 | 
			
		||||
                                    DOWNLOAD_ACTION_PLAY_FILE,
 | 
			
		||||
                                    VideoDownloadHelper.DownloadEpisodeCached(
 | 
			
		||||
                                        card.name,
 | 
			
		||||
                                        card.posterUrl,
 | 
			
		||||
                                        card.episode ?: 0,
 | 
			
		||||
                                        card.season,
 | 
			
		||||
                                        id,
 | 
			
		||||
                                        card.parentId ?: return,
 | 
			
		||||
                                        null,
 | 
			
		||||
                                        null,
 | 
			
		||||
                                        System.currentTimeMillis()
 | 
			
		||||
                                    )
 | 
			
		||||
                                )
 | 
			
		||||
                            )
 | 
			
		||||
                        )
 | 
			
		||||
                    } else {
 | 
			
		||||
                        activity.loadSearchResult(card, START_ACTION_LOAD_EP, card.id)
 | 
			
		||||
                        } else {
 | 
			
		||||
                            activity.loadSearchResult(card, START_ACTION_LOAD_EP, id)
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                } else {
 | 
			
		||||
                    handleSearchClickCallback(
 | 
			
		||||
                        activity,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,17 +34,21 @@ object DataStore {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    fun <T> Context.setKeyRaw(path: String, value: T, isEditingAppSettings: Boolean = false) {
 | 
			
		||||
        val editor: SharedPreferences.Editor =
 | 
			
		||||
            if (isEditingAppSettings) getDefaultSharedPrefs().edit() else getSharedPrefs().edit()
 | 
			
		||||
        when (value) {
 | 
			
		||||
            is Boolean -> editor.putBoolean(path, value)
 | 
			
		||||
            is Int -> editor.putInt(path, value)
 | 
			
		||||
            is String -> editor.putString(path, value)
 | 
			
		||||
            is Float -> editor.putFloat(path, value)
 | 
			
		||||
            is Long -> editor.putLong(path, value)
 | 
			
		||||
            (value as? Set<String> != null) -> editor.putStringSet(path, value as Set<String>)
 | 
			
		||||
        try {
 | 
			
		||||
            val editor: SharedPreferences.Editor =
 | 
			
		||||
                if (isEditingAppSettings) getDefaultSharedPrefs().edit() else getSharedPrefs().edit()
 | 
			
		||||
            when (value) {
 | 
			
		||||
                is Boolean -> editor.putBoolean(path, value)
 | 
			
		||||
                is Int -> editor.putInt(path, value)
 | 
			
		||||
                is String -> editor.putString(path, value)
 | 
			
		||||
                is Float -> editor.putFloat(path, value)
 | 
			
		||||
                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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -69,11 +73,15 @@ object DataStore {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    fun Context.removeKey(path: String) {
 | 
			
		||||
        val prefs = getSharedPrefs()
 | 
			
		||||
        if (prefs.contains(path)) {
 | 
			
		||||
            val editor: SharedPreferences.Editor = prefs.edit()
 | 
			
		||||
            editor.remove(path)
 | 
			
		||||
            editor.apply()
 | 
			
		||||
        try {
 | 
			
		||||
            val prefs = getSharedPrefs()
 | 
			
		||||
            if (prefs.contains(path)) {
 | 
			
		||||
                val editor: SharedPreferences.Editor = prefs.edit()
 | 
			
		||||
                editor.remove(path)
 | 
			
		||||
                editor.apply()
 | 
			
		||||
            }
 | 
			
		||||
        } catch (e: Exception) {
 | 
			
		||||
            logError(e)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -86,9 +94,13 @@ object DataStore {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    fun <T> Context.setKey(path: String, value: T) {
 | 
			
		||||
        val editor: SharedPreferences.Editor = getSharedPrefs().edit()
 | 
			
		||||
        editor.putString(path, mapper.writeValueAsString(value))
 | 
			
		||||
        editor.apply()
 | 
			
		||||
        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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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())
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue