Skip to content

Commit a78fea0

Browse files
authored
Added an option to Remove a new language description while uploading (#4406)
* implementation done modification required in card & more * Remove button reversed * Code beautification done * Code beautification done * minor issues fixed * java docs added
1 parent 4b7e75c commit a78fea0

File tree

5 files changed

+125
-90
lines changed

5 files changed

+125
-90
lines changed

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

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
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;
1113
import androidx.appcompat.widget.AppCompatEditText;
1214
import androidx.appcompat.widget.AppCompatSpinner;
1315
import androidx.recyclerview.widget.RecyclerView;
1416
import butterknife.BindView;
1517
import butterknife.ButterKnife;
18+
import com.google.android.material.textfield.TextInputEditText;
1619
import com.google.android.material.textfield.TextInputLayout;
1720
import fr.free.nrw.commons.R;
1821
import fr.free.nrw.commons.utils.AbstractTextWatcher;
@@ -72,24 +75,38 @@ public void addDescription(UploadMediaDetail uploadMediaDetail) {
7275
notifyItemInserted(uploadMediaDetails.size());
7376
}
7477

78+
/**
79+
* Remove description based on position from the list and notifies the RecyclerView Adapter that
80+
* data in adapter has been removed at that particular position.
81+
* @param uploadMediaDetail
82+
* @param position
83+
*/
84+
public void removeDescription(final UploadMediaDetail uploadMediaDetail, final int position) {
85+
this.uploadMediaDetails.remove(uploadMediaDetail);
86+
notifyItemRemoved(position);
87+
}
88+
7589
public class ViewHolder extends RecyclerView.ViewHolder {
7690

7791
@Nullable
7892
@BindView(R.id.spinner_description_languages)
79-
AppCompatSpinner spinnerDescriptionLanguages;
93+
Spinner spinnerDescriptionLanguages;
8094

8195
@BindView(R.id.description_item_edit_text)
82-
AppCompatEditText descItemEditText;
96+
TextInputEditText descItemEditText;
8397

8498
@BindView(R.id.description_item_edit_text_input_layout)
8599
TextInputLayout descInputLayout;
86100

87101
@BindView(R.id.caption_item_edit_text)
88-
AppCompatEditText captionItemEditText;
102+
TextInputEditText captionItemEditText;
89103

90104
@BindView(R.id.caption_item_edit_text_input_layout)
91105
TextInputLayout captionInputLayout;
92106

107+
@BindView(R.id.btn_remove)
108+
ImageView removeButton;
109+
93110
public ViewHolder(View itemView) {
94111
super(itemView);
95112
ButterKnife.bind(this, itemView);
@@ -110,6 +127,7 @@ public void bind(int position) {
110127
descItemEditText.setText(uploadMediaDetail.getDescriptionText());
111128

112129
if (position == 0) {
130+
removeButton.setVisibility(View.GONE);
113131
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
114132
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
115133
captionInputLayout.setEndIconOnClickListener(v ->
@@ -121,10 +139,13 @@ public void bind(int position) {
121139
callback.showAlert(R.string.media_detail_description, R.string.description_info));
122140

123141
} else {
142+
removeButton.setVisibility(View.VISIBLE);
124143
captionInputLayout.setEndIconDrawable(null);
125144
descInputLayout.setEndIconDrawable(null);
126145
}
127146

147+
removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position));
148+
128149
captionItemEditText.addTextChangedListener(new AbstractTextWatcher(
129150
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText)));
130151
initLanguageSpinner(position, uploadMediaDetail);
@@ -175,45 +196,36 @@ public void onNothingSelected(AdapterView<?> adapterView) {
175196
});
176197

177198

178-
if(description.getCaptionText().isEmpty() == false
179-
&& languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()) != -1){
180-
// If the user selects a nearby pin or location bookmark to upload a picture and language is present in spinner we set the language.
181-
spinnerDescriptionLanguages.setSelection(languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()));
182-
}
183-
else {
184-
// This is a contribution upload or the language from description is not present in spinner.
185-
if (description.getSelectedLanguageIndex() == -1) {
186-
if (!TextUtils.isEmpty(savedLanguageValue)) {
187-
// If user has chosen a default language from settings activity savedLanguageValue is not null
188-
spinnerDescriptionLanguages
189-
.setSelection(
190-
languagesAdapter.getIndexOfLanguageCode(savedLanguageValue));
199+
if (description.getSelectedLanguageIndex() == -1) {
200+
if (!TextUtils.isEmpty(savedLanguageValue)) {
201+
// If user has chosen a default language from settings activity
202+
// savedLanguageValue is not null
203+
spinnerDescriptionLanguages.setSelection(languagesAdapter
204+
.getIndexOfLanguageCode(savedLanguageValue));
205+
} else {
206+
//Checking whether Language Code attribute is null or not.
207+
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
208+
//If it is not null that means it is fetching details from the previous
209+
// upload (i.e. when user has pressed copy previous caption & description)
210+
//hence providing same language code for the current upload.
211+
spinnerDescriptionLanguages.setSelection(languagesAdapter
212+
.getIndexOfLanguageCode(uploadMediaDetails.get(position)
213+
.getLanguageCode()), true);
191214
} else {
192-
//Checking whether Language Code attribute is null or not.
193-
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
194-
//If it is not null that means it is fetching details from the previous upload (i.e. when user has pressed copy previous caption & description)
195-
//hence providing same language code for the current upload.
196-
spinnerDescriptionLanguages.setSelection(languagesAdapter
197-
.getIndexOfLanguageCode(
198-
uploadMediaDetails.get(position).getLanguageCode()), true);
215+
if (position == 0) {
216+
final int defaultLocaleIndex = languagesAdapter
217+
.getIndexOfUserDefaultLocale(spinnerDescriptionLanguages
218+
.getContext());
219+
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
199220
} else {
200-
if (position == 0) {
201-
int defaultLocaleIndex = languagesAdapter
202-
.getIndexOfUserDefaultLocale(
203-
spinnerDescriptionLanguages.getContext());
204-
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
205-
} else {
206-
spinnerDescriptionLanguages.setSelection(0, true);
207-
}
221+
spinnerDescriptionLanguages.setSelection(0, true);
208222
}
209223
}
210-
211-
} else {
212-
spinnerDescriptionLanguages
213-
.setSelection(description.getSelectedLanguageIndex());
214-
selectedLanguages
215-
.put(spinnerDescriptionLanguages, description.getLanguageCode());
216224
}
225+
226+
} else {
227+
spinnerDescriptionLanguages.setSelection(description.getSelectedLanguageIndex());
228+
selectedLanguages.put(spinnerDescriptionLanguages, description.getLanguageCode());
217229
}
218230
}
219231
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void onButtonAddDescriptionClicked() {
213213
UploadMediaDetail uploadMediaDetail = new UploadMediaDetail();
214214
uploadMediaDetail.setManuallyAdded(true);//This was manually added by the user
215215
uploadMediaDetailAdapter.addDescription(uploadMediaDetail);
216-
rvDescriptions.scrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
216+
rvDescriptions.smoothScrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
217217
}
218218

219219
@Override
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<vector android:height="24dp" android:tint="?attr/editTextColor"
3+
android:viewportHeight="24.0" android:viewportWidth="24.0"
4+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
5+
<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"/>
6+
</vector>
Lines changed: 68 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,69 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
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">
21-
<com.google.android.material.textfield.TextInputLayout
22-
android:id="@+id/caption_item_edit_text_input_layout"
23-
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"
34-
android:maxLength="255" />
35-
</com.google.android.material.textfield.TextInputLayout>
36-
37-
<com.google.android.material.textfield.TextInputLayout
38-
android:id="@+id/description_item_edit_text_input_layout"
39-
android:layout_width="match_parent"
40-
android:layout_height="wrap_content"
41-
>
42-
43-
<androidx.appcompat.widget.AppCompatEditText
44-
android:id="@+id/description_item_edit_text"
45-
android:layout_width="match_parent"
46-
android:layout_height="wrap_content"
47-
android:hint="@string/share_description_hint"
48-
android:imeOptions="actionNext|flagNoExtractUi"
49-
android:inputType="textMultiLine" />
50-
</com.google.android.material.textfield.TextInputLayout>
51-
52-
</LinearLayout>
53-
</LinearLayout>
2+
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:layout_marginHorizontal="8dp"
7+
android:layout_marginVertical="8dp"
8+
app:elevation="6dp">
9+
10+
<androidx.constraintlayout.widget.ConstraintLayout
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:layout_marginHorizontal="20dp"
14+
android:layout_marginVertical="20dp">
15+
16+
<ImageView
17+
android:id="@+id/btn_remove"
18+
android:layout_width="24dp"
19+
android:layout_height="wrap_content"
20+
android:contentDescription="@string/remove"
21+
android:visibility="visible"
22+
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:srcCompat="@drawable/ic_remove" />
25+
26+
<Spinner
27+
android:id="@+id/spinner_description_languages"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:spinnerMode="dialog"
31+
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
32+
app:layout_constraintStart_toStartOf="parent" />
33+
34+
<com.google.android.material.textfield.TextInputLayout
35+
android:id="@+id/caption_item_edit_text_input_layout"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
app:layout_constraintBottom_toTopOf="@id/description_item_edit_text_input_layout"
39+
app:layout_constraintEnd_toEndOf="parent"
40+
app:layout_constraintStart_toStartOf="parent">
41+
42+
<com.google.android.material.textfield.TextInputEditText
43+
android:id="@+id/caption_item_edit_text"
44+
android:layout_width="match_parent"
45+
android:layout_height="match_parent"
46+
android:hint="@string/share_caption_hint"
47+
android:imeOptions="actionNext|flagNoExtractUi"
48+
android:inputType="textMultiLine" />
49+
</com.google.android.material.textfield.TextInputLayout>
50+
51+
<com.google.android.material.textfield.TextInputLayout
52+
android:id="@+id/description_item_edit_text_input_layout"
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
app:layout_constraintBottom_toBottomOf="parent"
56+
app:layout_constraintEnd_toEndOf="parent"
57+
app:layout_constraintStart_toStartOf="parent">
58+
59+
<com.google.android.material.textfield.TextInputEditText
60+
android:id="@+id/description_item_edit_text"
61+
android:layout_width="match_parent"
62+
android:layout_height="match_parent"
63+
android:hint="@string/share_description_hint"
64+
android:imeOptions="actionNext|flagNoExtractUi"
65+
android:inputType="textMultiLine" />
66+
</com.google.android.material.textfield.TextInputLayout>
67+
68+
</androidx.constraintlayout.widget.ConstraintLayout>
69+
</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
@@ -610,6 +610,7 @@ Upload your first media by tapping on the add button.</string>
610610
<string name="media_detail_step_title">Media Details</string>
611611
<string name="menu_view_category_page">View category page</string>
612612
<string name="menu_view_item_page">View item page</string>
613+
<string name="remove">Removes a caption and description</string>
613614
<string name="read_help_link">Read more</string>
614615

615616
</resources>

0 commit comments

Comments
 (0)