From 5572384b51a83ecb874737553d142e2ded3dae05 Mon Sep 17 00:00:00 2001 From: faisalcodes Date: Sun, 17 Sep 2023 22:29:24 +0530 Subject: [PATCH] Added an option to toggle Arabic text --- .../android/activities/ActivityReader.java | 9 +- .../reference/ActivityReference.java | 2 +- .../frags/settings/FragSettingsMain.java | 119 +++++++++++------- .../android/utils/sharedPrefs/SPReader.java | 16 +++ .../utils/sharedPrefs/SPSubscription.java | 52 -------- .../android/utils/sharedPrefs/SPVerses.java | 18 ++- .../com/quranapp/android/utils/univ/Keys.kt | 7 ++ .../android/utils/verse/VerseUtils.java | 7 +- .../com/quranapp/android/views/VOTDView.java | 45 ++++--- .../android/views/reader/VerseView.java | 5 +- .../views/reader/dialogs/QuickReference.java | 3 +- .../lyt_reader_settings_item_switch.xml | 40 ++++++ app/src/main/res/values/strings.xml | 2 + 13 files changed, 193 insertions(+), 132 deletions(-) delete mode 100644 app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPSubscription.java create mode 100644 app/src/main/res/layout/lyt_reader_settings_item_switch.xml diff --git a/app/src/main/java/com/quranapp/android/activities/ActivityReader.java b/app/src/main/java/com/quranapp/android/activities/ActivityReader.java index 7c95bab6..6741c308 100644 --- a/app/src/main/java/com/quranapp/android/activities/ActivityReader.java +++ b/app/src/main/java/com/quranapp/android/activities/ActivityReader.java @@ -756,6 +756,8 @@ private void initTranslationVersesFinalAsync(Chapter chapter, int fromVerse, int toVerse ); + boolean arabicTextEnabled = SPReader.getArabicTextEnabled(this); + for (int verseNo = fromVerse, pos = 0; verseNo <= toVerse; verseNo++, pos++) { ReaderRecyclerItemModel model = new ReaderRecyclerItemModel(); final Verse verse = chapter.getVerse(verseNo); @@ -763,7 +765,7 @@ private void initTranslationVersesFinalAsync(Chapter chapter, int fromVerse, int List translations = listOfTranslations.get(pos); verse.setTranslations(translations); - verse.arabicTextSpannable = prepareVerseText(verse); + verse.arabicTextSpannable = arabicTextEnabled ? prepareVerseText(verse) : null; verse.translTextSpannable = prepareTranslSpannable(verse, translations, booksInfo); models.add(model.setViewType(VERSE).setVerse(verse)); @@ -882,13 +884,16 @@ private void makeJuzTranslationVerses( toVerse ); + boolean arabicTextEnabled = SPReader.getArabicTextEnabled(this); + for (int verseNo = fromVerse, pos = 0; verseNo <= toVerse; verseNo++, pos++) { Verse verse = chapter.getVerse(verseNo); ReaderRecyclerItemModel model = new ReaderRecyclerItemModel(); List translations = listOfTranslations.get(pos); verse.setTranslations(translations); - verse.arabicTextSpannable = prepareVerseText(verse); + + verse.arabicTextSpannable = arabicTextEnabled ? prepareVerseText(verse) : null; verse.translTextSpannable = prepareTranslSpannable(verse, translations, booksInfo); models.add(model.setViewType(VERSE).setVerse(verse)); diff --git a/app/src/main/java/com/quranapp/android/activities/reference/ActivityReference.java b/app/src/main/java/com/quranapp/android/activities/reference/ActivityReference.java index 5b58922a..6a6ee5e8 100644 --- a/app/src/main/java/com/quranapp/android/activities/reference/ActivityReference.java +++ b/app/src/main/java/com/quranapp/android/activities/reference/ActivityReference.java @@ -385,7 +385,7 @@ private ReferenceVerseItemModel prepareVerseModel( verseNo ); verse.setTranslations(translations); - verse.arabicTextSpannable = prepareVerseText(verse); + verse.arabicTextSpannable = SPReader.getArabicTextEnabled(this) ? prepareVerseText(verse) : null; verse.translTextSpannable = prepareTranslSpannable(verse, translations, booksInfo); return new ReferenceVerseItemModel(VIEWTYPE_VERSE, verse, chapterNo, -1, -1, null, false); diff --git a/app/src/main/java/com/quranapp/android/frags/settings/FragSettingsMain.java b/app/src/main/java/com/quranapp/android/frags/settings/FragSettingsMain.java index 8d6fbeeb..b6e4ffaf 100644 --- a/app/src/main/java/com/quranapp/android/frags/settings/FragSettingsMain.java +++ b/app/src/main/java/com/quranapp/android/frags/settings/FragSettingsMain.java @@ -27,6 +27,7 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.SeekBar; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -63,13 +64,13 @@ import com.peacedesign.android.widget.dialog.base.PeaceDialog; import com.quranapp.android.R; import com.quranapp.android.activities.readerSettings.ActivitySettings; -import com.quranapp.android.api.RetrofitInstance; import com.quranapp.android.api.models.recitation.RecitationInfoModel; import com.quranapp.android.api.models.recitation.RecitationTranslationInfoModel; import com.quranapp.android.api.models.tafsir.TafsirInfoModel; import com.quranapp.android.databinding.FragSettingsMainBinding; import com.quranapp.android.databinding.LytReaderIndexTabBinding; import com.quranapp.android.databinding.LytReaderSettingsItemBinding; +import com.quranapp.android.databinding.LytReaderSettingsItemSwitchBinding; import com.quranapp.android.databinding.LytReaderSettingsTextDecoratorBinding; import com.quranapp.android.databinding.LytReaderSettingsTextSizeBinding; import com.quranapp.android.databinding.LytResDownloadSourceSheetBinding; @@ -240,13 +241,14 @@ private void iniAppSettings() { initAppLanguage(mBinding.appSettings.getRoot()); initThemes(mBinding.appSettings.getRoot()); initVOTDToggleLauncher(mBinding.appSettings.getRoot()); + initArabicTextToggle(mBinding.appSettings.getRoot()); } private void initAppLanguage(LinearLayout parent) { LytReaderSettingsItemBinding appLangExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater, parent, false); - setupLauncherParams(R.drawable.dr_icon_language, appLangExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_language, appLangExplorerBinding); setupAppLangTitle(appLangExplorerBinding); appLangExplorerBinding.launcher.setOnClickListener(v -> launchFrag(FragSettingsLanguage.class, null)); @@ -269,12 +271,12 @@ private void setupAppLangTitle(LytReaderSettingsItemBinding binding) { } } - prepareTitle(binding, R.string.strTitleAppLanguage, selectedLanguageName); + prepareTitle(binding.launcher, R.string.strTitleAppLanguage, selectedLanguageName); } private void initThemes(LinearLayout parent) { LytReaderSettingsItemBinding binding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_theme, binding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_theme, binding); setupThemeTitle(binding); binding.launcher.setOnClickListener(v -> launchThemeExplorer(v.getContext(), binding)); @@ -284,7 +286,7 @@ private void initThemes(LinearLayout parent) { private void setupThemeTitle(LytReaderSettingsItemBinding binding) { String selectedTheme = ThemeUtils.resolveThemeTextFromMode(binding.getRoot().getContext()); - prepareTitle(binding, R.string.strTitleTheme, selectedTheme); + prepareTitle(binding.launcher, R.string.strTitleTheme, selectedTheme); } private void launchThemeExplorer(Context ctx, LytReaderSettingsItemBinding parentBinding) { @@ -322,26 +324,21 @@ private void launchThemeExplorer(Context ctx, LytReaderSettingsItemBinding paren sheetDialog.show(getParentFragmentManager()); } - private void initVOTDToggleLauncher(LinearLayout parent) { - LytReaderSettingsItemBinding binding = LytReaderSettingsItemBinding.inflate(mInflater, parent, false); + private void initArabicTextToggle(LinearLayout parent) { + Context context = parent.getContext(); - setupLauncherParams(R.drawable.dr_icon_heart_filled, binding); - setupVOTDToggleTitle(binding); + LytReaderSettingsItemSwitchBinding binding = LytReaderSettingsItemSwitchBinding.inflate( + mInflater, parent, true + ); + setupLauncherParams(binding.getRoot()); - binding.launcher.setOnClickListener(v -> launchVOTDToggleExplorer(v.getContext(), binding)); + binding.container.setOnClickListener(v -> binding.switcher.toggle()); + binding.switcher.setChecked(SPReader.getArabicTextEnabled(context)); - parent.addView(binding.getRoot()); - } + binding.switcher.setOnCheckedChangeListener((buttonView, isChecked) -> + SPReader.setArabicTextEnabled(context, isChecked)); - private void setupVOTDToggleTitle(LytReaderSettingsItemBinding binding) { - Context context = binding.getRoot().getContext(); - - String status = context.getString( - VOTDUtils.isVOTDTrulyEnabled(context) - ? R.string.strLabelOn - : R.string.strLabelOff - ); - prepareTitle(binding, R.string.strTitleVOTD, status); + prepareTitle(binding.text, R.string.titleArabicTextToggle, context.getString(R.string.msgArabicTextToggle)); } private void launchVOTDToggleExplorer(Context ctx, LytReaderSettingsItemBinding parentBinding) { @@ -407,6 +404,29 @@ private void requestAlarmPermission(Context ctx) { startActivity(new Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)); } + + private void initVOTDToggleLauncher(LinearLayout parent) { + LytReaderSettingsItemBinding binding = LytReaderSettingsItemBinding.inflate(mInflater, parent, false); + + setupLauncherParamsAndIcon(R.drawable.dr_icon_heart_filled, binding); + setupVOTDToggleTitle(binding); + + binding.launcher.setOnClickListener(v -> launchVOTDToggleExplorer(v.getContext(), binding)); + + parent.addView(binding.getRoot()); + } + + private void setupVOTDToggleTitle(LytReaderSettingsItemBinding binding) { + Context context = binding.getRoot().getContext(); + + String status = context.getString( + VOTDUtils.isVOTDTrulyEnabled(context) + ? R.string.strLabelOn + : R.string.strLabelOff + ); + prepareTitle(binding.launcher, R.string.strTitleVOTD, status); + } + private void initReaderSettings(Context ctx) { LytSettingsReaderBinding readerSettings = mBinding.readerSettings; @@ -425,7 +445,7 @@ private void initReaderSettings(Context ctx) { private void initTranslExplorer(LinearLayout parent) { mTranslExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_translations, mTranslExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_translations, mTranslExplorerBinding); setupTranslTitle(); mTranslExplorerBinding.launcher.setOnClickListener(v -> { @@ -467,13 +487,13 @@ private void setupTranslTitle() { final int size = slugs.size(); String subtext = size == 0 ? null : getString(R.string.strLabelSelectedCount, size); - prepareTitle(mTranslExplorerBinding, R.string.strTitleTranslations, subtext); + prepareTitle(mTranslExplorerBinding.launcher, R.string.strTitleTranslations, subtext); } private void initTafsirExplorer(LinearLayout parent) { mTafsirExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_tafsir, mTafsirExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_tafsir, mTafsirExplorerBinding); setupTafsirTitle(); mTafsirExplorerBinding.launcher.setOnClickListener(v -> launchFrag(FragSettingsTafsirs.class, null)); @@ -484,7 +504,7 @@ private void initTafsirExplorer(LinearLayout parent) { private void initScriptExplorer(LinearLayout parent) { mScriptExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_quran_script, mScriptExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_quran_script, mScriptExplorerBinding); setupScriptTitle(); mScriptExplorerBinding.launcher.setOnClickListener(v -> launchFrag(FragSettingsScripts.class, null)); @@ -499,18 +519,18 @@ private void setupScriptTitle() { String subtitle = QuranScriptUtilsKt.getQuranScriptName( SPReader.getSavedScript(mScriptExplorerBinding.getRoot().getContext()) ); - prepareTitle(mScriptExplorerBinding, R.string.strTitleSelectScripts, subtitle); + prepareTitle(mScriptExplorerBinding.launcher, R.string.strTitleSelectScripts, subtitle); } private void setupTafsirTitle() { if (mTafsirExplorerBinding == null) return; Context ctx = mTafsirExplorerBinding.getRoot().getContext(); - prepareTitle(mTafsirExplorerBinding, R.string.strTitleSelectTafsir, null); + prepareTitle(mTafsirExplorerBinding.launcher, R.string.strTitleSelectTafsir, null); TafsirManager.prepare(ctx, false, () -> { prepareTitle( - mTafsirExplorerBinding, + mTafsirExplorerBinding.launcher, R.string.strTitleSelectTafsir, TafsirUtils.getTafsirName(SPReader.getSavedTafsirKey(ctx)) ); @@ -522,7 +542,7 @@ private void setupTafsirTitle() { private void initRecitationExplorer(LinearLayout parent) { mRecitationExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_recitation, mRecitationExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_recitation, mRecitationExplorerBinding); setupRecitationTitle(); mRecitationExplorerBinding.launcher.setOnClickListener(v -> launchFrag(FragSettingsRecitations.class, null)); @@ -534,11 +554,11 @@ private void setupRecitationTitle() { if (mRecitationExplorerBinding == null) return; Context ctx = mRecitationExplorerBinding.getRoot().getContext(); - prepareTitle(mRecitationExplorerBinding, R.string.strTitleSelectReciter, null); + prepareTitle(mRecitationExplorerBinding.launcher, R.string.strTitleSelectReciter, null); RecitationManager.prepare(ctx, false, () -> { RecitationManager.prepareTranslations(ctx, false, () -> { prepareTitle( - mRecitationExplorerBinding, + mRecitationExplorerBinding.launcher, R.string.strTitleSelectReciter, RecitationManager.getCurrentReciterNameForAudioOption(ctx) ); @@ -553,9 +573,10 @@ private void initManageAudioExplorer(LinearLayout parent) { com.quranapp.android.databinding.LytReaderSettingsItemBinding mManageAudioExplorerBinding = LytReaderSettingsItemBinding.inflate( mInflater); - setupLauncherParams(R.drawable.dr_icon_download, mManageAudioExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_download, mManageAudioExplorerBinding); - prepareTitle(mManageAudioExplorerBinding, R.string.titleManageAudio, getString(R.string.downloadRecitations)); + prepareTitle(mManageAudioExplorerBinding.launcher, R.string.titleManageAudio, + getString(R.string.downloadRecitations)); mManageAudioExplorerBinding.launcher.setOnClickListener(v -> launchFrag(FragSettingsManageAudio.class, null)); @@ -572,8 +593,8 @@ private void setupLauncherIcon(int startIconRes, IconedTextView textView) { } @SuppressLint("RtlHardcoded") - private void prepareTitle(LytReaderSettingsItemBinding binding, int titleRes, String subtitle) { - Context ctx = binding.getRoot().getContext(); + private void prepareTitle(TextView txtView, int titleRes, String subtitle) { + Context ctx = txtView.getContext(); SpannableStringBuilder ssb = new SpannableStringBuilder(); int flag = SPAN_EXCLUSIVE_EXCLUSIVE; @@ -592,20 +613,22 @@ private void prepareTitle(LytReaderSettingsItemBinding binding, int titleRes, St ssb.append("\n").append(subtitleSS); } - binding.launcher.setText(ssb); - binding.launcher.setGravity(WindowUtils.isRTL(ctx) ? Gravity.RIGHT : Gravity.LEFT); + txtView.setText(ssb); + txtView.setGravity(WindowUtils.isRTL(ctx) ? Gravity.RIGHT : Gravity.LEFT); } - private void setupLauncherParams(int startIconRes, LytReaderSettingsItemBinding launcherBinding) { - View launcherRoot = launcherBinding.getRoot(); - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT); - LayoutParamsKt.updateMarginHorizontal(params, ContextKt.dp2px(launcherRoot.getContext(), 10)); - LayoutParamsKt.updateMarginVertical(params, ContextKt.dp2px(launcherRoot.getContext(), 5)); - launcherRoot.setLayoutParams(params); - + private void setupLauncherParamsAndIcon(int startIconRes, LytReaderSettingsItemBinding launcherBinding) { + setupLauncherParams(launcherBinding.getRoot()); setupLauncherIcon(startIconRes, launcherBinding.launcher); } + private void setupLauncherParams(View layout) { + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT); + LayoutParamsKt.updateMarginHorizontal(params, ContextKt.dp2px(layout.getContext(), 10)); + LayoutParamsKt.updateMarginVertical(params, ContextKt.dp2px(layout.getContext(), 5)); + layout.setLayoutParams(params); + } + private void initLayoutStyle(Context ctx) { CardView readerStyleContainer = mBinding.readerSettings.readerStyleContainer; @@ -809,7 +832,7 @@ private void iniOtherSettings() { private void initDownloadSource(LinearLayout parent) { LytReaderSettingsItemBinding binding = LytReaderSettingsItemBinding.inflate(mInflater); - setupLauncherParams(R.drawable.dr_icon_download, binding); + setupLauncherParamsAndIcon(R.drawable.dr_icon_download, binding); setupDownloadSrcTitle(binding); binding.launcher.setOnClickListener(v -> launchDownloadSourceSelector(v.getContext(), binding)); @@ -859,7 +882,7 @@ private void setupDownloadSrcTitle(LytReaderSettingsItemBinding binding) { final String selectedSource = DownloadSourceUtils.getCurrentSourceName( binding.getRoot().getContext() ); - prepareTitle(binding, R.string.titleResourceDownloadSource, selectedSource); + prepareTitle(binding.launcher, R.string.titleResourceDownloadSource, selectedSource); } private void initLogLauncher(LinearLayout parent) { @@ -868,9 +891,9 @@ private void initLogLauncher(LinearLayout parent) { LytReaderSettingsItemBinding logExplorerBinding = LytReaderSettingsItemBinding.inflate(mInflater, parent, false); - setupLauncherParams(R.drawable.icon_log, logExplorerBinding); + setupLauncherParamsAndIcon(R.drawable.icon_log, logExplorerBinding); prepareTitle( - logExplorerBinding, + logExplorerBinding.launcher, R.string.appLogs, TextUtils.concat(ctx.getString(R.string.crashLogs), ", ", ctx.getString(R.string.suppressedLogs)).toString() ); diff --git a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPReader.java b/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPReader.java index 342bfa1a..d1c17979 100644 --- a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPReader.java +++ b/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPReader.java @@ -1,5 +1,6 @@ package com.quranapp.android.utils.sharedPrefs; +import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import static com.quranapp.android.reader_managers.ReaderParams.READER_STYLE_DEFAULT; @@ -32,6 +33,8 @@ * SharedPreferences utility class for Reader */ public abstract class SPReader { + public static final String SP_READER = "sp_reader"; + public static final String SP_TEXT_STYLE = "sp_reader_text"; public static final String SP_TRANSL = "sp_reader_translations"; public static final String SP_RECITATION_OPTIONS = "sp_reader_recitation_options"; @@ -39,6 +42,19 @@ public abstract class SPReader { public static final String SP_SCRIPT = "sp_reader_script"; public static final String SP_READER_STYLE = "sp_reader_style"; + public static boolean getArabicTextEnabled(Context context) { + SharedPreferences sp = context.getSharedPreferences(SP_READER, Context.MODE_PRIVATE); + return sp.getBoolean(Keys.READER_KEY_ARABIC_TEXT_ENABLED, true); + } + + @SuppressLint("ApplySharedPref") + public static void setArabicTextEnabled(Context context, boolean enabled) { + SharedPreferences sp = context.getSharedPreferences(SP_READER, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putBoolean(Keys.READER_KEY_ARABIC_TEXT_ENABLED, enabled); + editor.commit(); + } + public static float getSavedTextSizeMultArabic(Context context) { SharedPreferences sp = context.getSharedPreferences(SP_TEXT_STYLE, Context.MODE_PRIVATE); diff --git a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPSubscription.java b/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPSubscription.java deleted file mode 100644 index 14188a39..00000000 --- a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPSubscription.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * (c) Faisal Khan. Created on 17/10/2021. - */ - -/* - * (c) Faisal Khan. Created on 12/10/2021. - */ - -package com.quranapp.android.utils.sharedPrefs; - -import android.content.Context; -import android.content.SharedPreferences; - -import java.util.HashSet; -import java.util.Set; - -public class SPSubscription { - private static final String SP_SUBSCRIPTION = "sp_subscription"; - private static final String KEY_UNLOCKED_TRANSLS = "key.unlocked_transls"; - private static final String KEY_UNLOCKED_RECITATIONS = "key.unlocked_recitations"; - - - public static Set getUnlockedTransls(Context ctx) { - SharedPreferences sp = ctx.getSharedPreferences(SP_SUBSCRIPTION, Context.MODE_PRIVATE); - if (sp.contains(KEY_UNLOCKED_TRANSLS)) { - return new HashSet<>(sp.getStringSet(KEY_UNLOCKED_TRANSLS, new HashSet<>())); - } - return new HashSet<>(); - } - - public static void setUnlockedTransls(Context ctx, Set unlockedTransls) { - SharedPreferences sp = ctx.getSharedPreferences(SP_SUBSCRIPTION, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sp.edit(); - editor.putStringSet(KEY_UNLOCKED_TRANSLS, unlockedTransls); - editor.apply(); - } - - public static Set getUnlockedRecitations(Context ctx) { - SharedPreferences sp = ctx.getSharedPreferences(SP_SUBSCRIPTION, Context.MODE_PRIVATE); - if (sp.contains(KEY_UNLOCKED_RECITATIONS)) { - return new HashSet<>(sp.getStringSet(KEY_UNLOCKED_RECITATIONS, new HashSet<>())); - } - return new HashSet<>(); - } - - public static void setUnlockedRecitations(Context ctx, Set unlockedRecitations) { - SharedPreferences sp = ctx.getSharedPreferences(SP_SUBSCRIPTION, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = sp.edit(); - editor.putStringSet(KEY_UNLOCKED_RECITATIONS, unlockedRecitations); - editor.apply(); - } -} diff --git a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPVerses.java b/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPVerses.java index c15b39a2..e26395b5 100644 --- a/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPVerses.java +++ b/app/src/main/java/com/quranapp/android/utils/sharedPrefs/SPVerses.java @@ -3,27 +3,25 @@ import android.content.Context; import android.content.SharedPreferences; +import com.quranapp.android.utils.univ.Keys; + /** * SharedPreferences utility class for verse related utils. */ public abstract class SPVerses { public static final String SP_VOTD = "sp_votd"; - public static final String KEY_VOTD_DATE = "votd_date"; - public static final String KEY_VOTD_CHAPTER_NO = "votd_chapter_no"; - public static final String KEY_VOTD_VERSE_NO = "votd_verse_no"; - public static final String KEY_VOTD_REMINDER_ENABLED = "votd_reminder_enabled"; public static void saveVOTD(Context context, long datetime, int chapterNo, int verseNo) { SharedPreferences.Editor editor = context.getSharedPreferences(SP_VOTD, Context.MODE_PRIVATE).edit(); - editor.putLong(KEY_VOTD_DATE, datetime); - editor.putInt(KEY_VOTD_CHAPTER_NO, chapterNo); - editor.putInt(KEY_VOTD_VERSE_NO, verseNo); + editor.putLong(Keys.KEY_VOTD_DATE, datetime); + editor.putInt(Keys.KEY_VOTD_CHAPTER_NO, chapterNo); + editor.putInt(Keys.KEY_VOTD_VERSE_NO, verseNo); editor.apply(); } public static int[] getVOTD(Context context) { SharedPreferences sp = context.getSharedPreferences(SP_VOTD, Context.MODE_PRIVATE); - return new int[]{sp.getInt(KEY_VOTD_CHAPTER_NO, -2), sp.getInt(KEY_VOTD_VERSE_NO, -2)}; + return new int[]{sp.getInt(Keys.KEY_VOTD_CHAPTER_NO, -2), sp.getInt(Keys.KEY_VOTD_VERSE_NO, -2)}; } public static void removeVOTD(Context context) { @@ -34,12 +32,12 @@ public static void removeVOTD(Context context) { public static void setVOTDReminderEnabled(Context context, boolean enabled) { SharedPreferences.Editor editor = context.getSharedPreferences(SP_VOTD, Context.MODE_PRIVATE).edit(); - editor.putBoolean(KEY_VOTD_REMINDER_ENABLED, enabled); + editor.putBoolean(Keys.KEY_VOTD_REMINDER_ENABLED, enabled); editor.apply(); } public static boolean getVOTDReminderEnabled(Context context) { SharedPreferences sp = context.getSharedPreferences(SP_VOTD, Context.MODE_PRIVATE); - return sp.getBoolean(KEY_VOTD_REMINDER_ENABLED, true); + return sp.getBoolean(Keys.KEY_VOTD_REMINDER_ENABLED, true); } } diff --git a/app/src/main/java/com/quranapp/android/utils/univ/Keys.kt b/app/src/main/java/com/quranapp/android/utils/univ/Keys.kt index 49cd7d06..e3426da6 100644 --- a/app/src/main/java/com/quranapp/android/utils/univ/Keys.kt +++ b/app/src/main/java/com/quranapp/android/utils/univ/Keys.kt @@ -14,9 +14,16 @@ object Keys { const val READER_KEY_SAVE_TRANSL_CHANGES = "reader.save_translation_changes" const val READER_KEY_PENDING_SCROLL = "reader.pending_scroll" const val READER_KEY_SETTING_IS_FROM_READER = "reader.setting_is_from_reader" + const val READER_KEY_ARABIC_TEXT_ENABLED = "reader.arabic_text_enabled" + const val KEY_REFERENCE_VERSE_MODEL = "verse_model" const val KEY_LANGUAGE = "language" const val KEY_ACTIVITY_RESUMED_FROM_NOTIFICATION = "key.resumeFromPlayerNotification" + const val KEY_VOTD_DATE = "votd_date" + const val KEY_VOTD_CHAPTER_NO = "votd_chapter_no" + const val KEY_VOTD_VERSE_NO = "votd_verse_no" + const val KEY_VOTD_REMINDER_ENABLED = "votd_reminder_enabled" + const val KEY_EXTRA_TITLE = "title" } diff --git a/app/src/main/java/com/quranapp/android/utils/verse/VerseUtils.java b/app/src/main/java/com/quranapp/android/utils/verse/VerseUtils.java index e8d1a08e..f7e7ca0d 100644 --- a/app/src/main/java/com/quranapp/android/utils/verse/VerseUtils.java +++ b/app/src/main/java/com/quranapp/android/utils/verse/VerseUtils.java @@ -26,6 +26,7 @@ import com.quranapp.android.utils.span.VerseArabicHighlightSpan; import com.quranapp.android.utils.thread.runner.RunnableTaskRunner; import com.quranapp.android.utils.thread.tasks.BaseRunnableTask; +import com.quranapp.android.utils.univ.Keys; import java.time.Duration; import java.util.Calendar; @@ -201,8 +202,8 @@ public void onFailed(@NonNull Exception e) { private static int[] getVOTD(Context ctx, QuranMeta quranMeta, boolean forceNew) { SharedPreferences sp = ctx.getSharedPreferences(SPVerses.SP_VOTD, Context.MODE_PRIVATE); - int chapterNo = sp.getInt(SPVerses.KEY_VOTD_CHAPTER_NO, -1); - int verseNo = sp.getInt(SPVerses.KEY_VOTD_VERSE_NO, -1); + int chapterNo = sp.getInt(Keys.KEY_VOTD_CHAPTER_NO, -1); + int verseNo = sp.getInt(Keys.KEY_VOTD_VERSE_NO, -1); boolean isChapterValid = QuranMeta.isChapterValid(chapterNo); boolean isVerseValid = quranMeta.isVerseValid4Chapter(chapterNo, verseNo); @@ -236,7 +237,7 @@ private static int[] getVOTD(Context ctx, QuranMeta quranMeta, boolean forceNew) private static boolean doesVOTDNeedReset(Context ctx, SharedPreferences sp) { try { - long lastDateTimeMillis = sp.getLong(SPVerses.KEY_VOTD_DATE, -1); + long lastDateTimeMillis = sp.getLong(Keys.KEY_VOTD_DATE, -1); if (lastDateTimeMillis == -1) { return true; } diff --git a/app/src/main/java/com/quranapp/android/views/VOTDView.java b/app/src/main/java/com/quranapp/android/views/VOTDView.java index 76438702..73baea6e 100644 --- a/app/src/main/java/com/quranapp/android/views/VOTDView.java +++ b/app/src/main/java/com/quranapp/android/views/VOTDView.java @@ -51,6 +51,9 @@ import kotlin.Pair; +/* + * A very ugly implementation of verse of the day view + */ public class VOTDView extends FrameLayout implements Destroyable, BookmarkCallbacks { private final CallableTaskRunner> taskRunner = new CallableTaskRunner<>(); private final BookmarkDBHelper mBookmarkDBHelper; @@ -64,6 +67,7 @@ public class VOTDView extends FrameLayout implements Destroyable, BookmarkCallba private int mVerseNo = -1; private String mLastScript; private String mLastTranslationSlug; + private boolean mLastArabicTextEnabled; private SpannableString mLastTranslationText; private SpannableString mLastAuthorText; private CharSequence mArText; @@ -198,7 +202,7 @@ private void setupQuran(QuranMeta quranMeta, Quran quran) { } private void prepareTransl(Context context, String scriptKey) { - taskRunner.callAsync(new BaseCallableTask>() { + taskRunner.callAsync(new BaseCallableTask<>() { QuranTranslationFactory factory; @Override @@ -228,11 +232,18 @@ public Pair call() { @Override public void onComplete(@Nullable Pair result) { + // if translation has changed, update with new translation if (result != null) { setupTranslation(mArText, result.getFirst(), result.getSecond()); - } else if (scriptKey != null && !Objects.equals(mLastTranslationSlug, scriptKey)) { + } + // Or if script has changed, update with old translation + else if (scriptKey != null && !Objects.equals(mLastScript, scriptKey)) { setupTranslation(mArText, null, null); } + // Or if arabic text enable status has changed, update with old script and old translation + else if (SPReader.getArabicTextEnabled(getContext()) != mLastArabicTextEnabled) { + showText(mArText, mLastTranslationText, mLastAuthorText); + } } }); } @@ -255,14 +266,16 @@ private QuranTranslBookInfo obtainOptimalSlug(Context ctx, QuranTranslationFacto return bookInfo; } - private void setupTranslation(CharSequence mArText, QuranTranslBookInfo bookInfo, Translation translation) { + private void setupTranslation(CharSequence arText, QuranTranslBookInfo bookInfo, Translation translation) { + // If translation is null, it means translation was not changed, update with old translation if (bookInfo == null || translation == null || TextUtils.isEmpty(translation.getText())) { - showText(mArText, mLastTranslationText, mLastAuthorText); + showText(arText, mLastTranslationText, mLastAuthorText); return; } mLastTranslationSlug = translation.getBookSlug(); + // Remove footnote markers etc String transl = StringUtils.removeHTML(translation.getText(), false); int txtSize = ContextKt.getDimenPx(getContext(), R.dimen.dmnCommonSize1_5); SpannableString translText = mVerseDecorator.setupTranslText(transl, -1, txtSize, translation.isUrdu()); @@ -277,27 +290,31 @@ private void setupTranslation(CharSequence mArText, QuranTranslBookInfo bookInfo mLastTranslationText = translText; mLastAuthorText = authorText; - showText(mArText, translText, authorText); + showText(arText, translText, authorText); } private void showText(CharSequence arText, SpannableString transl, SpannableString author) { SpannableStringBuilder sb = new SpannableStringBuilder(); - if (!TextUtils.isEmpty(arText)) { + mLastArabicTextEnabled = SPReader.getArabicTextEnabled(getContext()); + + boolean showArabicText = mLastArabicTextEnabled && !TextUtils.isEmpty(arText); + boolean showTranslation = !TextUtils.isEmpty(transl); + + // Show arabic text if enabled + if (showArabicText) { sb.append(arText); } - if (!TextUtils.isEmpty(transl)) { - if (!TextUtils.isEmpty(arText)) { - sb.append("\n\n"); - } + // Show translation if exists + if (showTranslation) { + if (showArabicText) sb.append("\n\n"); sb.append(transl); } - if (!TextUtils.isEmpty(author)) { - if (!TextUtils.isEmpty(transl) || !TextUtils.isEmpty(arText)) { - sb.append("\n"); - } + // Show author if translation exists + if (showTranslation) { + sb.append("\n"); author.setSpan(new LineHeightSpan2(15, true, false), 0, author.length(), SPAN_EXCLUSIVE_EXCLUSIVE); sb.append(author); } diff --git a/app/src/main/java/com/quranapp/android/views/reader/VerseView.java b/app/src/main/java/com/quranapp/android/views/reader/VerseView.java index c21c0af6..14b91bad 100644 --- a/app/src/main/java/com/quranapp/android/views/reader/VerseView.java +++ b/app/src/main/java/com/quranapp/android/views/reader/VerseView.java @@ -224,7 +224,10 @@ private void mapAyahContents(Verse verse) { mBinding.verseHeader.verseSerial.setContentDescription(verseSerialDesc); mBinding.verseHeader.verseSerial.setText(verseSerial); - mBinding.textArabic.setText(verse.arabicTextSpannable); + mBinding.textArabic.setVisibility(verse.arabicTextSpannable != null ? VISIBLE : GONE); + if (verse.arabicTextSpannable != null) { + mBinding.textArabic.setText(verse.arabicTextSpannable); + } mBinding.translTextSpannable.setText(verse.translTextSpannable); mBinding.translTextSpannable.setMovementMethod(SelectableLinkMovementMethod.getInstance()); } diff --git a/app/src/main/java/com/quranapp/android/views/reader/dialogs/QuickReference.java b/app/src/main/java/com/quranapp/android/views/reader/dialogs/QuickReference.java index 7b5434c6..55fea5d1 100644 --- a/app/src/main/java/com/quranapp/android/views/reader/dialogs/QuickReference.java +++ b/app/src/main/java/com/quranapp/android/views/reader/dialogs/QuickReference.java @@ -43,6 +43,7 @@ import com.quranapp.android.utils.extensions.ViewKt; import com.quranapp.android.utils.quran.QuranUtils; import com.quranapp.android.utils.reader.factory.ReaderFactory; +import com.quranapp.android.utils.sharedPrefs.SPReader; import com.quranapp.android.utils.thread.runner.CallableTaskRunner; import com.quranapp.android.utils.thread.tasks.BaseCallableTask; import com.quranapp.android.views.CardMessage; @@ -388,7 +389,7 @@ private void prepareVerse( verse.setIncludeChapterNameInSerial(true); verse.setTranslations(translations); - verse.arabicTextSpannable = actvt.prepareVerseText(verse); + verse.arabicTextSpannable = SPReader.getArabicTextEnabled(actvt) ? actvt.prepareVerseText(verse) : null; verse.translTextSpannable = actvt.prepareTranslSpannable(verse, translations, booksInfo); verses.add(verse); diff --git a/app/src/main/res/layout/lyt_reader_settings_item_switch.xml b/app/src/main/res/layout/lyt_reader_settings_item_switch.xml new file mode 100644 index 00000000..7e54f014 --- /dev/null +++ b/app/src/main/res/layout/lyt_reader_settings_item_switch.xml @@ -0,0 +1,40 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38f5039d..c5040413 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -410,4 +410,6 @@ Clear search history Resource download source Use this option to download Quran data from a different source if one is not working + Show Arabic Verse Text + Disabling this feature will hide Arabic verse text from all over the app. \ No newline at end of file