diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c46cb961c3..7816b11b37 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -18,6 +18,7 @@ quran android contributors * [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). 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..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 @@ -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: { @@ -93,6 +94,11 @@ public void onTranslationAction(PagerActivity activity, } break; } + case R.id.cab_copy_ayah_text_menu: { + 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..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, 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..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, 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..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, 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 00fbe13c89..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 @@ -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); @@ -66,8 +74,37 @@ 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); + copyButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View 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++) + { + menu.getMenu().add(Menu.NONE, i, 1, translations[i]); + } + menu.show(); + menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + + @Override + public boolean onMenuItemClick(MenuItem item) { + if (onTranslationActionListener != null && selectedAyah != null) + { + String selectedTranslation=(String)item.getTitle(); + onTranslationActionListener.onTranslationAction(selectedAyah, translations, selectedTranslation, R.id.cab_copy_ayah_text_menu); + return true; + } + return false; + } + }); + } + }); } public void setVerses(@NonNull QuranInfo quranInfo, @@ -144,7 +181,7 @@ public void unhighlightAyat() { @Override public boolean onMenuItemClick(MenuItem item) { 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 eda705c8c5..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 @@ -53,30 +53,55 @@ public void shareViaIntent(Activity activity, String text, @StringRes int titleR activity.startActivity(Intent.createChooser(intent, activity.getString(titleResId))); } + public String getShareTextperTranslation(Context context, + 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"); + } + 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) { + QuranAyahInfo ayahInfo, + String[] translationNames) { final StringBuilder sb = new StringBuilder(); if (ayahInfo.arabicText != null) { sb.append(ayahInfo.arabicText) - .append("\n\n"); + .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"); + .append(translationNames[i]) + .append(")\n"); } sb.append(ayahInfo.texts.get(i)) - .append("\n\n"); + .append("\n\n"); } sb.append('-') - .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); + .append(quranInfo.getSuraAyahString(context, ayahInfo.sura, ayahInfo.ayah)); return sb.toString(); } + private String getShareText(Activity activity, List verses) { final int size = verses.size(); 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 @@ +