All Projects → BlackBoxVision → Mvp Helpers

BlackBoxVision / Mvp Helpers

Licence: mit
♻️Helper classes to build Android Apps through MVP pattern in a faster way

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Mvp Helpers

Android Clean Architecture Boilerplate
Apply clean architecture on Android
Stars: ✭ 141 (+235.71%)
Mutual labels:  mvp-architecture, mvp-pattern
Trickl
trickl torrent client
Stars: ✭ 50 (+19.05%)
Mutual labels:  mvp-architecture, mvp-pattern
Kotlinmvparchitecture
Clean MVP Architecture with Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Added Unit Tests(Kotlin Tests)!
Stars: ✭ 143 (+240.48%)
Mutual labels:  mvp-architecture, mvp-pattern
Mvpandroid
Sample app to demonstrate MVP (Model - View - Presenter) architecture in android
Stars: ✭ 91 (+116.67%)
Mutual labels:  mvp-architecture, mvp-pattern
KotlinMvpTemplateGenerator
Android Studio template for Kotlin with MVP + Dagger2 + Retrofit2
Stars: ✭ 65 (+54.76%)
Mutual labels:  mvp-architecture, mvp-pattern
Mvparms
⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Stars: ✭ 10,146 (+24057.14%)
Mutual labels:  mvp-architecture, mvp-pattern
mezon
Mezon is a simple php framework wich will help you to create business applications.
Stars: ✭ 35 (-16.67%)
Mutual labels:  mvp-architecture, mvp-pattern
Kotlinrxmvparchitecture
Clean MVP Architecture with RxJava + Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Includes Unit Tests(Kotlin Tests)!
Stars: ✭ 94 (+123.81%)
Mutual labels:  mvp-architecture, mvp-pattern
mvp-architecture-kotlin-dagger-2-retrofit-android
Android Application MVP (Model-View-Presenter) architecture example using Dagger2 Dependency Injection (DI) and Retrofit Tutorial using Kotlin programming language.
Stars: ✭ 15 (-64.29%)
Mutual labels:  mvp-architecture, mvp-pattern
NiceDemo
iOS project, built on improved MVP architecture using Coordinator pattern for routing 😎
Stars: ✭ 54 (+28.57%)
Mutual labels:  mvp-architecture, mvp-pattern
Memorize
🚀 Japanese-English-Mongolian dictionary. It lets you find words, kanji and more quickly and easily
Stars: ✭ 72 (+71.43%)
Mutual labels:  mvp-architecture, mvp-pattern
Android Mvp Mvvm Flytour
🔥🔥🔥 FlyTour是Android MVVM+MVP+Dagger2+Retrofit+RxJava+组件化+插件组成的双编码架构+双工程架构+双语言Android应用开发框架,通过不断的升级迭代该框架已经有了十个不同的版本,5.0之前工程架构采用gradle配置实现组件化,5.0之后的工程架构采用VirtualAPK实现了插件化,5.0之前采用Java编码实现,5.0之后采用Kotlin编码实现,编码架构由MVVM和MVP组成,工程架构和编码架构及编码语言开发者可根据自己具体的项目实际需求去决定选择使用,该框架是Android组件化、Android插件化、Android MVP架构、Android MVVM架构的集大成者,帮助你快速的搭建自己的App项目开发框架,以便把主要的精…
Stars: ✭ 2,948 (+6919.05%)
Mutual labels:  mvp-architecture, mvp-pattern
Android Mvp Architecture
🏛 A basic sample android application to understand MVP in a very simple way. Just clone, build, run and understand MVP.
Stars: ✭ 203 (+383.33%)
Mutual labels:  mvp-architecture, mvp-pattern
wikilight
A lightweight Wikipedia Client
Stars: ✭ 50 (+19.05%)
Mutual labels:  mvp-architecture, mvp-pattern
visum
Android reactive MVP stack
Stars: ✭ 19 (-54.76%)
Mutual labels:  mvp-architecture, mvp-pattern
Mvpart
🎨 A new Android MVP architecture (此框架旨在解决传统 MVP 类和接口太多, 并且 Presenter 和 View 通过接口通信过于繁琐, 重用 Presenter 代价太大等问题).
Stars: ✭ 776 (+1747.62%)
Mutual labels:  mvp-architecture, mvp-pattern
Arcads
ArcAds is a DFP wrapper created by Arc Publishing with publishers in mind.
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
Nulldefense
Removes invalid objects during Gson parsing which are marked as required, yet null/empty.
Stars: ✭ 41 (-2.38%)
Mutual labels:  library
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
Stealtool
📚 盗取手机敏感信息,Android 6.0之上兼容
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
> Helper classes to build Android Apps through MVP pattern in a faster way

License: MIT Android Arsenal Build Status

This library exposes a minimal API, that should help you to build well architected Android Apps. ¡Check the following steps to get up and running!

Installation

Actually I don't have this library in JCenter/Maven Central, so if you want to use, follow the instructions. The library is distributed for Java and Kotlin. Looking for Kotlin variant? Go here

Gradle

  • Add it in your root build.gradle at the end of repositories:
allprojects {
	repositories {
		...
		maven { 
			url "https://jitpack.io" 
		}
	}
}
  • Add the dependency:
dependencies {
	 compile 'com.github.BlackBoxVision:mvp-helpers:v0.2.0'
}

Maven

  • Add this line to repositories section in pom.xml:
<repositories>
	<repository>
	   <id>jitpack.io</id>
		 <url>https://jitpack.io</url>
	</repository>
</repositories>
  • Add the dependency:
<dependency>
  <groupId>com.github.BlackBoxVision</groupId>
  <artifactId>mvp-helpers</artifactId>
	<version>v0.2.0</version>
</dependency>

SBT

  • Add it in your build.sbt at the end of resolvers:
  resolvers += "jitpack" at "https://jitpack.io"
  • Add the dependency:
  libraryDependencies += "com.github.BlackBoxVision" % "mvp-helpers" % "v0.2.0"	

Core Concepts

The concepts behind this library are the following ones:

  • View → The View is an interface that contains methods related to UI interaction. Those methods should be implemented in your Activity, Fragment or View.

  • Interactor → The Interactor is the class that do the hard work, all the blocking operations like I/O, Networking, Database Intectations should be done here.

  • Presenter → The presenter acts as a middle man between the Interactor and the View.

Usage example

The usage is really simple:

1 - Create your View interface by extending the BaseView. BaseView is an empty interface that acts as water mark for the Presenter.

public interface DetailsView extends BaseView {

    void onInfoReceived(@NonNull Bundle information);

    void onInfoError(@NonNull String errorMessage);
}

2 - Create an Interactor class by extending the BaseInteractor class. The BaseInteractor provides you a set of helper methods to deal with background execution and UIThread interaction. The methods are the following ones:

  • runOnUiThread → use it when you need to post data to the main thread.
  • runOnBackground → use it when you need to make background processing.
  • runOnBackground → use it when you need to make a scheduled task.
  • cancelTask → use it when you want to cancel a scheduled task.
//This example uses Java 8 features, I assume the usage of retrolambda
public final class DetailsInteractor extends BaseInteractor {

    public void retrieveDetailsFromService(@NonNull final String id, @NonNull final OnSuccessListener<Bundle> successListener, @NonNull final OnErrorListener<String> errorListener) {
        runOnBackground(() -> {
            //Getting data from somewhere
            final Bundle data = MockUtils.getMockedData(id);

            runOnUiThread(() -> {
                if (data != null) {
                    successListener.onSuccess(data);
                } else {
                    errorListener.onError("Ups, something went wrong");
                } 
            });
        });
    }
}

3 - Create a Presenter class by extending the BasePresenter class. The BasePresenter provides you with a set of helper methods to deal with View management. The methods are the following ones:

  • isViewAttached → check if you have set the view to the presenter, returns to you a boolean value that you should handle in your presenter implementation.
  • attachView → add the view to the presenter, so you can start to handle the cycle of view - presenter - interactor interaction.
  • detachView → dereference the view, setting it to null. This method should be called in the onDestroy method in case of use in Activity, and onDestroyView in case of Fragment usage.
  • getView → simple getter, to make your access to the view defined more cleaner.
  • onViewAttached → callback fired when the view is attached to the presenter, it gives you the view so you can start doing something like restoring state, instantiating the interactors.
  • onViewDetached → callback fired when the view is detached from the presenter, in this place you can dereference the objects you won't use anymore.
//I use method references from Java 8 to point the callbacks to interactor, I assume a working project with Retrolambda
public final class DetailsPresenter extends BasePresenter<DetailsView> {
    private DetailsInteractor interactor;
    
    @Override
    protected void onViewAttached(@NonNull DetailsView view) {
        interactor = new DetailsInteractor();
    }

    @Override
    protected void onViewDetached() {
        interactor = null;
    }

    public void findRequiredInformation(@NonNull String id) {
        if (isViewAttached()) {
            interactor.retrieveDetailsFromService(id, this::onSuccess, this::onError);
        }
    }

    private void onSuccess(@NonNull Bundle information) {
        if (isViewAttached()) {
            getView().onInfoReceived(information);
        }
    }

    private void onError(@NonNull String errorMessage) {
        if (isViewAttached()) {
            getView().onInfoError(errorMessage);
        }
    }
}

4 - Create a custom PresenterFactory class to provide the presenter instance. You should implement the PresenterFactory interface.

Now we have to create a Factory, because I have recently implemented a way to not loose presenter when configuration changes. The BaseActivity/BaseFragment use a Loader to provide the Presenter instance, Android Loaders can survive configuration changes, that's why I select them.

class DetailsPresenterFactory implements PresenterFactory<DetailsPresenter> {
	
	@Override
	public DetailsPresenter create() {
		return new DetailsPresenter();
	}
}

5 - Attach this cycle with Android specific classes. You can choice an Activity/Fragment or also a custom view. In this case I will show you an example with Fragment that inherits from BaseFragment

The BaseFragment comes with a resumed lifecycle, and a set of methods to implement. The methods are the following ones:

  • createPresenterFactory → in this method you have to create an instance of PresenterFactory.
  • getLayout → in this method you have pass the id reference to the layout.
  • getPresenter → simple getter, to make your access to the presenter more cleaner.
  • onPresenterCreated → In this method you can start doing something with the presenter. ¡Now the View is attached automatically to the Presenter!
  • onPresenterDestroyed → In this method you can do something, like saving app state.
public final class DetailsFragment extends BaseFragment<DetailsPresenter, DetailsView> implements DetailsView {
    
    @Override
    protected DetailsPresenterFactory createPresenterFactory() {
      	return new DetailsPresenterFactory();
    }
    
    @LayoutRes
    @Override
    protected int getLayout() {
      	return R.layout.fragment_details;
    }
    
    @Override
    protected void onPresenterCreated(@NonNull DetailsPresenter presenter) {
    	//Do something when presenter it's created
	    getPresenter().getInformationFromId("ssdWRGD132");
    }
    
    @Override
    protected void onPresenterDestroyed() {
	    //Do something when presenter is removed, this method is called in onDestroy	
    }
    
    @Override
    void onInfoReceived(@NonNull Bundle information) {
       Toast.makeText(getContext(), information.toString(), Toast.LENGTH_SHORT).show();
    }
    
    @Override
    void onInfoError(@NonNull String errorMessage) {
       Toast.makeText(getContext(), errorMessage, Toast.LENGTH_SHORT).show();
    }
} 

Advise about ButterKnife

From version 0.2.0 of this library, I have decided to remove butterKnife, in order to not force any dev to use butterKnife.

Issues

If you found a bug, or you have an answer, or whatever. Please, open an issue. I will do the best to fix it, or help you.

Contributing

Of course, if you see something that you want to upgrade from this library, or a bug that needs to be solved, PRs are welcome!

Release History

  • 0.2.0

    • CHANGE: BasePresenter has now two new callbacks, to be notified about view attachment/detachment.
    • CHANGE: BaseActivity/BaseFragment has now two new callbacks to be notified about presenter creation/destruction, also, addPresenter callback has been replace with createPresenterFactory
    • CHANGE: Added PresenterFactory interface to create custom factories to provide presenter instances
    • CHANGE: Added PresenterLoader, an Android Loader, that provides the presenter instance and survives configuration changes.
    • BUG FIX: Fixed issue with BaseInteractor runOnBackground method, this method was calling executor.isTerminated instead of calling executor.isShutdown, this produce a RuntimeException, because of troubles with ThreadPool reuse. Also, the methods have been refactored, to use a ExecutorService to get more control instead of an Executor.
  • 0.1.0

    • CHANGE: Folder refactor under UI package
    • CHANGE: Modified BasePresenter method registerView to attachView in order to get more consistence
    • CHANGE: Added new runOnBackground version in BaseInteractor that uses a ScheduledExecutorService and also cancel method to stop execution
    • CHANGE: Added Custom Views to extend BaseRelativeLayout, BaseFrameLayout and BaseLinearLayout
  • 0.0.3

    • CHANGE: Removed ButterKnife annotation processor
    • CHANGE: Rename mvphelper library to library
  • 0.0.2

    • CHANGE: Minor updates
  • 0.0.1

    • Work in progress

License

Distributed under the MIT license. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].