Home > Net >  Andorid Root package from file in Wizard Template Intellij
Andorid Root package from file in Wizard Template Intellij

Time:10-28

Create a file in the application package(top level) using Intellij Wizard Template.It's working in some machine and not working in linux machine.

fun getApplicationPackageFile(srcOut: File, applicationPackage: String): File {
    var applicationPackageFile = srcOut.path.toString()
    var pk = applicationPackage.replace(".", "\\")

    val status: Boolean = applicationPackageFile.contains(pk)
    return if (status) {
        var file =
            applicationPackageFile.substring(0, applicationPackageFile.indexOf(pk))   pk   "\\"
        File(file)
    } else {
        srcOut
    }
}

I think else part work on linux machine or some machines My inital structure can look like this

main-application-package
  -> package-i-created-myself
     -> Create template here

So It should create common package under main package along with AppViewModel and AppActivity

main-application-package
  -> common
     -> AppViewModel
     -> AppActivity
  -> package-i-created-myself
     -> Create template here

But in some machine it is under package-i-created-myself like

my-main-application-package
  
  -> package-i-created-myself
    -> common
       -> AppViewModel
       -> AppActivity
    -> Create template here

I am using above code like

  val pkFile = getApplicationPackageFile(srcOut, applicationPackage)

  save(
        getStrAppViewModel(applicationPackage),
        pkFile.resolve("common/AppViewModel.$ktOrJavaExt"
      )
        
 save(
        getStrAppClass(applicationPackage),
        pkFile.resolve("common/AppActivity.$ktOrJavaExt")
    )

Where srcOut is the directory(package) on click of which I add Template. and applicationPackage is get from

moduleData.projectTemplateData.applicationPackage

CodePudding user response:

Create a file in the application package(top level) using Intellij Wizard Template.It's working in some machine and not working in linux machine.

For linux and Mac machines You only need to change this line of code

var pk = applicationPackage.replace(".", "/")

Complete Code

fun getApplicationPackageFile(srcOut: File, applicationPackage: String): File {
    var applicationPackageFile = srcOut.path.toString()
    var pk = applicationPackage.replace(".", "/")

    val status: Boolean = applicationPackageFile.contains(pk)
    return if (status) {
        var file =
            applicationPackageFile.substring(0, applicationPackageFile.indexOf(pk))   pk 
        File(file)
    } else {
        srcOut
    }
}
  • Related