From 10a43f4d2176c68b36db97f72fac8eac6f69bda4 Mon Sep 17 00:00:00 2001 From: HelpForSoftware Date: Sun, 1 Apr 2018 18:28:43 +0300 Subject: [PATCH 01/16] Git Entegration Test 1 --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c46cb961c3..505afc11ba 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,6 @@ quran android contributors ========================== - +TEST1 ### code * [Ahmed El-Helw](https://twitter.com/ahmedre) From 772a30d384c635d1832e1cbce0cbd4a7055b7b9e Mon Sep 17 00:00:00 2001 From: HelpForSoftware Date: Sun, 1 Apr 2018 18:29:03 +0300 Subject: [PATCH 02/16] Git Entegration Test 2 --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 505afc11ba..f9b4e5f574 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,6 @@ quran android contributors ========================== -TEST1 +TEST2 ### code * [Ahmed El-Helw](https://twitter.com/ahmedre) From c9801fa46c1c30dbbb7f754fbd3ac5ed7c3d8feb Mon Sep 17 00:00:00 2001 From: HelpForSoftware Date: Tue, 3 Apr 2018 12:07:25 +0300 Subject: [PATCH 03/16] Ayah Copy per Translation. -Added Expandable Copy Menu beginning of AyahToolbar --- .../translation/TranslationPresenter.java | 7 ++- .../ui/translation/TranslationView.java | 55 ++++++++++++++++++- .../labs/androidquran/util/ShareUtil.java | 2 +- app/src/main/res/menu/share_menu.xml | 5 ++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java index 20704ed6b0..10a83c6967 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java @@ -85,7 +85,7 @@ public void onTranslationAction(PagerActivity activity, } case R.id.cab_share_ayah_text: case R.id.cab_copy_ayah: { - String shareText = shareUtil.getShareText(activity, ayah, translationNames); + String shareText = shareUtil.getShareText(activity, ayah, translationNames,true); if (actionId == R.id.cab_share_ayah_text) { shareUtil.shareViaIntent(activity, shareText, R.string.share_ayah_text); } else { @@ -93,8 +93,13 @@ public void onTranslationAction(PagerActivity activity, } break; } + case R.id.cab_copy_ayah_text_menu: { + String shareText = shareUtil.getShareText(activity, ayah, translationNames,false); + shareUtil.copyToClipboard(activity, shareText); + break; } } + } private int getPage(List result) { final int page; 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 00fbe13c89..37ec771518 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 @@ -7,9 +7,16 @@ import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.util.AttributeSet; +import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageButton; +import android.widget.PopupMenu; +import com.quran.labs.androidquran.util.ShareUtil; +import com.quran.labs.androidquran.common.LocalTranslation; +import com.quran.labs.androidquran.database.TranslationsDBAdapter; import com.quran.labs.androidquran.R; import com.quran.labs.androidquran.common.QuranAyahInfo; @@ -25,12 +32,13 @@ public class TranslationView extends FrameLayout implements View.OnClickListener MenuItem.OnMenuItemClickListener { private final TranslationAdapter translationAdapter; private final AyahToolBar ayahToolBar; - +private List translationList; private String[] translations; private QuranAyahInfo selectedAyah; private OnClickListener onClickListener; private OnTranslationActionListener onTranslationActionListener; private LinearLayoutManager layoutManager; + private TranslationsDBAdapter translationsDBAdapter; public TranslationView(Context context) { this(context, null); @@ -68,6 +76,49 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { ayahToolBar.setVisibility(View.GONE); addView(ayahToolBar, LayoutParams.WRAP_CONTENT, context.getResources().getDimensionPixelSize(R.dimen.toolbar_total_height)); + + ImageButton copyButton = (ImageButton) ayahToolBar.findViewById(R.id.cab_copy_ayah_text_menu); + PopupMenu popup = new PopupMenu(context,copyButton); + + copyButton.setOnClickListener(new View.OnClickListener() { + @Override + + public void onClick(View v) { + PopupMenu popmenu; + popmenu = new PopupMenu(context, v); + int items = translations.length; + String[] titles = new String[items]; + for (int i = 0; i < items; i++) { + popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); + } + + + popmenu.show(); + + popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + + if (onTranslationActionListener != null && selectedAyah != null) { + int id=item.getItemId(); + String translationName=(String)item.getTitle(); + + String[] translation = new String[1]; + translation[0]=translationName; + + onTranslationActionListener.onTranslationAction(selectedAyah, translation,R.id.cab_copy_ayah_text_menu); + return true; + + } + return false; + } + + + }); + } + }); + + } public void setVerses(@NonNull QuranInfo quranInfo, @@ -143,7 +194,9 @@ public void unhighlightAyat() { @Override public boolean onMenuItemClick(MenuItem item) { + int id=item.getItemId(); if (onTranslationActionListener != null && selectedAyah != null) { + onTranslationActionListener.onTranslationAction(selectedAyah, translations, item.getItemId()); return true; } diff --git a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java index eda705c8c5..05bd8ebb09 100644 --- a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java +++ b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java @@ -55,7 +55,7 @@ public void shareViaIntent(Activity activity, String text, @StringRes int titleR public String getShareText(Context context, QuranAyahInfo ayahInfo, - String[] translationNames) { + String[] translationNames,Boolean AddArabic) { final StringBuilder sb = new StringBuilder(); if (ayahInfo.arabicText != null) { sb.append(ayahInfo.arabicText) diff --git a/app/src/main/res/menu/share_menu.xml b/app/src/main/res/menu/share_menu.xml index e5ba9a3c77..884d917a9e 100644 --- a/app/src/main/res/menu/share_menu.xml +++ b/app/src/main/res/menu/share_menu.xml @@ -1,5 +1,10 @@ + Date: Tue, 3 Apr 2018 14:15:37 +0300 Subject: [PATCH 04/16] Ayah Copy per Trans-2(Bug Fix) :Edited translationOnAction Method to send selected translation as parameter --- .../translation/TranslationPresenter.java | 5 +-- .../ui/fragment/TabletFragment.java | 4 +-- .../ui/fragment/TranslationFragment.java | 4 +-- .../OnTranslationActionListener.java | 2 +- .../ui/translation/TranslationView.java | 9 ++--- .../labs/androidquran/util/ShareUtil.java | 36 +++++++++++++++---- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java index 10a83c6967..9e3b5322d3 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java @@ -76,6 +76,7 @@ public void onComplete() { public void onTranslationAction(PagerActivity activity, QuranAyahInfo ayah, String[] translationNames, + String selectedTranslation, int actionId) { switch (actionId) { case R.id.cab_share_ayah_link: { @@ -85,7 +86,7 @@ public void onTranslationAction(PagerActivity activity, } case R.id.cab_share_ayah_text: case R.id.cab_copy_ayah: { - String shareText = shareUtil.getShareText(activity, ayah, translationNames,true); + String shareText = shareUtil.getShareText(activity, ayah,translationNames); if (actionId == R.id.cab_share_ayah_text) { shareUtil.shareViaIntent(activity, shareText, R.string.share_ayah_text); } else { @@ -94,7 +95,7 @@ public void onTranslationAction(PagerActivity activity, break; } case R.id.cab_copy_ayah_text_menu: { - String shareText = shareUtil.getShareText(activity, ayah, translationNames,false); + String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames,selectedTranslation); shareUtil.copyToClipboard(activity, shareText); break; } diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java index 1cb91042c4..1046f5a121 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java @@ -238,11 +238,11 @@ public void onDetach() { } @Override - public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, int actionId) { + public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId) { Activity activity = getActivity(); if (activity instanceof PagerActivity) { translationPresenter.get() - .onTranslationAction((PagerActivity) activity, ayah, translationNames, actionId); + .onTranslationAction((PagerActivity) activity, ayah, translationNames,selectedTranslation, actionId); } int page = quranInfo.getPageFromSuraAyah(ayah.sura, ayah.ayah); 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 a9fd046be7..d7ed79c02e 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 @@ -109,10 +109,10 @@ public void onAttach(Context context) { } @Override - public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, int actionId) { + public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId) { Activity activity = getActivity(); if (activity instanceof PagerActivity) { - presenter.onTranslationAction((PagerActivity) activity, ayah, translationNames, actionId); + presenter.onTranslationAction((PagerActivity) activity, ayah,translationNames,selectedTranslation, actionId); } translationView.unhighlightAyat(); } diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java b/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java index ac06aba6f1..08cb383deb 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java @@ -3,5 +3,5 @@ import com.quran.labs.androidquran.common.QuranAyahInfo; public interface OnTranslationActionListener { - void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, int actionId); + void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId); } 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 37ec771518..d8ae81e656 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 @@ -101,12 +101,9 @@ public boolean onMenuItemClick(MenuItem item) { if (onTranslationActionListener != null && selectedAyah != null) { int id=item.getItemId(); - String translationName=(String)item.getTitle(); + String selectedTranslation=(String)item.getTitle(); - String[] translation = new String[1]; - translation[0]=translationName; - - onTranslationActionListener.onTranslationAction(selectedAyah, translation,R.id.cab_copy_ayah_text_menu); + onTranslationActionListener.onTranslationAction(selectedAyah, translations,selectedTranslation,R.id.cab_copy_ayah_text_menu); return true; } @@ -197,7 +194,7 @@ public boolean onMenuItemClick(MenuItem item) { int id=item.getItemId(); if (onTranslationActionListener != null && selectedAyah != null) { - onTranslationActionListener.onTranslationAction(selectedAyah, translations, item.getItemId()); + onTranslationActionListener.onTranslationAction(selectedAyah, translations,"", item.getItemId()); return true; } return false; diff --git a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java index 05bd8ebb09..5d08ce484b 100644 --- a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java +++ b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java @@ -53,16 +53,14 @@ public void shareViaIntent(Activity activity, String text, @StringRes int titleR activity.startActivity(Intent.createChooser(intent, activity.getString(titleResId))); } - public String getShareText(Context context, + public String getShareTextperTranslation(Context context, QuranAyahInfo ayahInfo, - String[] translationNames,Boolean AddArabic) { + String[] translationNames,String selectedTranslation) { final StringBuilder sb = new StringBuilder(); - if (ayahInfo.arabicText != null) { - sb.append(ayahInfo.arabicText) - .append("\n\n"); - } for (int i = 0, size = ayahInfo.texts.size(); i < size; i++) { + if(selectedTranslation ==translationNames[i]) + { if (i < translationNames.length) { sb.append('(') .append(translationNames[i]) @@ -70,12 +68,36 @@ public String getShareText(Context context, } sb.append(ayahInfo.texts.get(i)) .append("\n\n"); - } + }} sb.append('-') .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); return sb.toString(); } + public String getShareText(Context context, + QuranAyahInfo ayahInfo, + String[] translationNames) { + final StringBuilder sb = new StringBuilder(); + if (ayahInfo.arabicText != null) { + sb.append(ayahInfo.arabicText) + .append("\n\n"); + } + + for (int i = 0, size = ayahInfo.texts.size(); i < size; i++) { + if (i < translationNames.length) { + sb.append('(') + .append(translationNames[i]) + .append(")\n"); + } + sb.append(ayahInfo.texts.get(i)) + .append("\n\n"); + } + sb.append('-') + .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); + + return sb.toString(); + } + private String getShareText(Activity activity, List verses) { final int size = verses.size(); From 612e94c6fa8729478409eb5a557a17dd248405a9 Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sun, 8 Apr 2018 02:16:58 +0300 Subject: [PATCH 05/16] Test2 text removed and contributor added --- CONTRIBUTORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f9b4e5f574..7816b11b37 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,6 +1,6 @@ quran android contributors ========================== -TEST2 + ### code * [Ahmed El-Helw](https://twitter.com/ahmedre) @@ -18,6 +18,7 @@ TEST2 * [Ahmed Essam](http://twitter.com/neo_4583) * [Hosain Al Ahmad](https://github.com/hosainnet) * [Ahmed Abdelaal](https://github.com/Ahmed9914) +* [HelpForSoftware](https://github.com/HelpForSoftware) ### ui and design * [Somaia Gabr](http://twitter.com/somaiagabr). From 3dd0c97f761e4f47922dc21503da247f2386e720 Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sun, 8 Apr 2018 02:18:49 +0300 Subject: [PATCH 06/16] line spaces corrected --- .../presenter/translation/TranslationPresenter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java index 9e3b5322d3..02cf3debb6 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java @@ -86,7 +86,7 @@ public void onTranslationAction(PagerActivity activity, } case R.id.cab_share_ayah_text: case R.id.cab_copy_ayah: { - String shareText = shareUtil.getShareText(activity, ayah,translationNames); + String shareText = shareUtil.getShareText(activity, ayah, translationNames); if (actionId == R.id.cab_share_ayah_text) { shareUtil.shareViaIntent(activity, shareText, R.string.share_ayah_text); } else { @@ -95,7 +95,7 @@ public void onTranslationAction(PagerActivity activity, break; } case R.id.cab_copy_ayah_text_menu: { - String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames,selectedTranslation); + String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames, selectedTranslation); shareUtil.copyToClipboard(activity, shareText); break; } From 925d67cb5d00e8ddbaee9486bd7fd6f5235bf786 Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sun, 8 Apr 2018 02:20:05 +0300 Subject: [PATCH 07/16] line spaces corrected --- .../quran/labs/androidquran/ui/fragment/TabletFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java index 1046f5a121..dc72857652 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/fragment/TabletFragment.java @@ -238,11 +238,11 @@ public void onDetach() { } @Override - public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId) { + public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, String selectedTranslation, int actionId) { Activity activity = getActivity(); if (activity instanceof PagerActivity) { translationPresenter.get() - .onTranslationAction((PagerActivity) activity, ayah, translationNames,selectedTranslation, actionId); + .onTranslationAction((PagerActivity) activity, ayah, translationNames, selectedTranslation, actionId); } int page = quranInfo.getPageFromSuraAyah(ayah.sura, ayah.ayah); From ec2a24f337feeaeaba2a2f4fcea3bcc7f48f4648 Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sun, 8 Apr 2018 02:20:57 +0300 Subject: [PATCH 08/16] line spaces corrected --- .../labs/androidquran/ui/fragment/TranslationFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d7ed79c02e..98b14c40f7 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 @@ -109,10 +109,10 @@ public void onAttach(Context context) { } @Override - public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId) { + public void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, String selectedTranslation, int actionId) { Activity activity = getActivity(); if (activity instanceof PagerActivity) { - presenter.onTranslationAction((PagerActivity) activity, ayah,translationNames,selectedTranslation, actionId); + presenter.onTranslationAction((PagerActivity) activity, ayah, translationNames, selectedTranslation, actionId); } translationView.unhighlightAyat(); } From 051619f7f20181a33015f2b7f6371500f6365184 Mon Sep 17 00:00:00 2001 From: HelpForSoftware Date: Mon, 16 Apr 2018 12:10:00 +0300 Subject: [PATCH 09/16] Ayah Copy per Trans- fixed indentation and combined --- .../ui/translation/TranslationView.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) 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 d8ae81e656..9211414cf2 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 @@ -74,48 +74,38 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { ayahToolBar = new AyahToolBar(context, R.menu.share_menu); ayahToolBar.setOnItemSelectedListener(this); ayahToolBar.setVisibility(View.GONE); - addView(ayahToolBar, LayoutParams.WRAP_CONTENT, - context.getResources().getDimensionPixelSize(R.dimen.toolbar_total_height)); + addView(ayahToolBar, LayoutParams.WRAP_CONTENT, context.getResources().getDimensionPixelSize(R.dimen.toolbar_total_height)); ImageButton copyButton = (ImageButton) ayahToolBar.findViewById(R.id.cab_copy_ayah_text_menu); - PopupMenu popup = new PopupMenu(context,copyButton); - copyButton.setOnClickListener(new View.OnClickListener() { - @Override + @Override public void onClick(View v) { - PopupMenu popmenu; - popmenu = new PopupMenu(context, v); - int items = translations.length; - String[] titles = new String[items]; + PopupMenu popmenu = new PopupMenu(context, v); + int items = translations.length; + String[] titles = new String[items]; + for (int i = 0; i < items; i++) { popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); } - popmenu.show(); - popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override public boolean onMenuItemClick(MenuItem item) { - - if (onTranslationActionListener != null && selectedAyah != null) { + if (onTranslationActionListener != null && selectedAyah != null) + { int id=item.getItemId(); String selectedTranslation=(String)item.getTitle(); - onTranslationActionListener.onTranslationAction(selectedAyah, translations,selectedTranslation,R.id.cab_copy_ayah_text_menu); return true; - } - return false; + return false; } - - }); } }); - - } public void setVerses(@NonNull QuranInfo quranInfo, From 2c8a10b6b8e91373d69767250766e87851998d51 Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sat, 22 Jun 2019 15:40:21 +0300 Subject: [PATCH 10/16] ident fix. --- .../presenter/translation/TranslationPresenter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java index 02cf3debb6..90f95750ec 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java @@ -98,9 +98,9 @@ public void onTranslationAction(PagerActivity activity, String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames, selectedTranslation); shareUtil.copyToClipboard(activity, shareText); break; + } } } - } private int getPage(List result) { final int page; @@ -115,6 +115,7 @@ private int getPage(List result) { public interface TranslationScreen { void setVerses(int page, @NonNull String[] translations, @NonNull List verses); + void updateScrollPosition(); } } From e355fdaa306bf9359cfc1f61acddf12c32dacf5f Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sat, 22 Jun 2019 15:49:39 +0300 Subject: [PATCH 11/16] update scrollposirtion space fix.indention. --- .../ui/translation/TranslationView.java | 303 ++++++------------ 1 file changed, 90 insertions(+), 213 deletions(-) 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 9211414cf2..2a67db7bb2 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 @@ -1,243 +1,120 @@ -package com.quran.labs.androidquran.ui.translation; +package com.quran.labs.androidquran.presenter.translation; -import android.content.Context; import android.support.annotation.NonNull; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.ImageButton; -import android.widget.PopupMenu; -import com.quran.labs.androidquran.util.ShareUtil; -import com.quran.labs.androidquran.common.LocalTranslation; -import com.quran.labs.androidquran.database.TranslationsDBAdapter; import com.quran.labs.androidquran.R; import com.quran.labs.androidquran.common.QuranAyahInfo; import com.quran.labs.androidquran.data.QuranInfo; +import com.quran.labs.androidquran.data.SuraAyah; +import com.quran.labs.androidquran.database.TranslationsDBAdapter; +import com.quran.labs.androidquran.di.QuranPageScope; +import com.quran.labs.androidquran.model.translation.TranslationModel; +import com.quran.labs.androidquran.ui.PagerActivity; import com.quran.labs.androidquran.util.QuranSettings; -import com.quran.labs.androidquran.widgets.AyahToolBar; +import com.quran.labs.androidquran.util.ShareUtil; -import java.util.ArrayList; import java.util.List; -public class TranslationView extends FrameLayout implements View.OnClickListener, - TranslationAdapter.OnVerseSelectedListener, - MenuItem.OnMenuItemClickListener { - private final TranslationAdapter translationAdapter; - private final AyahToolBar ayahToolBar; -private List translationList; - private String[] translations; - private QuranAyahInfo selectedAyah; - private OnClickListener onClickListener; - private OnTranslationActionListener onTranslationActionListener; - private LinearLayoutManager layoutManager; - private TranslationsDBAdapter translationsDBAdapter; - - public TranslationView(Context context) { - this(context, null); - } - - public TranslationView(Context context, AttributeSet attrs) { - this(context, attrs, 0); +import javax.inject.Inject; + +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.observers.DisposableObserver; + +@QuranPageScope +public class TranslationPresenter extends + BaseTranslationPresenter { + private final Integer[] pages; + private final ShareUtil shareUtil; + private final QuranSettings quranSettings; + private final QuranInfo quranInfo; + + @Inject + TranslationPresenter(TranslationModel translationModel, + QuranSettings quranSettings, + TranslationsDBAdapter translationsAdapter, + ShareUtil shareUtil, + QuranInfo quranInfo, + Integer... pages) { + super(translationModel, translationsAdapter, quranInfo); + this.pages = pages; + this.quranInfo = quranInfo; + this.shareUtil = shareUtil; + this.quranSettings = quranSettings; } - public TranslationView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - RecyclerView translationRecycler = new RecyclerView(context); - layoutManager = new LinearLayoutManager(context); - translationRecycler.setLayoutManager(layoutManager); - translationRecycler.setItemAnimator(new DefaultItemAnimator()); - translationAdapter = new TranslationAdapter(context, translationRecycler, this, this); - translationRecycler.setAdapter(translationAdapter); - addView(translationRecycler, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - translationRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - - // do not modify the RecyclerView from this method or any method called from - // the onScrolled listener, since most modification methods cannot be called - // while the RecyclerView is computing layout or scrolling - if (selectedAyah != null) { - updateAyahToolBarPosition(); - } - } - }); - - ayahToolBar = new AyahToolBar(context, R.menu.share_menu); - ayahToolBar.setOnItemSelectedListener(this); - ayahToolBar.setVisibility(View.GONE); - addView(ayahToolBar, LayoutParams.WRAP_CONTENT, context.getResources().getDimensionPixelSize(R.dimen.toolbar_total_height)); - - ImageButton copyButton = (ImageButton) ayahToolBar.findViewById(R.id.cab_copy_ayah_text_menu); - copyButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - PopupMenu popmenu = new PopupMenu(context, v); - int items = translations.length; - String[] titles = new String[items]; + public void refresh() { + if (disposable != null) { + disposable.dispose(); + } - for (int i = 0; i < items; i++) { - popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); - } + disposable = Observable.fromArray(pages) + .flatMap(page -> getVerses(quranSettings.wantArabicInTranslationView(), + getTranslations(quranSettings), quranInfo.getVerseRangeForPage(page)) + .toObservable()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableObserver() { + @Override + public void onNext(ResultHolder result) { + if (translationScreen != null && result.ayahInformation.size() > 0) { + translationScreen.setVerses( + getPage(result.ayahInformation), result.translations, result.ayahInformation); + translationScreen.updateScrollPosition(); + } + } - popmenu.show(); - popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public void onError(Throwable e) { + } @Override - public boolean onMenuItemClick(MenuItem item) { - if (onTranslationActionListener != null && selectedAyah != null) - { - int id=item.getItemId(); - String selectedTranslation=(String)item.getTitle(); - onTranslationActionListener.onTranslationAction(selectedAyah, translations,selectedTranslation,R.id.cab_copy_ayah_text_menu); - return true; - } - return false; + public void onComplete() { } }); - } - }); } - public void setVerses(@NonNull QuranInfo quranInfo, - @NonNull String[] translations, - @NonNull List verses) { - this.translations = translations; - - List rows = new ArrayList<>(); - int currentSura = -1; - boolean wantTranslationHeaders = translations.length > 1; - for (int i = 0, size = verses.size(); i < size; i++) { - QuranAyahInfo verse = verses.get(i); - int sura = verse.sura; - if (sura != currentSura) { - rows.add(new TranslationViewRow(TranslationViewRow.Type.SURA_HEADER, verse, - quranInfo.getSuraName(getContext(), sura, true))); - currentSura = sura; + public void onTranslationAction(PagerActivity activity, + QuranAyahInfo ayah, + String[] translationNames, + String selectedTranslation, + int actionId) { + switch (actionId) { + case R.id.cab_share_ayah_link: { + SuraAyah bounds = new SuraAyah(ayah.sura, ayah.ayah); + activity.shareAyahLink(bounds, bounds); + break; } - - if (verse.ayah == 1 && sura != 1 && sura != 9) { - rows.add(new TranslationViewRow(TranslationViewRow.Type.BASMALLAH, verse)); - } - - rows.add(new TranslationViewRow(TranslationViewRow.Type.VERSE_NUMBER, verse)); - - if (verse.arabicText != null) { - rows.add(new TranslationViewRow(TranslationViewRow.Type.QURAN_TEXT, verse)); - } - - // added this to guard against a crash that happened when verse.texts was empty - int verseTexts = verse.texts.size(); - for (int j = 0; j < translations.length; j++) { - String text = verseTexts > j ? verse.texts.get(j) : ""; - if (!TextUtils.isEmpty(text)) { - if (wantTranslationHeaders) { - rows.add( - new TranslationViewRow(TranslationViewRow.Type.TRANSLATOR, verse, translations[j])); - } - rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATION_TEXT, verse, text)); + case R.id.cab_share_ayah_text: + case R.id.cab_copy_ayah: { + String shareText = shareUtil.getShareText(activity, ayah, translationNames); + if (actionId == R.id.cab_share_ayah_text) { + shareUtil.shareViaIntent(activity, shareText, R.string.share_ayah_text); + } else { + shareUtil.copyToClipboard(activity, shareText); } + break; } - - rows.add(new TranslationViewRow(TranslationViewRow.Type.SPACER, verse)); - } - - translationAdapter.setData(rows); - translationAdapter.notifyDataSetChanged(); - } - - public void refresh(@NonNull QuranSettings quranSettings) { - translationAdapter.refresh(quranSettings); - } - - public void setTranslationClickedListener(OnClickListener listener) { - onClickListener = listener; - } - - public void setOnTranslationActionListener(OnTranslationActionListener listener) { - onTranslationActionListener = listener; - } - - public void highlightAyah(int ayahId) { - translationAdapter.setHighlightedAyah(ayahId); - } - - public void unhighlightAyat() { - if (selectedAyah != null) { - selectedAyah = null; - ayahToolBar.hideMenu(); - } - translationAdapter.unhighlight(); - } - - @Override - public boolean onMenuItemClick(MenuItem item) { - int id=item.getItemId(); - if (onTranslationActionListener != null && selectedAyah != null) { - - onTranslationActionListener.onTranslationAction(selectedAyah, translations,"", item.getItemId()); - return true; - } - return false; - } - - @Override - public void onClick(View v) { - if (selectedAyah != null) { - ayahToolBar.hideMenu(); - unhighlightAyat(); - selectedAyah = null; - } - - if (onClickListener != null) { - onClickListener.onClick(v); - } - } - - /** - * This method updates the toolbar position when an ayah is selected - * This method is called from the onScroll listener, and as thus must make sure not to ask - * the RecyclerView to change anything (otherwise, it will result in a crash, as methods to - * update the RecyclerView cannot be called amidst scrolling or computing of a layout). - */ - private void updateAyahToolBarPosition() { - int[] versePopupPosition = translationAdapter.getSelectedVersePopupPosition(); - if (versePopupPosition != null) { - AyahToolBar.AyahToolBarPosition position = new AyahToolBar.AyahToolBarPosition(); - if (versePopupPosition[1] > getHeight() || versePopupPosition[1] < 0) { - ayahToolBar.hideMenu(); - } else { - position.x = versePopupPosition[0]; - position.y = versePopupPosition[1]; - position.pipPosition = AyahToolBar.PipPosition.UP; - if (!ayahToolBar.isShowing()) { - ayahToolBar.showMenu(); - } - ayahToolBar.updatePositionRelative(position); + case R.id.cab_copy_ayah_text_menu: { + String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames, selectedTranslation); + shareUtil.copyToClipboard(activity, shareText); + break; } } } - @Override - public void onVerseSelected(QuranAyahInfo ayahInfo) { - selectedAyah = ayahInfo; - updateAyahToolBarPosition(); - } - - public int findFirstCompletelyVisibleItemPosition() { - return layoutManager.findFirstCompletelyVisibleItemPosition(); + private int getPage(List result) { + final int page; + if (pages.length == 1) { + page = pages[0]; + } else { + QuranAyahInfo ayahInfo = result.get(0); + page = quranInfo.getPageFromSuraAyah(ayahInfo.sura, ayahInfo.ayah); + } + return page; } - public void setScrollPosition(int position) { - layoutManager.scrollToPosition(position); + public interface TranslationScreen { + void setVerses(int page, @NonNull String[] translations, @NonNull List verses); + void updateScrollPosition(); } -} +} From 90baf7f899ae326cb95fb5c3687bdba0017de45c Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sat, 22 Jun 2019 15:54:57 +0300 Subject: [PATCH 12/16] ident fix --- .../labs/androidquran/util/ShareUtil.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java index 5d08ce484b..49e8264e7c 100644 --- a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java +++ b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java @@ -54,26 +54,27 @@ public void shareViaIntent(Activity activity, String text, @StringRes int titleR } public String getShareTextperTranslation(Context context, - QuranAyahInfo ayahInfo, - String[] translationNames,String selectedTranslation) { + QuranAyahInfo ayahInfo, + String[] translationNames, String selectedTranslation) { final StringBuilder sb = new StringBuilder(); for (int i = 0, size = ayahInfo.texts.size(); i < size; i++) { - if(selectedTranslation ==translationNames[i]) - { - if (i < translationNames.length) { - sb.append('(') - .append(translationNames[i]) - .append(")\n"); + if (selectedTranslation == translationNames[i]) { + if (i < translationNames.length) { + sb.append('(') + .append(translationNames[i]) + .append(")\n"); + } + sb.append(ayahInfo.texts.get(i)) + .append("\n\n"); } - sb.append(ayahInfo.texts.get(i)) - .append("\n\n"); - }} + } sb.append('-') - .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); + .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); return sb.toString(); } + public String getShareText(Context context, QuranAyahInfo ayahInfo, String[] translationNames) { From b0d243d9e9dea9f6af300088409a5af848b4508a Mon Sep 17 00:00:00 2001 From: helpforsoftware <37977590+helpforsoftware@users.noreply.github.com> Date: Sat, 22 Jun 2019 16:04:56 +0300 Subject: [PATCH 13/16] space indent fix --- .../ui/translation/OnTranslationActionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java b/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java index 08cb383deb..81c12e46b6 100644 --- a/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java +++ b/app/src/main/java/com/quran/labs/androidquran/ui/translation/OnTranslationActionListener.java @@ -3,5 +3,5 @@ import com.quran.labs.androidquran.common.QuranAyahInfo; public interface OnTranslationActionListener { - void onTranslationAction(QuranAyahInfo ayah, String[] translationNames,String selectedTranslation, int actionId); + void onTranslationAction(QuranAyahInfo ayah, String[] translationNames, String selectedTranslation, int actionId); } From 2abe439a75b49490f0fbc22523e290248f25d1d6 Mon Sep 17 00:00:00 2001 From: helpforsoftware Date: Mon, 12 Aug 2024 22:51:08 +0300 Subject: [PATCH 14/16] Revert "update scrollposirtion space fix.indention." This reverts commit e355fdaa306bf9359cfc1f61acddf12c32dacf5f. --- .../ui/translation/TranslationView.java | 303 ++++++++++++------ 1 file changed, 213 insertions(+), 90 deletions(-) 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 2a67db7bb2..9211414cf2 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 @@ -1,120 +1,243 @@ -package com.quran.labs.androidquran.presenter.translation; +package com.quran.labs.androidquran.ui.translation; +import android.content.Context; import android.support.annotation.NonNull; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.ImageButton; +import android.widget.PopupMenu; +import com.quran.labs.androidquran.util.ShareUtil; +import com.quran.labs.androidquran.common.LocalTranslation; +import com.quran.labs.androidquran.database.TranslationsDBAdapter; import com.quran.labs.androidquran.R; import com.quran.labs.androidquran.common.QuranAyahInfo; import com.quran.labs.androidquran.data.QuranInfo; -import com.quran.labs.androidquran.data.SuraAyah; -import com.quran.labs.androidquran.database.TranslationsDBAdapter; -import com.quran.labs.androidquran.di.QuranPageScope; -import com.quran.labs.androidquran.model.translation.TranslationModel; -import com.quran.labs.androidquran.ui.PagerActivity; import com.quran.labs.androidquran.util.QuranSettings; -import com.quran.labs.androidquran.util.ShareUtil; +import com.quran.labs.androidquran.widgets.AyahToolBar; +import java.util.ArrayList; import java.util.List; -import javax.inject.Inject; - -import io.reactivex.Observable; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.observers.DisposableObserver; - -@QuranPageScope -public class TranslationPresenter extends - BaseTranslationPresenter { - private final Integer[] pages; - private final ShareUtil shareUtil; - private final QuranSettings quranSettings; - private final QuranInfo quranInfo; - - @Inject - TranslationPresenter(TranslationModel translationModel, - QuranSettings quranSettings, - TranslationsDBAdapter translationsAdapter, - ShareUtil shareUtil, - QuranInfo quranInfo, - Integer... pages) { - super(translationModel, translationsAdapter, quranInfo); - this.pages = pages; - this.quranInfo = quranInfo; - this.shareUtil = shareUtil; - this.quranSettings = quranSettings; +public class TranslationView extends FrameLayout implements View.OnClickListener, + TranslationAdapter.OnVerseSelectedListener, + MenuItem.OnMenuItemClickListener { + private final TranslationAdapter translationAdapter; + private final AyahToolBar ayahToolBar; +private List translationList; + private String[] translations; + private QuranAyahInfo selectedAyah; + private OnClickListener onClickListener; + private OnTranslationActionListener onTranslationActionListener; + private LinearLayoutManager layoutManager; + private TranslationsDBAdapter translationsDBAdapter; + + public TranslationView(Context context) { + this(context, null); } - public void refresh() { - if (disposable != null) { - disposable.dispose(); - } + public TranslationView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } - disposable = Observable.fromArray(pages) - .flatMap(page -> getVerses(quranSettings.wantArabicInTranslationView(), - getTranslations(quranSettings), quranInfo.getVerseRangeForPage(page)) - .toObservable()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeWith(new DisposableObserver() { - @Override - public void onNext(ResultHolder result) { - if (translationScreen != null && result.ayahInformation.size() > 0) { - translationScreen.setVerses( - getPage(result.ayahInformation), result.translations, result.ayahInformation); - translationScreen.updateScrollPosition(); - } - } + public TranslationView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + RecyclerView translationRecycler = new RecyclerView(context); + layoutManager = new LinearLayoutManager(context); + translationRecycler.setLayoutManager(layoutManager); + translationRecycler.setItemAnimator(new DefaultItemAnimator()); + translationAdapter = new TranslationAdapter(context, translationRecycler, this, this); + translationRecycler.setAdapter(translationAdapter); + addView(translationRecycler, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); + translationRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); - @Override - public void onError(Throwable e) { - } + // do not modify the RecyclerView from this method or any method called from + // the onScrolled listener, since most modification methods cannot be called + // while the RecyclerView is computing layout or scrolling + if (selectedAyah != null) { + updateAyahToolBarPosition(); + } + } + }); + + ayahToolBar = new AyahToolBar(context, R.menu.share_menu); + ayahToolBar.setOnItemSelectedListener(this); + ayahToolBar.setVisibility(View.GONE); + addView(ayahToolBar, LayoutParams.WRAP_CONTENT, context.getResources().getDimensionPixelSize(R.dimen.toolbar_total_height)); + + ImageButton copyButton = (ImageButton) ayahToolBar.findViewById(R.id.cab_copy_ayah_text_menu); + copyButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + PopupMenu popmenu = new PopupMenu(context, v); + int items = translations.length; + String[] titles = new String[items]; + + for (int i = 0; i < items; i++) { + popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); + } + + popmenu.show(); + popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override - public void onComplete() { + public boolean onMenuItemClick(MenuItem item) { + if (onTranslationActionListener != null && selectedAyah != null) + { + int id=item.getItemId(); + String selectedTranslation=(String)item.getTitle(); + onTranslationActionListener.onTranslationAction(selectedAyah, translations,selectedTranslation,R.id.cab_copy_ayah_text_menu); + return true; + } + return false; } }); + } + }); } - public void onTranslationAction(PagerActivity activity, - QuranAyahInfo ayah, - String[] translationNames, - String selectedTranslation, - int actionId) { - switch (actionId) { - case R.id.cab_share_ayah_link: { - SuraAyah bounds = new SuraAyah(ayah.sura, ayah.ayah); - activity.shareAyahLink(bounds, bounds); - break; + public void setVerses(@NonNull QuranInfo quranInfo, + @NonNull String[] translations, + @NonNull List verses) { + this.translations = translations; + + List rows = new ArrayList<>(); + int currentSura = -1; + boolean wantTranslationHeaders = translations.length > 1; + for (int i = 0, size = verses.size(); i < size; i++) { + QuranAyahInfo verse = verses.get(i); + int sura = verse.sura; + if (sura != currentSura) { + rows.add(new TranslationViewRow(TranslationViewRow.Type.SURA_HEADER, verse, + quranInfo.getSuraName(getContext(), sura, true))); + currentSura = sura; } - case R.id.cab_share_ayah_text: - case R.id.cab_copy_ayah: { - String shareText = shareUtil.getShareText(activity, ayah, translationNames); - if (actionId == R.id.cab_share_ayah_text) { - shareUtil.shareViaIntent(activity, shareText, R.string.share_ayah_text); - } else { - shareUtil.copyToClipboard(activity, shareText); - } - break; + + if (verse.ayah == 1 && sura != 1 && sura != 9) { + rows.add(new TranslationViewRow(TranslationViewRow.Type.BASMALLAH, verse)); } - case R.id.cab_copy_ayah_text_menu: { - String shareText = shareUtil.getShareTextperTranslation(activity, ayah, translationNames, selectedTranslation); - shareUtil.copyToClipboard(activity, shareText); - break; + + rows.add(new TranslationViewRow(TranslationViewRow.Type.VERSE_NUMBER, verse)); + + if (verse.arabicText != null) { + rows.add(new TranslationViewRow(TranslationViewRow.Type.QURAN_TEXT, verse)); } + + // added this to guard against a crash that happened when verse.texts was empty + int verseTexts = verse.texts.size(); + for (int j = 0; j < translations.length; j++) { + String text = verseTexts > j ? verse.texts.get(j) : ""; + if (!TextUtils.isEmpty(text)) { + if (wantTranslationHeaders) { + rows.add( + new TranslationViewRow(TranslationViewRow.Type.TRANSLATOR, verse, translations[j])); + } + rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATION_TEXT, verse, text)); + } + } + + rows.add(new TranslationViewRow(TranslationViewRow.Type.SPACER, verse)); } + + translationAdapter.setData(rows); + translationAdapter.notifyDataSetChanged(); + } + + public void refresh(@NonNull QuranSettings quranSettings) { + translationAdapter.refresh(quranSettings); + } + + public void setTranslationClickedListener(OnClickListener listener) { + onClickListener = listener; } - private int getPage(List result) { - final int page; - if (pages.length == 1) { - page = pages[0]; - } else { - QuranAyahInfo ayahInfo = result.get(0); - page = quranInfo.getPageFromSuraAyah(ayahInfo.sura, ayahInfo.ayah); + public void setOnTranslationActionListener(OnTranslationActionListener listener) { + onTranslationActionListener = listener; + } + + public void highlightAyah(int ayahId) { + translationAdapter.setHighlightedAyah(ayahId); + } + + public void unhighlightAyat() { + if (selectedAyah != null) { + selectedAyah = null; + ayahToolBar.hideMenu(); + } + translationAdapter.unhighlight(); + } + + @Override + public boolean onMenuItemClick(MenuItem item) { + int id=item.getItemId(); + if (onTranslationActionListener != null && selectedAyah != null) { + + onTranslationActionListener.onTranslationAction(selectedAyah, translations,"", item.getItemId()); + return true; } - return page; + return false; + } + + @Override + public void onClick(View v) { + if (selectedAyah != null) { + ayahToolBar.hideMenu(); + unhighlightAyat(); + selectedAyah = null; + } + + if (onClickListener != null) { + onClickListener.onClick(v); + } + } + + /** + * This method updates the toolbar position when an ayah is selected + * This method is called from the onScroll listener, and as thus must make sure not to ask + * the RecyclerView to change anything (otherwise, it will result in a crash, as methods to + * update the RecyclerView cannot be called amidst scrolling or computing of a layout). + */ + private void updateAyahToolBarPosition() { + int[] versePopupPosition = translationAdapter.getSelectedVersePopupPosition(); + if (versePopupPosition != null) { + AyahToolBar.AyahToolBarPosition position = new AyahToolBar.AyahToolBarPosition(); + if (versePopupPosition[1] > getHeight() || versePopupPosition[1] < 0) { + ayahToolBar.hideMenu(); + } else { + position.x = versePopupPosition[0]; + position.y = versePopupPosition[1]; + position.pipPosition = AyahToolBar.PipPosition.UP; + if (!ayahToolBar.isShowing()) { + ayahToolBar.showMenu(); + } + ayahToolBar.updatePositionRelative(position); + } + } + } + + @Override + public void onVerseSelected(QuranAyahInfo ayahInfo) { + selectedAyah = ayahInfo; + updateAyahToolBarPosition(); + } + + public int findFirstCompletelyVisibleItemPosition() { + return layoutManager.findFirstCompletelyVisibleItemPosition(); } - public interface TranslationScreen { - void setVerses(int page, @NonNull String[] translations, @NonNull List verses); - void updateScrollPosition(); + public void setScrollPosition(int position) { + layoutManager.scrollToPosition(position); } -} +} From 382c473a3de2bfd467d3c1982d8701cec0670285 Mon Sep 17 00:00:00 2001 From: helpforsoftware Date: Mon, 12 Aug 2024 23:31:50 +0300 Subject: [PATCH 15/16] indent fixes indent fix 4 indent fix 3 indent fix 2 (SHareUtil) --- .../presenter/translation/TranslationPresenter.java | 1 - .../androidquran/ui/translation/TranslationView.java | 10 ++++------ .../com/quran/labs/androidquran/util/ShareUtil.java | 4 +++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java index 90f95750ec..085648575e 100644 --- a/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java +++ b/app/src/main/java/com/quran/labs/androidquran/presenter/translation/TranslationPresenter.java @@ -115,7 +115,6 @@ private int getPage(List result) { public interface TranslationScreen { void setVerses(int page, @NonNull String[] translations, @NonNull List verses); - void updateScrollPosition(); } } 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 9211414cf2..70d7aedd62 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 @@ -32,7 +32,7 @@ public class TranslationView extends FrameLayout implements View.OnClickListener MenuItem.OnMenuItemClickListener { private final TranslationAdapter translationAdapter; private final AyahToolBar ayahToolBar; -private List translationList; + private List translationList; private String[] translations; private QuranAyahInfo selectedAyah; private OnClickListener onClickListener; @@ -85,7 +85,8 @@ public void onClick(View v) { int items = translations.length; String[] titles = new String[items]; - for (int i = 0; i < items; i++) { + for (int i = 0; i < items; i++) + { popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); } @@ -96,9 +97,8 @@ public void onClick(View v) { public boolean onMenuItemClick(MenuItem item) { if (onTranslationActionListener != null && selectedAyah != null) { - int id=item.getItemId(); String selectedTranslation=(String)item.getTitle(); - onTranslationActionListener.onTranslationAction(selectedAyah, translations,selectedTranslation,R.id.cab_copy_ayah_text_menu); + onTranslationActionListener.onTranslationAction(selectedAyah, translations, selectedTranslation, R.id.cab_copy_ayah_text_menu); return true; } return false; @@ -181,9 +181,7 @@ public void unhighlightAyat() { @Override public boolean onMenuItemClick(MenuItem item) { - int id=item.getItemId(); if (onTranslationActionListener != null && selectedAyah != null) { - onTranslationActionListener.onTranslationAction(selectedAyah, translations,"", item.getItemId()); return true; } diff --git a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java index 49e8264e7c..0fc2447a68 100644 --- a/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java +++ b/app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java @@ -55,7 +55,9 @@ public void shareViaIntent(Activity activity, String text, @StringRes int titleR public String getShareTextperTranslation(Context context, QuranAyahInfo ayahInfo, - String[] translationNames, String selectedTranslation) { + String[] translationNames, + String selectedTranslation) + { final StringBuilder sb = new StringBuilder(); for (int i = 0, size = ayahInfo.texts.size(); i < size; i++) { From a419e6ba45ac938b82f473d9ab656f954cd1a154 Mon Sep 17 00:00:00 2001 From: helpforsoftware Date: Mon, 12 Aug 2024 23:56:30 +0300 Subject: [PATCH 16/16] caching getmenu --- .../ui/translation/TranslationView.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 70d7aedd62..38d8b83374 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 @@ -81,18 +81,17 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @Override public void onClick(View v) { - PopupMenu popmenu = new PopupMenu(context, v); + final PopupMenu popMenu = new PopupMenu(context, v); int items = translations.length; String[] titles = new String[items]; - + Menu menu = popMenu.getMenu(); for (int i = 0; i < items; i++) { - popmenu.getMenu().add(Menu.NONE, i, 1, translations[i]); + menu.getMenu().add(Menu.NONE, i, 1, translations[i]); } - - popmenu.show(); - popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - + menu.show(); + menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override public boolean onMenuItemClick(MenuItem item) { if (onTranslationActionListener != null && selectedAyah != null)