Add button on image details to copy wikicode to clipboard (#1849)

* Add button on image details to copy wikicode to clipboard

* Make copy wikicode button width the same as the nominate deletion button width by filling in background
This commit is contained in:
albendz 2018-08-27 02:13:50 -07:00 committed by Josephine Lim
parent e945d45558
commit a059a3c2ef
3 changed files with 26 additions and 2 deletions

View file

@ -1,6 +1,8 @@
package fr.free.nrw.commons.media;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.DataSetObserver;
@ -50,6 +52,7 @@ import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.ui.widget.CompatTextView;
import timber.log.Timber;
import static android.content.Context.CLIPBOARD_SERVICE;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT;
@ -351,6 +354,17 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
}
}
@OnClick(R.id.copyWikicode)
public void onCopyWikicodeClicked(){
String data = "[[" + media.getFilename() + "|thumb|" + media.getDescription() + "]]";
ClipboardManager clipboard = (ClipboardManager) getContext().getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText("wikiCode", data));
Timber.d("Generated wikidata copy code: %s", data);
Toast.makeText(getContext(), getString(R.string.wikicode_copied), Toast.LENGTH_SHORT).show();
}
@OnClick(R.id.nominateDeletion)
public void onDeleteButtonClicked(){
//Reviewer correct me if i have misunderstood something over here