Skip to content

Commit 895dbd2

Browse files
committed
fix: creating the layout when creating an activity class
1 parent 7e07615 commit 895dbd2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

core/app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

core/app/src/main/res/layout/layout_create_file_class.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
<com.google.android.material.button.MaterialButton
2929
android:id="@+id/type_java"
3030
style="?attr/materialButtonOutlinedStyle"
31-
android:layout_width="wrap_content"
31+
android:layout_width="0dp"
3232
android:layout_height="wrap_content"
33+
android:layout_weight="1"
3334
android:text="@string/idepref_editor_category_java"
3435
app:icon="@drawable/ic_language_java" />
3536

3637
<com.google.android.material.button.MaterialButton
3738
android:id="@+id/type_kotlin"
3839
style="?attr/materialButtonOutlinedStyle"
39-
android:layout_width="wrap_content"
40+
android:layout_width="0dp"
4041
android:layout_height="wrap_content"
42+
android:layout_weight="1"
4143
android:text="@string/idepref_editor_category_kotlin"
4244
app:icon="@drawable/ic_language_kotlin" />
4345

0 commit comments

Comments
 (0)