1
1
package fr .free .nrw .commons .upload ;
2
2
3
+ import android .annotation .SuppressLint ;
3
4
import android .content .Context ;
4
5
import android .graphics .drawable .Drawable ;
5
- import androidx .annotation .NonNull ;
6
- import androidx .annotation .Nullable ;
7
- import androidx .appcompat .widget .AppCompatSpinner ;
8
- import androidx .recyclerview .widget .RecyclerView ;
9
6
import android .text .TextUtils ;
10
7
import android .view .LayoutInflater ;
8
+ import android .view .MotionEvent ;
11
9
import android .view .View ;
12
10
import android .view .ViewGroup ;
13
11
import android .widget .AdapterView ;
14
12
import android .widget .AdapterView .OnItemSelectedListener ;
13
+ import android .widget .EditText ;
15
14
16
15
import java .util .ArrayList ;
17
16
import java .util .List ;
18
17
18
+ import androidx .annotation .NonNull ;
19
+ import androidx .annotation .Nullable ;
20
+ import androidx .appcompat .widget .AppCompatSpinner ;
21
+ import androidx .recyclerview .widget .RecyclerView ;
19
22
import butterknife .BindView ;
20
23
import butterknife .ButterKnife ;
21
24
import fr .free .nrw .commons .R ;
22
- import fr .free .nrw .commons .ui .widget .CustomEditText ;
23
25
import fr .free .nrw .commons .utils .AbstractTextWatcher ;
24
26
import fr .free .nrw .commons .utils .BiMap ;
25
27
import fr .free .nrw .commons .utils .ViewUtil ;
@@ -117,7 +119,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
117
119
AppCompatSpinner spinnerDescriptionLanguages ;
118
120
119
121
@ BindView (R .id .description_item_edit_text )
120
- CustomEditText descItemEditText ;
122
+ EditText descItemEditText ;
121
123
122
124
private View view ;
123
125
@@ -128,6 +130,7 @@ public ViewHolder(View itemView) {
128
130
Timber .i ("descItemEditText:" + descItemEditText );
129
131
}
130
132
133
+ @ SuppressLint ("ClickableViewAccessibility" )
131
134
public void init (int position ) {
132
135
if (position == 0 ) {
133
136
Timber .d ("Title is " + title );
@@ -150,16 +153,19 @@ public void init(int position) {
150
153
}
151
154
});
152
155
153
- descItemEditText .setDrawableClickListener (target -> {
154
- switch (target ) {
155
- case RIGHT :
156
- if (getAdapterPosition () == 0 ) {
157
- callback .showAlert (R .string .media_detail_title , R .string .title_info );
158
- }
159
- break ;
160
- default :
161
- break ;
162
- }
156
+ descItemEditText .setOnTouchListener ((v , event ) -> {
157
+ // Check this is a touch up event
158
+ if (event .getAction () != MotionEvent .ACTION_UP ) return false ;
159
+
160
+ // Check we are tapping within 15px of the info icon
161
+ int extraTapArea = 15 ;
162
+ Drawable info = descItemEditText .getCompoundDrawables ()[2 ];
163
+ int infoHitboxX = descItemEditText .getWidth () - info .getBounds ().width ();
164
+ if (event .getX () + extraTapArea < infoHitboxX ) return false ;
165
+
166
+ // If the above are true, show the info dialog
167
+ callback .showAlert (R .string .media_detail_title , R .string .title_info );
168
+ return true ;
163
169
});
164
170
165
171
} else {
@@ -170,10 +176,24 @@ public void init(int position) {
170
176
} else {
171
177
descItemEditText .setText ("" );
172
178
}
179
+
180
+ // Show the info icon for the first description
173
181
if (position == 1 ) {
174
182
descItemEditText .setCompoundDrawablesWithIntrinsicBounds (null , null , getInfoIcon (), null );
175
- } else {
176
- descItemEditText .setCompoundDrawablesWithIntrinsicBounds (null , null , null , null );
183
+ descItemEditText .setOnTouchListener ((v , event ) -> {
184
+ // Check this is a touch up event
185
+ if (event .getAction () != MotionEvent .ACTION_UP ) return false ;
186
+
187
+ // Check we are tapping within 15px of the info icon
188
+ int extraTapArea = 15 ;
189
+ Drawable info = descItemEditText .getCompoundDrawables ()[2 ];
190
+ int infoHitboxX = descItemEditText .getWidth () - info .getBounds ().width ();
191
+ if (event .getX () + extraTapArea < infoHitboxX ) return false ;
192
+
193
+ // If the above are true, show the info dialog
194
+ callback .showAlert (R .string .media_detail_description , R .string .description_info );
195
+ return true ;
196
+ });
177
197
}
178
198
179
199
descItemEditText .addTextChangedListener (new AbstractTextWatcher (descriptionText ->{
@@ -188,20 +208,6 @@ public void init(int position) {
188
208
}
189
209
});
190
210
191
-
192
- descItemEditText .setDrawableClickListener (target -> {
193
- switch (target ) {
194
- case RIGHT :
195
- if (getAdapterPosition () == 1 ) {
196
- callback .showAlert (R .string .media_detail_description ,
197
- R .string .description_info );
198
- }
199
- break ;
200
- default :
201
- break ;
202
- }
203
- });
204
-
205
211
initLanguageSpinner (position , description );
206
212
}
207
213
0 commit comments