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

Add Share Translation #2805

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,12 +32,13 @@ public class TranslationView extends FrameLayout implements View.OnClickListener
MenuItem.OnMenuItemClickListener {
private final TranslationAdapter translationAdapter;
private final AyahToolBar ayahToolBar;

private List<LocalTranslation> 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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 32 additions & 7 deletions app/src/main/java/com/quran/labs/androidquran/util/ShareUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuranText> verses) {
final int size = verses.size();

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/share_menu.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/cab_copy_ayah_text_menu"
android:icon="@drawable/ic_action_expand"
android:title="@string/share_ayah"
/>
<item
android:id="@+id/cab_share_ayah_link"
android:icon="@drawable/ic_link"
Expand Down