diff --git a/app/build.gradle b/app/build.gradle index d2966da..1e16a19 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,6 +27,11 @@ android { viewBinding { enabled = true } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyFragment.kt b/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyFragment.kt index 18cb102..b637c51 100644 --- a/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyFragment.kt +++ b/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyFragment.kt @@ -21,6 +21,8 @@ import android.os.Bundle import android.view.Gravity import android.view.LayoutInflater import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.TextView @@ -57,6 +59,10 @@ class CurrencyFragment : Fragment() { initViewModel() initUI() populateSpinnerAdapter() + + currencyViewModel.isProgressVisible.observe(viewLifecycleOwner, Observer { visible -> + binding.progressBar.visibility = if (visible) VISIBLE else GONE + }) } private fun initializeDagger() { @@ -93,7 +99,10 @@ class CurrencyFragment : Fragment() { } private fun initConvertButton() { - binding.convertButton.setOnClickListener { convert() } + binding.convertButton.setOnClickListener { + convert() + currencyViewModel.progressVisible() + } } // You can move all this logic to the view model @@ -112,6 +121,7 @@ class CurrencyFragment : Fragment() { }) } else { + currencyViewModel.progressInvisible() Toast.makeText(activity, "Could not convert.", Toast.LENGTH_SHORT).show() } } @@ -131,7 +141,7 @@ class CurrencyFragment : Fragment() { val result = quantity.toString() + " " + fromCurrencyKey + " = " + exchangeResult.format(4) + " " + toCurrencyKey showResult(result) - + currencyViewModel.progressInvisible() } private fun showResult(result: String) { diff --git a/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyViewModel.kt b/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyViewModel.kt index 9a77a48..3f4b23d 100644 --- a/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyViewModel.kt +++ b/app/src/main/kotlin/erikjhordanrey/android_kotlin_devises/view/CurrencyViewModel.kt @@ -40,6 +40,16 @@ class CurrencyViewModel(private val currencyRepository: CurrencyRepository) : Vi private var liveCurrencyData: LiveData>? = null private var liveAvailableExchange: LiveData? = null + val isProgressVisible = MutableLiveData().apply { value = false } + + fun progressVisible() { + isProgressVisible.value = true + } + + fun progressInvisible() { + isProgressVisible.value = false + } + fun getAvailableExchange(currencies: String): LiveData? { liveAvailableExchange = null liveAvailableExchange = MutableLiveData() diff --git a/app/src/main/res/layout/currency_fragment.xml b/app/src/main/res/layout/currency_fragment.xml index 070bde4..5dad166 100644 --- a/app/src/main/res/layout/currency_fragment.xml +++ b/app/src/main/res/layout/currency_fragment.xml @@ -50,6 +50,11 @@ android:textSize="18sp" android:textStyle="bold" /> +