|
@@ -5,14 +5,11 @@ import androidx.fragment.app.Fragment
|
|
import android.view.LayoutInflater
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
-import androidx.lifecycle.Observer
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.google.android.material.tabs.TabLayout
|
|
import com.google.android.material.tabs.TabLayout
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.R
|
|
import com.sambath.kunkhmer.adapter.HighlightNewsAdapter
|
|
import com.sambath.kunkhmer.adapter.HighlightNewsAdapter
|
|
import com.sambath.kunkhmer.adapter.TopNewsAdapter
|
|
import com.sambath.kunkhmer.adapter.TopNewsAdapter
|
|
-import com.sambath.kunkhmer.adapter.TopNewsCardItem
|
|
|
|
-import com.sambath.kunkhmer.adapter.TopNewsHeaderAdapter
|
|
|
|
import com.sambath.kunkhmer.app.App
|
|
import com.sambath.kunkhmer.app.App
|
|
import com.sambath.kunkhmer.remote.HighlightData
|
|
import com.sambath.kunkhmer.remote.HighlightData
|
|
import com.sambath.kunkhmer.remote.News
|
|
import com.sambath.kunkhmer.remote.News
|
|
@@ -22,7 +19,7 @@ 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.selectedTabTextView
|
|
import kotlinx.android.synthetic.main.fragment_news.view.tabLayout
|
|
import kotlinx.android.synthetic.main.fragment_news.view.tabLayout
|
|
|
|
|
|
-class NewsFragment : Fragment() {
|
|
|
|
|
|
+class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
|
|
private var _root: View? = null
|
|
private var _root: View? = null
|
|
private val binding get() = _root!!
|
|
private val binding get() = _root!!
|
|
private lateinit var newsViewModel: NewsViewModel
|
|
private lateinit var newsViewModel: NewsViewModel
|
|
@@ -39,7 +36,7 @@ class NewsFragment : Fragment() {
|
|
// Inflate the layout for this fragment
|
|
// Inflate the layout for this fragment
|
|
_root = inflater.inflate(R.layout.fragment_news, container, false)
|
|
_root = inflater.inflate(R.layout.fragment_news, container, false)
|
|
|
|
|
|
- topNewsAdapter = TopNewsAdapter(mutableListOf())
|
|
|
|
|
|
+ topNewsAdapter = TopNewsAdapter(mutableListOf(), this)
|
|
highlightNewsAdapter = HighlightNewsAdapter(mutableListOf())
|
|
highlightNewsAdapter = HighlightNewsAdapter(mutableListOf())
|
|
|
|
|
|
// Set adapters
|
|
// Set adapters
|
|
@@ -153,4 +150,16 @@ class NewsFragment : Fragment() {
|
|
fun selectTab(tabIndex: Int) {
|
|
fun selectTab(tabIndex: Int) {
|
|
binding.tabLayout.getTabAt(tabIndex)?.select()
|
|
binding.tabLayout.getTabAt(tabIndex)?.select()
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ override fun onItemClick(newsItem: News) {
|
|
|
|
+ val topNewsDetailFragment = TopNewsDetailFragment()
|
|
|
|
+ val bundle = Bundle()
|
|
|
|
+ bundle.putString("news_id", newsItem.id)
|
|
|
|
+ topNewsDetailFragment.arguments = bundle
|
|
|
|
+
|
|
|
|
+ parentFragmentManager.beginTransaction()
|
|
|
|
+ .replace(R.id.nav_host_fragment_activity_main, topNewsDetailFragment)
|
|
|
|
+ .addToBackStack(null) // Add to back stack to handle the back navigation
|
|
|
|
+ .commit()
|
|
|
|
+ }
|
|
}
|
|
}
|