From 43403304fa95e3136f1d2d1339fb93a2bc358b71 Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Fri, 31 Mar 2023 13:03:03 +0530 Subject: [PATCH] fix: 'Create layout file' checkbox is always visible when creating Java files --- .../androidide/actions/filetree/NewFileAction.kt | 12 +++++++++--- app/src/main/res/layout/layout_create_file_java.xml | 9 +++++---- resources/src/main/res/values/strings.xml | 4 +++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt b/app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt index ec5ba3336..fd2a2dc90 100644 --- a/app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt +++ b/app/src/main/java/com/itsaky/androidide/actions/filetree/NewFileAction.kt @@ -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 } diff --git a/app/src/main/res/layout/layout_create_file_java.xml b/app/src/main/res/layout/layout_create_file_java.xml index e700ee3ed..a4bedd5b4 100755 --- a/app/src/main/res/layout/layout_create_file_java.xml +++ b/app/src/main/res/layout/layout_create_file_java.xml @@ -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"> + android:text="@string/create_auto_layout" + android:visibility="gone" /> diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index 65e8ae106..010cc4da0 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -138,10 +138,12 @@ Starting writing process Failed to create folder! Failed to create file! + Failed to create layout file! Folder created successfully! File created successfully! Folder already exists! File already exists! + Layout file already exists! Invalid Name! Create If the path contains File separator (\'/\'), then the required (parent) directories will be created if they don\'t exist. @@ -149,7 +151,7 @@ File Name New name New file - Create layout file automatically + Create layout file New Java class New XML resource New folder