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

View file

@ -312,6 +312,15 @@
android:textStyle="bold"/>
</LinearLayout>
<Button
android:id="@+id/copyWikicode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_gap"
android:background="@color/button_blue"
android:text="@string/copy_wikicode"
android:textColor="@color/primaryTextColor" />
<Button
android:id="@+id/nominateDeletion"
android:background="@drawable/bg_delete_button"
@ -319,8 +328,7 @@
android:layout_margin="@dimen/standard_gap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nominate_deletion"
android:visibility="gone"/>
android:text="@string/nominate_deletion"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -252,6 +252,8 @@
<string name="skip_login_title">Do you really want to skip login?</string>
<string name="skip_login_message">You will not be able to upload pictures.</string>
<string name="login_alert_message">Please log in to use this feature</string>
<string name="copy_wikicode">Copy Wikicode to clipboard</string>
<string name="wikicode_copied">Wikicode copied to clipboard</string>
<string name="nearby_location_has_not_changed">Location has not changed.</string>
<string name="nearby_location_not_available">Location not available.</string>