mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
subtitles correct scroll
This commit is contained in:
parent
e5189a1c7e
commit
9da1ce6032
3 changed files with 35 additions and 13 deletions
|
@ -14,6 +14,7 @@ import com.lagradost.cloudstream3.movieproviders.TrailersToProvider
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
|
||||||
const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0"
|
const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0"
|
||||||
val baseHeader = mapOf("User-Agent" to USER_AGENT)
|
val baseHeader = mapOf("User-Agent" to USER_AGENT)
|
||||||
|
@ -48,8 +49,10 @@ object APIHolder {
|
||||||
fun Activity.getApiSettings(): HashSet<String> {
|
fun Activity.getApiSettings(): HashSet<String> {
|
||||||
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
|
||||||
return settingsManager.getStringSet(this.getString(R.string.search_providers_list_key),
|
return settingsManager.getStringSet(
|
||||||
setOf(apis[defProvider].name))?.toHashSet() ?: hashSetOf(apis[defProvider].name)
|
this.getString(R.string.search_providers_list_key),
|
||||||
|
setOf(apis[defProvider].name)
|
||||||
|
)?.toHashSet() ?: hashSetOf(apis[defProvider].name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +75,12 @@ abstract class MainAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback is fired once a link is found, will return true if method is executed successfully
|
// callback is fired once a link is found, will return true if method is executed successfully
|
||||||
open fun loadLinks(data: String, isCasting: Boolean, subtitleCallback : (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit): Boolean {
|
open fun loadLinks(
|
||||||
|
data: String,
|
||||||
|
isCasting: Boolean,
|
||||||
|
subtitleCallback: (SubtitleFile) -> Unit,
|
||||||
|
callback: (ExtractorLink) -> Unit
|
||||||
|
): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +111,16 @@ fun sortUrls(urls: List<ExtractorLink>): List<ExtractorLink> {
|
||||||
return urls.sortedBy { t -> -t.quality }
|
return urls.sortedBy { t -> -t.quality }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sortSubs(urls: List<SubtitleFile>): List<SubtitleFile> {
|
||||||
|
val encounteredTimes = HashMap<String, Int>()
|
||||||
|
return urls.sortedBy { t -> t.lang }.map {
|
||||||
|
val times = encounteredTimes[it.lang]?.plus(1) ?: 1
|
||||||
|
encounteredTimes[it.lang] = times
|
||||||
|
|
||||||
|
SubtitleFile("${it.lang} ${if (times > 1) "($times)" else ""}", it.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class ShowStatus {
|
enum class ShowStatus {
|
||||||
Completed,
|
Completed,
|
||||||
Ongoing,
|
Ongoing,
|
||||||
|
@ -120,7 +138,7 @@ enum class TvType {
|
||||||
ONA,
|
ONA,
|
||||||
}
|
}
|
||||||
|
|
||||||
data class SubtitleFile(val lang : String, val url : String)
|
data class SubtitleFile(val lang: String, val url: String)
|
||||||
|
|
||||||
interface SearchResponse {
|
interface SearchResponse {
|
||||||
val name: String
|
val name: String
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.view.Menu
|
||||||
import android.view.View.*
|
import android.view.View.*
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.graphics.toColorInt
|
|
||||||
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
|
||||||
|
@ -118,11 +117,20 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
|
||||||
} else {
|
} else {
|
||||||
val arrayAdapter = ArrayAdapter<String>(view.context, R.layout.sort_bottom_single_choice)
|
val arrayAdapter = ArrayAdapter<String>(view.context, R.layout.sort_bottom_single_choice)
|
||||||
arrayAdapter.add("No Subtitles")
|
arrayAdapter.add("No Subtitles")
|
||||||
arrayAdapter.addAll(subTracks.map { it.name }.filterNotNull())
|
arrayAdapter.addAll(subTracks.mapNotNull { it.name })
|
||||||
|
|
||||||
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
||||||
subtitleList.adapter = arrayAdapter
|
subtitleList.adapter = arrayAdapter
|
||||||
|
|
||||||
|
val currentTracks = remoteMediaClient?.mediaStatus?.activeTrackIds
|
||||||
|
|
||||||
|
val subtitleIndex =
|
||||||
|
if (currentTracks == null) 0 else subTracks.map { it.id }
|
||||||
|
.indexOfFirst { currentTracks.contains(it) } + 1
|
||||||
|
|
||||||
|
subtitleList.setSelection(subtitleIndex)
|
||||||
|
subtitleList.setItemChecked(subtitleIndex, true)
|
||||||
|
|
||||||
subtitleList.setOnItemClickListener { _, _, which, _ ->
|
subtitleList.setOnItemClickListener { _, _, which, _ ->
|
||||||
if (which == 0) {
|
if (which == 0) {
|
||||||
remoteMediaClient.setActiveMediaTracks(longArrayOf()) // NO SUBS
|
remoteMediaClient.setActiveMediaTracks(longArrayOf()) // NO SUBS
|
||||||
|
@ -164,6 +172,7 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
|
||||||
|
|
||||||
providerList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
providerList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
|
||||||
providerList.adapter = arrayAdapter
|
providerList.adapter = arrayAdapter
|
||||||
|
providerList.setSelection(sotringIndex)
|
||||||
providerList.setItemChecked(sotringIndex, true)
|
providerList.setItemChecked(sotringIndex, true)
|
||||||
|
|
||||||
providerList.setOnItemClickListener { _, _, which, _ ->
|
providerList.setOnItemClickListener { _, _, which, _ ->
|
||||||
|
@ -359,11 +368,5 @@ class ControllerActivity : ExpandedControllerActivity() {
|
||||||
uiMediaController.bindViewToUIController(skipBackButton, SkipTimeController(skipBackButton, false))
|
uiMediaController.bindViewToUIController(skipBackButton, SkipTimeController(skipBackButton, false))
|
||||||
uiMediaController.bindViewToUIController(skipForwardButton, SkipTimeController(skipForwardButton, true))
|
uiMediaController.bindViewToUIController(skipForwardButton, SkipTimeController(skipForwardButton, true))
|
||||||
uiMediaController.bindViewToUIController(skipOpButton, SkipNextEpisodeController(skipOpButton))
|
uiMediaController.bindViewToUIController(skipOpButton, SkipNextEpisodeController(skipOpButton))
|
||||||
|
|
||||||
|
|
||||||
/* val progressBar: CastSeekBar? = findViewById(R.id.cast_seek_bar)
|
|
||||||
|
|
||||||
progressBar?.backgroundTintList = (UIHelper.adjustAlpha(colorFromAttribute(R.attr.colorPrimary), 0.35f))
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ import com.google.android.gms.cast.framework.media.RemoteMediaClient
|
||||||
import com.google.android.gms.common.api.PendingResult
|
import com.google.android.gms.common.api.PendingResult
|
||||||
import com.google.android.gms.common.images.WebImage
|
import com.google.android.gms.common.images.WebImage
|
||||||
import com.lagradost.cloudstream3.SubtitleFile
|
import com.lagradost.cloudstream3.SubtitleFile
|
||||||
|
import com.lagradost.cloudstream3.sortSubs
|
||||||
import com.lagradost.cloudstream3.ui.MetadataHolder
|
import com.lagradost.cloudstream3.ui.MetadataHolder
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
|
@ -50,7 +51,7 @@ object CastHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
var subIndex = 0
|
var subIndex = 0
|
||||||
val tracks = subtitles.map {
|
val tracks = sortSubs(subtitles).map {
|
||||||
MediaTrack.Builder(subIndex++.toLong(), MediaTrack.TYPE_TEXT)
|
MediaTrack.Builder(subIndex++.toLong(), MediaTrack.TYPE_TEXT)
|
||||||
.setName(it.lang)
|
.setName(it.lang)
|
||||||
.setSubtype(MediaTrack.SUBTYPE_SUBTITLES)
|
.setSubtype(MediaTrack.SUBTYPE_SUBTITLES)
|
||||||
|
|
Loading…
Reference in a new issue