blob: 642e0f227cd606c5ca7b10cf7d40eef4b9ce0254 (
plain)
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
|
package dev.msfjarvis.aps.util.extensions
import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import dev.msfjarvis.aps.R
/**
* Check if [permission] is granted to the app. Aliases to [isPermissionGranted] internally.
*/
fun Fragment.isPermissionGranted(permission: String): Boolean {
return requireActivity().isPermissionGranted(permission)
}
/**
* Calls `finish()` on the enclosing [androidx.fragment.app.FragmentActivity]
*/
fun Fragment.finish() = requireActivity().finish()
/**
* Perform a [commit] on this [FragmentManager] with custom animations and adding the [destinationFragment]
* to the fragment backstack
*/
fun FragmentManager.performTransactionWithBackStack(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) {
commit {
beginTransaction()
addToBackStack(destinationFragment.tag)
setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_left,
R.animator.slide_in_right,
R.animator.slide_out_right)
replace(containerViewId, destinationFragment)
}
}
|