diff options
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt index 01103d19..251f5259 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/FragmentExtensions.kt @@ -1,34 +1,29 @@ package com.zeapo.pwdstore.utils -import android.content.pm.PackageManager -import android.view.View import androidx.annotation.IdRes -import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.commit import com.zeapo.pwdstore.R +/** + * Check if [permission] is granted to the app. Aliases to [isPermissionGranted] internally. + */ fun Fragment.isPermissionGranted(permission: String): Boolean { - return ContextCompat.checkSelfPermission(requireActivity(), permission) == PackageManager.PERMISSION_GRANTED + return requireActivity().isPermissionGranted(permission) } +/** + * Calls `finish()` on the enclosing [androidx.fragment.app.FragmentActivity] + */ fun Fragment.finish() = requireActivity().finish() -fun FragmentManager.performTransaction(destinationFragment: Fragment, @IdRes containerViewId: Int = android.R.id.content) { - this.commit { - beginTransaction() - setCustomAnimations( - R.animator.slide_in_left, - R.animator.slide_out_left, - R.animator.slide_in_right, - R.animator.slide_out_right) - replace(containerViewId, destinationFragment) - } -} - +/** + * 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) { - this.commit { + commit { beginTransaction() addToBackStack(destinationFragment.tag) setCustomAnimations( @@ -39,14 +34,3 @@ fun FragmentManager.performTransactionWithBackStack(destinationFragment: Fragmen replace(containerViewId, destinationFragment) } } - -fun FragmentManager.performSharedElementTransaction(destinationFragment: Fragment, views: List<View>, @IdRes containerViewId: Int = android.R.id.content) { - this.commit { - beginTransaction() - for (view in views) { - addSharedElement(view, view.transitionName) - } - addToBackStack(destinationFragment.tag) - replace(containerViewId, destinationFragment) - } -} |
