Dola TENG 1 年間 前
コミット
9744b1abff

+ 9 - 1
app/src/main/java/com/sambath/sbc/app/MainActivity.kt

@@ -9,8 +9,9 @@ import androidx.navigation.ui.setupWithNavController
 import com.google.android.material.bottomnavigation.BottomNavigationView
 import androidx.navigation.ui.setupActionBarWithNavController
 import com.sambath.sbc.R
+import com.sambath.sbc.screen.fighter.FighterFragment
 
-class MainActivity : AppCompatActivity() {
+class MainActivity : AppCompatActivity(), FighterFragment.TabSelectionListener {
 
     lateinit var navView: BottomNavigationView
 
@@ -33,4 +34,11 @@ class MainActivity : AppCompatActivity() {
         //setupActionBarWithNavController(navController, appBarConfiguration)
         navView.setupWithNavController(navController)
     }
+
+    override fun onTabSelected(tabIndex: Int) {
+        val fragment = supportFragmentManager.findFragmentById(R.id.navigation_home)
+        if (fragment is FighterFragment) {
+            fragment.selectTab(tabIndex)
+        }
+    }
 }

+ 17 - 1
app/src/main/java/com/sambath/sbc/screen/fighter/FighterFragment.kt

@@ -19,6 +19,9 @@ class FighterFragment : Fragment() {
 
     private val binding get() = _root!!
 
+    // Inside your Fragment:
+    var tabSelectionListener: TabSelectionListener? = null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
     }
@@ -29,6 +32,11 @@ class FighterFragment : Fragment() {
     ): View? {
         _root = inflater.inflate(R.layout.fragment_fighter, container, false)
 
+        setTab()
+        return binding
+    }
+
+    private fun setTab() {
         val tabTitles = listOf("Fri 18 Aug", "Yesterday", "Today", "Tomorrow", "Tue 22 Aug")
 
         // Populate TabLayout with dynamic tabs
@@ -56,7 +64,7 @@ class FighterFragment : Fragment() {
             }
         })
 
-        return binding
+        binding.tabLayout.getTabAt(2)?.select()
     }
 
     private fun setFighters() {
@@ -80,4 +88,12 @@ class FighterFragment : Fragment() {
             // Add more card items as needed
         )
     }
+
+    interface TabSelectionListener {
+        fun onTabSelected(tabIndex: Int)
+    }
+
+    fun selectTab(tabIndex: Int) {
+        binding.tabLayout.getTabAt(tabIndex)?.select()
+    }
 }

+ 10 - 10
app/src/main/java/com/sambath/sbc/screen/splash/SplashScreenActivity.kt

@@ -55,16 +55,16 @@ class SplashScreenActivity : BaseActivity() {
             override fun onAnimationEnd(animation: Animation?) {
 
                     //Test
-//                    val intent = Intent(this@SplashScreenActivity, MainActivity::class.java)
-//                    startActivity(intent)
-
-                    if (prefHelper.getToken().isNotEmpty()) {
-                        val intent = Intent(this@SplashScreenActivity, ShareActivity::class.java)
-                        startActivity(intent)
-                    }else{
-                        val intent = Intent(this@SplashScreenActivity, LoginActivity::class.java)
-                        startActivity(intent)
-                    }
+                    val intent = Intent(this@SplashScreenActivity, MainActivity::class.java)
+                    startActivity(intent)
+
+//                    if (prefHelper.getToken().isNotEmpty()) {
+//                        val intent = Intent(this@SplashScreenActivity, ShareActivity::class.java)
+//                        startActivity(intent)
+//                    }else{
+//                        val intent = Intent(this@SplashScreenActivity, LoginActivity::class.java)
+//                        startActivity(intent)
+//                    }
 
                     finishAffinity()