fixed #1170 - Next episode release date

This commit is contained in:
LagradOst 2022-06-21 02:30:55 +02:00
parent 03b2197bbc
commit 1eb67ade7e
3 changed files with 96 additions and 12 deletions

View file

@ -41,6 +41,7 @@ import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.getApiFromName
import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.APIHolder.unixTime
import com.lagradost.cloudstream3.APIHolder.updateHasTrailers
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.CommonActivity.getCastSession
@ -100,6 +101,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File
import java.util.concurrent.TimeUnit
const val MAX_SYNO_LENGH = 1000
@ -654,6 +657,55 @@ class ResultFragment : ResultTrailerPlayer() {
loadTrailer()
}
private fun setNextEpisode(nextAiring: NextAiring?) {
result_next_airing_holder?.isVisible =
if (nextAiring == null || nextAiring.episode <= 0 || nextAiring.unixTime <= unixTime) {
false
} else {
val seconds = nextAiring.unixTime - unixTime
val days = TimeUnit.SECONDS.toDays(seconds)
val hours: Long = TimeUnit.SECONDS.toHours(seconds) - days * 24
val minute =
TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.SECONDS.toHours(seconds) * 60
// val second =
// TimeUnit.SECONDS.toSeconds(seconds) - TimeUnit.SECONDS.toMinutes(seconds) * 60
try {
val ctx = context
if (ctx == null) {
false
} else {
when {
days > 0 -> {
ctx.getString(R.string.next_episode_time_day_format).format(
days,
hours,
minute
)
}
hours > 0 -> ctx.getString(R.string.next_episode_time_hour_format)
.format(
hours,
minute
)
minute > 0 -> ctx.getString(R.string.next_episode_time_min_format)
.format(
minute
)
else -> null
}?.also { text ->
result_next_airing_time?.text = text
result_next_airing?.text =
ctx.getString(R.string.next_episode_format).format(nextAiring.episode)
} != null
}
} catch (e: Exception) { // mistranslation
result_next_airing_holder?.isVisible = false
logError(e)
false
}
}
}
private fun setActors(actors: List<ActorData>?) {
if (actors.isNullOrEmpty()) {
result_cast_text?.isVisible = false
@ -1801,7 +1853,7 @@ class ResultFragment : ResultTrailerPlayer() {
setRating(d.rating)
setRecommendations(d.recommendations, null)
setActors(d.actors)
setNextEpisode(if (d is EpisodeResponse) d.nextAiring else null)
setTrailers(d.trailers)
if (syncModel.addSyncs(d.syncData)) {

View file

@ -139,6 +139,7 @@
android:orientation="vertical">
<com.facebook.shimmer.ShimmerFrameLayout
tools:visibility="gone"
android:visibility="gone"
android:id="@+id/result_trailer_loading"
android:layout_width="match_parent"
@ -148,8 +149,7 @@
app:shimmer_auto_start="true"
app:shimmer_base_alpha="0.2"
app:shimmer_duration="@integer/loading_time"
app:shimmer_highlight_alpha="0.3"
tools:visibility="visible">
app:shimmer_highlight_alpha="0.3">
<LinearLayout
android:layout_width="match_parent"
@ -423,6 +423,7 @@
tools:text="Cast: Joe Ligma" />
<androidx.recyclerview.widget.RecyclerView
tools:visibility="gone"
android:nextFocusUp="@id/result_bookmark_button"
android:nextFocusDown="@id/result_play_movie"
@ -669,6 +670,7 @@
android:visibility="gone"
tools:visibility="visible">
<com.google.android.material.button.MaterialButton
android:id="@+id/result_resume_series_button"
style="@style/WhiteButton"
@ -747,6 +749,7 @@
tools:text="69m\nremaining" />
</LinearLayout>
<LinearLayout
android:id="@+id/result_episodes_tab"
android:layout_width="match_parent"
@ -765,6 +768,7 @@
style="@style/MultiSelectButton"
android:layout_gravity="center_vertical"
android:layout_marginStart="0dp"
android:layout_marginEnd="10dp"
android:nextFocusLeft="@id/result_episode_select"
android:nextFocusRight="@id/result_episode_select"
android:nextFocusUp="@id/result_description"
@ -779,6 +783,8 @@
android:layout_gravity="center_vertical"
android:layout_marginStart="0dp"
android:layout_marginEnd="10dp"
android:nextFocusLeft="@id/result_season_button"
android:nextFocusRight="@id/result_season_button"
@ -794,6 +800,7 @@
android:layout_gravity="center_vertical"
android:layout_marginStart="0dp"
android:layout_marginEnd="10dp"
android:nextFocusLeft="@id/result_season_button"
android:nextFocusRight="@id/result_season_button"
@ -816,16 +823,37 @@
tools:text="8 Episodes" />
</LinearLayout>
<!--TODO add next airing-->
<LinearLayout
android:id="@+id/result_next_airing_holder"
android:layout_gravity="start"
android:paddingBottom="15dp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:visibility="gone"
android:gravity="center"
android:id="@+id/result_next_airing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/grayTextColor"
android:textSize="17sp"
android:textStyle="normal"
android:text="Episode 1022 will be released in" />
<TextView
android:paddingStart="5dp"
android:gravity="center"
android:id="@+id/result_next_airing_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:textSize="17sp"
android:textStyle="bold"
tools:text="Episode 1022 will be released in" />
android:textStyle="normal"
tools:text="5d 3h 30m" />
</LinearLayout>
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/result_episode_loading"
android:layout_width="match_parent"

View file

@ -67,6 +67,10 @@
<string name="year_format" translatable="false" formatted="true">%d</string>
<string name="app_dub_sub_episode_text_format" formatted="true">%s Ep %d</string>
<string name="cast_format" formatted="true">Cast: %s</string>
<string name="next_episode_format" formatted="true">Episode %d will be released in</string>
<string name="next_episode_time_day_format" formatted="true">%dd %dh %dm</string>
<string name="next_episode_time_hour_format" formatted="true">%dh %dm</string>
<string name="next_episode_time_min_format" formatted="true">%dm</string>
<!-- IS NOT NEEDED TO TRANSLATE AS THEY ARE ONLY USED FOR SCREEN READERS AND WONT SHOW UP TO NORMAL USERS -->
<string name="result_poster_img_des">Poster</string>