Skip to content

Small Android library to help you achieve MVP (Model - View - Presenter) for your Android projects.

License

Notifications You must be signed in to change notification settings

KasparPeterson/SimpleMVP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SimpleMVP

Small Android library to help you achieve MVP (Model - View - Presenter) for your Android projects. State maintaining Presenter can be added to Activity or Fragment.

Usage

Create Contract:

interface MyCoolContract {

    interface View: MVPBaseView {
        fun show(state: MyCoolViewState)
    }

    abstract class Presenter: MVPBasePresenter<View>() {
        abstract fun onCoolButtonClicked()
    }

}

Create Presenter:

class MyCoolPresenter: MyCoolContract.Presenter() {

    override fun onCoolButtonClicked() {
        // do some business
        onView { it.show(coolState()) }
    }

}

Create Activity:

class MyCoolActivity: MVPBaseActivity<MyCoolContract.Presenter, MyCoolContract.View>(),
        MyCoolContract.View {

    override fun show(state: MyCoolViewState) {
        // show your new view state
    }
    
    override fun getView(): MyCoolContract.View {
        return this
    }
    
    override fun createPresenter(): MyCoolContract.Presenter {
        return MyCoolPresenter()
    }
}

Or create Fragment:

class MyCoolFragment : MVPBaseFragment<MyCoolContract.Presenter, MyCoolContract.View>(),
        MyCoolContract.View {
        
    override fun show(state: MyCoolViewState) {
        // show your new view state
    }

    override fun getFragmentView(): MyCoolContract.View {
        return this
    }

    override fun createPresenter(): MyCoolContract.Presenter {
        return MyCoolPresenter()
    }
    
}

Templates for Android Studio

  1. copy entire folder 'SimpleMVPTemplateKotlin' to /Applications/Android Studio.app/Contents/plugins/android/lib/templates/other/
  2. Restart AS
  3. Create package if needed (e.g. "settings")
  4. Right click on package -> New -> Other -> SimpleMVP Activity
  5. Enter name (e.g. "Settings")
  6. Finish

There is also template for Java as well named 'SimpleMVPTemplate

Download

compile 'com.kasparpeterson:simplemvp:2.3.0'

About

Small Android library to help you achieve MVP (Model - View - Presenter) for your Android projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published