added new episodes to home screen
This commit is contained in:
parent
aeb74dcb29
commit
a25ec81f6b
|
@ -32,7 +32,9 @@ import androidx.fragment.app.commit
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.mosad.teapod.parser.AoDParser
|
import org.mosad.teapod.parser.AoDParser
|
||||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||||
import org.mosad.teapod.ui.fragments.MediaFragment
|
import org.mosad.teapod.ui.fragments.MediaFragment
|
||||||
|
@ -120,8 +122,20 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||||
|
|
||||||
StorageController.load(this)
|
StorageController.load(this)
|
||||||
|
|
||||||
// initially load all media
|
// move to AoDParser
|
||||||
AoDParser().listAnimes()
|
val newEPJob = GlobalScope.async {
|
||||||
|
AoDParser().listNewEpisodes()
|
||||||
|
}
|
||||||
|
|
||||||
|
val listJob = GlobalScope.async {
|
||||||
|
AoDParser().listAnimes() // initially load all media
|
||||||
|
}
|
||||||
|
|
||||||
|
runBlocking {
|
||||||
|
newEPJob.await()
|
||||||
|
listJob.await()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO load home screen, can be parallel to listAnimes
|
// TODO load home screen, can be parallel to listAnimes
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ class AoDParser {
|
||||||
|
|
||||||
val mediaList = arrayListOf<Media>()
|
val mediaList = arrayListOf<Media>()
|
||||||
val itemMediaList = arrayListOf<ItemMedia>()
|
val itemMediaList = arrayListOf<ItemMedia>()
|
||||||
|
val newEpisodesList = arrayListOf<ItemMedia>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun login(): Boolean = runBlocking {
|
fun login(): Boolean = runBlocking {
|
||||||
|
@ -85,6 +86,7 @@ class AoDParser {
|
||||||
|
|
||||||
//println(resAnimes)
|
//println(resAnimes)
|
||||||
|
|
||||||
|
itemMediaList.clear()
|
||||||
mediaList.clear()
|
mediaList.clear()
|
||||||
resAnimes.select("div.animebox").forEach {
|
resAnimes.select("div.animebox").forEach {
|
||||||
val type = if (it.select("p.animebox-link").select("a").text().toLowerCase(Locale.ROOT) == "zur serie") {
|
val type = if (it.select("p.animebox-link").select("a").text().toLowerCase(Locale.ROOT) == "zur serie") {
|
||||||
|
@ -112,6 +114,29 @@ class AoDParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun listNewEpisodes() = runBlocking {
|
||||||
|
if (sessionCookies.isEmpty()) login()
|
||||||
|
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
|
val resHome = Jsoup.connect(baseUrl)
|
||||||
|
.cookies(sessionCookies)
|
||||||
|
.get()
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getMediaById(mediaId: Int): Media {
|
fun getMediaById(mediaId: Int): Media {
|
||||||
val media = mediaList.first { it.id == mediaId }
|
val media = mediaList.first { it.id == mediaId }
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import kotlinx.android.synthetic.main.fragment_home.*
|
import kotlinx.android.synthetic.main.fragment_home.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
@ -20,8 +19,8 @@ import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
|
|
||||||
private lateinit var adapter: MediaItemAdapter
|
private lateinit var adapterMyList: MediaItemAdapter
|
||||||
private lateinit var layoutManager: LinearLayoutManager
|
private lateinit var adapterNewEpisodes: MediaItemAdapter
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_home, container, false)
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||||
|
@ -37,14 +36,17 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
context?.let {
|
context?.let {
|
||||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
|
||||||
recycler_my_list.layoutManager = layoutManager
|
|
||||||
recycler_my_list.addItemDecoration(MediaItemDecoration(9))
|
recycler_my_list.addItemDecoration(MediaItemDecoration(9))
|
||||||
|
|
||||||
updateMyListMedia()
|
updateMyListMedia()
|
||||||
|
|
||||||
|
adapterNewEpisodes = MediaItemAdapter(AoDParser.newEpisodesList)
|
||||||
|
recycler_new_episodes.adapter = adapterNewEpisodes
|
||||||
|
recycler_new_episodes.addItemDecoration(MediaItemDecoration(9))
|
||||||
|
|
||||||
|
initActions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +58,17 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter = MediaItemAdapter(myListMedia)
|
adapterMyList = MediaItemAdapter(myListMedia)
|
||||||
adapter.onItemClick = { mediaId, _ ->
|
adapterMyList.onItemClick = { mediaId, _ ->
|
||||||
(activity as MainActivity).showMediaFragment(mediaId)
|
(activity as MainActivity).showMediaFragment(mediaId)
|
||||||
}
|
}
|
||||||
|
|
||||||
recycler_my_list.adapter = adapter
|
recycler_my_list.adapter = adapterMyList
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initActions() {
|
||||||
|
adapterNewEpisodes.onItemClick = { mediaId, _ ->
|
||||||
|
(activity as MainActivity).showMediaFragment(mediaId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,10 +19,11 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="7dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView"
|
android:id="@+id/text_my_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="10dp"
|
||||||
|
@ -42,20 +43,34 @@
|
||||||
tools:listitem="@layout/item_media" />
|
tools:listitem="@layout/item_media" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="7dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_new_episodes"
|
||||||
|
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_episodes"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_new_episodes"
|
||||||
|
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>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_home"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="20sp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
<!-- home fragment -->
|
<!-- home fragment -->
|
||||||
<string name="my_list">Meine Liste</string>
|
<string name="my_list">Meine Liste</string>
|
||||||
|
<string name="new_episodes">Neue Episoden</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>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
<!-- home fragment -->
|
<!-- home fragment -->
|
||||||
<string name="my_list">My list</string>
|
<string name="my_list">My list</string>
|
||||||
|
<string name="new_episodes">New episodes</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>
|
||||||
|
|
Loading…
Reference in New Issue