release 0.4.0 #34

Merged
Seil0 merged 29 commits from develop into master 1 year ago
  1. 15
      README.md
  2. 20
      app/build.gradle
  3. 26
      app/src/main/AndroidManifest.xml
  4. 219
      app/src/main/java/org/mosad/teapod/parser/AoDParser.kt
  5. 6
      app/src/main/java/org/mosad/teapod/preferences/Preferences.kt
  6. 3
      app/src/main/java/org/mosad/teapod/ui/activity/SplashActivity.kt
  7. 89
      app/src/main/java/org/mosad/teapod/ui/activity/main/MainActivity.kt
  8. 27
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AboutFragment.kt
  9. 7
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AccountFragment.kt
  10. 57
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/HomeFragment.kt
  11. 6
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/LibraryFragment.kt
  12. 210
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt
  13. 61
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragmentEpisodes.kt
  14. 41
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragmentSimilar.kt
  15. 6
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/SearchFragment.kt
  16. 48
      app/src/main/java/org/mosad/teapod/ui/activity/main/viewmodel/MediaFragmentViewModel.kt
  17. 54
      app/src/main/java/org/mosad/teapod/ui/activity/onboarding/OnLoginFragment.kt
  18. 31
      app/src/main/java/org/mosad/teapod/ui/activity/onboarding/OnWelcomeFragment.kt
  19. 79
      app/src/main/java/org/mosad/teapod/ui/activity/onboarding/OnboardingActivity.kt
  20. 129
      app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt
  21. 3
      app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerViewModel.kt
  22. 2
      app/src/main/java/org/mosad/teapod/ui/components/EpisodesListPlayer.kt
  23. 2
      app/src/main/java/org/mosad/teapod/ui/components/LanguageSettingsPlayer.kt
  24. 177
      app/src/main/java/org/mosad/teapod/ui/fragments/MediaFragment.kt
  25. 82
      app/src/main/java/org/mosad/teapod/util/ActivityUtils.kt
  26. 5
      app/src/main/java/org/mosad/teapod/util/DataTypes.kt
  27. 7
      app/src/main/java/org/mosad/teapod/util/Utils.kt
  28. 6
      app/src/main/java/org/mosad/teapod/util/adapter/EpisodeItemAdapter.kt
  29. 12
      app/src/main/res/drawable/dot_default.xml
  30. 12
      app/src/main/res/drawable/dot_selected.xml
  31. 6
      app/src/main/res/drawable/dot_tab_selector.xml
  32. 5
      app/src/main/res/drawable/ic_baseline_code_24.xml
  33. 5
      app/src/main/res/drawable/ic_baseline_description_24.xml
  34. 10
      app/src/main/res/drawable/ic_baseline_info_24.xml
  35. 5
      app/src/main/res/drawable/ic_baseline_people_24.xml
  36. 5
      app/src/main/res/drawable/ic_outline_info_24.xml
  37. 50
      app/src/main/res/layout/activity_onboarding.xml
  38. 2
      app/src/main/res/layout/activity_player.xml
  39. 2
      app/src/main/res/layout/button_rewind.xml
  40. 233
      app/src/main/res/layout/fragment_about.xml
  41. 4
      app/src/main/res/layout/fragment_account.xml
  42. 32
      app/src/main/res/layout/fragment_home.xml
  43. 2
      app/src/main/res/layout/fragment_library.xml
  44. 277
      app/src/main/res/layout/fragment_media.xml
  45. 19
      app/src/main/res/layout/fragment_media_episodes.xml
  46. 22
      app/src/main/res/layout/fragment_media_similar.xml
  47. 90
      app/src/main/res/layout/fragment_on_login.xml
  48. 74
      app/src/main/res/layout/fragment_on_welcome.xml
  49. 2
      app/src/main/res/layout/fragment_search.xml
  50. 8
      app/src/main/res/navigation/mobile_navigation.xml
  51. 34
      app/src/main/res/values-de-rDE/strings.xml
  52. 6
      app/src/main/res/values/dimens.xml
  53. 43
      app/src/main/res/values/strings.xml
  54. 7
      app/src/main/res/values/styles.xml
  55. 4
      build.gradle
  56. 6
      fastlane/metadata/android/de/changelogs/4000.txt
  57. 6
      fastlane/metadata/android/en-US/changelogs/4000.txt

15
README.md

@ -1,10 +1,8 @@
# teapod
# Teapod
A unofficial App for Anime-on-Demand.
Teapod is a unofficial App for Anime-on-Demand (AoD). It allows you to watch all your favourite animes from AoD on your Android Device.
Teapod is a unofficial App for Anime on Demand (AoD). It allows you to watch all your favourite animes from AoD on your android device. To use Teapod you need to have a subscription to AoD.
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="75">](https://f-droid.org/de/packages/org.mosad.teapod/)
[<img src="https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png" height="75">](https://apt.izzysoft.de/fdroid/index/apk/org.mosad.teapod)
## Features
* Watch all animes from AoD on your Android device
@ -19,13 +17,12 @@ Teapod is a unofficial App for Anime-on-Demand (AoD). It allows you to watch all
[<img src="https://www.mosad.xyz/images/Teapod/Teapod_Search.webp" width=180>](https://www.mosad.xyz/images/Teapod/Teapod_Search.webp)
### License
This Project is not associated with Anime-on-Demand in any way. Using this app may violates the ToS of AoD. Teapod is licensed under the terms and conditions of GPL 3.
### Known Issues
If a tv show is selected, the first episode will be marked as watched. This is due to parsing the website.
Teapod is licensed under the terms and conditions of GPL 3. This Project is not associated with Anime on Demand in any way. But they allow open source apps for their service.
### Contributing
If you want to contribute to Teapod and need an account on this gitea instance, please write me an email: seil0@mosad.xyz
Currentl you need to have an AoD account to contrtibut to Teapod. Contributing without on is kind of impossible.If you want to contribute to Teapod and need an account on this gitea instance, please write me an email.
### [FAQ](https://git.mosad.xyz/Seil0/teapod/wiki#hilfe)
#### Why is it called Teapod?
Teapod is a Acronym for "The ultimate anime app on demand", hence this project is called Teapod and not Teapot.

20
app/build.gradle

@ -10,8 +10,8 @@ android {
applicationId "org.mosad.teapod"
minSdkVersion 23
targetSdkVersion 30
versionCode 3000 //00.03.000
versionName "0.3.0"
versionCode 4000 //00.04.000
versionName "0.4.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "build_time", buildTime()
@ -46,20 +46,20 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.3'
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0-beta01'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.exoplayer:exoplayer-core:2.12.2'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.2'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.2'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.12.2'
implementation 'com.google.android.exoplayer:exoplayer-core:2.13.2'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.2'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.13.2'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.2'
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'

26
app/src/main/AndroidManifest.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.mosad.teapod">
<uses-permission android:name="android.permission.INTERNET" />
@ -10,9 +11,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.Light">
android:theme="@style/AppTheme.Dark">
<activity
android:name=".SplashActivity"
android:name="org.mosad.teapod.ui.activity.SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:screenOrientation="portrait">
@ -22,15 +23,28 @@
</intent-filter>
</activity>
<activity
android:name=".player.PlayerActivity"
android:name="org.mosad.teapod.ui.activity.onboarding.OnboardingActivity"
android:label="@string/app_name"
android:theme="@style/PlayerTheme"
android:configChanges="orientation|screenSize|layoutDirection" />
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan">
</activity>
<activity
android:name=".MainActivity"
android:name="org.mosad.teapod.ui.activity.main.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.mosad.teapod.ui.activity.player.PlayerActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|layoutDirection"
android:autoRemoveFromRecents="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:parentActivityName="org.mosad.teapod.ui.activity.main.MainActivity"
android:supportsPictureInPicture="true"
android:taskAffinity=".player.PlayerActivity"
android:theme="@style/PlayerTheme"
tools:targetApi="n" />
</application>
</manifest>

219
app/src/main/java/org/mosad/teapod/parser/AoDParser.kt

@ -41,7 +41,7 @@ object AoDParser {
private const val loginPath = "/users/sign_in"
private const val libraryPath = "/animes"
private const val userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"
private const val userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0"
private var sessionCookies = mutableMapOf<String, String>()
private var csrfToken: String = ""
@ -53,10 +53,11 @@ object AoDParser {
val newEpisodesList = arrayListOf<ItemMedia>()
val newSimulcastsList = arrayListOf<ItemMedia>()
val newTitlesList = arrayListOf<ItemMedia>()
val topTenList = arrayListOf<ItemMedia>()
fun login(): Boolean = runBlocking {
withContext(Dispatchers.Default) {
withContext(Dispatchers.IO) {
// get the authenticity token
val resAuth = Jsoup.connect(baseUrl + loginPath)
.header("User-Agent", userAgent)
@ -78,7 +79,7 @@ object AoDParser {
val resLogin = Jsoup.connect(baseUrl + loginPath)
.method(Connection.Method.POST)
.timeout(60000) // login can take some time
.timeout(60000) // login can take some time default is 60000 (60 sec)
.data(data)
.postDataCharset("UTF-8")
.cookies(authCookies)
@ -96,20 +97,11 @@ object AoDParser {
/**
* initially load all media and home screen data
* -> blocking
*/
fun initialLoading() = runBlocking {
val loadHomeJob = GlobalScope.async {
loadHome()
}
val listJob = GlobalScope.async {
fun initialLoading() = listOf(
loadHome(),
listAnimes()
}
loadHomeJob.await()
listJob.await()
}
)
/**
* get a media by it's ID (int)
@ -134,7 +126,7 @@ object AoDParser {
}
// TODO don't use jsoup here
fun sendCallback(callbackPath: String) = GlobalScope.launch(Dispatchers.IO) {
private fun sendCallback(callbackPath: String) = GlobalScope.launch(Dispatchers.IO) {
val headers = mutableMapOf(
Pair("Accept", "application/json, text/javascript, */*; q=0.01"),
Pair("Accept-Language", "de,en-US;q=0.7,en;q=0.3"),
@ -158,112 +150,112 @@ object AoDParser {
/**
* load all media from aod into itemMediaList and mediaList
*/
private fun listAnimes() = runBlocking {
if (sessionCookies.isEmpty()) login()
withContext(Dispatchers.Default) {
val resAnimes = Jsoup.connect(baseUrl + libraryPath)
.cookies(sessionCookies)
.get()
//println(resAnimes)
itemMediaList.clear()
mediaList.clear()
resAnimes.select("div.animebox").forEach {
val type = if (it.select("p.animebox-link").select("a").text().toLowerCase(Locale.ROOT) == "zur serie") {
MediaType.TVSHOW
} else {
MediaType.MOVIE
}
val mediaTitle = it.select("h3.animebox-title").text()
val mediaLink = it.select("p.animebox-link").select("a").attr("href")
val mediaImage = it.select("p.animebox-image").select("img").attr("src")
val mediaShortText = it.select("p.animebox-shorttext").text()
val mediaId = mediaLink.substringAfterLast("/").toInt()
itemMediaList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
mediaList.add(Media(mediaId, mediaLink, type).apply {
info.title = mediaTitle
info.posterUrl = mediaImage
info.shortDesc = mediaShortText
})
private fun listAnimes() = GlobalScope.launch(Dispatchers.IO) {
val resAnimes = Jsoup.connect(baseUrl + libraryPath).get()
//println(resAnimes)
itemMediaList.clear()
mediaList.clear()
resAnimes.select("div.animebox").forEach {
val type = if (it.select("p.animebox-link").select("a").text().toLowerCase(Locale.ROOT) == "zur serie") {
MediaType.TVSHOW
} else {
MediaType.MOVIE
}
Log.i(javaClass.name, "Total library size is: ${mediaList.size}")
val mediaTitle = it.select("h3.animebox-title").text()
val mediaLink = it.select("p.animebox-link").select("a").attr("href")
val mediaImage = it.select("p.animebox-image").select("img").attr("src")
val mediaShortText = it.select("p.animebox-shorttext").text()
val mediaId = mediaLink.substringAfterLast("/").toInt()
itemMediaList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
mediaList.add(Media(mediaId, mediaLink, type).apply {
info.title = mediaTitle
info.posterUrl = mediaImage
info.shortDesc = mediaShortText
})
}
Log.i(javaClass.name, "Total library size is: ${mediaList.size}")
}
/**
* load new episodes, titles and highlights
*/
private fun loadHome() = runBlocking {
if (sessionCookies.isEmpty()) login()
private fun loadHome() = GlobalScope.launch(Dispatchers.IO) {
val resHome = Jsoup.connect(baseUrl).get()
// get highlights from AoD
highlightsList.clear()
resHome.select("#aod-highlights").select("div.news-item").forEach {
val mediaId = it.select("div.news-item-text").select("a.serienlink")
.attr("href").substringAfterLast("/").toIntOrNull()
val mediaTitle = it.select("div.news-title").select("h2").text()
val mediaImage = it.select("img").attr("src")
if (mediaId != null) {
highlightsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
withContext(Dispatchers.Default) {
val resHome = Jsoup.connect(baseUrl)
.cookies(sessionCookies)
.get()
// get highlights from AoD
highlightsList.clear()
resHome.select("#aod-highlights").select("div.news-item").forEach {
val mediaId = it.select("div.news-item-text").select("a.serienlink")
.attr("href").substringAfterLast("/").toIntOrNull()
val mediaTitle = it.select("div.news-title").select("h2").text()
val mediaImage = it.select("img").attr("src")
if (mediaId != null) {
highlightsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
// get all new episodes from AoD
newEpisodesList.clear()
resHome.select("h2:contains(Neue Episoden)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = "${it.select("a").text()} - ${it.select("span.neweps").text()}"
if (mediaId != null) {
newEpisodesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
// get all new episodes from AoD
newEpisodesList.clear()
resHome.select("h2:contains(Neue Episoden)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = "${it.select("a").text()} - ${it.select("span.neweps").text()}"
// get new simulcasts from AoD
newSimulcastsList.clear()
resHome.select("h2:contains(Neue Simulcasts)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
if (mediaId != null) {
newEpisodesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
if (mediaId != null) {
newSimulcastsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
// get new simulcasts from AoD
newSimulcastsList.clear()
resHome.select("h2:contains(Neue Simulcasts)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
// get new titles from AoD
newTitlesList.clear()
resHome.select("h2:contains(Neue Anime-Titel)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
if (mediaId != null) {
newSimulcastsList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
if (mediaId != null) {
newTitlesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
// get new titles from AoD
newTitlesList.clear()
resHome.select("h2:contains(Neue Anime-Titel)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
// get top ten from AoD
topTenList.clear()
resHome.select("h2:contains(Anime Top 10)").next().select("li").forEach {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
if (mediaId != null) {
newTitlesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
if (mediaId != null) {
topTenList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
// if highlights is empty, add a random new title
if (highlightsList.isEmpty()) {
if (newTitlesList.isNotEmpty()) {
highlightsList.add(newTitlesList[Random.nextInt(0, newTitlesList.size)])
} else {
highlightsList.add(ItemMedia(0,"", ""))
}
// if highlights is empty, add a random new title
if (highlightsList.isEmpty()) {
if (newTitlesList.isNotEmpty()) {
highlightsList.add(newTitlesList[Random.nextInt(0, newTitlesList.size)])
} else {
highlightsList.add(ItemMedia(0,"", ""))
}
}
}
@ -272,7 +264,7 @@ object AoDParser {
* load streams for the media path, movies have one episode
* @param media is used as call ba reference
*/
private suspend fun loadStreams(media: Media) = GlobalScope.launch(Dispatchers.IO) {
private fun loadStreams(media: Media) = GlobalScope.launch(Dispatchers.IO) {
if (sessionCookies.isEmpty()) login()
if (!loginSuccess) {
@ -331,7 +323,7 @@ object AoDParser {
}
Log.i(javaClass.name, "Loaded playlists successfully")
// parse additional info from the media page
// additional info from the media page
res.select("table.vertical-table").select("tr").forEach { row ->
when (row.select("th").text().toLowerCase(Locale.ROOT)) {
"produktionsjahr" -> media.info.year = row.select("td").text().toInt()
@ -345,7 +337,21 @@ object AoDParser {
}
}
// parse additional information for tv shows the episode title (description) is loaded from the "api"
// similar titles from media page
media.info.similar = res.select("h2:contains(Ă„hnliche Animes)").next().select("li").mapNotNull {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toIntOrNull()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = it.select("a").text()
if (mediaId != null) {
ItemMedia(mediaId, mediaTitle, mediaImage)
} else {
null
}
}
// additional information for tv shows the episode title (description) is loaded from the "api"
if (media.type == MediaType.TVSHOW) {
res.select("div.three-box-container > div.episodebox").forEach { episodebox ->
// make sure the episode has a streaming link
@ -363,6 +369,7 @@ object AoDParser {
}
}
}
Log.i(javaClass.name, "media loaded successfully")
}
/**

6
app/src/main/java/org/mosad/teapod/preferences/Preferences.kt

@ -11,7 +11,7 @@ object Preferences {
internal set
var autoplay = true
internal set
var theme = DataTypes.Theme.LIGHT
var theme = DataTypes.Theme.DARK
internal set
private fun getSharedPref(context: Context): SharedPreferences {
@ -62,8 +62,8 @@ object Preferences {
)
theme = DataTypes.Theme.valueOf(
sharedPref.getString(
context.getString(R.string.save_key_theme), DataTypes.Theme.LIGHT.toString()
) ?: DataTypes.Theme.LIGHT.toString()
context.getString(R.string.save_key_theme), DataTypes.Theme.DARK.toString()
) ?: DataTypes.Theme.DARK.toString()
)
}

3
app/src/main/java/org/mosad/teapod/SplashActivity.kt → app/src/main/java/org/mosad/teapod/ui/activity/SplashActivity.kt

@ -1,8 +1,9 @@
package org.mosad.teapod
package org.mosad.teapod.ui.activity
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.mosad.teapod.ui.activity.main.MainActivity
class SplashActivity : AppCompatActivity() {

89
app/src/main/java/org/mosad/teapod/MainActivity.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/MainActivity.kt

@ -20,7 +20,7 @@
*
*/
package org.mosad.teapod
package org.mosad.teapod.ui.activity.main
import android.content.Intent
import android.os.Bundle
@ -29,16 +29,27 @@ import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.runBlocking
import org.mosad.teapod.R
import org.mosad.teapod.databinding.ActivityMainBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.player.PlayerActivity
import org.mosad.teapod.ui.activity.player.PlayerActivity
import org.mosad.teapod.preferences.EncryptedPreferences
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.components.LoginDialog
import org.mosad.teapod.ui.fragments.*
import org.mosad.teapod.ui.activity.main.fragments.AccountFragment
import org.mosad.teapod.ui.activity.main.fragments.HomeFragment
import org.mosad.teapod.ui.activity.main.fragments.LibraryFragment
import org.mosad.teapod.ui.activity.main.fragments.SearchFragment
import org.mosad.teapod.ui.activity.onboarding.OnboardingActivity
import org.mosad.teapod.util.DataTypes
import org.mosad.teapod.util.StorageController
import org.mosad.teapod.util.exitAndRemoveTask
import java.net.SocketTimeoutException
import kotlin.system.measureTimeMillis
class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {
@ -48,6 +59,11 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
companion object {
var wasInitialized = false
lateinit var instance: MainActivity
}
init {
instance = this
}
override fun onCreate(savedInstanceState: Bundle?) {
@ -111,39 +127,57 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private fun getThemeResource(): Int {
return when (Preferences.theme) {
DataTypes.Theme.DARK -> R.style.AppTheme_Dark
else -> R.style.AppTheme_Light
DataTypes.Theme.LIGHT -> R.style.AppTheme_Light
else -> R.style.AppTheme_Dark
}
}
/**
* initial loading and login are run in parallel, as initial loading doesn't require
* any login cookies
*/
private fun load() {
// running login and list in parallel does not bring any speed improvements
val time = measureTimeMillis {
Preferences.load(this)
val loadingJob = AoDParser.initialLoading() // start the initial loading
// make sure credentials are set, run's async
// load all saved stuff here
Preferences.load(this)
EncryptedPreferences.readCredentials(this)
StorageController.load(this)
// show onbaording
if (EncryptedPreferences.password.isEmpty()) {
showLoginDialog(true)
showOnboarding()
} else {
// try to login in, as most sites can only bee loaded once loged in
if (!AoDParser.login()) showLoginDialog(false)
try {
if (!AoDParser.login()) {
showLoginDialog()
}
} catch (ex: SocketTimeoutException) {
Log.w(javaClass.name, "Timeout during login!")
// show waring dialog before finishing
MaterialDialog(this).show {
title(R.string.dialog_timeout_head)
message(R.string.dialog_timeout_desc)
onDismiss { exitAndRemoveTask() }
}
}
}
StorageController.load(this)
AoDParser.initialLoading()
wasInitialized = true
runBlocking { loadingJob.joinAll() } // wait for initial loading to finish
}
Log.i(javaClass.name, "login and list in $time ms")
Log.i(javaClass.name, "loading and login in $time ms")
wasInitialized = true
}
private fun showLoginDialog(firstTry: Boolean) {
LoginDialog(this, firstTry).positiveButton {
private fun showLoginDialog() {
LoginDialog(this, false).positiveButton {
EncryptedPreferences.saveCredentials(login, password, context)
if (!AoDParser.login()) {
showLoginDialog(false)
showLoginDialog()
Log.w(javaClass.name, "Login failed, please try again.")
}
}.negativeButton {
@ -153,18 +187,16 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
/**
* Show a fragment on top of the current fragment.
* The current fragment is replaced and the new one is added
* to the back stack.
* start the onboarding activity and finish the main activity
*/
fun showFragment(fragment: Fragment) {
supportFragmentManager.commit {
replace(R.id.nav_host_fragment, fragment, fragment.javaClass.simpleName)
addToBackStack(fragment.javaClass.name)
show(fragment)
}
private fun showOnboarding() {
startActivity(Intent(this, OnboardingActivity::class.java))
finish()
}
/**
* start the player as new activity
*/
fun startPlayer(mediaId: Int, episodeId: Int) {
val intent = Intent(this, PlayerActivity::class.java).apply {
putExtra(getString(R.string.intent_media_id), mediaId)
@ -183,5 +215,4 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
startActivity(restartIntent)
}
}

27
app/src/main/java/org/mosad/teapod/ui/fragments/AboutFragment.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AboutFragment.kt

@ -1,5 +1,7 @@
package org.mosad.teapod.ui.fragments
package org.mosad.teapod.ui.activity.main.fragments
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@ -17,6 +19,7 @@ import java.lang.StringBuilder
class AboutFragment : Fragment() {
private val teapodRepoUrl = "https://git.mosad.xyz/Seil0/teapod"
private lateinit var binding: FragmentAboutBinding
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
@ -27,7 +30,7 @@ class AboutFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.textVersion.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
binding.textVersionDesc.text = getString(R.string.version_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
getThirdPartyComponents().forEach { thirdParty ->
val componentBinding = ItemComponentBinding.inflate(layoutInflater) //(R.layout.item_component, container, false)
@ -44,10 +47,25 @@ class AboutFragment : Fragment() {
binding.linearThirdParty.addView(componentBinding.root)
}
initActions()
}
private fun initActions() {
binding.linearSource.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(teapodRepoUrl)))
}
binding.linearLicense.setOnClickListener {
MaterialDialog(requireContext())
.title(text = License.GPL3.long)
.message(text = parseLicense(R.raw.gpl_3_full))
.show()
}
}
private fun getThirdPartyComponents(): List<ThirdPartyComponent> {
return listOf<ThirdPartyComponent>(
return listOf(
ThirdPartyComponent("AndroidX", "", "The Android Open Source Project",
"https://developer.android.com/jetpack/androidx", License.APACHE2),
ThirdPartyComponent("Material Components for Android", "2020", "The Android Open Source Project",
@ -79,13 +97,10 @@ class AboutFragment : Fragment() {
License.MIT -> parseLicense(R.raw.mit_full)
}
println("showing: ${license.long}")
MaterialDialog(requireContext())
.title(text = license.long)
.message(text = licenseText)
.show()
}
private fun parseLicense(@RawRes id: Int): String {

7
app/src/main/java/org/mosad/teapod/ui/fragments/AccountFragment.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/AccountFragment.kt

@ -1,4 +1,4 @@
package org.mosad.teapod.ui.fragments
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.util.Log
@ -9,7 +9,7 @@ import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import org.mosad.teapod.BuildConfig
import org.mosad.teapod.MainActivity
import org.mosad.teapod.ui.activity.main.MainActivity
import org.mosad.teapod.R
import org.mosad.teapod.databinding.FragmentAccountBinding
import org.mosad.teapod.parser.AoDParser
@ -17,6 +17,7 @@ import org.mosad.teapod.preferences.EncryptedPreferences
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.components.LoginDialog
import org.mosad.teapod.util.DataTypes.Theme
import org.mosad.teapod.util.showFragment
class AccountFragment : Fragment() {
@ -53,7 +54,7 @@ class AccountFragment : Fragment() {
}
binding.linearInfo.setOnClickListener {
(activity as MainActivity).showFragment(AboutFragment())
activity?.showFragment(AboutFragment())
}
binding.switchSecondary.setOnClickListener {

57
app/src/main/java/org/mosad/teapod/ui/fragments/HomeFragment.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/HomeFragment.kt

@ -1,27 +1,25 @@
package org.mosad.teapod.ui.fragments
package org.mosad.teapod.ui.activity.main.fragments
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.mosad.teapod.MainActivity
import org.mosad.teapod.R
import org.mosad.teapod.ui.activity.main.MainActivity
import org.mosad.teapod.databinding.FragmentHomeBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.util.ItemMedia
import org.mosad.teapod.util.StorageController
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.setDrawableTop
import org.mosad.teapod.util.showFragment
class HomeFragment : Fragment() {
@ -30,6 +28,7 @@ class HomeFragment : Fragment() {
private lateinit var adapterNewEpisodes: MediaItemAdapter
private lateinit var adapterNewSimulcasts: MediaItemAdapter
private lateinit var adapterNewTitles: MediaItemAdapter
private lateinit var adapterTopTen: MediaItemAdapter
private lateinit var highlightMedia: ItemMedia
@ -59,9 +58,9 @@ class HomeFragment : Fragment() {
.into(binding.imageHighlight)
if (StorageController.myList.contains(highlightMedia.id)) {
loadIntoCompoundDrawable(R.drawable.ic_baseline_check_24, binding.textHighlightMyList)
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
} else {
loadIntoCompoundDrawable(R.drawable.ic_baseline_add_24, binding.textHighlightMyList)
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
}
}
}
@ -71,6 +70,7 @@ class HomeFragment : Fragment() {
binding.recyclerNewEpisodes.addItemDecoration(MediaItemDecoration(9))
binding.recyclerNewSimulcasts.addItemDecoration(MediaItemDecoration(9))
binding.recyclerNewTitles.addItemDecoration(MediaItemDecoration(9))
binding.recyclerTopTen.addItemDecoration(MediaItemDecoration(9))
// my list
val myListMedia = StorageController.myList.map { elementId ->
@ -79,9 +79,6 @@ class HomeFragment : Fragment() {
}
}
adapterMyList = MediaItemAdapter(myListMedia)
adapterMyList.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
}
binding.recyclerMyList.adapter = adapterMyList
// new episodes
@ -95,6 +92,10 @@ class HomeFragment : Fragment() {
// new titles
adapterNewTitles = MediaItemAdapter(AoDParser.newTitlesList)
binding.recyclerNewTitles.adapter = adapterNewTitles
// top ten
adapterTopTen = MediaItemAdapter(AoDParser.topTenList)
binding.recyclerTopTen.adapter = adapterTopTen
}
private fun initActions() {
@ -111,10 +112,10 @@ class HomeFragment : Fragment() {
binding.textHighlightMyList.setOnClickListener {
if (StorageController.myList.contains(highlightMedia.id)) {
StorageController.myList.remove(highlightMedia.id)
loadIntoCompoundDrawable(R.drawable.ic_baseline_add_24, binding.textHighlightMyList)
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_add_24)
} else {
StorageController.myList.add(highlightMedia.id)
loadIntoCompoundDrawable(R.drawable.ic_baseline_check_24, binding.textHighlightMyList)
binding.textHighlightMyList.setDrawableTop(R.drawable.ic_baseline_check_24)
}
StorageController.saveMyList(requireContext())
@ -122,19 +123,27 @@ class HomeFragment : Fragment() {
}
binding.textHighlightInfo.setOnClickListener {
(activity as MainActivity).showFragment(MediaFragment(highlightMedia.id))
activity?.showFragment(MediaFragment(highlightMedia.id))
}
adapterMyList.onItemClick = { mediaId, _ ->
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewEpisodes.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewSimulcasts.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
adapterNewTitles.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
adapterTopTen.onItemClick = { mediaId, _ ->
activity?.showFragment(MediaFragment(mediaId))
}
}
@ -155,18 +164,4 @@ class HomeFragment : Fragment() {
adapterMyList.notifyDataSetChanged()
}
private fun loadIntoCompoundDrawable(drawable: Int, textView: TextView) {
Glide.with(requireContext())
.load(drawable)
.into(object : CustomTarget<Drawable>(48, 48) {
override fun onLoadCleared(drawable: Drawable?) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null)
}
override fun onResourceReady(res: Drawable, transition: Transition<in Drawable>?) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, res, null, null)
}
})
}
}

6
app/src/main/java/org/mosad/teapod/ui/fragments/LibraryFragment.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/LibraryFragment.kt

@ -1,4 +1,4 @@
package org.mosad.teapod.ui.fragments
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.view.LayoutInflater
@ -9,11 +9,11 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.mosad.teapod.MainActivity
import org.mosad.teapod.databinding.FragmentLibraryBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
class LibraryFragment : Fragment() {
@ -35,7 +35,7 @@ class LibraryFragment : Fragment() {
context?.let {
adapter = MediaItemAdapter(AoDParser.itemMediaList)
adapter.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
binding.recyclerMediaLibrary.adapter = adapter

210
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt

@ -0,0 +1,210 @@
package org.mosad.teapod.ui.activity.main.fragments
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayoutMediator
import jp.wasabeef.glide.transformations.BlurTransformation
import kotlinx.coroutines.*
import org.mosad.teapod.R
import org.mosad.teapod.databinding.FragmentMediaBinding
import org.mosad.teapod.ui.activity.main.MainActivity
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
import org.mosad.teapod.util.*
import org.mosad.teapod.util.DataTypes.MediaType
/**
* The media detail fragment.
* Note: the fragment is created only once, when selecting a similar title etc.
* therefore fragments may be not empty and model may be the old one
*/
class MediaFragment(private val mediaId: Int) : Fragment() {
private lateinit var binding: FragmentMediaBinding
private lateinit var pagerAdapter: FragmentStateAdapter
private val fragments = arrayListOf<Fragment>()
private val model: MediaFragmentViewModel by activityViewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentMediaBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.frameLoading.visibility = View.VISIBLE
// tab layout and pager TODO
pagerAdapter = ScreenSlidePagerAdapter(requireActivity())
// fix material components issue #1878, if more tabs are added increase
binding.pagerEpisodesSimilar.offscreenPageLimit = 2
binding.pagerEpisodesSimilar.adapter = pagerAdapter
TabLayoutMediator(binding.tabEpisodesSimilar, binding.pagerEpisodesSimilar) { tab, position ->
tab.text = if (model.media.type == MediaType.TVSHOW && position == 0) {
getString(R.string.episodes)
} else {
getString(R.string.similar_titles)
}
}.attach()
GlobalScope.launch(Dispatchers.Main) {
model.load(mediaId) // load the streams and tmdb for the selected media
if (this@MediaFragment.isAdded) {
updateGUI()
initActions()
}
}
}
override fun onResume() {
super.onResume()
// update the next ep text if there is one, since it may have changed
if (model.nextEpisode.title.isNotEmpty()) {
binding.textTitle.text = model.nextEpisode.title
}
}
/**
* if tmdb data is present, use it, else use the aod data
*/
private fun updateGUI() = with(model) {
// generic gui
val backdropUrl = if (tmdb.backdropUrl.isNotEmpty()) tmdb.backdropUrl else media.info.posterUrl
val posterUrl = if (tmdb.posterUrl.isNotEmpty()) tmdb.posterUrl else media.info.posterUrl
Glide.with(requireContext()).load(backdropUrl)
.apply(RequestOptions.placeholderOf(ColorDrawable(Color.DKGRAY)))
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
.into(binding.imageBackdrop)
Glide.with(requireContext()).load(posterUrl)
.into(binding.imagePoster)
binding.textTitle.text = media.info.title
binding.textYear.text = media.info.year.toString()
binding.textAge.text = media.info.age.toString()
binding.textOverview.text = media.info.shortDesc
if (StorageController.myList.contains(media.id)) {
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
} else {
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
}
// clear fragments, since it lives in onCreate scope (don't do this in onPause/onStop -> FragmentManager transaction)
fragments.clear()
pagerAdapter.notifyDataSetChanged()
// specific gui
if (media.type == MediaType.TVSHOW) {
// get next episode
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
media.episodes.first{ !it.watched }
} else {
media.episodes.first()
}
// title is the next episodes title
binding.textTitle.text = nextEpisode.title
// episodes count
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
R.plurals.text_episodes_count,
media.info.episodesCount,
media.info.episodesCount
)
// episodes
fragments.add(MediaFragmentEpisodes())
pagerAdapter.notifyDataSetChanged()
} else if (media.type == MediaType.MOVIE) {
if (tmdb.runtime > 0) {
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
R.plurals.text_runtime,
tmdb.runtime,
tmdb.runtime
)
} else {
binding.textEpisodesOrRuntime.visibility = View.GONE
}
}
// if has similar titles
if (media.info.similar.isNotEmpty()) {
fragments.add(MediaFragmentSimilar())
pagerAdapter.notifyDataSetChanged()
}
// disable scrolling on appbar, if no tabs where added
if(fragments.isEmpty()) {
val params = binding.linearMedia.layoutParams as AppBarLayout.LayoutParams
params.scrollFlags = 0 // clear all scroll flags
}
binding.frameLoading.visibility = View.GONE // hide loading indicator
}
private fun initActions() = with(model) {
binding.buttonPlay.setOnClickListener {
when (media.type) {
MediaType.MOVIE -> playEpisode(media.episodes.first())
MediaType.TVSHOW -> playEpisode(nextEpisode)
else -> Log.e(javaClass.name, "Wrong Type: $media.type")
}
}
// add or remove media from myList
binding.linearMyListAction.setOnClickListener {
if (StorageController.myList.contains(media.id)) {
StorageController.myList.remove(media.id)
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
} else {
StorageController.myList.add(media.id)
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
}
StorageController.saveMyList(requireContext())
// notify home fragment on change
parentFragmentManager.findFragmentByTag("HomeFragment")?.let {
(it as HomeFragment).updateMyListMedia()
}
}
}
/**
* play the current episode
* TODO this is also used in MediaFragmentEpisode, we should only have on implementation
*/
private fun playEpisode(ep: Episode) {
(activity as MainActivity).startPlayer(model.media.id, ep.id)
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
model.updateNextEpisode(ep) // set the correct next episode
}
/**
* A simple pager adapter
*/
private inner class ScreenSlidePagerAdapter(fa: FragmentActivity) : FragmentStateAdapter(fa) {
override fun getItemCount(): Int = fragments.size
override fun createFragment(position: Int): Fragment = fragments[position]
}
}

61
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragmentEpisodes.kt

@ -0,0 +1,61 @@
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import org.mosad.teapod.ui.activity.main.MainActivity
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
import org.mosad.teapod.databinding.FragmentMediaEpisodesBinding
import org.mosad.teapod.util.Episode
import org.mosad.teapod.util.adapter.EpisodeItemAdapter
class MediaFragmentEpisodes : Fragment() {
private lateinit var binding: FragmentMediaEpisodesBinding
private lateinit var adapterRecEpisodes: EpisodeItemAdapter
private val model: MediaFragmentViewModel by activityViewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentMediaEpisodesBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapterRecEpisodes = EpisodeItemAdapter(model.media.episodes)
binding.recyclerEpisodes.adapter = adapterRecEpisodes
// set onItemClick only in adapter is initialized
if (this::adapterRecEpisodes.isInitialized) {
adapterRecEpisodes.onImageClick = { _, position ->
playEpisode(model.media.episodes[position])
}
}
}
override fun onResume() {
super.onResume()
// if adapterRecEpisodes is initialized, update the watched state for the episodes
if (this::adapterRecEpisodes.isInitialized) {
model.media.episodes.forEachIndexed { index, episode ->
adapterRecEpisodes.updateWatchedState(episode.watched, index)
}
adapterRecEpisodes.notifyDataSetChanged()
}
}
private fun playEpisode(ep: Episode) {
(activity as MainActivity).startPlayer(model.media.id, ep.id)
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
model.updateNextEpisode(ep) // set the correct next episode
}
}

41
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragmentSimilar.kt

@ -0,0 +1,41 @@
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import org.mosad.teapod.databinding.FragmentMediaSimilarBinding
import org.mosad.teapod.ui.activity.main.viewmodel.MediaFragmentViewModel
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.showFragment
class MediaFragmentSimilar : Fragment() {
private lateinit var binding: FragmentMediaSimilarBinding
private val model: MediaFragmentViewModel by activityViewModels()
private lateinit var adapterSimilar: MediaItemAdapter
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentMediaSimilarBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapterSimilar = MediaItemAdapter(model.media.info.similar)
binding.recyclerMediaSimilar.adapter = adapterSimilar
binding.recyclerMediaSimilar.addItemDecoration(MediaItemDecoration(9))
// set onItemClick only in adapter is initialized
if (this::adapterSimilar.isInitialized) {
adapterSimilar.onItemClick = { mediaId, _ ->
activity?.showFragment(MediaFragment(mediaId))
}
}
}
}

6
app/src/main/java/org/mosad/teapod/ui/fragments/SearchFragment.kt → app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/SearchFragment.kt

@ -1,4 +1,4 @@
package org.mosad.teapod.ui.fragments
package org.mosad.teapod.ui.activity.main.fragments
import android.os.Bundle
import android.view.LayoutInflater
@ -7,11 +7,11 @@ import android.view.ViewGroup
import android.widget.SearchView
import androidx.fragment.app.Fragment
import kotlinx.coroutines.*
import org.mosad.teapod.MainActivity
import org.mosad.teapod.databinding.FragmentSearchBinding
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.util.decoration.MediaItemDecoration
import org.mosad.teapod.util.adapter.MediaItemAdapter
import org.mosad.teapod.util.showFragment
class SearchFragment : Fragment() {
@ -33,7 +33,7 @@ class SearchFragment : Fragment() {
adapter = MediaItemAdapter(AoDParser.itemMediaList)
adapter!!.onItemClick = { mediaId, _ ->
binding.searchText.clearFocus()
(activity as MainActivity).showFragment(MediaFragment(mediaId))
activity?.showFragment(MediaFragment(mediaId))
}
binding.recyclerMediaSearch.adapter = adapter

48
app/src/main/java/org/mosad/teapod/ui/activity/main/viewmodel/MediaFragmentViewModel.kt

@ -0,0 +1,48 @@
package org.mosad.teapod.ui.activity.main.viewmodel