-
Notifications
You must be signed in to change notification settings - Fork 50
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ import android.content.res.Configuration | |
import android.os.Bundle | ||
import android.provider.Settings | ||
import android.util.Log | ||
import android.view.Gravity | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import android.widget.ImageView | ||
import androidx.activity.addCallback | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import be.scri.R | ||
|
@@ -39,9 +42,34 @@ class MainFragment : ScribeFragment("Main") { | |
} | ||
(requireActivity() as MainActivity).setActionBarButtonVisibility(false) | ||
callback.isEnabled = true | ||
isArabicLanguage() | ||
return binding.root | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
private fun applyUserDarkModePreference() { | ||
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE) | ||
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.