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 calledonPostCreate
.onStart
. Called when the activity calledonStart
.onResume
. Called when the activity calledonResume
.onStop
. Called when the activity calledonStop
.onActivityResult
. Called when the activity calledonActivityResult
.onSavedInstanceState
. Called when the activity calledonSavedInstanceState
.
-
Interactor extends ViperContract.Interactor
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when interactor created.onPostCreate
. Called when the activity calledonPostCreate
.onStart
. Called when the activity calledonStart
.onResume
. Called when the activity calledonResume
.onStop
. Called when the activity calledonStop
.onActivityResult
. Called when the activity calledonActivityResult
.onSavedInstanceState
. Called when the activity calledonSavedInstanceState
.
-
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 calledonViewCreated
.onStart
. Called when the fragment calledonStart
.onResume
. Called when the fragment calledonResume
.onStop
. Called when the fragment calledonStop
.onActivityResult
. Called when the fragment calledonActivityResult
.onSavedInstanceState
. Called when the fragment calledonSavedInstanceState
.
-
Interactor extends ViperContract.Interactor
onCreate(extras: Bundle?, savedInstanceState: Bundle?)
. Called when interactor created.onViewCreated
. Called when fragment calledonViewCreated
.onStart
. Called when the activity calledonStart
.onResume
. Called when the activity calledonResume
.onStop
. Called when the activity calledonStop
.onActivityResult
. Called when the activity calledonActivityResult
.onSavedInstanceState
. Called when the activity calledonSavedInstanceState
.
-
InteractorOutput extends ViperContract.InteractorOutput
finishActivity
-
ViewBehavior extends ViperFragmentContract.ViewBehavior
dismiss
-
Presenter extends ViperFragmentContract.Presenter
onCreateDialog
. Called when dialog fragment callonCreateDialog
.
-
Interactor extends ViperFragmentContract.Interactor
-
InteractorOutput extends ViperContract.InteractorOutput
dismiss
Basically, ViperActivity will inherit AppCompatActivity. Custom inherit in ViperActivity see below.
- open
contentResId: Int
defaultR.id.container
. Require ViewGroup id. - open
layoutResId: Int
defaultR.layout.activity_base
. ForsetContentView(layoutResId)
fragment: ? extends Fragment
defaultnull
.presenter: ? extends ViperActivityContract.Presenter
defaultnull
.container: ViewGroup bindView(contentResId)
hasFragment: Boolean
. Check if already has fragment (because saved instance state) or not.- open
onRestoreFragment: ? extends Fragment
. This function called if onlyhasFragment == true
. - open
onFragmentRestored(fragment: ? extends Fragment?)
. This function called if onlyhasFragment == true
and after onRestoreFragment. - open
onCreateFragment: ? extends Fragment?
. This function called if onlyhasFragment == false
. - open
onFragmentCreated(fragment: ? extends Fragment?)
. This function called if onlyhasFragment == false
and after onCreateFragment. - open
onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter. - open
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.- open
onCreateDrawerMenu(inflater: LayoutInflater?, navigationView: NavigationView)
. Override this function for custom the navigation view. Either inflate or set menu id.
- open
menuResId: Int
. The menu id will inflate. - open
attachToRoot: Boolean
- open
layoutResId: Int
. For decide which layout fragment will inflate. presenter: ViperFragmentContract.Presenter
hasOptionsMenu
. True if menuResId not null.- open
onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter. - open
onPresenterCreated(presenter: ? extends ViperActivityContract.Presenter?)
. This function called after onCreatePresenter.
- open
layoutResId: Int
. For decide which layout fragment will inflate. presenter: ViperFragmentContract.Presenter
- open
onCreatePresenter: ? extends ViperActivityContract.Presenter?
. Override this function if only have custom presenter. - open
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
- ViperPresenter implements ViperContract.Presenter
- ViperInteractor implements ViperContract.Interactor
- ViperRouter implements ViperContract.Router