diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/quran/ayahtracker/AyahTranslationTrackerItem.java b/app/src/main/java/com/quran/labs/androidquran/presenter/quran/ayahtracker/AyahTranslationTrackerItem.java index d4e7a6e0ad..f5b7cdfe2d 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/quran/ayahtracker/AyahTranslationTrackerItem.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/quran/ayahtracker/AyahTranslationTrackerItem.java @@ -26,17 +26,17 @@ public AyahTranslationTrackerItem(int page, @Override boolean onHighlightAyah(int page, int sura, int ayah, HighlightType type, boolean scrollToAyah) { if (this.page == page) { - ayahView.highlightAyah(new SuraAyah(sura, ayah), quranInfo.getAyahId(sura, ayah)); + ayahView.highlightAyah(new SuraAyah(sura, ayah), quranInfo.getAyahId(sura, ayah), type); return true; } - ayahView.unhighlightAyat(); + ayahView.unhighlightAyah(type); return false; } @Override void onUnHighlightAyah(int page, int sura, int ayah, HighlightType type) { if (this.page == page) { - ayahView.unhighlightAyat(); + ayahView.unhighlightAyah(type); } } diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TranslationFragment.java b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TranslationFragment.java index 72d12ec23e..b57d0cc74a 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TranslationFragment.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TranslationFragment.java @@ -39,12 +39,9 @@ public class TranslationFragment extends Fragment implements TranslationPresenter.TranslationScreen, PageController { private static final String PAGE_NUMBER_EXTRA = "pageNumber"; - private static final String SI_PAGE_NUMBER = "SI_PAGE_NUMBER"; - private static final String SI_HIGHLIGHTED_AYAH = "SI_HIGHLIGHTED_AYAH"; private static final String SI_SCROLL_POSITION = "SI_SCROLL_POSITION"; private int pageNumber; - private int highlightedAyah; private int scrollPosition; private TranslationView translationView; @@ -71,14 +68,6 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { - int page = savedInstanceState.getInt(SI_PAGE_NUMBER, -1); - if (page == pageNumber) { - int highlightedAyah = - savedInstanceState.getInt(SI_HIGHLIGHTED_AYAH, -1); - if (highlightedAyah > 0) { - this.highlightedAyah = highlightedAyah; - } - } scrollPosition = savedInstanceState.getInt(SI_SCROLL_POSITION); } setHasOptionsMenu(true); @@ -156,10 +145,6 @@ public void setVerses(int page, @NonNull LocalTranslation[] translations, @NonNull List verses) { translationView.setVerses(quranDisplayData, translations, verses); - if (highlightedAyah > 0) { - translationView.highlightAyah(quranInfo.getSuraAyahFromAyahId(highlightedAyah), - highlightedAyah); - } } @Override @@ -173,9 +158,6 @@ public void refresh() { @Override public void onSaveInstanceState(@NonNull Bundle outState) { - if (highlightedAyah > 0) { - outState.putInt(SI_HIGHLIGHTED_AYAH, highlightedAyah); - } scrollPosition = translationView.findFirstCompletelyVisibleItemPosition(); outState.putInt(SI_SCROLL_POSITION, scrollPosition); super.onSaveInstanceState(outState); diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationAdapter.kt b/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationAdapter.kt index 760489c014..d7386954fd 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationAdapter.kt +++ b/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationAdapter.kt @@ -20,6 +20,7 @@ import com.quran.labs.androidquran.common.QuranAyahInfo import com.quran.data.model.SuraAyah import com.quran.labs.androidquran.model.translation.ArabicDatabaseUtils import com.quran.labs.androidquran.ui.helpers.ExpandTafseerSpan +import com.quran.labs.androidquran.ui.helpers.HighlightType import com.quran.labs.androidquran.ui.helpers.UthmaniSpan import com.quran.labs.androidquran.ui.util.TypefaceManager import com.quran.labs.androidquran.util.QuranSettings @@ -46,6 +47,7 @@ internal class TranslationAdapter(private val context: Context, private var highlightedAyah: Int = 0 private var highlightedRowCount: Int = 0 private var highlightedStartPosition: Int = 0 + private var highlightType: HighlightType? = null private val expandedTafaseerAyahs = mutableSetOf>() private val expandedHyperlinks = mutableSetOf>() @@ -84,19 +86,19 @@ internal class TranslationAdapter(private val context: Context, expandedTafaseerAyahs.clear(); this.data.addAll(data) if (highlightedAyah > 0) { - highlightAyah(highlightedAyah, false) + highlightAyah(highlightedAyah, false, highlightType ?: HighlightType.SELECTION) } } - fun setHighlightedAyah(ayahId: Int) { - highlightAyah(ayahId, true) + fun setHighlightedAyah(ayahId: Int, highlightType: HighlightType) { + highlightAyah(ayahId, true, highlightType) } fun highlightedAyahInfo(): QuranAyahInfo? { return data.firstOrNull { it.ayahInfo.ayahId == highlightedAyah }?.ayahInfo } - private fun highlightAyah(ayahId: Int, notify: Boolean) { + private fun highlightAyah(ayahId: Int, notify: Boolean, highlightedType: HighlightType) { if (ayahId != highlightedAyah) { val matches = data.withIndex().filter { it.value.ayahInfo.ayahId == ayahId } val (startPosition, count) = (matches.firstOrNull()?.index ?: -1) to matches.size @@ -130,8 +132,8 @@ internal class TranslationAdapter(private val context: Context, recyclerView.handler.post { notifyItemRangeChanged(startChangeRange, startChangeCount, HIGHLIGHT_CHANGE) val layoutManager = recyclerView.layoutManager - if (layoutManager is LinearLayoutManager) { - layoutManager.scrollToPositionWithOffset(startPosition, 52) + if (highlightedType == HighlightType.AUDIO && layoutManager is LinearLayoutManager) { + layoutManager.scrollToPositionWithOffset(startPosition, 64) } else { recyclerView.smoothScrollToPosition(startPosition) } @@ -141,6 +143,7 @@ internal class TranslationAdapter(private val context: Context, highlightedAyah = ayahId highlightedStartPosition = startPosition highlightedRowCount = count + highlightType = highlightedType } } @@ -184,7 +187,7 @@ internal class TranslationAdapter(private val context: Context, val position = recyclerView.getChildAdapterPosition(view) if (highlightedAyah != 0 && position != RecyclerView.NO_POSITION) { val ayahInfo = data[position].ayahInfo - if (ayahInfo.ayahId != highlightedAyah) { + if (ayahInfo.ayahId != highlightedAyah && highlightType == HighlightType.SELECTION) { onVerseSelectedListener.onVerseSelected(ayahInfo) return } @@ -196,7 +199,7 @@ internal class TranslationAdapter(private val context: Context, val position = recyclerView.getChildAdapterPosition(view) if (position != RecyclerView.NO_POSITION) { val ayahInfo = data[position].ayahInfo - highlightAyah(ayahInfo.ayahId, true) + highlightAyah(ayahInfo.ayahId, true, HighlightType.SELECTION) onVerseSelectedListener.onVerseSelected(ayahInfo) return true } diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationView.java b/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationView.java index 4a87ce4575..a9c4ed5e44 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationView.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/translation/TranslationView.java @@ -15,6 +15,7 @@ import com.quran.labs.androidquran.common.QuranAyahInfo; import com.quran.labs.androidquran.common.TranslationMetadata; import com.quran.labs.androidquran.data.QuranDisplayData; +import com.quran.labs.androidquran.ui.helpers.HighlightType; import com.quran.labs.androidquran.ui.util.PageController; import com.quran.labs.androidquran.util.QuranSettings; @@ -165,15 +166,26 @@ public void setTranslationClickedListener(OnClickListener listener) { onClickListener = listener; } - public void highlightAyah(SuraAyah suraAyah, int ayahId) { - selectedAyah = suraAyah; - translationAdapter.setHighlightedAyah(ayahId); + public void highlightAyah(SuraAyah suraAyah, int ayahId, HighlightType highlightType) { + if (highlightType == HighlightType.SELECTION) { + selectedAyah = suraAyah; + } else if (selectedAyah != null) { + hideMenu(); + } + translationAdapter.setHighlightedAyah(ayahId, highlightType); } private void hideMenu() { pageController.endAyahMode(); } + public void unhighlightAyah(HighlightType highlightType) { + if (highlightType == HighlightType.SELECTION) { + selectedAyah = null; + } + translationAdapter.unhighlight(); + } + public void unhighlightAyat() { if (selectedAyah != null) { selectedAyah = null; @@ -248,9 +260,14 @@ private void updateAyahToolBarPosition() { @Override public void onVerseSelected(@NonNull QuranAyahInfo ayahInfo) { final SuraAyah suraAyah = new SuraAyah(ayahInfo.sura, ayahInfo.ayah); - if (selectedAyah != null && !selectedAyah.equals(suraAyah)) { + if (selectedAyah != null) { + final boolean isUnselectingSelectedVerse = selectedAyah.equals(suraAyah); hideMenu(); + if (isUnselectingSelectedVerse) { + return; + } } + pageController.handleLongPress(suraAyah); pageController.requestMenuPositionUpdate(); }