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

Fix #5039 Terms of Service and Privacy Policy content should still be left-aligned, even if the app is in an RTL language. #5181

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.OppiaLocaleContext
import org.oppia.android.app.model.PoliciesFragmentArguments
import org.oppia.android.app.model.PolicyPage
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.PoliciesFragmentBinding
import org.oppia.android.util.locale.AndroidLocaleFactory
import org.oppia.android.util.locale.DisplayLocaleImpl
import org.oppia.android.util.locale.OppiaBidiFormatter
import org.oppia.android.util.locale.OppiaLocale
import org.oppia.android.util.parser.html.HtmlParser
import org.oppia.android.util.parser.html.PolicyType
import javax.inject.Inject
Expand All @@ -22,6 +28,16 @@ class PoliciesFragmentPresenter @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler
) : HtmlParser.PolicyOppiaTagActionListener {

/** Injected variables to make an object of [DisplayLocaleImpl] class. */
@Inject
lateinit var machineLocale: OppiaLocale.MachineLocale

@Inject
lateinit var androidLocaleFactory: AndroidLocaleFactory

@Inject
lateinit var formatterFactory: OppiaBidiFormatter.Factory

/** Handles onCreate() method of the [PoliciesFragment]. */
fun handleCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -55,9 +71,32 @@ class PoliciesFragmentPresenter @Inject constructor(
policyWebLink = resourceHandler.getStringInLocale(R.string.terms_of_service_web_link)
}

/** Made an object of [DisplayLocaleImpl] and manipulate the getLayoutDirection() method. */
val ltrLocale = object : DisplayLocaleImpl(
OppiaLocaleContext.getDefaultInstance(),
machineLocale,
androidLocaleFactory,
formatterFactory
) {
override fun getLayoutDirection(): Int {
return ViewCompat.LAYOUT_DIRECTION_LTR
}
}

// Ensure that the Terms of Service and Privacy Policy are displayed with a left-aligned layout,
// even when the app is set to an RTL language.
if (resourceHandler.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL) {
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
binding.policyDescriptionTextView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END
}

binding.policyDescriptionTextView.text = htmlParserFactory.create(
policyOppiaTagActionListener = this,
displayLocale = resourceHandler.getDisplayLocale()
displayLocale = if (resourceHandler.getLayoutDirection() == ViewCompat.LAYOUT_DIRECTION_RTL) {
ltrLocale
} else {
resourceHandler.getDisplayLocale()
}

).parseOppiaHtml(
policyDescription,
binding.policyDescriptionTextView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.Objects

// TODO(#3766): Restrict to be 'internal'.
/** Implementation of [OppiaLocale.DisplayLocale]. */
class DisplayLocaleImpl(
open class DisplayLocaleImpl(
localeContext: OppiaLocaleContext,
private val machineLocale: MachineLocale,
private val androidLocaleFactory: AndroidLocaleFactory,
Expand Down
Loading