|
|
|
|
@ -56,6 +56,7 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
initData() |
|
|
|
|
initUI() |
|
|
|
|
updateUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
@ -65,17 +66,17 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
activity?.setResult(RESULT_OK, data) |
|
|
|
|
activity?.finish() |
|
|
|
|
} else { |
|
|
|
|
BankrollReportManager.reportForBankroll(this.bankrollId) { |
|
|
|
|
updateUI(it) |
|
|
|
|
} |
|
|
|
|
updateUI() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateUI(bankrollReport: BankrollReport) { |
|
|
|
|
this.initRows(bankrollReport) |
|
|
|
|
this.updateMenuUI() |
|
|
|
|
this.bankrollAdapter.notifyDataSetChanged() |
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { |
|
|
|
|
menu?.clear() |
|
|
|
|
inflater?.inflate(R.menu.toolbar_comparison_chart, menu) // TODO R.menu.toolbar_comparison_chart? |
|
|
|
|
this.bankrollDetailsMenu = menu |
|
|
|
|
updateMenuUI() |
|
|
|
|
super.onCreateOptionsMenu(menu, inflater) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -87,10 +88,33 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
this.bankroll = getRealm().findById(id) ?: throw PAIllegalStateException("Bankroll not found, id=$id") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BankrollReportManager.reportForBankroll(this.bankrollId) { |
|
|
|
|
updateUI(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
this.updateMenuUI() |
|
|
|
|
|
|
|
|
|
bankrollAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = bankrollAdapter |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateUI() { |
|
|
|
|
this.updateMenuUI() |
|
|
|
|
BankrollReportManager.reportForBankroll(this.bankrollId) { bankrollReport -> |
|
|
|
|
this.initRows(bankrollReport) |
|
|
|
|
this.bankrollAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initRows(bankrollReport: BankrollReport) { |
|
|
|
|
@ -99,9 +123,10 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
|
|
|
|
|
rows.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.global)) |
|
|
|
|
|
|
|
|
|
val totalComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.total) |
|
|
|
|
val netComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.netResult) |
|
|
|
|
val netBankedComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.netBanked) |
|
|
|
|
val currency = this.bankroll.utilCurrency |
|
|
|
|
val totalComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.total, currency = currency) |
|
|
|
|
val netComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.netResult, currency = currency) |
|
|
|
|
val netBankedComputedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.netBanked, currency = currency) |
|
|
|
|
|
|
|
|
|
rows.add( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
@ -130,7 +155,7 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
bankrollReport.transactionBuckets.keys.forEach { key -> |
|
|
|
|
bankrollReport.transactionBuckets[key]?.let { transactionBucket -> |
|
|
|
|
val typeName = transactionBucket.name |
|
|
|
|
val computedStat = ComputedStat(Stat.NET_RESULT, transactionBucket.total) |
|
|
|
|
val computedStat = ComputedStat(Stat.NET_RESULT, transactionBucket.total, currency = currency) |
|
|
|
|
rows.add( |
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
RowViewType.TITLE_VALUE, |
|
|
|
|
@ -144,25 +169,6 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Init UI |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
this.updateMenuUI() |
|
|
|
|
|
|
|
|
|
bankrollAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = bankrollAdapter |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update menu UI |
|
|
|
|
*/ |
|
|
|
|
@ -175,7 +181,6 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
setToolbarTitle(this.bankroll.name) |
|
|
|
|
bankrollDetailsMenu?.findItem(R.id.settings)?.isVisible = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// StaticRowRepresentableDataSource |
|
|
|
|
@ -190,16 +195,8 @@ class BankrollDetailsFragment : RealmFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { |
|
|
|
|
menu?.clear() |
|
|
|
|
inflater?.inflate(R.menu.toolbar_comparison_chart, menu) |
|
|
|
|
this.bankrollDetailsMenu = menu |
|
|
|
|
updateMenuUI() |
|
|
|
|
super.onCreateOptionsMenu(menu, inflater) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem?): Boolean { |
|
|
|
|
when (item!!.itemId) { |
|
|
|
|
when (item?.itemId) { |
|
|
|
|
R.id.settings -> editBankroll() |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
|