Skip to content

Commit

Permalink
Introduce the new lifecycle methods
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur3486 committed Apr 14, 2020
1 parent 0de808f commit f842fb1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ dependencies {
implementation project(":imageloading")
implementation project(":imageloading-glide")

implementation "com.arthurivanets.mvvm:mvvm-core:1.4.1"
implementation "com.arthurivanets.mvvm:mvvm-navigation:1.4.1"
implementation "com.arthurivanets.mvvm:mvvm-navigation-dagger:1.4.1"
implementation "com.arthurivanets.mvvm:mvvm-core:1.5.0"
implementation "com.arthurivanets.mvvm:mvvm-navigation:1.5.0"
implementation "com.arthurivanets.mvvm:mvvm-navigation-dagger:1.5.0"

testImplementation unitTestingDependencies
androidTestImplementation instrumentationTestingDependencies
Expand Down
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.4.1"
releaseVersionCode = 8
releaseVersion = "1.5.0"
releaseVersionCode = 9
releaseWebsite = "https://github.com/arthur3486/android-mvvm"
releaseLicense = ["Apache-2.0"]

Expand Down

This file was deleted.

26 changes: 20 additions & 6 deletions mvvm/src/main/java/com/arthurivanets/mvvm/MvvmActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ abstract class MvvmActivity<VDB : ViewDataBinding, VM : BaseViewModel>(
postInit()
performDataBinding()
subscribeViewStateObservers()
onBind()
}


Expand Down Expand Up @@ -177,17 +178,21 @@ abstract class MvvmActivity<VDB : ViewDataBinding, VM : BaseViewModel>(
protected abstract fun createViewModel() : VM


/**
* Executes the pending Data Binding operations.
*/
@CallSuper
protected open fun performDataBinding() {
private fun performDataBinding() {
if(isDataBindingEnabled) {
viewDataBinding?.executePendingBindings()
} else {
Log.e(this::class.java.canonicalName, "The DataBinding is disabled for this Activity.")
Log.i(this::class.java.canonicalName, "The DataBinding is disabled for this Activity.")
}
}


/**
* Override this lifecycle method if you need to perform the manual view-state specific binding.
*/
protected open fun onBind() {
// to be overridden.
}


@CallSuper
Expand Down Expand Up @@ -283,9 +288,18 @@ abstract class MvvmActivity<VDB : ViewDataBinding, VM : BaseViewModel>(

final override fun onDestroy() {
disposeViewStateSubscriptions()
onUnbind()
onRecycle()
super.onDestroy()
}


/**
* Override this method if you need to manually unbind the previously bound view-state specific observers.
*/
protected open fun onUnbind() {
// to be overridden.
}


/**
Expand Down
26 changes: 20 additions & 6 deletions mvvm/src/main/java/com/arthurivanets/mvvm/MvvmFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ abstract class MvvmFragment<VDB : ViewDataBinding, VM : BaseViewModel>(

performDataBinding()
subscribeViewStateObservers()
onBind()

// performing the state restoring only in cases when the view was created for the first time
// (otherwise there's no need to restore the state, as the current view already holds the most recent state)
Expand Down Expand Up @@ -232,19 +233,23 @@ abstract class MvvmFragment<VDB : ViewDataBinding, VM : BaseViewModel>(
}


/**
* Executes the pending Data Binding operations.
*/
@CallSuper
protected open fun performDataBinding() {
private fun performDataBinding() {
if(isDataBindingEnabled) {
viewDataBinding?.executePendingBindings()
} else {
Log.e(this::class.java.canonicalName, "The DataBinding is disabled for this Fragment.")
Log.i(this::class.java.canonicalName, "The DataBinding is disabled for this Fragment.")
}
}


/**
* Override this lifecycle method if you need to perform the manual view-state specific binding.
*/
protected open fun onBind() {
// to be overridden.
}


/**
* Looks up the [View] for the specified viewId within the current view hierarchy.
*
Expand Down Expand Up @@ -449,6 +454,15 @@ abstract class MvvmFragment<VDB : ViewDataBinding, VM : BaseViewModel>(
super.onDestroyView()

disposeViewStateSubscriptions()
onUnbind()
}


/**
* Override this method if you need to manually unbind the previously bound view-state specific observers.
*/
protected open fun onUnbind() {
// to be overridden.
}


Expand Down

0 comments on commit f842fb1

Please sign in to comment.