Skip to content

Commit

Permalink
Merge pull request #73 from shivan42/master
Browse files Browse the repository at this point in the history
Added Moxy templates for Kotlin
  • Loading branch information
senneco authored Jan 15, 2017
2 parents f97b471 + 1d7623d commit 11ba2f0
Show file tree
Hide file tree
Showing 35 changed files with 424 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions moxy-templates/Kotlin/MoxyActivity/globals.xml.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<globals>
<#include "../common/common_globals.xml.ftl" />
<global id="subpackage" value="<#if useSubPackage>${subPackage}/<#else></#if>" />
<global id="dotSubpackage" value="<#if useSubPackage>.${subPackage}<#else></#if>" />
</globals>
34 changes: 34 additions & 0 deletions moxy-templates/Kotlin/MoxyActivity/recipe.xml.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<recipe>

<#if includeLayout>
<instantiate from="res/layout/activity_blank.xml.ftl"
to="${escapeXmlAttribute(resOut)}/layout/${escapeXmlAttribute(activityName)}.xml" />

<open file="${escapeXmlAttribute(resOut)}/layout/${escapeXmlAttribute(activityName)}.xml" />
</#if>


<instantiate from="src/app_package/ui/activity/BlankActivity.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/ui/activity/${subpackage}${className}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/ui/activity/${subpackage}${className}.kt" />

<#if includeView>
<instantiate from="src/app_package/presentation/view/BlankView.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/presentation/view/${subpackage}${viewName}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/presentation/view/${subpackage}${viewName}.kt" />
</#if>

<#if includePresenter>
<instantiate from="src/app_package/presentation/presenter/BlankPresenter.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/presentation/presenter/${subpackage}${presenterName}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/presentation/presenter/${subpackage}${presenterName}.kt" />
</#if>

<merge from="AndroidManifest.xml.ftl"
to="${escapeXmlAttribute(manifestOut)}/AndroidManifest.xml" />

</recipe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >

<application>
<activity android:name=".ui.activity${dotSubpackage}.${className}"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.ui.activity${dotSubpackage}.${className}">



</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ${packageName}.presentation.presenter${dotSubpackage}

import com.arellomobile.mvp.InjectViewState
import com.arellomobile.mvp.MvpPresenter
import ${packageName}.presentation.view${dotSubpackage}.${viewName}

@InjectViewState
class ${presenterName} : MvpPresenter<${viewName}>() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ${packageName}.presentation.view${dotSubpackage}

import com.arellomobile.mvp.MvpView

interface ${viewName} : MvpView {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ${packageName}.ui.activity${dotSubpackage}

import android.content.Context
import android.content.Intent
import android.os.Bundle
<#if !extendsBaseActivity>
import com.arellomobile.mvp.MvpActivity
</#if>
import com.arellomobile.mvp.presenter.InjectPresenter
import ${packageName}.R
import ${packageName}.presentation.view${dotSubpackage}.${viewName}
import ${packageName}.presentation.presenter${dotSubpackage}.${presenterName}
<#if extendsBaseActivity>
import ${packageName}.ui.activity.BaseActivity
</#if>

class ${className} : <#if extendsBaseActivity>BaseActivity()<#else>MvpActivity()</#if>, ${viewName} {
companion object {
const val TAG = "${className}"
<#if includeFactory>
fun getIntent(context: Context): Intent = Intent(context, ${className}::class.java)
</#if>
}

@InjectPresenter
lateinit var m${presenterName}: ${presenterName}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
<#if includeLayout>
setContentView(R.layout.${activityName})
</#if>
}
}
109 changes: 109 additions & 0 deletions moxy-templates/Kotlin/MoxyActivity/template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0"?>
<template
format="4"
revision="1"
name="Moxy activity"
description="MVP activity constructor"
minApi="9"
minBuildApi="14">

<category value="Moxy" />

<parameter
id="className"
name="Activity Name"
type="string"
constraints="class|nonempty|unique"
default="BlankActivity"
help="The name of the activity class to create" />

<parameter
id="useSubPackage"
name="Use sub package?"
type="boolean"
default="true"
help="Add generated classes to specified package" />

<parameter
id="subPackage"
name="Package name"
type="string"
default="blank"
visibility="useSubPackage"
help="Package name" />

<parameter
id="includeLayout"
name="Create layout XML?"
type="boolean"
default="true"
help="Generate a layout XML for the activity" />

<parameter
id="includeView"
name="Create View?"
type="boolean"
default="true"
help="Generate a view for the activity" />

<parameter
id="includePresenter"
name="Create Presenter?"
type="boolean"
default="true"
help="Generate a presenter for the activity" />

<parameter
id="extendsBaseActivity"
name="extends from Base Activity"
type="boolean"
default="true"
help="extends from your_package_name/ui/activity/BaseActivity otherwise MvpActivity" />


<parameter
id="activityName"
name="Activity Layout Name"
type="string"
constraints="layout|nonempty|unique"
default="activity_blank"
visibility="includeLayout"
suggest="activity_${classToResource(className)}"
help="The name of the layout to create" />

<parameter
id="includeFactory"
name="Include activity factory method?"
type="boolean"
default="true"
help="Generate static activity factory method for easy instantiation" />

<parameter
id="viewName"
name="View Name"
type="string"
constraints="class|nonempty|unique"
default="BlankView"
visibility="includeView"
suggest="${underscoreToCamelCase(classToResource(className))}View"
help="The name of the view interface to create" />

<parameter
id="presenterName"
name="Presenter Name"
type="string"
constraints="class|nonempty|unique"
default="BlankPresenter"
visibility="includePresenter"
suggest="${underscoreToCamelCase(classToResource(className))}Presenter"
help="The name of the presenter interface to create" />


<thumbs>
<thumb>template_moxy_activity.png</thumb>
</thumbs>

<globals file="globals.xml.ftl" />
<execute file="recipe.xml.ftl" />

</template>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions moxy-templates/Kotlin/MoxyFragment/globals.xml.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<globals>
<#include "../common/common_globals.xml.ftl" />
<global id="subpackage" value="<#if useSubPackage>${subPackage}/<#else></#if>" />
<global id="dotSubpackage" value="<#if useSubPackage>.${subPackage}<#else></#if>" />
</globals>
30 changes: 30 additions & 0 deletions moxy-templates/Kotlin/MoxyFragment/recipe.xml.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<recipe>

<#if includeLayout>
<instantiate from="res/layout/fragment_blank.xml.ftl"
to="${escapeXmlAttribute(resOut)}/layout/${escapeXmlAttribute(fragmentName)}.xml" />

<open file="${escapeXmlAttribute(resOut)}/layout/${escapeXmlAttribute(fragmentName)}.xml" />
</#if>

<instantiate from="src/app_package/ui/fragment/BlankFragment.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/ui/fragment/${subpackage}${className}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/ui/fragment/${subpackage}${className}.kt" />

<#if includeView>
<instantiate from="src/app_package/presentation/view/BlankView.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/presentation/view/${subpackage}${viewName}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/presentation/view/${subpackage}${viewName}.kt" />
</#if>

<#if includePresenter>
<instantiate from="src/app_package/presentation/presenter/BlankPresenter.kt.ftl"
to="${escapeXmlAttribute(srcOut)}/presentation/presenter/${subpackage}${presenterName}.kt" />

<open file="${escapeXmlAttribute(srcOut)}/presentation/presenter/${subpackage}${presenterName}.kt" />
</#if>

</recipe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.ui.fragment${dotSubpackage}.${className}">

</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ${packageName}.presentation.presenter${dotSubpackage}

import com.arellomobile.mvp.InjectViewState
import com.arellomobile.mvp.MvpPresenter
import ${packageName}.presentation.view${dotSubpackage}.${viewName}

@InjectViewState
class ${presenterName} : MvpPresenter<${viewName}>() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ${packageName}.presentation.view${dotSubpackage}

import com.arellomobile.mvp.MvpView

interface ${viewName} : MvpView {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ${packageName}.ui.fragment${dotSubpackage}

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import ${packageName}.R
import ${packageName}.presentation.view${dotSubpackage}.${viewName}
import ${packageName}.presentation.presenter${dotSubpackage}.${presenterName}

import com.arellomobile.mvp.MvpFragment
import com.arellomobile.mvp.presenter.InjectPresenter

class ${className} : MvpFragment(), ${viewName} {
companion object {
const val TAG = "${className}"
<#if includeFactory>

fun newInstance(): ${className} {
val fragment: ${className} = ${className}()
val args: Bundle = Bundle()
fragment.arguments = args
return fragment
}
</#if>
}

@InjectPresenter
lateinit var m${presenterName}: ${presenterName}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
<#if includeLayout>
return inflater.inflate(R.layout.${fragmentName}, container, false)
</#if>
}

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

}
}
Loading

0 comments on commit 11ba2f0

Please sign in to comment.