Skip to content

Commit d0295c0

Browse files
committed
layout 디렉토리 버그 수정
1 parent a779b71 commit d0295c0

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/main/kotlin/kr/co/finda/androidtemplate/feature/createFindaTemplate/dialog/CreateFindaTemplateDialogPresenter.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ class CreateFindaTemplateDialogPresenter(
2626
}
2727

2828
val packageName = fileHelper.getPackageNameByPath(selectedDirectory.path)
29-
// val appModule = fileHelper.getModulePathByPath(selectedDirectory.path)
3029
createUiCodeFile(name, packageName, screenType, selectedDirectory)
3130
createViewModelFile(name, packageName, selectedDirectory)
32-
createLayoutFile(project, name, packageName, screenType)
31+
createLayoutFile(project, name, packageName, screenType, selectedDirectory)
3332
}
3433

3534
private fun getConflictedFileName(
@@ -95,15 +94,21 @@ class CreateFindaTemplateDialogPresenter(
9594
project: Project,
9695
name: String,
9796
packageName: String,
98-
screenType: ScreenType
97+
screenType: ScreenType,
98+
selectedDirectory: VirtualFile
9999
) {
100-
val layoutDirectory = fileHelper.getLayoutDirectory(project.basePath!!)
100+
val layoutName = getLayoutName(screenType, name)
101+
val layoutDirectory = fileHelper.getLayoutDirectory(selectedDirectory.path)
102+
if (layoutDirectory == null) {
103+
view.showErrorDialog(project, PluginError.FT104)
104+
return
105+
}
101106

102107
val templateName = "LayoutTemplate"
103108

104109
fileHelper.createFileWithTemplate(
105-
layoutDirectory!!,
106-
getLayoutName(screenType, name),
110+
layoutDirectory,
111+
layoutName,
107112
FileExtension.XML,
108113
templateName,
109114
Replacements(

src/main/kotlin/kr/co/finda/androidtemplate/model/FileHelper.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import com.intellij.openapi.vfs.VirtualFileManager
66
import com.intellij.util.ResourceUtil
77
import kr.co.finda.androidtemplate.ext.replaceAll
88
import kr.co.finda.androidtemplate.type.FileExtension
9+
import java.io.File
10+
import java.net.URI
11+
import java.nio.file.Files
12+
import java.nio.file.Paths
913

1014
interface FileHelper {
1115

@@ -21,7 +25,7 @@ interface FileHelper {
2125

2226
fun getPackageNameByPath(path: String): String
2327

24-
fun getLayoutDirectory(projectBasePath: String): VirtualFile?
28+
fun getLayoutDirectory(selectedDirectoryPath: String): VirtualFile?
2529
}
2630

2731
class FileHelperImpl(
@@ -61,9 +65,11 @@ class FileHelperImpl(
6165
}
6266
}
6367

64-
override fun getLayoutDirectory(projectBasePath: String): VirtualFile? {
68+
override fun getLayoutDirectory(selectedDirectoryPath: String): VirtualFile? {
69+
val mainPath = selectedDirectoryPath.split("src/main")[0]
70+
val layoutPath = "${mainPath}/src/main/res/layout"
6571
return VirtualFileManager.getInstance()
66-
.findFileByUrl("file://${projectBasePath}/src/main/res/layout")
72+
.findFileByUrl("file://${layoutPath}")
6773
}
6874

6975
private fun getTemplateContentByName(templateName: String): String {

src/main/kotlin/kr/co/finda/androidtemplate/type/PluginError.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ enum class PluginError(
1010
*/
1111
FT101("선택된 위치를 찾을 수 없습니다", "FT101"),
1212
FT102("유효하지 않은 경로입니다", "FT102-'src/main/(java|kotlin)'경로에 해당하지 않습니다"),
13-
FT103("중복된 이름이 존재합니다", "FT103-이미 생성된 Activity 혹은 ViewModel을 확인해주세요")
13+
FT103("중복된 이름이 존재합니다", "FT103-이미 생성된 Activity 혹은 ViewModel을 확인해주세요"),
14+
FT104("레이아웃 폴더를 찾을 수 없습니다", "FT104-레이아웃 파일이 생성되지 못했습니다")
1415
}

0 commit comments

Comments
 (0)