Skip to content

Commit 4622e8e

Browse files
albendzilgazer
authored andcommitted
Add button on image details to copy wikicode to clipboard (commons-app#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
1 parent b807d3f commit 4622e8e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fr.free.nrw.commons.media;
22

33
import android.app.AlertDialog;
4+
import android.content.ClipData;
5+
import android.content.ClipboardManager;
46
import android.content.DialogInterface;
57
import android.content.Intent;
68
import android.database.DataSetObserver;
@@ -50,6 +52,7 @@
5052
import fr.free.nrw.commons.ui.widget.CompatTextView;
5153
import timber.log.Timber;
5254

55+
import static android.content.Context.CLIPBOARD_SERVICE;
5356
import static android.view.View.GONE;
5457
import static android.view.View.VISIBLE;
5558
import static android.widget.Toast.LENGTH_SHORT;
@@ -351,6 +354,17 @@ public void onMediaDetailCoordinatesClicked(){
351354
}
352355
}
353356

357+
@OnClick(R.id.copyWikicode)
358+
public void onCopyWikicodeClicked(){
359+
String data = "[[" + media.getFilename() + "|thumb|" + media.getDescription() + "]]";
360+
ClipboardManager clipboard = (ClipboardManager) getContext().getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
361+
clipboard.setPrimaryClip(ClipData.newPlainText("wikiCode", data));
362+
363+
Timber.d("Generated wikidata copy code: %s", data);
364+
365+
Toast.makeText(getContext(), getString(R.string.wikicode_copied), Toast.LENGTH_SHORT).show();
366+
}
367+
354368
@OnClick(R.id.nominateDeletion)
355369
public void onDeleteButtonClicked(){
356370
//Reviewer correct me if i have misunderstood something over here

app/src/main/res/layout/fragment_media_detail.xml

+10-2
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,23 @@
312312
android:textStyle="bold"/>
313313
</LinearLayout>
314314

315+
<Button
316+
android:id="@+id/copyWikicode"
317+
android:layout_width="match_parent"
318+
android:layout_height="wrap_content"
319+
android:layout_margin="@dimen/standard_gap"
320+
android:background="@color/button_blue"
321+
android:text="@string/copy_wikicode"
322+
android:textColor="@color/primaryTextColor" />
323+
315324
<Button
316325
android:id="@+id/nominateDeletion"
317326
android:background="@drawable/bg_delete_button"
318327
android:textColor="@color/primaryTextColor"
319328
android:layout_margin="@dimen/standard_gap"
320329
android:layout_width="match_parent"
321330
android:layout_height="wrap_content"
322-
android:text="@string/nominate_deletion"
323-
android:visibility="gone"/>
331+
android:text="@string/nominate_deletion"/>
324332
</LinearLayout>
325333
</LinearLayout>
326334
</ScrollView>

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@
252252
<string name="skip_login_title">Do you really want to skip login?</string>
253253
<string name="skip_login_message">You will not be able to upload pictures.</string>
254254
<string name="login_alert_message">Please log in to use this feature</string>
255+
<string name="copy_wikicode">Copy Wikicode to clipboard</string>
256+
<string name="wikicode_copied">Wikicode copied to clipboard</string>
255257

256258
<string name="nearby_location_has_not_changed">Location has not changed.</string>
257259
<string name="nearby_location_not_available">Location not available.</string>

0 commit comments

Comments
 (0)