11package fr .free .nrw .commons .upload ;
22
33import android .content .Context ;
4- import android .graphics .drawable .Drawable ;
54import android .text .TextUtils ;
65import android .util .DisplayMetrics ;
76import android .view .LayoutInflater ;
8- import android .view .MotionEvent ;
97import android .view .View ;
108import android .view .ViewGroup ;
119import android .widget .AdapterView ;
1715import androidx .recyclerview .widget .RecyclerView ;
1816import butterknife .BindView ;
1917import butterknife .ButterKnife ;
18+ import com .google .android .material .textfield .TextInputLayout ;
2019import fr .free .nrw .commons .R ;
2120import fr .free .nrw .commons .utils .AbstractTextWatcher ;
2221import java .util .ArrayList ;
@@ -93,9 +92,15 @@ public class ViewHolder extends RecyclerView.ViewHolder {
9392 @ BindView (R .id .description_item_edit_text )
9493 AppCompatEditText descItemEditText ;
9594
95+ @ BindView (R .id .description_item_edit_text_input_layout )
96+ TextInputLayout descInputLayout ;
97+
9698 @ BindView (R .id .caption_item_edit_text )
9799 AppCompatEditText captionItemEditText ;
98100
101+ @ BindView (R .id .caption_item_edit_text_input_layout )
102+ TextInputLayout captionInputLayout ;
103+
99104 public ViewHolder (View itemView ) {
100105 super (itemView );
101106 ButterKnife .bind (this , itemView );
@@ -116,38 +121,19 @@ public void bind(int position) {
116121 }));
117122
118123 if (position == 0 ) {
119- captionItemEditText .setCompoundDrawablesWithIntrinsicBounds (null , null , getInfoIcon (),
120- null );
121- captionItemEditText .setOnTouchListener ((v , event ) -> {
122- //2 is for drawable right
123- if (event .getAction () == MotionEvent .ACTION_UP && (event .getRawX () >= (captionItemEditText .getRight () - captionItemEditText .getCompoundDrawables ()[2 ].getBounds ().width ()))) {
124- if (getAdapterPosition () == 0 ) {
125- callback .showAlert (R .string .media_detail_caption ,
126- R .string .caption_info );
127- }
128- return true ;
129- }
130- return false ;
131- });
132-
133- descItemEditText .setCompoundDrawablesWithIntrinsicBounds (null , null , getInfoIcon (),
134- null );
135- descItemEditText .setOnTouchListener ((v , event ) -> {
136- //2 is for drawable right
137- float twelveDpInPixels = convertDpToPixel (12 , descItemEditText .getContext ());
138- if (event .getAction () == MotionEvent .ACTION_UP && descItemEditText .getCompoundDrawables ()[2 ].getBounds ().contains ((int )(descItemEditText .getWidth ()-(event .getX ()+twelveDpInPixels )),(int )(event .getY ()-twelveDpInPixels ))){
139- if (getAdapterPosition () == 0 ) {
140- callback .showAlert (R .string .media_detail_description ,
141- R .string .description_info );
142- }
143- return true ;
144- }
145- return false ;
146- });
124+ captionInputLayout .setEndIconMode (TextInputLayout .END_ICON_CUSTOM );
125+ captionInputLayout .setEndIconDrawable (R .drawable .mapbox_info_icon_default );
126+ captionInputLayout .setEndIconOnClickListener (v ->
127+ callback .showAlert (R .string .media_detail_caption , R .string .caption_info ));
128+
129+ descInputLayout .setEndIconMode (TextInputLayout .END_ICON_CUSTOM );
130+ descInputLayout .setEndIconDrawable (R .drawable .mapbox_info_icon_default );
131+ descInputLayout .setEndIconOnClickListener (v ->
132+ callback .showAlert (R .string .media_detail_description , R .string .description_info ));
147133
148134 } else {
149- captionItemEditText . setCompoundDrawablesWithIntrinsicBounds ( null , null , null , null );
150- descItemEditText . setCompoundDrawablesWithIntrinsicBounds ( null , null , null , null );
135+ captionInputLayout . setEndIconDrawable ( null );
136+ descInputLayout . setEndIconDrawable ( null );
151137 }
152138
153139 captionItemEditText .addTextChangedListener (new AbstractTextWatcher (
@@ -218,15 +204,6 @@ public void onNothingSelected(AdapterView<?> adapterView) {
218204 selectedLanguages .put (spinnerDescriptionLanguages , description .getLanguageCode ());
219205 }
220206 }
221-
222- /**
223- * Extracted out the method to get the icon drawable
224- */
225- private Drawable getInfoIcon () {
226- return descItemEditText .getContext ()
227- .getResources ()
228- .getDrawable (R .drawable .mapbox_info_icon_default );
229- }
230207 }
231208
232209 public interface Callback {
0 commit comments