resume watching, added #564

This commit is contained in:
LagradOst 2022-02-04 15:46:48 +01:00
parent a0667bd245
commit f15e21f0d5
4 changed files with 115 additions and 4 deletions

View File

@ -7,7 +7,6 @@ import android.util.Log
import android.widget.FrameLayout
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
import com.google.android.exoplayer2.extractor.ExtractorsFactory
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MergingMediaSource
@ -19,12 +18,12 @@ import com.google.android.exoplayer2.trackselection.TrackSelector
import com.google.android.exoplayer2.ui.SubtitleView
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.upstream.cache.CacheDataSource
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
import com.google.android.exoplayer2.upstream.cache.SimpleCache
import com.google.android.exoplayer2.util.MimeTypes
import com.lagradost.cloudstream3.USER_AGENT
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
import com.lagradost.cloudstream3.utils.ExtractorLink
@ -266,7 +265,7 @@ class CS3IPlayer : IPlayer {
companion object {
private fun createOnlineSource(link: ExtractorLink): DataSource.Factory {
// Because Trailers.to seems to fail with http/1.1 the normal one uses.
return OkHttpDataSource.Factory(app.baseClient).apply {
return DefaultHttpDataSource.Factory().apply {
setUserAgent(USER_AGENT)
val headers = mapOf(
"referer" to link.referer,
@ -280,7 +279,7 @@ class CS3IPlayer : IPlayer {
setDefaultRequestProperties(headers)
//https://stackoverflow.com/questions/69040127/error-code-io-bad-http-status-exoplayer-android
// setAllowCrossProtocolRedirects(true)
setAllowCrossProtocolRedirects(true)
}
}

View File

@ -526,6 +526,8 @@ class ResultFragment : Fragment() {
private fun updateUI() {
viewModel.reloadEpisodes()
}
@SuppressLint("SetTextI18n")
@ -1020,6 +1022,31 @@ class ResultFragment : Fragment() {
observe(viewModel.episodes) { episodeList ->
lateFixDownloadButton(episodeList.size <= 1) // movies can have multible parts but still be *movies* this will fix this
var isSeriesVisible = false
DataStoreHelper.getLastWatched(currentId)?.let { resume ->
if (currentIsMovie == false && episodeList.size >= 3) {
isSeriesVisible = true
result_resume_series_button?.setOnClickListener {
episodeList.firstOrNull { it.id == resume.episodeId }?.let {
handleAction(EpisodeClickEvent(ACTION_PLAY_EPISODE_IN_PLAYER, it))
}
}
result_resume_series_title?.text =
if (resume.season == null)
"${getString(R.string.episode)} ${resume.episode}"
else
" \"${getString(R.string.season_short)}${resume.season}:${getString(R.string.episode_short)}${resume.episode}\""
getViewPos(resume.episodeId)?.let { viewPos ->
result_resume_series_progress?.apply {
max = (viewPos.duration / 1000).toInt()
progress = (viewPos.position / 1000).toInt()
}
result_resume_series_progress_text?.text = getString(R.string.resume_time_left).format((viewPos.duration - viewPos.position) / (60_000))
}
}
}
result_series_parent?.isVisible = isSeriesVisible
when (startAction) {
START_ACTION_RESUME_LATEST -> {

View File

@ -339,6 +339,7 @@
style="@style/SmallBlackButton"
android:layout_gravity="center_vertical"
tools:text="Gogoanime" />
<TextView
android:id="@+id/result_meta_type"
android:paddingStart="5dp"
@ -351,6 +352,7 @@
android:textColor="?attr/textColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingStart="5dp"
android:paddingEnd="5dp"
@ -673,6 +675,87 @@
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:visibility="gone"
tools:visibility="visible"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:id="@+id/result_series_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:layout_marginBottom="10dp"
android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_download_movie"
android:id="@+id/result_resume_series_button"
style="@style/WhiteButton"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:visibility="visible"
tools:visibility="visible"
android:layout_gravity="center_vertical"
android:text="@string/resume"
app:icon="@drawable/ic_baseline_play_arrow_24"
android:layout_width="match_parent" />
<com.google.android.material.button.MaterialButton
android:layout_marginBottom="10dp"
android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_download_movie"
android:id="@+id/result_next_series_button"
style="@style/WhiteButton"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:visibility="gone"
android:layout_gravity="center_vertical"
android:text="@string/next_episode"
app:icon="@drawable/cast_ic_mini_controller_skip_next"
android:layout_width="match_parent" />
<TextView
android:textColor="?attr/textColor"
android:id="@+id/result_resume_series_title"
android:textStyle="bold"
android:textSize="17sp"
tools:text="S1E1 Episode 1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.core.widget.ContentLoadingProgressBar
android:layout_height="20dp"
tools:progress="50"
android:id="@+id/result_resume_series_progress"
android:indeterminate="false"
style="?android:attr/progressBarStyleHorizontal"
android:progressBackgroundTint="?attr/colorPrimary"
android:max="100"
android:layout_gravity="end|center_vertical"
android:progress="0"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="visible"
tools:visibility="visible" />
<TextView
android:id="@+id/result_resume_series_progress_text"
android:layout_gravity="center"
android:paddingStart="10dp"
android:gravity="center"
tools:text="69m\nremaining"
android:layout_weight="0"
android:textColor="?attr/grayTextColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="RtlSymmetry" />
</LinearLayout>
</LinearLayout>
<!--<TextView
android:visibility="gone"
android:drawableLeft="@drawable/ic_baseline_play_arrow_24"

View File

@ -235,6 +235,8 @@
<string name="go_back_30">-30</string>
<string name="go_forward_30">+30</string>
<string name="delete_message" formatted="true">This will permanently delete %s\nAre you sure?</string>
<string name="resume_time_left" formatted="true">%dm\nremaining</string>
<string name="status_ongoing">Ongoing</string>
<string name="status_completed">Completed</string>