Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
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;
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;
Expand Down Expand Up @@ -72,24 +75,38 @@ public void addDescription(UploadMediaDetail uploadMediaDetail) {
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);
Expand All @@ -110,6 +127,7 @@ public void bind(int position) {
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 ->
Expand All @@ -121,10 +139,13 @@ public void bind(int position) {
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);
Expand Down Expand Up @@ -175,45 +196,36 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});


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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void onButtonAddDescriptionClicked() {
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
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/ic_remove.xml
Original file line number Diff line number Diff line change
@@ -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>
120 changes: 68 additions & 52 deletions app/src/main/res/layout/row_item_description.xml
Original file line number Diff line number Diff line change
@@ -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.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.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>

<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"
>

<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>

</LinearLayout>
</LinearLayout>
<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.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="20dp">

<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" />

<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" />

<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">

<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>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>