{"id":27966481,"url":"https://github.com/techery/presenta","last_synced_at":"2025-08-19T08:02:49.497Z","repository":{"id":28174425,"uuid":"31675816","full_name":"techery/presenta","owner":"techery","description":"Easy MVP upon Mortar and Flow","archived":false,"fork":false,"pushed_at":"2016-02-12T15:35:24.000Z","size":203,"stargazers_count":50,"open_issues_count":2,"forks_count":6,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-08-19T08:02:39.027Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-04T19:32:42.000Z","updated_at":"2022-05-11T15:02:13.000Z","dependencies_parsed_at":"2022-07-13T00:00:30.425Z","dependency_job_id":null,"html_url":"https://github.com/techery/presenta","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/techery/presenta","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fpresenta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fpresenta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fpresenta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fpresenta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techery","download_url":"https://codeload.github.com/techery/presenta/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fpresenta/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271121168,"owners_count":24702723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-07T20:19:02.713Z","updated_at":"2025-08-19T08:02:49.402Z","avatar_url":"https://github.com/techery.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## What's this for?\nMortar and flow together provide a good way to follow MVP pattern and get rid of [lol-cycle with Fragments uglyness](https://corner.squareup.com/2014/10/advocating-against-android-fragments.html).\nNevertheless it adds some boilerplate to create a single Screen:\n\n1. Create `Path` class;\n2. Create inner-class `@module` (for Dagger 1) or `@component` + `@module` (for Dagger 2) to provide view with presenter;\n3. Inject `Presenter` into the `View`.\n\n`Mortar` already gives a way to provide view with presenter via scoped context, and step 2 is odd in most cases – that's what `Presenta` for. `Presenta` uses basic `mortar + flow` example with extra extra annotation to skip `Dagger` in the middle of `preseter-view` injection.\n\n## Getting started\n*Workflow is identical to mortar-sample:*\n\n1. Add root scope for Mortar, optionally link it with your Dagger main component;\n2. Add Flow support to main activity;\n3. Create Path screen with presenter and view refs.\n\nPresenta provides `InjectablePresenter` as a base class for presenters which want to benefit from Dagger and Mortar, so you have Dagger injections available inside presenter with no hassle.\n\n#### 1. Declare your `Path` using `@WithPresenter`\n```java\n@Layout(R.layout.chat_list_view) @WithPresenter(ChatListScreen.Presenter.class)\npublic class ChatListScreen extends Path {\n  ...\n}\n```\n#### 2. Add Presenter\n```java\npublic static class Presenter extends InjectablePresenter\u003cChatListView\u003e {\n\n    @Inject Chats chats;\n    List\u003cChat\u003e chatList;\n\n    public Presenter(PresenterInjector injector) {\n      super(injector); // Dagger injection will be held there\n      this.chatList = chats.getAll();\n    }\n    \n  }\n```\n#### 3. Use Mortar service to get presenter from View\n```java\npublic class ChatListView extends ListView {\n  Presenter presenter;\n\n  public ChatListView(Context context, AttributeSet attrs) {\n    super(context, attrs);\n    presenter = PresenterService.getPresenter(context);\n  }\n  ...\n```\n## Arguments for presenter\nMost of the time `Path` would have arguments for presenter, which identifies data on screen to be loaded. It's easy with inner-class like presenter and still safe – as presenter is already linked to flow path and will be destroyed even before path is. Note `messageId` and `chatId` in next sample:\n```java\n@Layout(R.layout.message_view) @WithPresenter(MessageScreen.Presenter.class)\npublic class MessageScreen extends Path {\n  private final int chatId;\n  private final int messageId;\n\n  public MessageScreen(int chatId, int messageId) {\n    this.chatId = chatId;\n    this.messageId = messageId;\n  }\n\n  public class Presenter extends InjectablePresenter\u003cMessageView\u003e {\n    private final Observable\u003cMessage\u003e messageSource;\n    private Message message;\n    @Inject Chats service;\n\n    public Presenter(PresenterInjector injector) {\n      super(injector);\n      this.messageSource = service.getChat(chatId).getMessage(messageId);\n    }\n    ...\n  }\n}\n```\n## Dagger's Component support \nIs still here. It's recommended to use @Scoped injection for singletons per path context. Presenta comes with `AppScope` and `ScreenScope` for this purpose. \n```java\n@Layout(R.layout.friend_view) @WithComponent(FriendScreen.Component.class)\npublic class FriendScreen extends Path implements HasParent {\n  private final int index;\n\n  public FriendScreen(int index) {\n    this.index = index;\n  }\n\n  @Override public FriendListScreen getParent() {\n    return new FriendListScreen();\n  }\n\n  @ScreenScope(FriendScreen.class)\n  @dagger.Component(dependencies = MortarDemoActivity.Component.class, modules = Module.class)\n  public static interface Component{\n    void inject(FriendView view);\n  }\n\n  @dagger.Module\n  public class Module {\n    @Provides User provideFriend(Chats chats) {\n      return chats.getFriend(index);\n    }\n  }\n\n  @ScreenScope(FriendScreen.class)\n  public static class Presenter extends ViewPresenter\u003cFriendView\u003e {\n    private final User friend;\n\n    @Inject\n    public Presenter(User friend) {\n      this.friend = friend;\n    }\n\n    @Override public void onLoad(Bundle savedInstanceState) {\n      super.onLoad(savedInstanceState);\n      if (!hasView()) return;\n      getView().setFriend(friend.name);\n    }\n  }\n}\n```\n## Additions\nMortar-flow sample has useful PathContainers to show up working example of it's philisophy. Those containers and view helpers are reused in `library-additions`\n## Dev. status\nExperimental, trying to use in prod. build.\n## Installation\nUse jitpack.io\n```groovy\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:1.1.3'\n        classpath 'com.github.dcendents:android-maven-plugin:1.2'\n    }\n}\n...\napply plugin: 'com.android.application'\napply plugin: 'com.neenbedankt.android-apt'\n...\nrepositories {\n    jcenter()\n    maven { url \"https://oss.sonatype.org/content/repositories/snapshots/\" }\n    maven { url \"https://jitpack.io\" }\n}\n\ndependencies {\n    compile 'com.github.techery.presenta:library:{version}'\n    compile 'com.github.techery.presenta:library-additions:{version}'\n    ...\n    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'\n    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'\n    provided 'org.glassfish:javax.annotation:10.0-b28'\n    ...\n    compile 'com.google.code.gson:gson:2.3.1'\n}\n```\n[![Analytics](https://ga-beacon.appspot.com/UA-60536876-1/presenta/readme?pixel)](https://github.com/igrigorik/ga-beacon)\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/techery/presenta/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechery%2Fpresenta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechery%2Fpresenta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechery%2Fpresenta/lists"}