From 26365170c418390682a093a6153da2441ce5633a Mon Sep 17 00:00:00 2001 From: Linfye Date: Mon, 11 Nov 2024 21:39:11 +0800 Subject: [PATCH 1/5] Top left corner triangle for Arabic --- .../java/be/scri/fragments/MainFragment.kt | 23 +++++++++++++++++++ app/src/main/res/layout/fragment_main.xml | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index 997086be..76b75466 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -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,29 @@ 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 + 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" + } + private fun applyUserDarkModePreference() { val sharedPref = requireActivity().getSharedPreferences("app_preferences", Context.MODE_PRIVATE) val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 485179b2..13f2cba8 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -109,12 +109,14 @@ + android:src="@drawable/corner_polygon"/> Date: Mon, 11 Nov 2024 21:46:15 +0800 Subject: [PATCH 2/5] Fix lint issues --- app/src/main/java/be/scri/fragments/MainFragment.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index 76b75466..1db2fad3 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -51,8 +51,13 @@ class MainFragment : ScribeFragment("Main") { 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 + 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 From b9c7b477fcbe83b6ded34ad6a97b852149d2ddaa Mon Sep 17 00:00:00 2001 From: Linfye Date: Wed, 13 Nov 2024 19:13:44 +0800 Subject: [PATCH 3/5] Split method and update layout --- .../java/be/scri/fragments/MainFragment.kt | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index 1db2fad3..619d9629 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -6,11 +6,9 @@ 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 @@ -42,15 +40,11 @@ class MainFragment : ScribeFragment("Main") { } (requireActivity() as MainActivity).setActionBarButtonVisibility(false) callback.isEnabled = true - isArabicLanguage() + moveCorner() 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 + private fun isRTLLanguage(): Boolean { val currentLocale = requireActivity() .resources.configuration.locales @@ -58,16 +52,14 @@ class MainFragment : ScribeFragment("Main") { val languageCode = currentLocale .language - if (languageCode == "ar") { - paramsTriangleLayout.gravity = Gravity.TOP or Gravity.START - paramsCogLayout.gravity = Gravity.TOP or Gravity.START + return languageCode == "de" || languageCode == "fa" || languageCode == "he" + } + + private fun moveCorner() { + val cornerTriangleImageView: ImageView = binding.cornerTriangle + if (isRTLLanguage()) { cornerTriangleImageView.scaleX = -1f - cornerCogImageView.scaleX = -1f - Log.d("Debug", "Arabic") - } else { - Log.d("Debug", "Not Arabic") } - return languageCode == "ar" } private fun applyUserDarkModePreference() { From 18188c28b953b8d966fe8bcece952fdf2aae5ec4 Mon Sep 17 00:00:00 2001 From: Linfye Date: Thu, 14 Nov 2024 11:38:39 +0800 Subject: [PATCH 4/5] Update the condition method --- .../java/be/scri/fragments/MainFragment.kt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index 619d9629..f0e9d5e3 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.content.res.Configuration import android.os.Bundle import android.provider.Settings +import android.util.LayoutDirection import android.util.Log import android.view.LayoutInflater import android.view.View @@ -12,9 +13,11 @@ import android.view.ViewGroup import android.widget.ImageView import androidx.activity.addCallback import androidx.appcompat.app.AppCompatDelegate +import androidx.core.text.layoutDirection import be.scri.R import be.scri.activities.MainActivity import be.scri.databinding.FragmentMainBinding +import java.util.Locale class MainFragment : ScribeFragment("Main") { private var _binding: FragmentMainBinding? = null @@ -43,21 +46,10 @@ class MainFragment : ScribeFragment("Main") { moveCorner() return binding.root } - - private fun isRTLLanguage(): Boolean { - val currentLocale = - requireActivity() - .resources.configuration.locales - .get(0) - val languageCode = - currentLocale - .language - return languageCode == "de" || languageCode == "fa" || languageCode == "he" - } - + private fun moveCorner() { val cornerTriangleImageView: ImageView = binding.cornerTriangle - if (isRTLLanguage()) { + if (Locale.getDefault().layoutDirection == LayoutDirection.RTL) { cornerTriangleImageView.scaleX = -1f } } From ef6d66c85f82e25eab2caa117c592ee14c54e89c Mon Sep 17 00:00:00 2001 From: Linfye Date: Thu, 14 Nov 2024 11:45:14 +0800 Subject: [PATCH 5/5] Fix detekt issues --- app/src/main/java/be/scri/fragments/MainFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/fragments/MainFragment.kt b/app/src/main/java/be/scri/fragments/MainFragment.kt index f0e9d5e3..004b4715 100644 --- a/app/src/main/java/be/scri/fragments/MainFragment.kt +++ b/app/src/main/java/be/scri/fragments/MainFragment.kt @@ -46,7 +46,7 @@ class MainFragment : ScribeFragment("Main") { moveCorner() return binding.root } - + private fun moveCorner() { val cornerTriangleImageView: ImageView = binding.cornerTriangle if (Locale.getDefault().layoutDirection == LayoutDirection.RTL) {