Last active
April 20, 2019 11:39
-
-
Save roiacult/2e663e31e42499ad7d23aaaef143090c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity { | |
companion object { | |
//tag for each fragment | |
const val TAG_HOME = "home" | |
const val TAG_SEARCH = "search" | |
const val TAG_NOTIFICATION = "notification" | |
const val TAG_PROFILE = "profile" | |
} | |
//fragments | |
private val homeFragment : HomeFragment by lazy { | |
val fr = supportFragmentManager.findFragmentByTag(TAG_HOME) | |
if(fr != null)fr as HomeFragment | |
else HomeFragment() | |
} | |
private val searchFragment : SearchFragment by lazy { | |
val fr = supportFragmentManager.findFragmentByTag(TAG_SEARCH) | |
if(fr != null) fr as SearchFragment | |
else SearchFragment() | |
} | |
private val notificationFragment : TrendingFragment by lazy { | |
val fr = supportFragmentManager.findFragmentByTag(TAG_NOTIFICATION) | |
if(fr != null) fr as TrendingFragment | |
else TrendingFragment() | |
} | |
private val profileFragment : ProfileFragment by lazy { | |
val fr = supportFragmentManager.findFragmentByTag(TAG_PROFILE) | |
if(fr != null) fr as ProfileFragment | |
else ProfileFragment.getInstance() | |
} | |
private lateinit var binding : MainActivityBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = DataBindingUtil.setContentView(this,R.layout.main_activity) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment