dola преди 1 година
родител
ревизия
885d791582

+ 1 - 1
app/src/main/java/com/sambath/kunkhmer/screen/news/NewsFragment.kt

@@ -159,7 +159,7 @@ class NewsFragment : Fragment(), TopNewsAdapter.OnItemClickListener {
 
         parentFragmentManager.beginTransaction()
             .replace(R.id.nav_host_fragment_activity_main, topNewsDetailFragment)
-            .addToBackStack(null) // Add to back stack to handle the back navigation
+            .addToBackStack("NewsFragment") // Add to back stack to handle the back navigation
             .commit()
     }
 }

+ 11 - 0
app/src/main/java/com/sambath/kunkhmer/screen/news/TopNewsDetailFragment.kt

@@ -5,12 +5,14 @@ import androidx.fragment.app.Fragment
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.navigation.fragment.findNavController
 import androidx.recyclerview.widget.LinearLayoutManager
 import com.sambath.kunkhmer.R
 import com.sambath.kunkhmer.adapter.TopNewsDetailAdapter
 import com.sambath.kunkhmer.app.App
 import com.sambath.kunkhmer.remote.News
 import com.sambath.kunkhmer.remote.NewsDetail
+import kotlinx.android.synthetic.main.fragment_top_news_detail.view.back_iv
 import kotlinx.android.synthetic.main.fragment_top_news_detail.view.recyclerViewTopNewDetail
 
 class TopNewsDetailFragment : Fragment() {
@@ -43,6 +45,15 @@ class TopNewsDetailFragment : Fragment() {
             render(it)
         })
 
+        binding.back_iv.setOnClickListener{
+            val newsFragmentId = R.id.newsFragment
+            findNavController().popBackStack()
+        }
+
+        binding.back_iv.setOnClickListener {
+            requireActivity().supportFragmentManager.popBackStack()
+        }
+
         return _root
     }
 

BIN
app/src/main/res/drawable/ic_back_white_50_.png


BIN
app/src/main/res/drawable/ic_share_white_48.png


+ 36 - 2
app/src/main/res/layout/fragment_top_news_detail.xml

@@ -1,11 +1,45 @@
 <?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:background="@color/color_black"
+    android:orientation="vertical"
     tools:context=".screen.news.TopNewsDetailFragment">
 
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
+        android:paddingTop="5dp"
+        android:paddingBottom="5dp">
+
+        <ImageView
+            android:id="@+id/back_iv"
+            android:layout_width="35dp"
+            android:layout_height="35dp"
+            android:layout_weight="0.5"
+            android:src="@drawable/ic_back_white_50_" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:layout_weight="1"
+            android:gravity="center"
+            android:text="@string/top_news"
+            android:textColor="@color/color_white" />
+
+        <ImageView
+            android:id="@+id/share_iv"
+            android:layout_width="30dp"
+            android:layout_height="30dp"
+            android:layout_weight="0.5"
+            android:src="@drawable/ic_share_white_48" />
+
+    </LinearLayout>
+
     <androidx.core.widget.NestedScrollView
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
@@ -17,4 +51,4 @@
             app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
     </androidx.core.widget.NestedScrollView>
 
-</FrameLayout>
+</androidx.appcompat.widget.LinearLayoutCompat>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -84,4 +84,5 @@
     <string name="shope_title_2">WHAT YOU NEED TO TRAIN AT HOME</string>
     <string name="news_detail_title">News Title</string>
     <string name="description">Description</string>
+    <string name="top_news">TOP NEWS</string>
 </resources>