1
1
package fr .free .nrw .commons .upload ;
2
2
3
3
import android .content .Context ;
4
- import android .graphics .drawable .Drawable ;
5
4
import android .text .TextUtils ;
6
5
import android .util .DisplayMetrics ;
7
6
import android .view .LayoutInflater ;
8
- import android .view .MotionEvent ;
9
7
import android .view .View ;
10
8
import android .view .ViewGroup ;
11
9
import android .widget .AdapterView ;
17
15
import androidx .recyclerview .widget .RecyclerView ;
18
16
import butterknife .BindView ;
19
17
import butterknife .ButterKnife ;
18
+ import com .google .android .material .textfield .TextInputLayout ;
20
19
import fr .free .nrw .commons .R ;
21
20
import fr .free .nrw .commons .utils .AbstractTextWatcher ;
22
21
import java .util .ArrayList ;
@@ -93,9 +92,15 @@ public class ViewHolder extends RecyclerView.ViewHolder {
93
92
@ BindView (R .id .description_item_edit_text )
94
93
AppCompatEditText descItemEditText ;
95
94
95
+ @ BindView (R .id .description_item_edit_text_input_layout )
96
+ TextInputLayout descInputLayout ;
97
+
96
98
@ BindView (R .id .caption_item_edit_text )
97
99
AppCompatEditText captionItemEditText ;
98
100
101
+ @ BindView (R .id .caption_item_edit_text_input_layout )
102
+ TextInputLayout captionInputLayout ;
103
+
99
104
public ViewHolder (View itemView ) {
100
105
super (itemView );
101
106
ButterKnife .bind (this , itemView );
@@ -116,38 +121,19 @@ public void bind(int position) {
116
121
}));
117
122
118
123
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 ));
147
133
148
134
} else {
149
- captionItemEditText . setCompoundDrawablesWithIntrinsicBounds ( null , null , null , null );
150
- descItemEditText . setCompoundDrawablesWithIntrinsicBounds ( null , null , null , null );
135
+ captionInputLayout . setEndIconDrawable ( null );
136
+ descInputLayout . setEndIconDrawable ( null );
151
137
}
152
138
153
139
captionItemEditText .addTextChangedListener (new AbstractTextWatcher (
@@ -218,15 +204,6 @@ public void onNothingSelected(AdapterView<?> adapterView) {
218
204
selectedLanguages .put (spinnerDescriptionLanguages , description .getLanguageCode ());
219
205
}
220
206
}
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
- }
230
207
}
231
208
232
209
public interface Callback {
0 commit comments