Skip to content

Commit 0a1c3d0

Browse files
committed
change layout file name
1 parent 6a0c998 commit 0a1c3d0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/main/kotlin/com/longforus/mvpautocodeplus/TemplateCons.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ public interface TemplateCons {
2727
" interface View : ${VN}${VG}{}\n" + " interface ${P_OR_M} : ${PN}${PG}{}\n" + "}\n";
2828

2929
String COMMON_IMPL_TP_CONTENT_JAVA =
30-
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME};#end\n" + "\n" + "import ${CONTRACT};\n" + "#if (${IMPL} != \"\")import ${IMPL};#end\n" + "\n" + "\n" + "/**\n" +
30+
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME};#end\n" + "\n" + "import ${CONTRACT};\n" + "import ${PACKAGE_NAME}.R;\n" + "#if (${IMPL} != \"\")import ${IMPL};#end\n" + "\n" + "\n" + "/**\n" +
3131
" * @describe \n" + " * @author ${USER}\n" + " * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" +
3232
"public class ${NAME}${IMPL_TYPE} #if(${IMPL}!=\"\") extends ${IMPL}${VG}#end implements I${NAME}Contract.${TYPE} {\n" + "\n" + "}\n" + "\n";
3333

34+
//todo R文件的报名应该是清单里面的报名
35+
3436
String COMMON_IMPL_TP_CONTENT_KOTLIN =
35-
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME}#end\n" + "\n" + "import ${CONTRACT}\n" + "#if (${IMPL} != \"\")import ${IMPL}#end\n" + "\n" + "/**\n" +
37+
"#if (${PACKAGE_NAME} != \"\")package ${PACKAGE_NAME}#end\n" + "\n" + "import ${CONTRACT}\n" + "import ${PACKAGE_NAME}.R\n" + "#if (${IMPL} != \"\")import ${IMPL}#end\n" + "\n" + "/**\n" +
3638
" * @describe \n" + " * @author ${USER}\n" + " * @date ${DATE} ${TIME}\n" + " * \t\t\t\t\t\t\t\t - generate by MvpAutoCodePlus plugin.\n" + " */\n" + "\n" +
3739
"class ${NAME}${IMPL_TYPE} :#if (${IMPL_NP} != \"\") ${IMPL_NP}${VG}(),#end ${CONTRACT_NP}.${TYPE} {\n" + "\n" + "}\n" + "\n";
3840
}

src/main/kotlin/com/longforus/mvpautocodeplus/maker/LayoutCreator.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.longforus.mvpautocodeplus.maker
22

33
import com.android.resources.ResourceFolderType
4+
import com.android.tools.idea.util.dependsOnAndroidx
45
import com.intellij.openapi.application.ApplicationManager
56
import com.intellij.openapi.command.WriteCommandAction
67
import com.intellij.openapi.project.Project
@@ -16,6 +17,7 @@ import org.jetbrains.android.facet.AndroidRootUtil
1617
import org.jetbrains.android.util.AndroidResourceUtil
1718
import org.jetbrains.android.util.AndroidUtils
1819
import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
20+
import org.jetbrains.kotlin.psi.psiUtil.findFunctionByName
1921

2022
/**
2123
* @describe
@@ -52,18 +54,29 @@ fun createLayoutFileForActivityOrFragment(ic: ItemConfigBean,facet: AndroidFacet
5254
if (className != null) {
5355
// val layoutFile = CreateResourceFileAction.createFileResource(facet, ResourceFolderType.LAYOUT, "activity_auto", null, null, true, "Create Layout For '$className'",
5456
// resDirectory, null, false)
57+
val nameSb = StringBuilder()
58+
ic.name.forEach {
59+
if (it >= "A"[0] && it <= "Z"[0]) {
60+
nameSb.append("_")
61+
}
62+
nameSb.append(it)
63+
}
64+
65+
val layoutFileOriginName = if (isActivity) "activity${nameSb.toString().toLowerCase()}" else "frag${nameSb.toString().toLowerCase()}"
66+
67+
val rootLayoutName = if (facet.module.dependsOnAndroidx()) "androidx.constraintlayout.widget.ConstraintLayout" else "android.support.constraint.ConstraintLayout"
5568

5669
val layoutFile = AndroidResourceUtil.createFileResource(
57-
if (isActivity) "activity_${ic.name.toLowerCase()}" else "frag_${ic.name.toLowerCase()}", resDirectory.findSubdirectory("layout")!!,
58-
"android.support.constraint.ConstraintLayout",
70+
layoutFileOriginName, resDirectory.findSubdirectory("layout")!!,
71+
rootLayoutName,
5972
ResourceFolderType.LAYOUT.getName(), false)
6073
val layoutFileName = layoutFile?.name
6174
val onCreateMethods = activityClass.findMethodsByName("getLayoutId", false)//todo 生成viewBinding
6275
if (onCreateMethods.size != 1) {
6376
return
6477
}
6578
if (activityClass is KtUltraLightClass){
66-
// activityClass.kotlinOrigin.findFunctionByName("getLayoutId")
79+
activityClass.kotlinOrigin.findFunctionByName("getLayoutId")
6780
activityClass.ownMethods.find {
6881
it.name=="getLayoutId"
6982
}?.let {

0 commit comments

Comments
 (0)