|
@@ -11,20 +11,23 @@ import com.sambath.kunkhmer.R
|
|
|
import com.sambath.kunkhmer.adapter.HighlightNewsAdapter
|
|
|
import com.sambath.kunkhmer.adapter.TopNewsAdapter
|
|
|
import com.sambath.kunkhmer.app.App
|
|
|
+import com.sambath.kunkhmer.remote.Highlight
|
|
|
import com.sambath.kunkhmer.remote.HighlightData
|
|
|
import com.sambath.kunkhmer.remote.News
|
|
|
import com.sambath.kunkhmer.remote.NewsData
|
|
|
+import com.sambath.kunkhmer.screen.lives.LiveDetailFragment
|
|
|
import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNews
|
|
|
import kotlinx.android.synthetic.main.fragment_news.view.recyclerViewNewsHeader
|
|
|
import kotlinx.android.synthetic.main.fragment_news.view.selectedTabTextView
|
|
|
import kotlinx.android.synthetic.main.fragment_news.view.tabLayout
|
|
|
|
|
|
-class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
|
|
|
+class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener, HighlightNewsAdapter.OnItemClickListener {
|
|
|
private var _root: View? = null
|
|
|
private val binding get() = _root!!
|
|
|
private lateinit var newsViewModel: NewsViewModel
|
|
|
private lateinit var topNewsAdapter: TopNewsAdapter
|
|
|
private lateinit var highlightNewsAdapter: HighlightNewsAdapter
|
|
|
+ private var cardList: List<Highlight>? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -37,7 +40,7 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
|
|
|
_root = inflater.inflate(R.layout.fragment_news, container, false)
|
|
|
|
|
|
topNewsAdapter = TopNewsAdapter(mutableListOf(), this)
|
|
|
- highlightNewsAdapter = HighlightNewsAdapter(mutableListOf())
|
|
|
+ highlightNewsAdapter = HighlightNewsAdapter(mutableListOf(), this)
|
|
|
|
|
|
// Set adapters
|
|
|
binding.recyclerViewNews.apply {
|
|
@@ -63,6 +66,7 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
|
|
|
|
|
|
if(state.highlightData != null) {
|
|
|
updateHighlight(state.highlightData)
|
|
|
+ cardList = state.highlightData.obj
|
|
|
}
|
|
|
}
|
|
|
// Other state handling...
|
|
@@ -162,4 +166,23 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
|
|
|
.addToBackStack("NewsFragment") // Add to back stack to handle the back navigation
|
|
|
.commit()
|
|
|
}
|
|
|
+
|
|
|
+ override fun onItemClick(position: Int) {
|
|
|
+ val clickedItem = cardList!![position]
|
|
|
+ val liveDetailFragment = LiveDetailFragment()
|
|
|
+
|
|
|
+ // You can pass data to the LiveDetailFragment using arguments if needed
|
|
|
+ val bundle = Bundle()
|
|
|
+ bundle.putString("image_url", "")
|
|
|
+ bundle.putString("title", clickedItem.title)
|
|
|
+ bundle.putString("description", clickedItem.title)
|
|
|
+ bundle.putString("url", clickedItem.url)
|
|
|
+ liveDetailFragment.arguments = bundle
|
|
|
+
|
|
|
+ // Replace the current fragment with the LiveDetailFragment
|
|
|
+ parentFragmentManager.beginTransaction()
|
|
|
+ .replace(R.id.nav_host_fragment_activity_main, liveDetailFragment)
|
|
|
+ .addToBackStack(null) // Add to back stack to handle the back navigation
|
|
|
+ .commit()
|
|
|
+ }
|
|
|
}
|