fix: 'Create layout file' checkbox is always visible when creating Java files

This commit is contained in:
Akash Yadav
2023-03-31 13:03:03 +05:30
parent 31957186d2
commit 43403304fa
3 changed files with 17 additions and 8 deletions
@@ -19,6 +19,7 @@ package com.itsaky.androidide.actions.filetree
import android.content.Context
import android.view.LayoutInflater
import androidx.core.view.isVisible
import com.blankj.utilcode.util.FileIOUtils
import com.itsaky.androidide.actions.ActionData
import com.itsaky.androidide.actions.requireFile
@@ -132,6 +133,9 @@ class NewFileAction(context: Context) :
val builder = DialogUtils.newMaterialDialogBuilder(context)
val binding: LayoutCreateFileJavaBinding =
LayoutCreateFileJavaBinding.inflate(LayoutInflater.from(context))
binding.typeGroup.addOnButtonCheckedListener { _, _, _ ->
binding.createLayout.isVisible = binding.typeGroup.checkedButtonId == binding.typeActivity.id
}
binding.name.editText?.addTextChangedListener(
object : SingleTextWatcher() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
@@ -154,7 +158,9 @@ class NewFileAction(context: Context) :
}
val name: String = binding.name.editText!!.text.toString().trim()
val autoLayout = binding.checkButton.isChecked
val autoLayout =
binding.typeGroup.checkedButtonId == binding.typeActivity.id &&
binding.createLayout.isChecked
val pkgName = ProjectWriter.getPackageName(file)
if (pkgName == null || pkgName.trim { it <= ' ' }.isEmpty()) {
flashError(R.string.msg_get_package_failed)
@@ -234,12 +240,12 @@ class NewFileAction(context: Context) :
val layoutName = ProjectWriter.createLayoutName(fileName.replace(".java", ".xml"))
val newFileLayout = File(dir, layoutName)
if (newFileLayout.exists()) {
flashError(R.string.msg_file_exists)
flashError(R.string.msg_layout_file_exists)
return
}
if (!FileIOUtils.writeFileFromString(newFileLayout, ProjectWriter.createLayout())) {
flashError(R.string.msg_file_creation_failed)
flashError(R.string.msg_layout_file_creation_failed)
return
}
@@ -4,8 +4,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp">
android:paddingTop="16dp"
android:paddingBottom="16dp">
<HorizontalScrollView
android:layout_width="match_parent"
@@ -83,12 +83,13 @@
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/checkButton"
android:id="@+id/create_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:checked="true"
android:text="@string/create_auto_layout" />
android:text="@string/create_auto_layout"
android:visibility="gone" />
</LinearLayout>
+3 -1
View File
@@ -138,10 +138,12 @@
<string name="msg_begin_project_write">Starting writing process</string>
<string name="msg_folder_creation_failed">Failed to create folder!</string>
<string name="msg_file_creation_failed">Failed to create file!</string>
<string name="msg_layout_file_creation_failed">Failed to create layout file!</string>
<string name="msg_folder_created">Folder created successfully!</string>
<string name="msg_file_created">File created successfully!</string>
<string name="msg_folder_exists">Folder already exists!</string>
<string name="msg_file_exists">File already exists!</string>
<string name="msg_layout_file_exists">Layout file already exists!</string>
<string name="msg_invalid_name">Invalid Name!</string>
<string name="text_create">Create</string>
<string name="msg_can_contain_slashes">If the path contains File separator (\'/\'), then the required (parent) directories will be created if they don\'t exist.</string>
@@ -149,7 +151,7 @@
<string name="file_name">File Name</string>
<string name="new_name">New name</string>
<string name="new_file">New file</string>
<string name="create_auto_layout">Create layout file automatically</string>
<string name="create_auto_layout">Create layout file</string>
<string name="new_java_class">New Java class</string>
<string name="new_xml_resource">New XML resource</string>
<string name="new_folder">New folder</string>