Viper framework for android
Viper framework for android
repositories {
maven {
url 'https://dl.bintray.com/adef145/maven/'
}
maven {
url 'https://jitpack.io'
}
}
...
dependencies {
// for maven central
compile 'com.adefruandta.viper:viper:0.6.5'
// for jitpack
compile 'com.github.adef145:ViperAndroid:0.6.3'
}
In this library the presenter & interactor implement the base lifecycle of Activity or Fragment. For more detail, see below.
ViewBehavior
Presenter
unregister
. Called when view destroyed.Interactor
unregister
. Called when view destroyed.setInteractorOutput
. Called when Interactor created and the output should implemented in presenter.InteractorOutput
Router
unregister
. Called when view destroyed.ViewBehavior extends ViperContract.ViewBehavior
setTitle(title: String)
setTitle(titleResId: Int)
showToolbar
. Showing action bar.hideToolbar
. Hiding action bar.showBackButton
. Showing back button / home button.hideBackButton
. Hiding back button / home button.finish
. Finish the activity.Presenter extends ViperContract.Presenter
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when presenter created.onPostCreate
. Called when the activity called onPostCreate
.onStart
. Called when the activity called onStart
.onResume
. Called when the activity called onResume
.onStop
. Called when the activity called onStop
.onActivityResult
. Called when the activity called onActivityResult
.onSavedInstanceState
. Called when the activity called onSavedInstanceState
.Interactor extends ViperContract.Interactor
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when interactor created.onPostCreate
. Called when the activity called onPostCreate
.onStart
. Called when the activity called onStart
.onResume
. Called when the activity called onResume
.onStop
. Called when the activity called onStop
.onActivityResult
. Called when the activity called onActivityResult
.onSavedInstanceState
. Called when the activity called onSavedInstanceState
.InteractorOutput extends ViperContract.InteractorOutput
ViewBehavior extends ViperActivityContract.ViewBehavior
closeDrawers
Presenter extends ViperActivityContract.Presenter
Interactor extends ViperActivityContract.Interactor
InteractorOutput extends ViperActivityContract.InteractorOutput
ViewBehavior extends ViperContract.ViewBehavior
setTitle(title: String)
setTitle(titleResId: Int)
finishActivity
Presenter extends ViperContract.Presenter
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when presenter created.onViewCreated
. Called when fragment called onViewCreated
.onStart
. Called when the fragment called onStart
.onResume
. Called when the fragment called onResume
.onStop
. Called when the fragment called onStop
.onActivityResult
. Called when the fragment called onActivityResult
.onSavedInstanceState
. Called when the fragment called onSavedInstanceState
.Interactor extends ViperContract.Interactor
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when interactor created.onViewCreated
. Called when fragment called onViewCreated
.onStart
. Called when the activity called onStart
.onResume
. Called when the activity called onResume
.onStop
. Called when the activity called onStop
.onActivityResult
. Called when the activity called onActivityResult
.onSavedInstanceState
. Called when the activity called onSavedInstanceState
.InteractorOutput extends ViperContract.InteractorOutput
finishActivity
ViewBehavior extends ViperFragmentContract.ViewBehavior
dismiss
Presenter extends ViperFragmentContract.Presenter
onCreateDialog
. Called when dialog fragment call onCreateDialog
.Interactor extends ViperFragmentContract.Interactor
InteractorOutput extends ViperContract.InteractorOutput
dismiss
Basically, ViperActivity will inherit AppCompatActivity. Custom inherit in ViperActivity see below.
contentResId: Int
default R.id.container
. Require ViewGroup id.layoutResId: Int
default R.layout.activity_base
. For setContentView(layoutResId)
fragment: ? extends Fragment
default null
.presenter: ? extends ViperActivityContract.Presenter
default null
.container: ViewGroup bindView(contentResId)
hasFragment: Boolean
. Check if already has fragment (because saved instance state) or not.onRestoreFragment: ? extends Fragment
. This function called if only hasFragment == true
.onFragmentRestored(fragment: ? extends Fragment?)
. This function called if only hasFragment == true
and after onRestoreFragment.onCreateFragment: ? extends Fragment?
. This function called if only hasFragment == false
.onFragmentCreated(fragment: ? extends Fragment?)
. This function called if only hasFragment == false
and after onCreateFragment.onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter.onPresenterCreated(presenter: ? extends ViperActivityContract.Presenter?)
. This function called after onCreatePresenter.drawerToggle: ActionBarDrawerToggle
drawerLayout: DrawerLayout by bindView(R.id.drawerLayout)
navigationView: NavigationView by bindView(R.id.navigationView)
isDrawerOpen
. Check is drawer open or not.onCreateDrawerMenu(inflater: LayoutInflater?, navigationView: NavigationView)
. Override this function for custom the navigation view. Either inflate or set menu id.menuResId: Int
. The menu id will inflate.attachToRoot: Boolean
layoutResId: Int
. For decide which layout fragment will inflate.presenter: ViperFragmentContract.Presenter
hasOptionsMenu
. True if menuResId not null.onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter.onPresenterCreated(presenter: ? extends ViperActivityContract.Presenter?)
. This function called after onCreatePresenter.layoutResId: Int
. For decide which layout fragment will inflate.presenter: ViperFragmentContract.Presenter
onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter.onPresenterCreated(presenter: ? extends ViperActivityContract.Presenter?)
. This function called after onCreatePresenter.activity
fragment
context
intent
open
startActivity(intent: Intent)
startActivity(intent: Intent, options: Bundle?)
startActivity(intent: Intent, requestCode: Int)
finish