added new episodes to home screen
This commit is contained in:
@ -32,7 +32,9 @@ import androidx.fragment.app.commit
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.ui.fragments.MediaFragment
|
||||
@ -120,8 +122,20 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
||||
|
||||
StorageController.load(this)
|
||||
|
||||
// initially load all media
|
||||
AoDParser().listAnimes()
|
||||
// move to AoDParser
|
||||
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
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class AoDParser {
|
||||
|
||||
val mediaList = arrayListOf<Media>()
|
||||
val itemMediaList = arrayListOf<ItemMedia>()
|
||||
val newEpisodesList = arrayListOf<ItemMedia>()
|
||||
}
|
||||
|
||||
fun login(): Boolean = runBlocking {
|
||||
@ -85,6 +86,7 @@ class AoDParser {
|
||||
|
||||
//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") {
|
||||
@ -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 {
|
||||
val media = mediaList.first { it.id == mediaId }
|
||||
|
||||
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
@ -20,8 +19,8 @@ import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private lateinit var adapter: MediaItemAdapter
|
||||
private lateinit var layoutManager: LinearLayoutManager
|
||||
private lateinit var adapterMyList: MediaItemAdapter
|
||||
private lateinit var adapterNewEpisodes: MediaItemAdapter
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fragment_home, container, false)
|
||||
@ -37,14 +36,17 @@ class HomeFragment : Fragment() {
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
context?.let {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
recycler_my_list.layoutManager = layoutManager
|
||||
recycler_my_list.addItemDecoration(MediaItemDecoration(9))
|
||||
|
||||
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)
|
||||
adapter.onItemClick = { mediaId, _ ->
|
||||
adapterMyList = MediaItemAdapter(myListMedia)
|
||||
adapterMyList.onItemClick = { 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user