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

Allow Ayah and translation font sizes to be independently changed #2644

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object Constants {
const val PREF_LAST_PAGE = "lastPage"
const val PREF_LOCK_ORIENTATION = "lockOrientation"
const val PREF_LANDSCAPE_ORIENTATION = "landscapeOrientation"
const val PREF_AYAH_TEXT_SIZE = "ayahTextSize"
const val PREF_TRANSLATION_TEXT_SIZE = "translationTextSize"
const val PREF_ACTIVE_TRANSLATION = "activeTranslation"
const val PREF_ACTIVE_TRANSLATIONS = "activeTranslations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.util.AttributeSet
import android.view.View
import android.widget.SeekBar

class SeekBarTextSizePreference(
class SeekBarAyahTextSizePreference(
context: Context, attrs: AttributeSet
) : SeekBarPreference(context, attrs) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.quran.labs.androidquran.ui.preference

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.SeekBar

class SeekBarTranslationTextSizePreference(
context: Context, attrs: AttributeSet
) : SeekBarPreference(context, attrs) {

override fun getPreviewVisibility(): Int = View.VISIBLE

override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
super.onProgressChanged(seekBar, progress, fromUser)
previewText.textSize = progress.toFloat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ internal class TranslationAdapter(
private val inflater: LayoutInflater = LayoutInflater.from(context)
private val data: MutableList<TranslationViewRow> = mutableListOf()

private var fontSize: Int = 0
private var ayahFontSize: Int = 0
private var translationFontSize: Int = 0
private var textColor: Int = 0
private var footnoteColor: Int = 0
private var inlineAyahColor: Int = 0
Expand Down Expand Up @@ -197,7 +198,8 @@ internal class TranslationAdapter(
}

fun refresh(quranSettings: QuranSettings) {
this.fontSize = quranSettings.translationTextSize
this.ayahFontSize = quranSettings.ayahTextSize
this.translationFontSize = quranSettings.translationTextSize
isNightMode = quranSettings.isNightMode
if (isNightMode) {
val originalTextBrightness = quranSettings.nightModeTextBrightness
Expand Down Expand Up @@ -327,7 +329,7 @@ internal class TranslationAdapter(

text = str
holder.text.setTextColor(arabicTextColor)
holder.text.textSize = ARABIC_MULTIPLIER * fontSize
holder.text.textSize = ARABIC_MULTIPLIER * ayahFontSize
} else {
if (row.type == TranslationViewRow.Type.TRANSLATOR) {
text = row.data
Expand Down Expand Up @@ -396,7 +398,7 @@ internal class TranslationAdapter(

holder.text.movementMethod = LinkMovementMethod.getInstance()
holder.text.setTextColor(textColor)
holder.text.textSize = fontSize.toFloat()
holder.text.textSize = translationFontSize.toFloat()
}
}
holder.text.text = text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public int getPreferredDownloadAmount() {
return val;
}

public int getAyahTextSize() {
return prefs.getInt(Constants.PREF_AYAH_TEXT_SIZE,
Constants.DEFAULT_TEXT_SIZE);
}

public int getTranslationTextSize() {
return prefs.getInt(Constants.PREF_TRANSLATION_TEXT_SIZE,
Constants.DEFAULT_TEXT_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class InlineTranslationView @JvmOverloads constructor(

@StyleRes
private var textStyle = 0
private var fontSize = 0
private var ayahFontSize = 0
private var translationFontSize = 0
private var footerSpacerHeight = 0
private var inlineAyahColor: Int = 0

Expand All @@ -62,7 +63,8 @@ class InlineTranslationView @JvmOverloads constructor(

private fun initResources() {
val settings = QuranSettings.getInstance(context)
fontSize = settings.translationTextSize
ayahFontSize = settings.ayahTextSize
translationFontSize = settings.translationTextSize
textStyle = R.style.TranslationText
inlineAyahColor = ContextCompat.getColor(context, R.color.translation_translator_color)
}
Expand Down Expand Up @@ -109,14 +111,14 @@ class InlineTranslationView @JvmOverloads constructor(
val ayahNumber = ayah.ayah
val ayahHeader = TextView(context)
ayahHeader.setTextColor(Color.WHITE)
ayahHeader.textSize = fontSize.toFloat()
ayahHeader.textSize = ayahFontSize.toFloat()
ayahHeader.setTypeface(null, Typeface.BOLD)
ayahHeader.text = context.resources.getString(R.string.sura_ayah, suraNumber, ayahNumber)
linearLayout.addView(ayahHeader, params)
val ayahView = TextView(context)
ayahView.setTextAppearance(context, textStyle)
ayahView.setTextColor(Color.WHITE)
ayahView.textSize = fontSize.toFloat()
ayahView.textSize = ayahFontSize.toFloat()

// translation
val showHeader = translations.size > 1
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/preferences_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string translatable="false" name="prefs_highlight_bookmarks">highlightBookmarks</string>
<string translatable="false" name="prefs_lock_orientation">lockOrientation</string>
<string translatable="false" name="prefs_landscape_orientation">landscapeOrientation</string>
<string translatable="false" name="prefs_ayah_text_size">ayahTextSize</string>
<string translatable="false" name="prefs_translation_text_size">translationTextSize</string>
<string translatable="false" name="prefs_ayah_before_translation">ayahBeforeTranslation</string>
<string translatable="false" name="prefs_use_dyslexic_font">useDyslexicFont</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<string name="prefs_display_marker_summary">Display popup on reaching juz\', hizb, etc.</string>
<string name="prefs_highlight_bookmarks_title">Highlight bookmarks</string>
<string name="prefs_highlight_bookmarks_summary">Highlight bookmarked ayahs while reading</string>
<string name="prefs_ayah_text_title">Ayah text size</string>
<string name="prefs_translation_text_title">Translation text size</string>
<string name="prefs_translations">Translations</string>
<string name="prefs_translations_summary">Download and manage translations</string>
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/res/xml/quran_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,19 @@
android:title="@string/prefs_use_dyslexic_font_title"
app:iconSpaceReserved="false"/>

<com.quran.labs.androidquran.ui.preference.SeekBarTextSizePreference
<com.quran.labs.androidquran.ui.preference.SeekBarAyahTextSizePreference
android:defaultValue="15"
android:key="@string/prefs_translation_text_size"
android:key="@string/prefs_ayah_text_size"
android:max="40"
android:persistent="true"
android:title="@string/prefs_translation_text_title"/>
android:title="@string/prefs_ayah_text_title"/>

<com.quran.labs.androidquran.ui.preference.SeekBarTranslationTextSizePreference
android:defaultValue="15"
android:key="@string/prefs_translation_text_size"
android:max="40"
android:persistent="true"
android:title="@string/prefs_translation_text_title"/>
</PreferenceCategory>

<PreferenceCategory
Expand Down