hopefully fixed crash issue

This commit is contained in:
LagradOst 2021-07-31 14:33:15 +02:00
parent 5523d6539a
commit 938a8e2a18
3 changed files with 35 additions and 26 deletions

View file

@ -273,7 +273,8 @@ class ShiroProvider : MainAPI() {
val episodes = val episodes =
ArrayList<AnimeEpisode>( ArrayList<AnimeEpisode>(
data.episodes?.distinctBy { it.episode_number }?.sortedBy { it.episode_number } data.episodes?.distinctBy { it.episode_number }?.sortedBy { it.episode_number }
?.map { AnimeEpisode(it.videos[0].video_id) } ?.filter { it.videos.isNotEmpty() }
?.map { AnimeEpisode(it.videos.first().video_id) }
?: ArrayList<AnimeEpisode>()) ?: ArrayList<AnimeEpisode>())
val status = when (data.status) { val status = when (data.status) {
"current" -> ShowStatus.Ongoing "current" -> ShowStatus.Ongoing

View file

@ -574,7 +574,7 @@ class ResultFragment : Fragment() {
val subs = currentSubs val subs = currentSubs
val outputDir = requireContext().cacheDir val outputDir = requireContext().cacheDir
val outputFile = withContext(Dispatchers.IO) { val outputFile = withContext(Dispatchers.IO) {
File.createTempFile("mirrorlist", ".m3u8", outputDir) File.createTempFile("mirrorlist", ".m3u8", outputDir)
} }
var text = "#EXTM3U" var text = "#EXTM3U"
@ -738,11 +738,9 @@ class ResultFragment : Fragment() {
observe(viewModel.publicEpisodes) { episodes -> observe(viewModel.publicEpisodes) { episodes ->
if (result_episodes == null || result_episodes.adapter == null) return@observe if (result_episodes == null || result_episodes.adapter == null) return@observe
currentEpisodes = episodes currentEpisodes = episodes
activity?.runOnUiThread { (result_episodes?.adapter as EpisodeAdapter?)?.cardList = episodes
(result_episodes.adapter as EpisodeAdapter).cardList = episodes (result_episodes?.adapter as EpisodeAdapter?)?.updateLayout()
(result_episodes.adapter as EpisodeAdapter).updateLayout() (result_episodes?.adapter as EpisodeAdapter?)?.notifyDataSetChanged()
(result_episodes.adapter as EpisodeAdapter).notifyDataSetChanged()
}
} }
observe(viewModel.selectedRange) { range -> observe(viewModel.selectedRange) { range ->

View file

@ -18,7 +18,9 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.setBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
const val EPISODE_RANGE_SIZE = 50 const val EPISODE_RANGE_SIZE = 50
const val EPISODE_RANGE_OVERLOAD = 60 const val EPISODE_RANGE_OVERLOAD = 60
@ -50,28 +52,31 @@ class ResultViewModel : ViewModel() {
private val _watchStatus: MutableLiveData<WatchType> = MutableLiveData() private val _watchStatus: MutableLiveData<WatchType> = MutableLiveData()
val watchStatus: LiveData<WatchType> get() = _watchStatus val watchStatus: LiveData<WatchType> get() = _watchStatus
fun updateWatchStatus(context: Context, status: WatchType) { fun updateWatchStatus(context: Context, status: WatchType) = viewModelScope.launch {
val currentId = id.value ?: return val currentId = id.value ?: return@launch
_watchStatus.postValue(status) _watchStatus.postValue(status)
context.setResultWatchState(currentId, status.internalId)
val resultPage = page.value val resultPage = page.value
if (resultPage != null) {
val current = context.getBookmarkedData(currentId) withContext(Dispatchers.IO) {
val currentTime = System.currentTimeMillis() context.setResultWatchState(currentId, status.internalId)
context.setBookmarkedData( if (resultPage != null) {
currentId, val current = context.getBookmarkedData(currentId)
DataStoreHelper.BookmarkedData( val currentTime = System.currentTimeMillis()
context.setBookmarkedData(
currentId, currentId,
current?.bookmarkedTime ?: currentTime, DataStoreHelper.BookmarkedData(
currentTime, currentId,
resultPage.name, current?.bookmarkedTime ?: currentTime,
resultPage.url, currentTime,
resultPage.apiName, resultPage.name,
resultPage.type, resultPage.url,
resultPage.posterUrl, resultPage.apiName,
resultPage.year resultPage.type,
resultPage.posterUrl,
resultPage.year
)
) )
) }
} }
} }
@ -91,7 +96,12 @@ class ResultViewModel : ViewModel() {
} }
val seasons = seasonTypes.toList().map { it.first } val seasons = seasonTypes.toList().map { it.first }
seasonSelections.postValue(seasons) seasonSelections.postValue(seasons)
val realSelection = if (!seasonTypes.containsKey(selection)) seasons[0] else selection if(seasons.isEmpty()) { // WHAT THE FUCK DID YOU DO????? HOW DID YOU DO THIS
_publicEpisodes.postValue(ArrayList())
return
}
val realSelection = if (!seasonTypes.containsKey(selection)) seasons.first() else selection
val internalId = id.value val internalId = id.value
if (internalId != null) context.setResultSeason(internalId, realSelection) if (internalId != null) context.setResultSeason(internalId, realSelection)