Skip to content

Commit

Permalink
Completed UI
Browse files Browse the repository at this point in the history
Added navigation functionality
  • Loading branch information
ken-ruster committed May 18, 2023
1 parent fdad601 commit a76fa94
Show file tree
Hide file tree
Showing 40 changed files with 1,456 additions and 142 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-parcelize'

}

android {
Expand Down Expand Up @@ -40,16 +43,14 @@ android {

dependencies {

implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.github.lisawray.groupie:groupie:2.10.1'
implementation "com.github.lisawray.groupie:groupie-viewbinding:2.10.1"
implementation 'androidx.core:core-ktx:1.8.0'
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'
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/example/myapplication/ExpListItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.myapplication

import android.view.View
import android.view.View.OnClickListener
import com.example.myapplication.data.TaxProfile
import com.example.myapplication.databinding.ExpRowBinding
import com.xwray.groupie.viewbinding.BindableItem


open class ExpListItem(private val profile: TaxProfile, private val listener: OnClickListener): BindableItem<ExpRowBinding>(profile.fy.toLong()) {

override fun bind(viewBinding: ExpRowBinding, position: Int) {
with(viewBinding) {
expName.text = profile.exps[position].expName
expType.text = if (profile.exps[position].expType == 0) "Type: Material Cost"
else "Type: Allowable Business Expense"
expVal.text = "Amount: $${profile.exps[position].amt}"
proportions.text = "Proportions: ${profile.exps[position].portion}"
editIcon.setOnClickListener(listener)
}
}

override fun getLayout(): Int = R.layout.exp_row

override fun initializeViewBinding(view: View): ExpRowBinding = ExpRowBinding.bind(view)
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/example/myapplication/JobListItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.myapplication

import android.view.View
import android.view.View.OnClickListener
import com.example.myapplication.data.TaxProfile
import com.example.myapplication.databinding.JobRowBinding
import com.xwray.groupie.viewbinding.BindableItem


open class JobListItem(private val profile: TaxProfile, private val listener: OnClickListener): BindableItem<JobRowBinding>(profile.fy.toLong()) {

lateinit var binding: JobRowBinding

override fun bind(viewBinding: JobRowBinding, position: Int) {
with(viewBinding) {
itemName.text = profile.jobs[position].jobName
jobType.text = "Type: ${profile.jobs[position].jobType}"
editIcon.setOnClickListener(listener)
}
}

override fun getLayout(): Int = R.layout.job_row

override fun initializeViewBinding(view: View): JobRowBinding = JobRowBinding.bind(view)
}
13 changes: 4 additions & 9 deletions app/src/main/java/com/example/myapplication/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ import android.os.Bundle
import androidx.recyclerview.widget.RecyclerView
import com.example.myapplication.databinding.ActivityMainBinding
import com.xwray.groupie.GroupieAdapter
import com.example.myapplication.data.TaxProfile
import com.example.myapplication.storage.FileReader

class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding
var profileArray: Array<TaxProfile> = emptyArray()
private lateinit var profileArray: List<TaxProfile>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)

val yaAdapter: GroupieAdapter = GroupieAdapter()
val recyclerView: RecyclerView = binding.listProfiles
recyclerView.adapter = yaAdapter

for(profile in profileArray){
yaAdapter.add(ProfileItem(profile))
}

setContentView(binding.root)
}
}
41 changes: 23 additions & 18 deletions app/src/main/java/com/example/myapplication/ProfileItem.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package com.example.myapplication

import android.view.View
import android.view.View.OnClickListener
import com.example.myapplication.data.TaxProfile
import com.example.myapplication.databinding.ProfileItemBinding
import com.example.myapplication.databinding.ProfileRowExpBinding
import com.example.myapplication.databinding.ProfileRowJobBinding
import com.example.myapplication.databinding.ProfileRowRevBinding
import com.xwray.groupie.viewbinding.BindableItem


open class ProfileItem(private val profile: TaxProfile): BindableItem<ProfileItemBinding>(profile.fy.toLong()) {

lateinit var profileItemBinding: ProfileItemBinding
lateinit var jobRowBinding: ProfileRowJobBinding
lateinit var revRowBinding: ProfileRowRevBinding
lateinit var expRowBinding: ProfileRowExpBinding
open class ProfileItem(
private val profile: TaxProfile,
private val listener: OnClickListener,
private val jobOverviewListener: OnClickListener,
private val revOverviewListener: OnClickListener,
private val expOverviewListener: OnClickListener
): BindableItem<ProfileItemBinding>(profile.fy.toLong()) {

//lateinit var profileItemBinding: ProfileItemBinding

override fun bind(viewBinding: ProfileItemBinding, position: Int) {
profileItemBinding.headerView.text = "YA" + profile.fy.toString()
jobRowBinding.jobsList.text = profile.jobString()
revRowBinding.revAmt.text = profile.totalRev().toString()
expRowBinding.expAmt.text = (profile.totalAllowableExp() + profile.totalMatCost()).toString()

jobRowBinding.editJobIcon.setOnClickListener { }
revRowBinding.editRevIcon.setOnClickListener { }
expRowBinding.editExpIcon.setOnClickListener { }
profileItemBinding.generateButton.setOnClickListener { }
with (viewBinding) {
headerView.text = "YA ${profile.fy}"
profileRow.jobsList.text = profile.jobString()
profileRowRev.revAmt.text = "$${profile.totalRev()}"
profileRowExp.expAmt.text = "$${(profile.totalAllowableExp() + profile.totalMatCost())}"
generateButton.setOnClickListener(listener)

profileRow.editJobIcon.setOnClickListener(jobOverviewListener)
profileRowRev.editRevIcon.setOnClickListener(revOverviewListener)
profileRowExp.editExpIcon.setOnClickListener(expOverviewListener)
}


}

override fun getLayout(): Int = R.layout.profile_item
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/example/myapplication/RevListItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.myapplication

import android.view.View
import android.view.View.OnClickListener
import com.example.myapplication.data.TaxProfile
import com.example.myapplication.databinding.RevRowBinding
import com.xwray.groupie.viewbinding.BindableItem


open class RevListItem(private val profile: TaxProfile, private val listener: OnClickListener): BindableItem<RevRowBinding>(profile.fy.toLong()) {

override fun bind(viewBinding: RevRowBinding, position: Int) {
with(viewBinding) {
revName.text = profile.revs[position].revName
revType.text = if (profile.revs[position].revType == 0) "Type: Salary/commission"
else "Type: Grant/incentive"
revVal.text = "Amount: $${profile.revs[position].amt}"

editIcon.setOnClickListener(listener)
}
}

override fun getLayout(): Int = R.layout.rev_row

override fun initializeViewBinding(view: View): RevRowBinding = RevRowBinding.bind(view)
}

This file was deleted.

6 changes: 5 additions & 1 deletion app/src/main/java/com/example/myapplication/data/Exp.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.example.myapplication.data

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Exp (
val expType: Int, // 0 is mat cost, 1 is allowable expense
val expName: String,
var amt: Float,
val portion: Map<String, Float> // <jobID, portion in %>
){}
) : Parcelable {}
6 changes: 5 additions & 1 deletion app/src/main/java/com/example/myapplication/data/Job.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.example.myapplication.data

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Job(
val jobType: String,
var jobName: String,
)
) : Parcelable



Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/example/myapplication/data/Rev.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.example.myapplication.data

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Rev (
val revType: Int, // 0 is revenue, 1 is govt grant/incentive/etc
val revName: String,
var amt: Float
){}
) : Parcelable {}
29 changes: 23 additions & 6 deletions app/src/main/java/com/example/myapplication/data/TaxProfile.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package com.example.myapplication.data

import android.os.Parcelable
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnore
import kotlinx.parcelize.Parcelize
import java.time.LocalDate

@Parcelize
class TaxProfile(
val jobs: List<Job>,
val revs: List<Rev>,
val exps: List<Exp>,
var fy: Int
) {
val jobs: List<Job> = emptyList<Job>().plus(Job(
"Private Hire/Taxi Driver",
"Grab"
)),
val revs: List<Rev> = emptyList<Rev>().plus(Rev(
0,
"Grab",
0.0F
)),
val exps: List<Exp> = emptyList<Exp>().plus(Exp(
1,
"Fuel",
0.0F,
emptyMap<String, Float>().plus(Pair("Grab", 100F))
)),

var fy: Int = LocalDate.now().year
) : Parcelable {
fun totalRev(): Float = revs.sumOf { it.amt.toDouble() }.toFloat()
fun totalMatCost(): Float = exps.sumOf { it.amt.toDouble() * (1 - it.expType) }.toFloat()
fun totalAllowableExp(): Float = exps.sumOf { it.amt.toDouble() * it.expType }.toFloat()
Expand All @@ -27,4 +44,4 @@ class TaxProfile(

@JsonIgnore
fun isEmpty(): Boolean {return jobs.isEmpty()}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.myapplication.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
import com.example.myapplication.databinding.ExpEditBinding

class ExpEditFragment:Fragment() {
lateinit var binding: ExpEditBinding
val args: ExpsOverviewFragmentArgs by navArgs()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = ExpEditBinding.inflate(layoutInflater)

with(binding){

}

return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.myapplication.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.RecyclerView
import com.example.myapplication.ExpListItem
import com.example.myapplication.databinding.ExpsOverviewBinding
import com.xwray.groupie.GroupieAdapter

class ExpsOverviewFragment(): Fragment() {
lateinit var binding: ExpsOverviewBinding
val args: ExpsOverviewFragmentArgs by navArgs()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
super.onCreateView(inflater, container, savedInstanceState)
binding = ExpsOverviewBinding.inflate(layoutInflater)
val profile = args.profile

val yaAdapter: GroupieAdapter = GroupieAdapter()
val recyclerView: RecyclerView = binding.listExps
recyclerView.adapter = yaAdapter

for(exp in profile.exps){
val listener = View.OnClickListener {
val action = ExpsOverviewFragmentDirections.openExpEdit(exp)
findNavController().navigate(action)
}

yaAdapter.add(ExpListItem(profile, listener))
}

return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.myapplication.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.navArgs
import com.example.myapplication.databinding.JobEditBinding

class JobEditFragment:Fragment() {
lateinit var binding: JobEditBinding
val args: JobsOverviewFragmentArgs by navArgs()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = JobEditBinding.inflate(layoutInflater)

with(binding){

}

return binding.root
}
}
Loading

0 comments on commit a76fa94

Please sign in to comment.