Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated gradle dependencies, added progress bar #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ android {
viewBinding {
enabled = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -112,6 +121,7 @@ class CurrencyFragment : Fragment() {
})

} else {
currencyViewModel.progressInvisible()
Toast.makeText(activity, "Could not convert.", Toast.LENGTH_SHORT).show()
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class CurrencyViewModel(private val currencyRepository: CurrencyRepository) : Vi
private var liveCurrencyData: LiveData<List<Currency>>? = null
private var liveAvailableExchange: LiveData<AvailableExchange>? = null

val isProgressVisible = MutableLiveData<Boolean>().apply { value = false }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should expose as livedata in order to avoid altering the state in the fragment


fun progressVisible() {
isProgressVisible.value = true
}

fun progressInvisible() {
isProgressVisible.value = false
}

fun getAvailableExchange(currencies: String): LiveData<AvailableExchange>? {
liveAvailableExchange = null
liveAvailableExchange = MutableLiveData()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/currency_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
android:textSize="18sp"
android:textStyle="bold" />

<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

<Spinner
android:id="@+id/from_currency_spinner"
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ buildscript {
'targetSdk' : 28,
'androidGradle' : '3.6.3',
'androidx' : '1.1.0',
'androidxAppcompat': '1.0.2',
'androidxAppcompat': '1.1.0',
'lifecycle' : '2.2.0',
'persistence' : '2.2.5',
'material' : '1.1.0',
'rxAndroid' : '2.1.1',
'rxJava' : '2.2.8',
'dagger' : '2.25.4',
'retrofit' : '2.5.0',
'okhttp' : '3.12.0',
'kotlin' : '1.3.71'
'rxJava' : '2.2.18',
'dagger' : '2.26',
'retrofit' : '2.8.1',
'okhttp' : '4.5.0',
'kotlin' : '1.3.72'
]

repositories {
Expand Down