diff --git a/android/src/main/java/com/wbrawner/budget/ui/Constants.kt b/android/src/main/java/com/wbrawner/budget/ui/Constants.kt index 6cb7089..4731dc1 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/Constants.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/Constants.kt @@ -2,4 +2,5 @@ package com.wbrawner.budget.ui const val EXTRA_BUDGET_ID = "budgetId" const val EXTRA_CATEGORY_ID = "categoryId" +const val EXTRA_CATEGORY_NAME = "categoryName" const val EXTRA_TRANSACTION_ID = "transactionId" \ No newline at end of file diff --git a/android/src/main/java/com/wbrawner/budget/ui/ViewUtils.kt b/android/src/main/java/com/wbrawner/budget/ui/ViewUtils.kt index dc7c0e7..764c539 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/ViewUtils.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/ViewUtils.kt @@ -10,6 +10,8 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.google.android.material.floatingactionbutton.FloatingActionButton import com.wbrawner.budget.R +import java.text.NumberFormat +import java.util.* fun RecyclerView.hideFabOnScroll(fab: FloatingActionButton) { addOnScrollListener(object : RecyclerView.OnScrollListener() { @@ -38,8 +40,10 @@ fun EditText.ensureNotEmpty(): Boolean { } fun Long.toAmountSpannable(context: Context? = null): Spannable { - val spannableStringBuilder = SpannableStringBuilder() - spannableStringBuilder.append(String.format("${'$'}%.02f", this / 100.0f)) + val currency = NumberFormat.getCurrencyInstance().apply { + currency = Currency.getInstance(Locale.getDefault()) + }.format(this / 100.0f) + val spannableStringBuilder = SpannableStringBuilder(currency) if (context == null) { return spannableStringBuilder } 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 e69bbc4..77b74e3 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 @@ -15,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.EXTRA_CATEGORY_NAME import com.wbrawner.budget.ui.toAmountSpannable import com.wbrawner.budget.ui.transactions.TransactionListFragment import kotlinx.android.synthetic.main.fragment_category_details.* @@ -39,6 +40,7 @@ class CategoryDetailsFragment : Fragment() { inflater.inflate(R.layout.fragment_category_details, container, false) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + activity?.title = arguments?.getString(EXTRA_CATEGORY_NAME) viewModel.state.observe(viewLifecycleOwner, Observer { state -> when (state) { is AsyncState.Loading -> { 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 b116cc9..a95b284 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 @@ -13,6 +13,7 @@ import com.wbrawner.budget.AllowanceApplication import com.wbrawner.budget.R import com.wbrawner.budget.common.category.Category import com.wbrawner.budget.ui.EXTRA_CATEGORY_ID +import com.wbrawner.budget.ui.EXTRA_CATEGORY_NAME import com.wbrawner.budget.ui.base.BindableAdapter import com.wbrawner.budget.ui.base.BindableData import com.wbrawner.budget.ui.base.ListWithAddButtonFragment @@ -82,6 +83,7 @@ class CategoryViewHolder( itemView.setOnClickListener { val bundle = Bundle().apply { putLong(EXTRA_CATEGORY_ID, category.id ?: -1) + putString(EXTRA_CATEGORY_NAME, category.title) } navController.navigate(R.id.categoryFragment, bundle) } diff --git a/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewFragment.kt b/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewFragment.kt index e7d7e4e..ea359cd 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewFragment.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewFragment.kt @@ -41,7 +41,8 @@ class OverviewFragment : Fragment() { overviewContent.visibility = View.VISIBLE noData.visibility = View.GONE progressBar.visibility = View.GONE - balance.text = state.data.toAmountSpannable(view.context) + activity?.title = state.data.budget.name + balance.text = state.data.balance.toAmountSpannable(view.context) } is AsyncState.Error -> { overviewContent.visibility = View.GONE diff --git a/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewViewModel.kt b/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewViewModel.kt index 184254d..182eae6 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewViewModel.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/overview/OverviewViewModel.kt @@ -5,13 +5,14 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wbrawner.budget.AsyncState +import com.wbrawner.budget.common.budget.Budget import com.wbrawner.budget.common.budget.BudgetRepository import com.wbrawner.budget.common.transaction.TransactionRepository import kotlinx.coroutines.launch import javax.inject.Inject class OverviewViewModel : ViewModel() { - val state = MutableLiveData>(AsyncState.Loading) + val state = MutableLiveData>(AsyncState.Loading) @Inject lateinit var budgetRepo: BudgetRepository @@ -38,10 +39,18 @@ class OverviewViewModel : ViewModel() { balance += it.amount } } - state.postValue(AsyncState.Success(balance)) + state.postValue(AsyncState.Success(OverviewState( + budget, + balance + ))) } catch (e: Exception) { state.postValue(AsyncState.Error(e)) } } } } + +data class OverviewState( + val budget: Budget, + val balance: Long +) \ No newline at end of file diff --git a/android/src/main/res/layout/fragment_category_details.xml b/android/src/main/res/layout/fragment_category_details.xml index b70e886..5350c9a 100644 --- a/android/src/main/res/layout/fragment_category_details.xml +++ b/android/src/main/res/layout/fragment_category_details.xml @@ -1,6 +1,7 @@ @@ -58,9 +59,12 @@ android:layout_height="wrap_content" android:padding="8dp" android:textAlignment="center" + android:textColor="@color/colorTextPrimary" + android:textSize="20sp" app:layout_constraintEnd_toStartOf="@+id/balance" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/totalLabel" /> + app:layout_constraintTop_toBottomOf="@+id/totalLabel" + tools:text="$60.00" /> + app:layout_constraintTop_toBottomOf="@+id/balanceLabel" + tools:text="$40.00" /> + app:layout_constraintTop_toBottomOf="@+id/remainingLabel" + tools:text="$20.00" /> + app:layout_constraintTop_toBottomOf="@+id/total" + tools:progress="40" />