-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.kt
More file actions
46 lines (36 loc) · 1.36 KB
/
Copy pathRouter.kt
File metadata and controls
46 lines (36 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.example.qwe2r.myapplication
import android.support.v4.app.FragmentManager
class Router {
companion object {
private const val CONTAINER_ID = R.id.base_fragment_container
}
lateinit var fragmentManager: FragmentManager
private val postponedTransactionInfoList = mutableListOf<TransactionInfo>()
fun postponeBaseNavigation(): NavigationView {
return NavigationFragment().also {
postponedTransactionInfoList.add(TransactionInfo(it, it.javaClass.name, false))
}
}
fun commitPostponed() {
postponedTransactionInfoList.takeIf { !it.isEmpty() }?.run {
forEach { changeFragment(it) }
clear()
}
}
fun openNavigation(): NavigationFragment {
val fragment = NavigationFragment()
changeFragment(TransactionInfo(fragment, fragment.javaClass.name, false))
return fragment
}
fun changeFragment(transactionInfo: TransactionInfo) {
fragmentManager.beginTransaction()
.apply {
if (transactionInfo.saveToBackStack) {
addToBackStack(transactionInfo.tag)
}
}
.setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
.replace(CONTAINER_ID, transactionInfo.fragment, transactionInfo.tag)
.commit()
}
}