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
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions app/src/main/java/be/scri/fragments/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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.

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
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.

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 :)


private fun applyUserDarkModePreference() {
val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/corner_triangle"
android:layout_width="75dp"
android:layout_height="76dp"
android:layout_gravity="top|end"
android:alpha="0.9"
android:src="@drawable/corner_polygon" />
android:src="@drawable/corner_polygon"/>
<ImageView
android:id="@+id/corner_cog"
android:layout_width="26dp"
android:layout_height="25dp"
android:layout_gravity="top|end"
Expand Down
Loading