Improve some minor UI glitches

This commit is contained in:
William Brawner 2020-08-07 17:13:57 -07:00
parent a1da7582b4
commit 511cb5a376
7 changed files with 39 additions and 9 deletions

View file

@ -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"

View file

@ -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
}

View file

@ -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 -> {

View file

@ -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)
}

View file

@ -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

View file

@ -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<Long>>(AsyncState.Loading)
val state = MutableLiveData<AsyncState<OverviewState>>(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
)

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -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" />
<TextView
android:id="@+id/balance"
@ -68,9 +72,12 @@
android:layout_height="wrap_content"
android:padding="8dp"
android:textAlignment="center"
android:textColor="@color/colorTextPrimary"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="@+id/remaining"
app:layout_constraintStart_toEndOf="@+id/total"
app:layout_constraintTop_toBottomOf="@+id/balanceLabel" />
app:layout_constraintTop_toBottomOf="@+id/balanceLabel"
tools:text="$40.00" />
<TextView
android:id="@+id/remaining"
@ -78,16 +85,20 @@
android:layout_height="wrap_content"
android:padding="8dp"
android:textAlignment="center"
android:textColor="@color/colorTextPrimary"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/balance"
app:layout_constraintTop_toBottomOf="@+id/remainingLabel" />
app:layout_constraintTop_toBottomOf="@+id/remainingLabel"
tools:text="$20.00" />
<ProgressBar
android:id="@+id/categoryProgress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/total" />
app:layout_constraintTop_toBottomOf="@+id/total"
tools:progress="40" />
<FrameLayout
android:id="@+id/transactionsFragmentContainer"