mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
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:
parent
4b7e75c42c
commit
a78fea09d7
5 changed files with 120 additions and 85 deletions
|
|
@ -6,6 +6,8 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Spinner;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.AppCompatEditText;
|
import androidx.appcompat.widget.AppCompatEditText;
|
||||||
|
|
@ -13,6 +15,7 @@ import androidx.appcompat.widget.AppCompatSpinner;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.utils.AbstractTextWatcher;
|
import fr.free.nrw.commons.utils.AbstractTextWatcher;
|
||||||
|
|
@ -72,24 +75,38 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
||||||
notifyItemInserted(uploadMediaDetails.size());
|
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 {
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@BindView(R.id.spinner_description_languages)
|
@BindView(R.id.spinner_description_languages)
|
||||||
AppCompatSpinner spinnerDescriptionLanguages;
|
Spinner spinnerDescriptionLanguages;
|
||||||
|
|
||||||
@BindView(R.id.description_item_edit_text)
|
@BindView(R.id.description_item_edit_text)
|
||||||
AppCompatEditText descItemEditText;
|
TextInputEditText descItemEditText;
|
||||||
|
|
||||||
@BindView(R.id.description_item_edit_text_input_layout)
|
@BindView(R.id.description_item_edit_text_input_layout)
|
||||||
TextInputLayout descInputLayout;
|
TextInputLayout descInputLayout;
|
||||||
|
|
||||||
@BindView(R.id.caption_item_edit_text)
|
@BindView(R.id.caption_item_edit_text)
|
||||||
AppCompatEditText captionItemEditText;
|
TextInputEditText captionItemEditText;
|
||||||
|
|
||||||
@BindView(R.id.caption_item_edit_text_input_layout)
|
@BindView(R.id.caption_item_edit_text_input_layout)
|
||||||
TextInputLayout captionInputLayout;
|
TextInputLayout captionInputLayout;
|
||||||
|
|
||||||
|
@BindView(R.id.btn_remove)
|
||||||
|
ImageView removeButton;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
ButterKnife.bind(this, itemView);
|
ButterKnife.bind(this, itemView);
|
||||||
|
|
@ -110,6 +127,7 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
||||||
descItemEditText.setText(uploadMediaDetail.getDescriptionText());
|
descItemEditText.setText(uploadMediaDetail.getDescriptionText());
|
||||||
|
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
|
removeButton.setVisibility(View.GONE);
|
||||||
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
|
captionInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
|
||||||
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
|
captionInputLayout.setEndIconDrawable(R.drawable.mapbox_info_icon_default);
|
||||||
captionInputLayout.setEndIconOnClickListener(v ->
|
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));
|
callback.showAlert(R.string.media_detail_description, R.string.description_info));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
removeButton.setVisibility(View.VISIBLE);
|
||||||
captionInputLayout.setEndIconDrawable(null);
|
captionInputLayout.setEndIconDrawable(null);
|
||||||
descInputLayout.setEndIconDrawable(null);
|
descInputLayout.setEndIconDrawable(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position));
|
||||||
|
|
||||||
captionItemEditText.addTextChangedListener(new AbstractTextWatcher(
|
captionItemEditText.addTextChangedListener(new AbstractTextWatcher(
|
||||||
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText)));
|
captionText -> uploadMediaDetails.get(position).setCaptionText(captionText)));
|
||||||
initLanguageSpinner(position, uploadMediaDetail);
|
initLanguageSpinner(position, uploadMediaDetail);
|
||||||
|
|
@ -175,45 +196,36 @@ public class UploadMediaDetailAdapter extends RecyclerView.Adapter<UploadMediaDe
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if(description.getCaptionText().isEmpty() == false
|
if (description.getSelectedLanguageIndex() == -1) {
|
||||||
&& languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()) != -1){
|
if (!TextUtils.isEmpty(savedLanguageValue)) {
|
||||||
// If the user selects a nearby pin or location bookmark to upload a picture and language is present in spinner we set the language.
|
// If user has chosen a default language from settings activity
|
||||||
spinnerDescriptionLanguages.setSelection(languagesAdapter.getIndexOfLanguageCode(description.getLanguageCode()));
|
// savedLanguageValue is not null
|
||||||
}
|
spinnerDescriptionLanguages.setSelection(languagesAdapter
|
||||||
else {
|
.getIndexOfLanguageCode(savedLanguageValue));
|
||||||
// This is a contribution upload or the language from description is not present in spinner.
|
} else {
|
||||||
if (description.getSelectedLanguageIndex() == -1) {
|
//Checking whether Language Code attribute is null or not.
|
||||||
if (!TextUtils.isEmpty(savedLanguageValue)) {
|
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
|
||||||
// If user has chosen a default language from settings activity savedLanguageValue is not null
|
//If it is not null that means it is fetching details from the previous
|
||||||
spinnerDescriptionLanguages
|
// upload (i.e. when user has pressed copy previous caption & description)
|
||||||
.setSelection(
|
//hence providing same language code for the current upload.
|
||||||
languagesAdapter.getIndexOfLanguageCode(savedLanguageValue));
|
spinnerDescriptionLanguages.setSelection(languagesAdapter
|
||||||
|
.getIndexOfLanguageCode(uploadMediaDetails.get(position)
|
||||||
|
.getLanguageCode()), true);
|
||||||
} else {
|
} else {
|
||||||
//Checking whether Language Code attribute is null or not.
|
if (position == 0) {
|
||||||
if (uploadMediaDetails.get(position).getLanguageCode() != null) {
|
final int defaultLocaleIndex = languagesAdapter
|
||||||
//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)
|
.getIndexOfUserDefaultLocale(spinnerDescriptionLanguages
|
||||||
//hence providing same language code for the current upload.
|
.getContext());
|
||||||
spinnerDescriptionLanguages.setSelection(languagesAdapter
|
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
|
||||||
.getIndexOfLanguageCode(
|
|
||||||
uploadMediaDetails.get(position).getLanguageCode()), true);
|
|
||||||
} else {
|
} else {
|
||||||
if (position == 0) {
|
spinnerDescriptionLanguages.setSelection(0, true);
|
||||||
int defaultLocaleIndex = languagesAdapter
|
|
||||||
.getIndexOfUserDefaultLocale(
|
|
||||||
spinnerDescriptionLanguages.getContext());
|
|
||||||
spinnerDescriptionLanguages.setSelection(defaultLocaleIndex, true);
|
|
||||||
} else {
|
|
||||||
spinnerDescriptionLanguages.setSelection(0, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
spinnerDescriptionLanguages
|
|
||||||
.setSelection(description.getSelectedLanguageIndex());
|
|
||||||
selectedLanguages
|
|
||||||
.put(spinnerDescriptionLanguages, description.getLanguageCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
spinnerDescriptionLanguages.setSelection(description.getSelectedLanguageIndex());
|
||||||
|
selectedLanguages.put(spinnerDescriptionLanguages, description.getLanguageCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
UploadMediaDetail uploadMediaDetail = new UploadMediaDetail();
|
UploadMediaDetail uploadMediaDetail = new UploadMediaDetail();
|
||||||
uploadMediaDetail.setManuallyAdded(true);//This was manually added by the user
|
uploadMediaDetail.setManuallyAdded(true);//This was manually added by the user
|
||||||
uploadMediaDetailAdapter.addDescription(uploadMediaDetail);
|
uploadMediaDetailAdapter.addDescription(uploadMediaDetail);
|
||||||
rvDescriptions.scrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
|
rvDescriptions.smoothScrollToPosition(uploadMediaDetailAdapter.getItemCount()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
6
app/src/main/res/drawable/ic_remove.xml
Normal file
6
app/src/main/res/drawable/ic_remove.xml
Normal 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>
|
||||||
|
|
@ -1,53 +1,69 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:orientation="horizontal"
|
android:layout_height="wrap_content"
|
||||||
android:weightSum="8">
|
android:layout_marginHorizontal="8dp"
|
||||||
|
android:layout_marginVertical="8dp"
|
||||||
|
app:elevation="6dp">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatSpinner
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/spinner_description_languages"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginHorizontal="20dp"
|
||||||
android:layout_weight="0"
|
android:layout_marginVertical="20dp">
|
||||||
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
|
<ImageView
|
||||||
android:id="@+id/caption_item_edit_text"
|
android:id="@+id/btn_remove"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="24dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/share_caption_hint"
|
android:contentDescription="@string/remove"
|
||||||
android:imeOptions="actionNext|flagNoExtractUi"
|
android:visibility="visible"
|
||||||
android:inputType="textMultiLine"
|
app:layout_constraintBottom_toTopOf="@+id/caption_item_edit_text_input_layout"
|
||||||
android:maxLength="255" />
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
app:srcCompat="@drawable/ic_remove" />
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<Spinner
|
||||||
android:id="@+id/description_item_edit_text_input_layout"
|
android:id="@+id/spinner_description_languages"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/description_item_edit_text"
|
android:id="@+id/caption_item_edit_text_input_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/share_description_hint"
|
app:layout_constraintBottom_toTopOf="@id/description_item_edit_text_input_layout"
|
||||||
android:imeOptions="actionNext|flagNoExtractUi"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:inputType="textMultiLine" />
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
</LinearLayout>
|
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>
|
||||||
|
|
|
||||||
|
|
@ -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="media_detail_step_title">Media Details</string>
|
||||||
<string name="menu_view_category_page">View category page</string>
|
<string name="menu_view_category_page">View category page</string>
|
||||||
<string name="menu_view_item_page">View item 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>
|
<string name="read_help_link">Read more</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue