Skip to content

Commit

Permalink
Expand the Navigation specific APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur3486 committed May 17, 2020
1 parent f842fb1 commit f6f56ff
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
4 changes: 2 additions & 2 deletions common/constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ project.ext {
releaseRepoName = "maven"
releaseUserOrg = "arthurlabs"
releaseGroupId = "com.arthurivanets.mvvm"
releaseVersion = "1.5.0"
releaseVersionCode = 9
releaseVersion = "1.6.0"
releaseVersionCode = 10
releaseWebsite = "https://github.com/arthur3486/android-mvvm"
releaseLicense = ["Apache-2.0"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.annotation.NavigationRes
import androidx.databinding.ViewDataBinding
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.Navigator
import androidx.navigation.findNavController
import androidx.navigation.*
import androidx.navigation.fragment.NavHostFragment
import com.arthurivanets.mvvm.BaseViewModel
import com.arthurivanets.mvvm.MvvmActivity
Expand Down Expand Up @@ -87,24 +84,53 @@ abstract class MvvmActivity<VDB : ViewDataBinding, VM : BaseViewModel>(@LayoutRe
*
* @param destinationId the id of the destination screen (either the new Activity or Fragment)
* @param extras the extra arguments to be passed to the destination screen
* @param navOptions
* @param navigationExtras
*/
protected fun navigate(
@IdRes destinationId : Int,
extras : Bundle? = null,
navOptions : NavOptions? = null,
navigationExtras : Navigator.Extras? = null
) {
navController.navigate(
destinationId,
extras,
navOptions,
navigationExtras
)
}


/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destination screen.
*/
protected fun navigate(@IdRes destinationId : Int, extras : Bundle? = null) {
navController.navigate(destinationId, extras)
protected fun navigate(directions : NavDirections) {
navController.navigate(directions)
}


/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destiantion screen.
* @param directions the direction that leads to the destination screen.
* @param navigationExtras
*/
protected fun navigate(directions : NavDirections, navigationExtras : Navigator.Extras? = null) {
navigationExtras?.let { navExtras ->
navController.navigate(directions, navExtras)
} ?: run {
navController.navigate(directions)
}
protected fun navigate(directions : NavDirections, navigationExtras : Navigator.Extras) {
navController.navigate(directions, navigationExtras)
}


/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destination screen.
* @param navOptions
*/
protected fun navigate(directions : NavDirections, navOptions : NavOptions) {
navController.navigate(directions, navOptions)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import androidx.navigation.NavDirections
import androidx.navigation.NavOptions
import androidx.navigation.Navigator
import androidx.navigation.fragment.findNavController
import com.arthurivanets.mvvm.BaseViewModel
Expand All @@ -37,17 +38,19 @@ abstract class MvvmFragment<VDB : ViewDataBinding, VM : BaseViewModel>(@LayoutRe
*
* @param destinationId the id of the destination screen (either the new Activity or Fragment)
* @param extras the extra arguments to be passed to the destination screen
* @param navOptions
* @param navigationExtras
*/
protected fun navigate(
@IdRes destinationId : Int,
extras : Bundle? = null,
navOptions : NavOptions? = null,
navigationExtras : Navigator.Extras? = null
) {
findNavController().navigate(
destinationId,
extras,
null,
navOptions,
navigationExtras
)
}
Expand All @@ -56,15 +59,32 @@ abstract class MvvmFragment<VDB : ViewDataBinding, VM : BaseViewModel>(@LayoutRe
/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destiantion screen.
* @param directions the direction that leads to the destination screen.
*/
protected fun navigate(directions : NavDirections) {
findNavController().navigate(directions)
}


/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destination screen.
* @param navOptions
*/
protected fun navigate(directions : NavDirections, navOptions : NavOptions) {
findNavController().navigate(directions, navOptions)
}


/**
* Navigates to the specified destination screen.
*
* @param directions the direction that leads to the destination screen.
* @param navigationExtras
*/
protected fun navigate(directions : NavDirections, navigationExtras : Navigator.Extras? = null) {
navigationExtras?.let { navExtras ->
findNavController().navigate(directions, navExtras)
} ?: run {
findNavController().navigate(directions)
}
protected fun navigate(directions : NavDirections, navigationExtras : Navigator.Extras) {
findNavController().navigate(directions, navigationExtras)
}


Expand Down

0 comments on commit f6f56ff

Please sign in to comment.