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
This commit is contained in:
Ayan Sarkar 2021-05-15 05:44:29 +05:30 committed by GitHub
parent 4b7e75c42c
commit a78fea09d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 120 additions and 85 deletions

View file

@ -6,6 +6,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;
@ -13,6 +15,7 @@ import androidx.appcompat.widget.AppCompatSpinner;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.utils.AbstractTextWatcher;
@ -72,24 +75,38 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
notifyItemInserted(uploadMediaDetails.size());
}
/**
* Remove description based on position from the list and notifies the RecyclerView Adapter that
* data in adapter has been removed at that particular position.
* @param uploadMediaDetail
* @param position
*/
public void removeDescription(final UploadMediaDetail uploadMediaDetail, final int position) {
this.uploadMediaDetails.remove(uploadMediaDetail);
notifyItemRemoved(position);
}
public class ViewHolder extends RecyclerView.ViewHolder {
@Nullable
@BindView(R.id.spinner_description_languages)
AppCompatSpinner spinnerDescriptionLanguages;
Spinner spinnerDescriptionLanguages;
@BindView(R.id.description_item_edit_text)
AppCompatEditText descItemEditText;
TextInputEditText descItemEditText;
@BindView(R.id.description_item_edit_text_input_layout)
TextInputLayout descInputLayout;
@BindView(R.id.caption_item_edit_text)
AppCompatEditText captionItemEditText;
TextInputEditText captionItemEditText;
@BindView(R.id.caption_item_edit_text_input_layout)
TextInputLayout captionInputLayout;
@BindView(R.id.btn_remove)
ImageView removeButton;
public ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
@ -110,6 +127,7 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
descItemEditText.setText(uploadMediaDetail.getDescriptionText());
if (position == 0) {
removeButton.setVisibility(View.GONE);
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
captionInputLayout.setEndIconOnClickListener(v ->
@ -121,10 +139,13 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
callback.showAlert(R.string.media_detail_description, R.string.description_info));
} else {
removeButton.setVisibility(View.VISIBLE);
captionInputLayout.setEndIconDrawable(null);
descInputLayout.setEndIconDrawable(null);
}
removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position));
captionItemEditText.addTextChangedListener(new AbstractTextWatcher(
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText)));
initLanguageSpinner(position, uploadMediaDetail);
@ -175,45 +196,36 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
});
if(description.getCaptionText().isEmpty() == false
&& languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()) != -1){
// If the user selects a nearby pin or location bookmark to upload a picture and language is present in spinner we set the language.
spinnerDescriptionLanguages.setSelection(languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()));
}
else {
// This is a contribution upload or the language from description is not present in spinner.
if (description.getSelectedLanguageIndex() == -1) {
if (!TextUtils.isEmpty(savedLanguageValue)) {
// If user has chosen a default language from settings activity savedLanguageValue is not null
spinnerDescriptionLanguages
.setSelection(
languagesAdapter.getIndexOfLanguageCode(savedLanguageValue));
if (description.getSelectedLanguageIndex() == -1) {
if (!TextUtils.isEmpty(savedLanguageValue)) {
// If user has chosen a default language from settings activity
// savedLanguageValue is not null
spinnerDescriptionLanguages.setSelection(languagesAdapter
.getIndexOfLanguageCode(savedLanguageValue));
} else {
//Checking whether Language Code attribute is null or not.
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
//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)
//hence providing same language code for the current upload.
spinnerDescriptionLanguages.setSelection(languagesAdapter
.getIndexOfLanguageCode(uploadMediaDetails.get(position)
.getLanguageCode()), true);
} else {
//Checking whether Language Code attribute is null or not.
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
//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)
//hence providing same language code for the current upload.
spinnerDescriptionLanguages.setSelection(languagesAdapter
.getIndexOfLanguageCode(
uploadMediaDetails.get(position).getLanguageCode()), true);
if (position == 0) {
final int defaultLocaleIndex = languagesAdapter
.getIndexOfUserDefaultLocale(spinnerDescriptionLanguages
.getContext());
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
} else {
if (position == 0) {
int defaultLocaleIndex = languagesAdapter
.getIndexOfUserDefaultLocale(
spinnerDescriptionLanguages.getContext());
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
} else {
spinnerDescriptionLanguages.setSelection(0, true);
}
spinnerDescriptionLanguages.setSelection(0, true);
}
}
} else {
spinnerDescriptionLanguages
.setSelection(description.getSelectedLanguageIndex());
selectedLanguages
.put(spinnerDescriptionLanguages, description.getLanguageCode());
}
} else {
spinnerDescriptionLanguages.setSelection(description.getSelectedLanguageIndex());
selectedLanguages.put(spinnerDescriptionLanguages, description.getLanguageCode());
}
}
}

View file

@ -213,7 +213,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
UploadMediaDetail uploadMediaDetail = new UploadMediaDetail();
uploadMediaDetail.setManuallyAdded(true);//This was manually added by the user
uploadMediaDetailAdapter.addDescription(uploadMediaDetail);
rvDescriptions.scrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
rvDescriptions.smoothScrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
}
@Override

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector android:height="24dp" android:tint="?attr/editTextColor"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<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"/>
</vector>

View file

@ -1,53 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="8">
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="8dp"
app:elevation="6dp">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/spinner_description_languages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:minWidth="@dimen/tiny_height"
android:padding="@dimen/dimen_0"
android:spinnerMode="dialog" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="8">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/caption_item_edit_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="20dp">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/caption_item_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/share_caption_hint"
android:imeOptions="actionNext|flagNoExtractUi"
android:inputType="textMultiLine"
android:maxLength="255" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/btn_remove"
android:layout_width="24dp"
android:layout_height="wrap_content"
android:contentDescription="@string/remove"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_remove" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/description_item_edit_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Spinner
android:id="@+id/spinner_description_languages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
app:layout_constraintStart_toStartOf="parent" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/description_item_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/share_description_hint"
android:imeOptions="actionNext|flagNoExtractUi"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/caption_item_edit_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/description_item_edit_text_input_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
</LinearLayout>
</LinearLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/caption_item_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/share_caption_hint"
android:imeOptions="actionNext|flagNoExtractUi"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/description_item_edit_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/description_item_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/share_description_hint"
android:imeOptions="actionNext|flagNoExtractUi"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

View file

@ -610,6 +610,7 @@ Upload your first media by tapping on the add button.</string>
<string name="media_detail_step_title">Media Details</string>
<string name="menu_view_category_page">View category page</string>
<string name="menu_view_item_page">View item page</string>
<string name="remove">Removes a caption and description</string>
<string name="read_help_link">Read more</string>
</resources>