Skip to content

Commit

Permalink
Add file reading system
Browse files Browse the repository at this point in the history
  • Loading branch information
POeticPotatoes committed May 17, 2023
1 parent 9ff73e9 commit 5aa16a3
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 14 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/*
.DS_Store
/build
/captures
Expand Down
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
implementation 'com.fasterxml.jackson:jackson-base:2.15.0'
implementation 'com.fasterxml.jackson:jackson-datatype-json-org:1.8.0'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.15.0'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
FileReader.saveFile()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.myapplication
package com.example.myapplication.data

data class Exp (
val expType: Int, // 0 is mat cost, 1 is allowable expense
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.myapplication
package com.example.myapplication.data

class Job(
data class Job(
val jobType: String,
var jobName: String,
) {}
)



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.myapplication
package com.example.myapplication.data

data class Rev (
val revType: Int, // 0 is revenue, 1 is govt grant/incentive/etc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.example.myapplication
package com.example.myapplication.data

import com.fasterxml.jackson.annotation.JsonFormat

class TaxProfile(
private val jobs: List<Job>,
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/example/myapplication/storage/FileReader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.myapplication.storage
import com.example.myapplication.data.TaxProfile
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File

class FileReader {
companion object {
private val mapper = jacksonObjectMapper()

fun readFile(filename: String): TaxProfile {
val json: String = File(filename).readText()
return mapper.readValue<TaxProfile>(json)
}

fun saveFile(profile: TaxProfile) {
val filename = profile.fy.toString() + ".json"
val json: String = mapper.writeValueAsString(profile)
File(filename).writeBytes(json.toByteArray())
}
}
}

0 comments on commit 5aa16a3

Please sign in to comment.