Skip to content

Commit

Permalink
fix: creating the layout when creating an activity class
Browse files Browse the repository at this point in the history
  • Loading branch information
teixeira0x committed Dec 11, 2024
1 parent 7e07615 commit 895dbd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ class NewFileAction(context: Context, override val order: Int) :
val fileTypeId: Int = binding.fileTypeGroup.checkedButtonId
val classTypeId: Int = binding.classTypeGroup.checkedButtonId

val isKotlin = fileTypeId == binding.typeKotlin.id

val created =
doCreateClassFile(
binding,
file,
fileTypeId == binding.typeKotlin.id,
isKotlin,
classTypeId,
name,
pkgName,
Expand All @@ -225,7 +227,7 @@ class NewFileAction(context: Context, override val order: Int) :

if (created && autoLayout) {
val packagePath = pkgName.toString().replace(".", "/")
createAutoLayout(context, file, name, packagePath)
createAutoLayout(context, isKotlin, file, name, packagePath)
}
}

Expand Down Expand Up @@ -304,13 +306,20 @@ class NewFileAction(context: Context, override val order: Int) :

private fun createAutoLayout(
context: Context,
isKotlin: Boolean,
directory: File,
fileName: String,
packagePath: String,
) {
val dir = directory.toString().replace("java/$packagePath", "res/layout/")
val dir =
directory.absolutePath.replaceFirst(
Regex("java|kotlin/($packagePath)?"),
"res/layout/",
)
val layoutName =
ProjectWriter.createLayoutName(fileName.replace(".java", ".xml"))
ProjectWriter.createLayoutName(
fileName.replace(if (isKotlin) ".kt" else ".java", ".xml")
)
val newFileLayout = File(dir, layoutName)
if (newFileLayout.exists()) {
flashError(R.string.msg_layout_file_exists)
Expand Down
6 changes: 4 additions & 2 deletions core/app/src/main/res/layout/layout_create_file_class.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/type_java"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idepref_editor_category_java"
app:icon="@drawable/ic_language_java" />

<com.google.android.material.button.MaterialButton
android:id="@+id/type_kotlin"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/idepref_editor_category_kotlin"
app:icon="@drawable/ic_language_kotlin" />

Expand Down

0 comments on commit 895dbd2

Please sign in to comment.