GithubHelp home page GithubHelp logo

oldmetalmind / android-studio-group-templates-mvp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from riggaroo/android-studio-group-templates-mvp

0.0 2.0 0.0 4 KB

Example of template for Android Studio, to create a set of files for MVP functionality.

FreeMarker 100.00%

android-studio-group-templates-mvp's Introduction

android-studio-group-templates-mvp

Example of template for Android Studio, to create a set of files for MVP functionality.

Please read the blog post first as this is just an example implementation of the concepts described in the blog post: https://riggaroo.co.za/custom-file-template-group-android-studiointellij/

Important Note: This is just an example usage of file templates, I am not advocating this is the perfect solution for using MVP in Android. This sample is merely to show how you can create a set of files based on a template of files.

In order to use this in your project.

  • Create the following files in your project:

MvpView.java

public interface MvpView {
}

MvpPresenter.java

public interface MvpPresenter<V extends MvpView> {

    void attachView(V mvpView);

    void detachView();
}

BasePresenter.java

  /**
   * Base class that implements the Presenter interface and provides a base implementation for
   * attachView() and detachView(). It also handles keeping a reference to the mvpView that
   * can be accessed from the children classes by calling getView().
   */
  public class BasePresenter<T extends MvpView> implements MvpPresenter<T> {
  
      private T view;
  
      private CompositeSubscription compositeSubscription = new CompositeSubscription();
  
      @Override
      public void attachView(T mvpView) {
          view = mvpView;
      }
  
      @Override
      public void detachView() {
          view = null;
          compositeSubscription.clear();
      }
  
      public T getView() {
          return view;
      }
  
      public void checkViewAttached() {
          if (!isViewAttached()) {
              throw new MvpViewNotAttachedException();
          }
      }
  
      public boolean isViewAttached() {
          return view != null;
      }
  
      public void addSubscription(Subscription subscription) {
          this.compositeSubscription.add(subscription);
      }
  
      public static class MvpViewNotAttachedException extends RuntimeException {
          public MvpViewNotAttachedException() {
              super("Please call Presenter.attachView(MvpView) before" + " requesting data to the Presenter");
          }
      }
  }
  • You will need to change the package name of the import statement in the template files, as when you generate this template it will generate different import statements. You need to change it in the following places:

    • root/src/app_package/Contract.java.ftl,
    • root/src/app_package/MvpView.java.ftl
    • root/src/pp_package/Presenter.java.ftl

    Change the import statements in each of those files, to correspond with your package name.

  • Then place the folder from this project into your '.android/' of your system:

~/.android/templates/other/
  • Restart Android Studio, and then when you right click on a folder to create a new file, you will be able to see the new option to create a MVP Function.

android-studio-group-templates-mvp's People

Contributors

oldmetalmind avatar riggaroo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.