diff --git a/android/src/main/java/com/wbrawner/budget/ui/MainActivity.kt b/android/src/main/java/com/wbrawner/budget/ui/MainActivity.kt index d5fd0b0..95a05bf 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/MainActivity.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/MainActivity.kt @@ -23,7 +23,7 @@ class MainActivity : AppCompatActivity() { getString(R.string.title_overview) -> false getString(R.string.title_transactions) -> false getString(R.string.title_profile) -> false - getString(R.string.title_budgets) -> false + getString(R.string.title_categories) -> false else -> true } supportActionBar?.setDisplayHomeAsUpEnabled(showHomeAsUp) diff --git a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsFragment.kt b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsFragment.kt index ee76262..e69bbc4 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsFragment.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsFragment.kt @@ -2,6 +2,7 @@ package com.wbrawner.budget.ui.categories import android.content.Context +import android.os.Build import android.os.Bundle import android.view.* import android.widget.Toast @@ -14,6 +15,7 @@ import com.wbrawner.budget.AsyncState import com.wbrawner.budget.R import com.wbrawner.budget.ui.EXTRA_BUDGET_ID import com.wbrawner.budget.ui.EXTRA_CATEGORY_ID +import com.wbrawner.budget.ui.toAmountSpannable import com.wbrawner.budget.ui.transactions.TransactionListFragment import kotlinx.android.synthetic.main.fragment_category_details.* @@ -48,7 +50,29 @@ class CategoryDetailsFragment : Fragment() { progressBar.visibility = View.GONE val category = state.data.category activity?.title = category.title - categoryDescription.text = category.description + val tintColor = if (category.expense) R.color.colorTextRed else R.color.colorTextGreen + val colorStateList = with(view.context) { + android.content.res.ColorStateList.valueOf(getColor(tintColor)) + } + categoryProgress.progressTintList = colorStateList + categoryProgress.max = category.amount.toInt() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + categoryProgress.setProgress( + state.data.balance.toInt(), + true + ) + } else { + categoryProgress.progress = state.data.balance.toInt() + } + total.text = category.amount.toAmountSpannable() + balance.text = state.data.balance.toAmountSpannable() + remaining.text = state.data.remaining.toAmountSpannable() + if (category.description.isNullOrBlank()) { + categoryDescription.visibility = View.GONE + } else { + categoryDescription.visibility = View.VISIBLE + categoryDescription.text = category.description + } childFragmentManager.fragments.firstOrNull()?.let { if (it !is TransactionListFragment) return@let it.reloadItems() diff --git a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsViewModel.kt b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsViewModel.kt index 508e192..a9a826c 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsViewModel.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryDetailsViewModel.kt @@ -23,10 +23,11 @@ class CategoryDetailsViewModel : ViewModel(), AsyncViewModel { launch { val category = categoryRepo.findById(id) val multiplier = if (category.expense) -1 else 1 - val balance = categoryRepo.getBalance(category.id!!).toInt() * multiplier + val balance = categoryRepo.getBalance(category.id!!) * multiplier CategoryDetails( category, - balance + balance, + category.amount - balance ) } } @@ -34,5 +35,6 @@ class CategoryDetailsViewModel : ViewModel(), AsyncViewModel { data class CategoryDetails( val category: Category, - val balance: Int + val balance: Long, + val remaining: Long ) \ No newline at end of file diff --git a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListFragment.kt b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListFragment.kt index 84d8f66..b116cc9 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListFragment.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListFragment.kt @@ -12,7 +12,6 @@ import androidx.navigation.fragment.findNavController import com.wbrawner.budget.AllowanceApplication import com.wbrawner.budget.R import com.wbrawner.budget.common.category.Category -import com.wbrawner.budget.ui.EXTRA_BUDGET_ID import com.wbrawner.budget.ui.EXTRA_CATEGORY_ID import com.wbrawner.budget.ui.base.BindableAdapter import com.wbrawner.budget.ui.base.BindableData @@ -23,7 +22,7 @@ class CategoryListFragment : ListWithAddButtonFragment = BindableData(data, CATEGORY_VIEW) diff --git a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListViewModel.kt b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListViewModel.kt index a9300cd..97018ab 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListViewModel.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/categories/CategoryListViewModel.kt @@ -19,7 +19,8 @@ class CategoryListViewModel : ViewModel(), AsyncViewModel> { @Inject lateinit var categoryRepo: CategoryRepository - fun getCategories(budgetId: Long? = null) { + fun getCategories() { + val budgetId = budgetRepo.currentBudget?.id if (budgetId == null) { state.postValue(AsyncState.Error("Invalid budget ID")) return diff --git a/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt b/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt index bfb3b39..7d1d958 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt @@ -32,7 +32,7 @@ class TransactionListFragment : ListWithAddButtonFragment TransactionViewHolder(v, findNavController()) }) override fun reloadItems() { - viewModel.getTransactions(arguments?.getLong(EXTRA_CATEGORY_ID)) + viewModel.getTransactions(categoryId = arguments?.getLong(EXTRA_CATEGORY_ID)) } override fun bindData(data: Transaction): BindableData = BindableData(data, TRANSACTION_VIEW) diff --git a/android/src/main/res/layout/fragment_category_details.xml b/android/src/main/res/layout/fragment_category_details.xml index a9d48e4..b70e886 100644 --- a/android/src/main/res/layout/fragment_category_details.xml +++ b/android/src/main/res/layout/fragment_category_details.xml @@ -1,52 +1,106 @@ - + android:layout_height="match_parent"> - + android:padding="16dp" + app:layout_constraintTop_toTopOf="parent" /> - + - + - + - - - + + + + + + + + + + + - \ No newline at end of file + diff --git a/android/src/main/res/menu/main_navigation.xml b/android/src/main/res/menu/main_navigation.xml index 59b9bef..c8f8cc5 100644 --- a/android/src/main/res/menu/main_navigation.xml +++ b/android/src/main/res/menu/main_navigation.xml @@ -9,9 +9,9 @@ android:icon="@drawable/ic_attach_money_black_24dp" android:title="@string/title_transactions" /> + android:title="@string/title_categories" /> Year Archived Overview + Total + Balance + Remaining