Skip to content

Commit ba33114

Browse files
committed
Added Option to Remove Description Caption pair
1 parent 95372f3 commit ba33114

File tree

6 files changed

+89
-49
lines changed

6 files changed

+89
-49
lines changed

app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import android.view.ViewGroup;
77
import android.widget.AdapterView;
88
import android.widget.AdapterView.OnItemSelectedListener;
9+
import android.widget.ImageView;
10+
import android.widget.Spinner;
911
import androidx.annotation.NonNull;
1012
import androidx.annotation.Nullable;
11-
import androidx.appcompat.widget.AppCompatEditText;
12-
import androidx.appcompat.widget.AppCompatSpinner;
1313
import androidx.recyclerview.widget.RecyclerView;
1414
import butterknife.BindView;
1515
import butterknife.ButterKnife;
16+
import com.google.android.material.textfield.TextInputEditText;
1617
import com.google.android.material.textfield.TextInputLayout;
1718
import fr.free.nrw.commons.R;
1819
import fr.free.nrw.commons.utils.AbstractTextWatcher;
@@ -76,29 +77,37 @@ public List<UploadMediaDetail> getUploadMediaDetails() {
7677
return uploadMediaDetails;
7778
}
7879

79-
public void addDescription(UploadMediaDetail uploadMediaDetail) {
80+
public void addDescription(final UploadMediaDetail uploadMediaDetail) {
8081
this.uploadMediaDetails.add(uploadMediaDetail);
8182
notifyItemInserted(uploadMediaDetails.size());
8283
}
8384

85+
private void removeDescription(final UploadMediaDetail uploadMediaDetail, final int pos) {
86+
this.uploadMediaDetails.remove(uploadMediaDetail);
87+
notifyItemRemoved(pos);
88+
}
89+
8490
public class ViewHolder extends RecyclerView.ViewHolder {
8591

8692
@Nullable
8793
@BindView(R.id.spinner_description_languages)
88-
AppCompatSpinner spinnerDescriptionLanguages;
94+
Spinner spinnerDescriptionLanguages;
8995

9096
@BindView(R.id.description_item_edit_text)
91-
AppCompatEditText descItemEditText;
97+
TextInputEditText descItemEditText;
9298

9399
@BindView(R.id.description_item_edit_text_input_layout)
94100
TextInputLayout descInputLayout;
95101

96102
@BindView(R.id.caption_item_edit_text)
97-
AppCompatEditText captionItemEditText;
103+
TextInputEditText captionItemEditText;
98104

99105
@BindView(R.id.caption_item_edit_text_input_layout)
100106
TextInputLayout captionInputLayout;
101107

108+
@BindView(R.id.btn_remove)
109+
ImageView removeButton;
110+
102111
public ViewHolder(View itemView) {
103112
super(itemView);
104113
ButterKnife.bind(this, itemView);
@@ -119,6 +128,7 @@ public void bind(int position) {
119128
}));
120129

121130
if (position == 0) {
131+
removeButton.setVisibility(View.GONE);
122132
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
123133
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
124134
captionInputLayout.setEndIconOnClickListener(v ->
@@ -130,10 +140,13 @@ public void bind(int position) {
130140
callback.showAlert(R.string.media_detail_description, R.string.description_info));
131141

132142
} else {
143+
removeButton.setVisibility(View.VISIBLE);
133144
captionInputLayout.setEndIconDrawable(null);
134145
descInputLayout.setEndIconDrawable(null);
135146
}
136147

148+
removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position));
149+
137150
captionItemEditText.addTextChangedListener(new AbstractTextWatcher(
138151
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText)));
139152
initLanguageSpinner(position, uploadMediaDetail);
@@ -148,6 +161,7 @@ public void bind(int position) {
148161
} else {
149162
captionItemEditText.clearFocus();
150163
}
164+
151165
}
152166

153167
/**

app/src/main/java/fr/free/nrw/commons/upload/mediaDetails/UploadMediaDetailFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public void onButtonAddDescriptionClicked() {
195195
UploadMediaDetail uploadMediaDetail = new UploadMediaDetail();
196196
uploadMediaDetail.setManuallyAdded(true);//This was manually added by the user
197197
uploadMediaDetailAdapter.addDescription(uploadMediaDetail);
198+
rvDescriptions.smoothScrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
198199
}
199200

200201
@Override
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="?attr/editTextColor"
2+
android:viewportHeight="24.0" android:viewportWidth="24.0"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#8F000000" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
5+
</vector>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
android:layout_marginTop="@dimen/standard_gap"
8383
android:orientation="vertical">
8484

85-
<fr.free.nrw.commons.widget.HeightLimitedRecyclerView
85+
<androidx.recyclerview.widget.RecyclerView
8686
android:id="@+id/rv_descriptions"
8787
android:layout_width="match_parent"
8888
android:layout_height="wrap_content"
Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,71 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:layout_marginHorizontal="8dp"
8+
android:layout_marginVertical="8dp"
9+
app:elevation="6dp">
10+
11+
<androidx.constraintlayout.widget.ConstraintLayout
312
android:layout_width="match_parent"
4-
android:layout_height="wrap_content"
5-
android:orientation="horizontal"
6-
android:weightSum="8">
7-
8-
<androidx.appcompat.widget.AppCompatSpinner
9-
android:id="@+id/spinner_description_languages"
10-
android:layout_width="wrap_content"
11-
android:layout_height="wrap_content"
12-
android:layout_weight="0"
13-
android:minWidth="@dimen/tiny_height"
14-
android:padding="@dimen/dimen_0"
15-
android:spinnerMode="dialog" />
16-
<LinearLayout
17-
android:layout_width="match_parent"
18-
android:layout_height="wrap_content"
19-
android:orientation="vertical"
20-
android:layout_weight="8">
13+
android:layout_height="match_parent"
14+
android:layout_marginHorizontal="20dp"
15+
android:layout_marginVertical="20dp">
16+
17+
<ImageView
18+
android:id="@+id/btn_remove"
19+
android:layout_width="24dp"
20+
android:layout_height="wrap_content"
21+
android:contentDescription="@string/remove"
22+
android:visibility="visible"
23+
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
24+
app:layout_constraintEnd_toEndOf="parent"
25+
app:srcCompat="@drawable/ic_clear_24dp" />
26+
27+
<Spinner
28+
android:id="@+id/spinner_description_languages"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:spinnerMode="dialog"
32+
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
33+
app:layout_constraintStart_toStartOf="parent" />
34+
2135
<com.google.android.material.textfield.TextInputLayout
22-
android:id="@+id/caption_item_edit_text_input_layout"
36+
android:id="@+id/caption_item_edit_text_input_layout"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
app:layout_constraintBottom_toTopOf="@id/description_item_edit_text_input_layout"
40+
app:layout_constraintEnd_toEndOf="parent"
41+
app:layout_constraintStart_toStartOf="parent">
42+
43+
<com.google.android.material.textfield.TextInputEditText
44+
android:id="@+id/caption_item_edit_text"
2345
android:layout_width="match_parent"
24-
android:layout_height="wrap_content"
25-
>
26-
27-
<androidx.appcompat.widget.AppCompatEditText
28-
android:id="@+id/caption_item_edit_text"
29-
android:layout_width="match_parent"
30-
android:layout_height="wrap_content"
31-
android:hint="@string/share_caption_hint"
32-
android:imeOptions="actionNext|flagNoExtractUi"
33-
android:inputType="textMultiLine" />
46+
android:layout_height="match_parent"
47+
android:hint="@string/share_caption_hint"
48+
android:imeOptions="actionNext|flagNoExtractUi"
49+
android:inputType="textMultiLine" />
3450
</com.google.android.material.textfield.TextInputLayout>
3551

3652
<com.google.android.material.textfield.TextInputLayout
37-
android:id="@+id/description_item_edit_text_input_layout"
53+
android:id="@+id/description_item_edit_text_input_layout"
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"
56+
app:layout_constraintBottom_toBottomOf="parent"
57+
app:layout_constraintEnd_toEndOf="parent"
58+
app:layout_constraintStart_toStartOf="parent">
59+
60+
<com.google.android.material.textfield.TextInputEditText
61+
android:id="@+id/description_item_edit_text"
3862
android:layout_width="match_parent"
39-
android:layout_height="wrap_content"
40-
>
41-
42-
<androidx.appcompat.widget.AppCompatEditText
43-
android:id="@+id/description_item_edit_text"
44-
android:layout_width="match_parent"
45-
android:layout_height="wrap_content"
46-
android:hint="@string/share_description_hint"
47-
android:imeOptions="actionNext|flagNoExtractUi"
48-
android:inputType="textMultiLine" />
63+
android:layout_height="match_parent"
64+
android:hint="@string/share_description_hint"
65+
android:imeOptions="actionNext|flagNoExtractUi"
66+
android:inputType="textMultiLine" />
4967
</com.google.android.material.textfield.TextInputLayout>
5068

51-
</LinearLayout>
52-
</LinearLayout>
69+
</androidx.constraintlayout.widget.ConstraintLayout>
70+
71+
</androidx.cardview.widget.CardView>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,5 +628,6 @@ Upload your first media by tapping on the add button.</string>
628628
<string name="ask_to_turn_location_on">Turn on location?</string>
629629
<string name="nearby_needs_location">Nearby needs location enabled to work properly</string>
630630
<string name="use_location_from_similar_image">Did you shoot these two pictures at the same place? Do you want to use the latitude/longitude of the picture on the right?</string>
631+
<string name="remove">Removes a caption and description</string>
631632

632633
</resources>

0 commit comments

Comments
 (0)