@@ -212,11 +212,13 @@ class NewFileAction(context: Context, override val order: Int) :
212212 val fileTypeId: Int = binding.fileTypeGroup.checkedButtonId
213213 val classTypeId: Int = binding.classTypeGroup.checkedButtonId
214214
215+ val isKotlin = fileTypeId == binding.typeKotlin.id
216+
215217 val created =
216218 doCreateClassFile(
217219 binding,
218220 file,
219- fileTypeId == binding.typeKotlin.id ,
221+ isKotlin ,
220222 classTypeId,
221223 name,
222224 pkgName,
@@ -225,7 +227,7 @@ class NewFileAction(context: Context, override val order: Int) :
225227
226228 if (created && autoLayout) {
227229 val packagePath = pkgName.toString().replace(" ." , " /" )
228- createAutoLayout(context, file, name, packagePath)
230+ createAutoLayout(context, isKotlin, file, name, packagePath)
229231 }
230232 }
231233
@@ -304,13 +306,20 @@ class NewFileAction(context: Context, override val order: Int) :
304306
305307 private fun createAutoLayout (
306308 context : Context ,
309+ isKotlin : Boolean ,
307310 directory : File ,
308311 fileName : String ,
309312 packagePath : String ,
310313 ) {
311- val dir = directory.toString().replace(" java/$packagePath " , " res/layout/" )
314+ val dir =
315+ directory.absolutePath.replaceFirst(
316+ Regex (" java|kotlin/($packagePath )?" ),
317+ " res/layout/" ,
318+ )
312319 val layoutName =
313- ProjectWriter .createLayoutName(fileName.replace(" .java" , " .xml" ))
320+ ProjectWriter .createLayoutName(
321+ fileName.replace(if (isKotlin) " .kt" else " .java" , " .xml" )
322+ )
314323 val newFileLayout = File (dir, layoutName)
315324 if (newFileLayout.exists()) {
316325 flashError(R .string.msg_layout_file_exists)
0 commit comments