AA-4 | Reyaz & Shashidhara | Reuse same fragment for my loans if it exists

This commit is contained in:
Reyaz Ahmad
2019-11-06 16:52:52 +05:30
parent a822aa1557
commit df442a3d9a
2 changed files with 5 additions and 3 deletions

View File

@@ -26,7 +26,11 @@ class BottomNavigationActivity : AppCompatActivity() {
private fun navigateToMyLoans(): Boolean {
val fragmentManager = supportFragmentManager.beginTransaction()
fragmentManager.add(R.id.content_view, MyLoansFragment(), MyLoansFragment.TAG)
supportFragmentManager.findFragmentByTag(MyLoansFragment.TAG)?.let { fragment ->
fragmentManager.replace(R.id.content_view, fragment, MyLoansFragment.TAG)
} ?: run {
fragmentManager.add(R.id.content_view, MyLoansFragment(), MyLoansFragment.TAG)
}
fragmentManager.commit()
return true
}

View File

@@ -56,8 +56,6 @@ class MyLoansFragment : Fragment() {
viewModel.fetchMyLoans()
}
}
companion object {