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

Top left corner triangle for Arabic #241

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

Linfye
Copy link
Collaborator

@Linfye Linfye commented Nov 11, 2024

Contributor checklist


Description

When the language is set to Arabic, the "installation corner" on the main page will move to the top-left corner. Since internationalization (i18n) has not yet introduced Arabic, you can use "de" to test the code. 😊
image
This is tested in German since Arabic is not introduced currently.
image

Related issue

Copy link

github-actions bot commented Nov 11, 2024

Thank you for the pull request!

The Scribe team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Android rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

  • The linting and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The CHANGELOG has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

@MahmoudMabrok
Copy link
Contributor

@Linfye thanks for PR, could you please add screenshot from app before and after the fix.

@andrewtavis andrewtavis self-requested a review November 12, 2024 23:17
@Linfye
Copy link
Collaborator Author

Linfye commented Nov 13, 2024

@Linfye thanks for PR, could you please add screenshot from app before and after the fix.

Done. :)

Comment on lines 49 to 71
private fun isArabicLanguage(): Boolean {
val cornerTriangleImageView: ImageView = binding.cornerTriangle
val cornerCogImageView: ImageView = binding.cornerCog
val paramsTriangleLayout = binding.cornerTriangle.layoutParams as FrameLayout.LayoutParams
val paramsCogLayout = binding.cornerCog.layoutParams as FrameLayout.LayoutParams
val currentLocale =
requireActivity()
.resources.configuration.locales
.get(0)
val languageCode =
currentLocale
.language
if (languageCode == "ar") {
paramsTriangleLayout.gravity = Gravity.TOP or Gravity.START
paramsCogLayout.gravity = Gravity.TOP or Gravity.START
cornerTriangleImageView.scaleX = -1f
cornerCogImageView.scaleX = -1f
Log.d("Debug", "Arabic")
} else {
Log.d("Debug", "Not Arabic")
}
return languageCode == "ar"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to make a single responsibility to this method, i.e. making it do single task.

from it's name, 'isArabicLanguage' , which mean it check the language so it should not have logic related to change the UI configuration such as scale/gravity.

so I think we would split it into two method, one to check language and other to change the view data.

checking language would be in separate util function and would be unit tested.

Copy link
Member

Choose a reason for hiding this comment

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

isArabicLanguage should also be isRTLLanguage so that we can have it be general from the start :)

Comment on lines 49 to 50
private fun isArabicLanguage(): Boolean {
val cornerTriangleImageView: ImageView = binding.cornerTriangle
Copy link
Contributor

Choose a reason for hiding this comment

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

what about checking layout direction, so we would cover all RTL languages without need to explicitly check each language.

Copy link
Member

Choose a reason for hiding this comment

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

If this is possible, then yes, but we can also just save a local variable for RTL languages that we support as as of now the plan is just Arabic and eventually Hebrew.

currentLocale
.language
if (languageCode == "ar") {
paramsTriangleLayout.gravity = Gravity.TOP or Gravity.START
Copy link
Contributor

Choose a reason for hiding this comment

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

for gravity, I think we do not need to handle it, as it already handled in xml, it set to top|end so in RTL it will be automatically be on left of screen.

@Linfye
Copy link
Collaborator Author

Linfye commented Nov 13, 2024

@MahmoudMabrok Could you review it again? I think this is what you mentioned before. 😊

@Linfye Linfye requested a review from MahmoudMabrok November 13, 2024 11:33
@MahmoudMabrok
Copy link
Contributor

MahmoudMabrok commented Nov 13, 2024

for me all is fine, just for scalability , if we can use if (Locale.getDefault().layoutDirection == LayoutDirection.RTL) instead of hardcode the names of languages.

if not stable solution, so PR is fine for me.

@andrewtavis
Copy link
Member

This makes sense to me as well, as we actually have de in there now on accident, so let's go with RTL. Thanks for the suggestion, @MahmoudMabrok! @Linfye, do you want to make the change and then I can merge it in?

@Linfye
Copy link
Collaborator Author

Linfye commented Nov 14, 2024

This makes sense to me as well, as we actually have de in there now on accident, so let's go with RTL. Thanks for the suggestion, @MahmoudMabrok! @Linfye, do you want to make the change and then I can merge it in?

Is this OK now? 😊

cc @MahmoudMabrok

@MahmoudMabrok
Copy link
Contributor

This makes sense to me as well, as we actually have de in there now on accident, so let's go with RTL. Thanks for the suggestion, @MahmoudMabrok! @Linfye, do you want to make the change and then I can merge it in?

Is this OK now? 😊

cc @MahmoudMabrok

Thanks so much for your efforts. You did a great work.

For me, it is ready now.

Copy link
Member

@andrewtavis andrewtavis left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @Linfye and @MahmoudMabrok! Let's give this another check post localizations and bringing in the Arabic texts 🌐

@andrewtavis andrewtavis merged commit b7e59b5 into scribe-org:main Nov 14, 2024
3 checks passed
@Linfye Linfye deleted the RTL-installation-corner branch November 17, 2024 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants