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

Cleanup/Minor changes for code readability #11

Open
wants to merge 3 commits into
base: kotlin
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,43 @@ constructor(@AppContext context: Context, countryRepo: CountryRepo, private val
private fun calculateLanguages(): CharSequence {
val languageList = ArrayList<String>(country.languages!!.size)

for (language in country.languages!!) {
languageList.add(Locale(language).getDisplayLanguage(BaseCountryViewModel.Companion.DISPLAY_LOCALE))
country.languages!!.forEach {
language ->

languageList.add(Locale(language).getDisplayLanguage(BaseCountryViewModel.DISPLAY_LOCALE))
}

Collections.sort(languageList)
languageList.sort()

return SpannableStringBuilder(ctx.getText(R.string.country_languages)).append(TextUtils.join(", ", languageList))
}

private fun calculateNameTranslations(): CharSequence {
val nameList = ArrayList<String>(country.translations!!.size)

for (entry in country.translations!!) {
nameList.add(entry.value + " <i>(" + Locale(entry.key).getDisplayLanguage(BaseCountryViewModel.Companion.DISPLAY_LOCALE) + ")</i>")
country.translations!!.forEach { entry ->
nameList.add(entry.value + " <i>(" + Locale(entry.key).getDisplayLanguage(BaseCountryViewModel.DISPLAY_LOCALE) + ")</i>")
}

Collections.sort(nameList)
nameList.sort()

return SpannableStringBuilder(ctx.getText(R.string.country_name_translations)).append(Html.fromHtml(TextUtils.join(", ", nameList)))
}

private fun calculateCurrencies(): CharSequence {
val currenciesList = ArrayList<String>(country.currencies!!.size)

for (currencyString in country.currencies!!) {
country.currencies!!.forEach {
currencyString ->

if (Build.VERSION.SDK_INT >= 19) {
try {
val currency = Currency.getInstance(currencyString)
var currencySymbol = currency.symbol
if (currencyString != currencySymbol) {
currencySymbol = currencyString + ", " + currencySymbol
currencySymbol = "$currencyString, $currencySymbol"
}
currenciesList.add(currency.getDisplayName(BaseCountryViewModel.Companion.DISPLAY_LOCALE) + " (" + currencySymbol + ")")
currenciesList.add("""${currency.getDisplayName(BaseCountryViewModel.DISPLAY_LOCALE)} ($currencySymbol)""")
} catch (ignore: IllegalArgumentException) {
currenciesList.add(currencyString)
}
Expand All @@ -139,7 +143,7 @@ constructor(@AppContext context: Context, countryRepo: CountryRepo, private val
}
}

Collections.sort(currenciesList)
currenciesList.sort()

return SpannableStringBuilder(ctx.getText(R.string.country_currencies)).append(TextUtils.join(", ", currenciesList))
}
Expand All @@ -163,7 +167,9 @@ constructor(@AppContext context: Context, countryRepo: CountryRepo, private val
val borderList = ArrayList<String?>(country.borders!!.size)
val alpha3List = ArrayList<String?>(country.borders!!.size)

for (borderAlpha3CodeString in country.borders!!) {

country.borders!!.forEach {
borderAlpha3CodeString ->
alpha3List.add(borderAlpha3CodeString)
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:id="@+id/country_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:text="@{vm.name}"
style="@style/TextAppearance.AppCompat.Headline"
tools:text="Country"/>
Expand All @@ -56,7 +56,7 @@
android:id="@+id/country_name_translations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:paddingTop="4dp"
android:text='@{vm.nameTranslations}'
style="@style/TextAppearance.AppCompat"
Expand All @@ -66,7 +66,7 @@
android:id="@+id/country_region"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:paddingTop="4dp"
android:text='@{vm.region}'
style="@style/TextAppearance.AppCompat"
Expand All @@ -76,7 +76,7 @@
android:id="@+id/country_capital"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:paddingTop="4dp"
android:visibility="@{vm.capitalVisible}"
android:text='@{vm.capital}'
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/card_country.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/card_outer_padding"
android:layout_marginStart="@dimen/card_outer_padding"
android:layout_marginTop="@dimen/card_outer_padding"
android:layout_marginRight="@dimen/card_outer_padding"
android:layout_marginEnd="@dimen/card_outer_padding"
android:layout_marginBottom='@{vm.cardBottomMargin}'
android:foreground="?attr/selectableItemBackground"
android:onClick="@{vm::onCardClick}"
Expand All @@ -24,17 +24,17 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="vertical">

<TextView
android:id="@+id/country_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:text="@{vm.name}"
style="@style/TextAppearance.AppCompat.Headline"
tools:text="Country"/>
Expand All @@ -43,7 +43,7 @@
android:id="@+id/country_region"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_marginEnd="40dp"
android:paddingTop="4dp"
android:text='@{vm.region}'
style="@style/TextAppearance.AppCompat"
Expand Down