Skip to content

Commit d066412

Browse files
authored
#3680 Tip appears even when not tapping the (i) icon - use TextInputLayout EndIcons (#3683)
* #3680 Tip appears even when not tapping the (i) icon - use TextInputLayout EndIcons * #3680 Tip appears even when not tapping the (i) icon - reaorder endIcon mode call so tinting is applied
1 parent e0f1bff commit d066412

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

app/src/main/java/fr/free/nrw/commons/upload/UploadMediaDetailAdapter.java

+18-41
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package fr.free.nrw.commons.upload;
22

33
import android.content.Context;
4-
import android.graphics.drawable.Drawable;
54
import android.text.TextUtils;
65
import android.util.DisplayMetrics;
76
import android.view.LayoutInflater;
8-
import android.view.MotionEvent;
97
import android.view.View;
108
import android.view.ViewGroup;
119
import android.widget.AdapterView;
@@ -17,6 +15,7 @@
1715
import androidx.recyclerview.widget.RecyclerView;
1816
import butterknife.BindView;
1917
import butterknife.ButterKnife;
18+
import com.google.android.material.textfield.TextInputLayout;
2019
import fr.free.nrw.commons.R;
2120
import fr.free.nrw.commons.utils.AbstractTextWatcher;
2221
import 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 {

app/src/main/res/layout/row_item_description.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
android:orientation="vertical"
2020
android:layout_weight="8">
2121
<com.google.android.material.textfield.TextInputLayout
22+
android:id="@+id/caption_item_edit_text_input_layout"
2223
android:layout_width="match_parent"
2324
android:layout_height="wrap_content"
2425
>
@@ -33,6 +34,7 @@
3334
</com.google.android.material.textfield.TextInputLayout>
3435

3536
<com.google.android.material.textfield.TextInputLayout
37+
android:id="@+id/description_item_edit_text_input_layout"
3638
android:layout_width="match_parent"
3739
android:layout_height="wrap_content"
3840
>
@@ -47,4 +49,4 @@
4749
</com.google.android.material.textfield.TextInputLayout>
4850

4951
</LinearLayout>
50-
</LinearLayout>
52+
</LinearLayout>

0 commit comments

Comments
 (0)