add new simulcasts and new titles to home screen

* simulcasts and new titles
* update some libraries
* don't crash if AoDPraser fails to parse mediaId
This commit is contained in:
Jannik 2020-12-11 10:54:40 +01:00
parent 98636d326e
commit ab180ddd89
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
7 changed files with 131 additions and 23 deletions

View File

@ -41,14 +41,14 @@ android {
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1' implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'androidx.security:security-crypto:1.1.0-alpha02' implementation 'androidx.security:security-crypto:1.1.0-alpha03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha04' implementation 'com.google.android.material:material:1.3.0-alpha04'

View File

@ -45,10 +45,12 @@ object AoDParser {
private var csrfToken: String = "" private var csrfToken: String = ""
private var loginSuccess = false private var loginSuccess = false
private val mediaList = arrayListOf<Media>() private val mediaList = arrayListOf<Media>() // actual media (data)
val itemMediaList = arrayListOf<ItemMedia>() val itemMediaList = arrayListOf<ItemMedia>() // gui media
val highlightsList = arrayListOf<ItemMedia>() val highlightsList = arrayListOf<ItemMedia>()
val newEpisodesList = arrayListOf<ItemMedia>() val newEpisodesList = arrayListOf<ItemMedia>()
val newSimulcastsList = arrayListOf<ItemMedia>()
val newTitlesList = arrayListOf<ItemMedia>()
fun login(): Boolean = runBlocking { fun login(): Boolean = runBlocking {
@ -95,7 +97,7 @@ object AoDParser {
* -> blocking * -> blocking
*/ */
fun initialLoading() = runBlocking { fun initialLoading() = runBlocking {
val newEPJob = GlobalScope.async { val loadHomeJob = GlobalScope.async {
loadHome() loadHome()
} }
@ -103,7 +105,7 @@ object AoDParser {
listAnimes() listAnimes()
} }
newEPJob.await() loadHomeJob.await()
listJob.await() listJob.await()
} }
@ -183,7 +185,7 @@ object AoDParser {
} }
/** /**
* load new episodes and highlights * load new episodes, titles and highlights
*/ */
private fun loadHome() = runBlocking { private fun loadHome() = runBlocking {
if (sessionCookies.isEmpty()) login() if (sessionCookies.isEmpty()) login()
@ -193,19 +195,6 @@ object AoDParser {
.cookies(sessionCookies) .cookies(sessionCookies)
.get() .get()
// get all new episodes from AoD
newEpisodesList.clear()
resHome.select("div.jcarousel-container-new").select("li").forEach {
if (it.select("span").hasClass("neweps")) {
val mediaId = it.select("a.thumbs").attr("href")
.substringAfterLast("/").toInt()
val mediaImage = it.select("a.thumbs > img").attr("src")
val mediaTitle = "${it.select("a").text()} - ${it.select("span.neweps").text()}"
newEpisodesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
// get highlights from AoD // get highlights from AoD
highlightsList.clear() highlightsList.clear()
resHome.select("#aod-highlights").select("div.news-item").forEach { resHome.select("#aod-highlights").select("div.news-item").forEach {
@ -219,6 +208,45 @@ object AoDParser {
} }
} }
// 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 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) {
newSimulcastsList.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()
if (mediaId != null) {
newTitlesList.add(ItemMedia(mediaId, mediaTitle, mediaImage))
}
}
} }
} }

View File

@ -28,6 +28,8 @@ class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding private lateinit var binding: FragmentHomeBinding
private lateinit var adapterMyList: MediaItemAdapter private lateinit var adapterMyList: MediaItemAdapter
private lateinit var adapterNewEpisodes: MediaItemAdapter private lateinit var adapterNewEpisodes: MediaItemAdapter
private lateinit var adapterNewSimulcasts: MediaItemAdapter
private lateinit var adapterNewTitles: MediaItemAdapter
private lateinit var highlightMedia: ItemMedia private lateinit var highlightMedia: ItemMedia
@ -65,6 +67,8 @@ class HomeFragment : Fragment() {
private fun initRecyclerViews() { private fun initRecyclerViews() {
binding.recyclerMyList.addItemDecoration(MediaItemDecoration(9)) binding.recyclerMyList.addItemDecoration(MediaItemDecoration(9))
binding.recyclerNewEpisodes.addItemDecoration(MediaItemDecoration(9)) binding.recyclerNewEpisodes.addItemDecoration(MediaItemDecoration(9))
binding.recyclerNewSimulcasts.addItemDecoration(MediaItemDecoration(9))
binding.recyclerNewTitles.addItemDecoration(MediaItemDecoration(9))
// my list // my list
val myListMedia = StorageController.myList.map { elementId -> val myListMedia = StorageController.myList.map { elementId ->
@ -81,6 +85,14 @@ class HomeFragment : Fragment() {
// new episodes // new episodes
adapterNewEpisodes = MediaItemAdapter(AoDParser.newEpisodesList) adapterNewEpisodes = MediaItemAdapter(AoDParser.newEpisodesList)
binding.recyclerNewEpisodes.adapter = adapterNewEpisodes binding.recyclerNewEpisodes.adapter = adapterNewEpisodes
// new simulcasts
adapterNewSimulcasts = MediaItemAdapter(AoDParser.newSimulcastsList)
binding.recyclerNewSimulcasts.adapter = adapterNewSimulcasts
// new titles
adapterNewTitles = MediaItemAdapter(AoDParser.newTitlesList)
binding.recyclerNewTitles.adapter = adapterNewTitles
} }
private fun initActions() { private fun initActions() {
@ -114,6 +126,14 @@ class HomeFragment : Fragment() {
adapterNewEpisodes.onItemClick = { mediaId, _ -> adapterNewEpisodes.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId)) (activity as MainActivity).showFragment(MediaFragment(mediaId))
} }
adapterNewSimulcasts.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
}
adapterNewTitles.onItemClick = { mediaId, _ ->
(activity as MainActivity).showFragment(MediaFragment(mediaId))
}
} }
/** /**

View File

@ -163,6 +163,62 @@
tools:listitem="@layout/item_media" /> tools:listitem="@layout/item_media" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/linear_new_simulcasts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="7dp">
<TextView
android:id="@+id/text_new_simulcasts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingTop="15dp"
android:paddingEnd="5dp"
android:paddingBottom="5dp"
android:text="@string/new_simulcasts"
android:textSize="16sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_new_simulcasts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_media" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear_new_titles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="7dp">
<TextView
android:id="@+id/text_new_titles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:paddingTop="15dp"
android:paddingEnd="5dp"
android:paddingBottom="5dp"
android:text="@string/new_titles"
android:textSize="16sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_new_titles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_media" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -9,6 +9,8 @@
<string name="highlight_media">Highlight</string> <string name="highlight_media">Highlight</string>
<string name="my_list">Meine Liste</string> <string name="my_list">Meine Liste</string>
<string name="new_episodes">Neue Episoden</string> <string name="new_episodes">Neue Episoden</string>
<string name="new_simulcasts">Neue Simulcasts</string>
<string name="new_titles">Neue Titel</string>
<!-- search fragment --> <!-- search fragment -->
<string name="search_hint">Suche nach Filmen und Serien</string> <string name="search_hint">Suche nach Filmen und Serien</string>

View File

@ -9,6 +9,8 @@
<string name="highlight_media">Highlight</string> <string name="highlight_media">Highlight</string>
<string name="my_list">My list</string> <string name="my_list">My list</string>
<string name="new_episodes">New episodes</string> <string name="new_episodes">New episodes</string>
<string name="new_simulcasts">New simulcasts</string>
<string name="new_titles">New titles</string>
<!-- search fragment --> <!-- search fragment -->
<string name="search_hint">Search for movies and series</string> <string name="search_hint">Search for movies and series</string>

View File

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = "1.4.20" ext.kotlin_version = "1.4.21"
repositories { repositories {
google() google()
jcenter() jcenter()