Skip to content

Commit

Permalink
refactor(health-sdk): Fix for custom localization
Browse files Browse the repository at this point in the history
  • Loading branch information
llevente committed Oct 15, 2024
1 parent 6e80470 commit bebb0f0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class ConfigurationFragment: Fragment() {
}

val languages = arrayOf(GiniLocalization.GERMAN, GiniLocalization.ENGLISH)
context?.let {
context?.let { it ->
val languageAdapter = ArrayAdapter(it, android.R.layout.simple_spinner_dropdown_item, languages)
binding.languageSpinner.apply {
adapter = languageAdapter
onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
languageAdapter.getItem(p2)?.let {
viewModel.setGiniHealthLanguage(it, context)
languageAdapter.getItem(p2)?.let { language ->
viewModel.setGiniHealthLanguage(language, context)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ReviewFragment private constructor(

override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater {
val inflater = super.onGetLayoutInflater(savedInstanceState)
return this.getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, viewModel.paymentComponent.giniPaymentLanguage)
return this.getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, viewModel.paymentComponent.getGiniPaymentLanguage(requireContext()))
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand Down Expand Up @@ -257,7 +257,7 @@ class ReviewFragment private constructor(
}

private fun GhsFragmentReviewBinding.showSnackbar(text: String, onRetry: () -> Unit) {
val context = requireContext().wrappedWithGiniPaymentThemeAndLocale(viewModel.paymentComponent.giniPaymentLanguage)
val context = requireContext().wrappedWithGiniPaymentThemeAndLocale(viewModel.paymentComponent.getGiniPaymentLanguage(requireContext()))
errorSnackbar?.dismiss()
errorSnackbar = Snackbar.make(context, root, text, Snackbar.LENGTH_INDEFINITE).apply {
if (context.getFontScale() < 1.5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.imageview.ShapeableImageView
import kotlinx.coroutines.launch
import net.gini.android.internal.payment.GiniInternalPaymentModule
import net.gini.android.internal.payment.R
import net.gini.android.internal.payment.databinding.GpsBottomSheetBankSelectionBinding
import net.gini.android.internal.payment.databinding.GpsItemPaymentProviderAppBinding
Expand Down Expand Up @@ -52,7 +53,7 @@ class BankSelectionBottomSheet private constructor(private val paymentComponent:

override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater {
val inflater = super.onGetLayoutInflater(savedInstanceState)
return getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, viewModel.paymentComponent?.giniPaymentLanguage)
return getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, GiniInternalPaymentModule.getSDKLanguage(requireContext())?.languageLocale())
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
Expand All @@ -61,7 +62,7 @@ class BankSelectionBottomSheet private constructor(private val paymentComponent:
binding.gpsPaymentProviderAppsList.layoutManager = LinearLayoutManager(requireContext())
binding.gpsPaymentProviderAppsList.adapter =
PaymentProviderAppsAdapter(emptyList(),
viewModel.paymentComponent?.giniPaymentLanguage,
viewModel.paymentComponent?.getGiniPaymentLanguage(requireContext()),
object : PaymentProviderAppsAdapter.OnItemClickListener {
override fun onItemClick(paymentProviderApp: PaymentProviderApp) {
LOG.debug("Selected payment provider app: {}", paymentProviderApp.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.launch
import net.gini.android.internal.payment.GiniInternalPaymentModule
import net.gini.android.internal.payment.R
import net.gini.android.internal.payment.databinding.GpsFragmentPaymentMoreInformationBinding
import net.gini.android.internal.payment.databinding.GpsPaymentProviderIconHolderBinding
Expand Down Expand Up @@ -67,7 +68,7 @@ class MoreInformationFragment private constructor(

override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater {
val inflater = super.onGetLayoutInflater(savedInstanceState)
return this.getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, viewModel.getLocale())
return this.getLayoutInflaterWithGiniPaymentThemeAndLocale(inflater, GiniInternalPaymentModule.getSDKLanguage(requireContext())?.languageLocale())
}

override fun onCreateView(
Expand All @@ -82,7 +83,6 @@ class MoreInformationFragment private constructor(

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
resources.configuration.setLocale(viewModel.getLocale())
binding.gpsMoreInformationDetails.text = buildSpannedString {
append(getLocaleStringResource(R.string.gps_more_information_details))
append(" ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal class MoreInformationViewModel(val paymentComponent: PaymentComponent?)
}
}

fun getLocale(): Locale? = paymentComponent?.giniPaymentLanguage
fun getLocale(): Locale? = paymentComponent?.getGiniPaymentLanguage()

private fun processError(throwable: Throwable) {
LOG.error("Error loading payment provider apps", throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.gini.android.internal.payment.GiniInternalPaymentModule
import net.gini.android.internal.payment.paymentProvider.PaymentProviderApp
import net.gini.android.internal.payment.paymentProvider.getPaymentProviderApps
import org.slf4j.LoggerFactory
import java.util.Locale

/**
* The [PaymentComponent] manages the data and state used by every [PaymentComponentView], the [MoreInformationFragment],
Expand Down Expand Up @@ -49,7 +50,10 @@ class PaymentComponent(@get:VisibleForTesting internal val context: Context, val
@VisibleForTesting
internal val paymentComponentPreferences = PaymentComponentPreferences(context)

val giniPaymentLanguage = GiniInternalPaymentModule.getSDKLanguage(context)?.languageLocale()
fun getGiniPaymentLanguage(context: Context? = null) =
context?.let {
GiniInternalPaymentModule.getSDKLanguage(it)?.languageLocale()
} ?: GiniInternalPaymentModule.getSDKLanguage(this.context)?.languageLocale()

/**
* A listener for the payment component. It exposes the user interactions with all of the [PaymentComponentView]s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import net.gini.android.internal.payment.utils.extensions.getLayoutInflaterWithG
import net.gini.android.internal.payment.utils.extensions.setBackgroundTint
import net.gini.android.internal.payment.utils.extensions.setIntervalClickListener
import net.gini.android.internal.payment.utils.extensions.wrappedWithGiniPaymentTheme
import net.gini.android.internal.payment.utils.extensions.wrappedWithGiniPaymentThemeAndLocale
import org.slf4j.LoggerFactory
import kotlin.coroutines.CoroutineContext

Expand Down Expand Up @@ -190,7 +191,7 @@ class PaymentComponentView(context: Context, attrs: AttributeSet?) : ConstraintL

private fun restoreBankPickerDefaultState() {
LOG.debug("Restoring bank picker default state")
context?.wrappedWithGiniPaymentTheme()?.let { context ->
context?.wrappedWithGiniPaymentThemeAndLocale(GiniInternalPaymentModule.getSDKLanguage(context)?.languageLocale())?.let { context ->
payInvoiceButton.visibility = View.GONE
paymentProviderAppIconHolder.root.visibility = View.GONE
selectBankButton.text = context.getString(R.string.gps_select_bank)
Expand All @@ -205,7 +206,7 @@ class PaymentComponentView(context: Context, attrs: AttributeSet?) : ConstraintL

private fun customizeBankPicker(paymentProviderApp: PaymentProviderApp) {
LOG.debug("Customizing bank picker for payment provider app: {}", paymentProviderApp.name)
context?.wrappedWithGiniPaymentTheme()?.let { context ->
context?.wrappedWithGiniPaymentThemeAndLocale(GiniInternalPaymentModule.getSDKLanguage(context)?.languageLocale())?.let { context ->
selectBankButton.apply {
text = if (paymentComponent?.bankPickerRows == BankPickerRows.SINGLE) "" else paymentProviderApp.name
setCompoundDrawablesWithIntrinsicBounds(
Expand Down Expand Up @@ -255,7 +256,7 @@ class PaymentComponentView(context: Context, attrs: AttributeSet?) : ConstraintL

private fun restorePayInvoiceButtonDefaultState() {
LOG.debug("Restoring pay invoice button default state")
context?.wrappedWithGiniPaymentTheme()?.let { context ->
context?.wrappedWithGiniPaymentThemeAndLocale(GiniInternalPaymentModule.getSDKLanguage(context)?.languageLocale())?.let { context ->
payInvoiceButton.apply {
setBackgroundTint(
ContextCompat.getColor(
Expand Down

0 comments on commit bebb0f0

Please sign in to comment.