Simple Mvp Implementation

Related tags

App Froggy
Overview

Froggy

Simple Mvp Implementation

Download

Gragle:

compile 'ru.bullyboo.mvp:froggy:1.0.2'

Maven:

<dependency> 
  <groupId>ru.bullyboo.mvp</groupId> 
  <artifactId>froggy</artifactId> 
  <version>1.0.2</version> 
  <type>pom</type> 
</dependency>

Samples

Apk of Demo version

Usage

To create presenter, you need to inherit from class FrogPresenter and parametrized its with Model and View.

public class ExamplePresenter extends FrogPresenter<ExampleModel, ExampleActivity> {
  //...
}

Each presenter has a life cycle. It contains next methods:

/**
* Calling when view and model was set
*/
@Override
protected void onUpdateView(ExampleModel model, ExampleView view) {
    
}

/**
* Calling when new presenter was create
*/
@Override
protected void onCreatePresenter(){

}

/**
* Calling when view attached
*/
@Override
protected void onAttachedViewFirstTime(ExampleView view){

}

/**
* Calling when view attached
*/
@Override
protected void onAttachedModelFirstTime(ExampleModel model){

}

/**
* Calling when view attached
*/
@Override
protected void onAttachedView(ExampleView view){

}

/**
* Calling when model attached
*/
@Override
protected void onAttachedModel(ExampleModel model){

}

/**
* Calling when view detach
*/
@Override
protected void onDetachView(ExampleView view){

}

/**
* Calling when model detach
*/
@Override
protected void onDetachModel(ExampleModel model){

}

To attach presenter to your Activity, you need to inherit from class FrogActivity or FrogAppCompatActivity.

public class MainActivity extends FrogActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setPresenter(ExamplePresenter.class);
        //...
    }
    //...
}

To get the object of the presenter and access to its methods, you need to use next method in your View:

//...
(ExamplePresenter) getPresenter();
//...

But, if you don't want to use converting, you can parametrize inheritable class with your presenter:

public class MainActivity extends FrogActivity<ExamplePresenter> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setPresenter(ExamplePresenter.class);
        //...
    }
    //...
}

In this case getting object of presenter will look like:

//...
getPresenter();
//...

It's absolutely the same with fragments:

public class TextFragment extends FrogFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setPresenter(ExamplePresenter.class);
        //...
    }
}

Getting object of the presenter:

//...
(ExamplePresenter) getPresenter();
//...

Parametrized class:

public class TextFragment extends FrogFragment<ExamplePresenter> {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setPresenter(ExamplePresenter.class);
        //...
    }
}

Getting object of the presenter:

//...
getPresenter();
//...

Calling of method setPresenter can be done in other places, but you need to do it after calling super.onCreate(savedInstanceState); and before calling onResume();.

Usage with RecyclerAdapter

First at all you need to create adapter, which will inherit from FrogRecyclerAdapter parametrized with Model, View and Presenter.

public class RecyclerAdapter extends FrogRecyclerAdapter<ExampleModel, ExampleViewHolder, ExamplePresenter> {
  //...
}

In the adapter you need to override three methods. The method of presenter creation. The method of ViewHolder creation. The method to getting model's id.

Also you need to create your own ViewHolder, which will inherit from FrogRecyclerHolder paramtrized with Presenter.

public class ExampleHolder extends FrogRecyclerHolder<ExamplePresenter>{
  //...
}

Your adapter is ready. To create and fill it with your data, use:

ExampleAdapter adapter = new ExampleAdapter();
adapter.addAll(modelList);

Thanks to

android-arch-sample

License

  Copyright (C) 2017 BullyBoo

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
You might also like...
New-SplashScreen-API - SplashScreen API Implementation Sample

SplashScreen API Implementation Sample Installation - Usage style name="Theme.A

Android News App built in kotlin with implementation of MVVM architecture, android navigation components and retrofit. Displays news to users allowing them to share and save news.
Android News App built in kotlin with implementation of MVVM architecture, android navigation components and retrofit. Displays news to users allowing them to share and save news.

News-App Android news app built in kotlin that fetches news data from news api with Retrofit and displays news to users. This App follow MVVM architec

Cql-cds-hooks - HL7 CDS HOOKS Implementation with CQL support

CQL CDS HOOKS HL7 CDS HOOKS implementation with CQL (Clinical Quality Language)

Glickotlin - Kotlin implementation of the Glicko2 algorithm

Glickotlin Glickotlin is a Kotlin implementation of the Glicko2 algorithm. Glick

Wandroid project based on Kotlin + JetPack + concurrent implementation of MVVM architecture for playing Android App
Wandroid project based on Kotlin + JetPack + concurrent implementation of MVVM architecture for playing Android App

Wandroid project based on Kotlin + JetPack + concurrent implementation of MVVM architecture for playing Android App

Firebase Authentication and realtime database implementation in Android Kotlin

Androidfirebaseauthentication Firebase is Google’s mobile platform that helps you develop high-quality apps and provides hosted backend services such

Multi Roots TreeView implementation for Android Platform with a lot of options and customization
Multi Roots TreeView implementation for Android Platform with a lot of options and customization

TreeView Multi Roots TreeView implementation for Android Platform with a lot of options and customization Demo Features: - No Custom Views. - Easy use

A powerful library for easy implementation of HMS Location Kit.

AdvancedLocation A powerful library for easy implementation of HMS Location Kit. 💙 Request location with couple lines of code (no more boilerplate) C

React Native Stone SDK Implementation (Support for both Mobile and POS versions)

react-native-stone-pos Stone Android POS Native Module Installation Stone has a private packageCloud repository, so we need to have your token before

Owner
Rostislav Sharafutdinov
Rostislav Sharafutdinov
Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information about Marvel's vast library of comics. :zap:

Villains & Heroes Android app built with MVP architectural approach and uses Marvel Comics API that allows developers everywhere to access information

André Mion 53 Jul 13, 2022
This is a work-in-progress (🔧️) ultraviolet index viewer app for demonstrating Instant Apps + Kotlin + Dagger + MVP

UV Index A simple ultraviolet index viewer app for demonstrating: Instant Apps + Kotlin + Dagger + MVP Built With Weatherbit as weather API Android In

Mustafa Berkay Mutlu 65 Oct 31, 2022
Movie discovery app showcasing MVP, RxJava, Dagger 2 and Clean Architecture

MovieGuide ?? Refactoring in progress ??‍♀️ ⛏ ?? ??️ ?? ?? ?? Comments and new issues are welcome. ?? Currently not accepting external PRs that touch

Arun Sasidharan 2.6k Dec 25, 2022
A simple implementation of the Android In-App Billing API.

Google In-App Billing Library v4+ A simple implementation of the Android In-App Billing API. It supports: in-app purchases (both consumable and non-co

Moisoni Ioan 79 Dec 12, 2022
The implementation of https://dribbble.com/shots/2067564-Replace

FlyRefresh The Android implementation of Replace, designed by Zee Youn. I implement this as a FlyRefresh layout. The content of the layout can be any

吴晶 2.9k Nov 29, 2022
Implementation of Instagram with Material Design (originally based on Emmanuel Pacamalan's concept)

InstaMaterial Updated Current source code contains UI elements from Design Support Library. If you still want to see how custom implementations of e.g

Mirosław Stanek 5k Dec 27, 2022
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Jan 8, 2023
Implementation of the application using the latest Android Tech Stack and the GitHub REST API.

GitHub Viewer Implementation of the application using the latest Android Tech Stack and the GitHub REST API. <!-- Github login. You can change the use

Vitaliy Zarubin 53 Jan 3, 2023
A project for the implementation of the car animation feature in most ride-sharing/ food delivery apps

CarAnimation This is a test project to practice the implementation of the car animation feature in most ride-sharing/ food delivery apps. Slowly build

Samurai 45 Dec 23, 2022
Implementation of useful hooks inspired by React for Compose

useCompose React inspired hooks for Compose Installation Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the

Pavitra Golchha 20 Nov 14, 2022