2021-04-30 17:20:15 +00:00
|
|
|
package com.lagradost.cloudstream3.ui.home
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2021-07-29 00:54:27 +00:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2021-04-30 17:20:15 +00:00
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.lifecycle.ViewModelProvider
|
2021-07-29 00:19:42 +00:00
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-04-30 17:20:15 +00:00
|
|
|
import com.lagradost.cloudstream3.R
|
2021-07-29 00:54:27 +00:00
|
|
|
import com.lagradost.cloudstream3.UIHelper.fixPaddingStatusbar
|
|
|
|
import com.lagradost.cloudstream3.UIHelper.loadResult
|
2021-07-29 00:19:42 +00:00
|
|
|
import com.lagradost.cloudstream3.mvvm.Resource
|
|
|
|
import com.lagradost.cloudstream3.mvvm.observe
|
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
|
|
|
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
|
|
|
import com.lagradost.cloudstream3.utils.HOMEPAGE_API
|
|
|
|
import kotlinx.android.synthetic.main.fragment_child_downloads.*
|
|
|
|
import kotlinx.android.synthetic.main.fragment_home.*
|
2021-04-30 17:20:15 +00:00
|
|
|
|
|
|
|
class HomeFragment : Fragment() {
|
|
|
|
private lateinit var homeViewModel: HomeViewModel
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
|
|
|
): View? {
|
|
|
|
homeViewModel =
|
|
|
|
ViewModelProvider(this).get(HomeViewModel::class.java)
|
2021-07-29 00:19:42 +00:00
|
|
|
|
|
|
|
return inflater.inflate(R.layout.fragment_home, container, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
|
|
observe(homeViewModel.apiName) {
|
|
|
|
context?.setKey(HOMEPAGE_API, it)
|
|
|
|
}
|
|
|
|
|
|
|
|
observe(homeViewModel.page) {
|
|
|
|
when (it) {
|
|
|
|
is Resource.Success -> {
|
|
|
|
val d = it.value
|
|
|
|
(home_master_recycler?.adapter as ParentItemAdapter?)?.itemList = d.items
|
|
|
|
home_master_recycler?.adapter?.notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
is Resource.Failure -> {
|
|
|
|
|
|
|
|
}
|
|
|
|
is Resource.Loading -> {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 00:54:27 +00:00
|
|
|
val adapter: RecyclerView.Adapter<RecyclerView.ViewHolder> = ParentItemAdapter(listOf(), { card ->
|
|
|
|
(activity as AppCompatActivity).loadResult(card.url, card.slug, card.apiName)
|
|
|
|
}, {
|
2021-07-29 00:19:42 +00:00
|
|
|
|
2021-07-29 00:54:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
context?.fixPaddingStatusbar(home_root)
|
2021-07-29 00:19:42 +00:00
|
|
|
|
|
|
|
home_master_recycler.adapter = adapter
|
|
|
|
home_master_recycler.layoutManager = GridLayoutManager(context, 1)
|
|
|
|
|
|
|
|
homeViewModel.load(context?.getKey(HOMEPAGE_API))
|
2021-04-30 17:20:15 +00:00
|
|
|
}
|
|
|
|
}
|