Skip to content

Commit 730f314

Browse files
Jason-WhitmoreRitikaPahwa4444nicolas-raoul
authored
Fixes Issue #6384: java.lang.NullPointerException in ReviewActivity (#6394)
* activity_review.xml: add new GUI elements to replace old ones Before this commit, the info icon shared the same GUI element with the "Skip this image" text. This made the Kotlin code to handle taps on the info icon difficult to write, and would crash with a NPE when the user used a language that is read right to left and the info icon was pressed. This commit creates new GUI elements. Notably, the info icon has it's own element. A LinearLayout is used to place the skip button and the info icon button together. Kotlin code can now be simplified and the NPE bug can be fixed. * ReviewActivity.kt: simplify info icon code to work with some languages Before this commit, if the language was set to a language that is read right to left, pressing the info icon would crash the app with a NPE. This was because the Kotlin code assumed that the icon would always be on the right of the skip button (index 2 in the drawable array). When a right to left language was used, the icon would be on the left and index 2 would be null. This commit builds upon prior GUI changes. The info icon now has its own button. Kotlin changes now remove the use of the drawable array to find the info icon and instead directly references the new info icon button. The info icon button now works properly for both left-to-right and right-to-left languages while maintaining correct positioning. * activity_review.xml: fix xml to be more readable This commit moves around some lines in the XML to make it more readable. * activity_review.xml: change button configuration This change simplifies the button configuration XML and makes the info icon button slightly smaller --------- Co-authored-by: Ritika Pahwa <83745993+RitikaPahwa4444@users.noreply.github.com> Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 81da5c9 commit 730f314

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ class ReviewActivity : BaseActivity() {
109109
setUpMediaDetailFragment()
110110
}
111111

112-
binding.skipImage.setOnTouchListener { _, event ->
113-
if (event.action == MotionEvent.ACTION_UP &&
114-
event.rawX >= (binding.skipImage.right - binding.skipImage.compoundDrawables[2].bounds.width())
115-
) {
112+
binding.skipImageInfo?.setOnTouchListener { _, event ->
113+
if (event.action == MotionEvent.ACTION_UP) {
116114
showSkipImageInfo()
117115
true
118116
} else {

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

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,35 @@
2424
android:id="@+id/toolbarBinding"
2525
layout="@layout/toolbar" />
2626

27-
28-
<androidx.appcompat.widget.AppCompatButton
29-
android:id="@+id/skip_image"
30-
style="@style/Widget.AppCompat.Button.Borderless"
31-
android:layout_width="wrap_content"
27+
<LinearLayout
28+
android:id="@+id/skip_image_layout"
29+
android:layout_width="match_parent"
3230
android:layout_height="wrap_content"
33-
android:layout_gravity="center_horizontal"
34-
android:drawableEnd="@drawable/ic_info_outline_24dp"
35-
android:drawablePadding="@dimen/medium_height"
36-
android:drawableTint="@color/button_blue_dark"
37-
android:paddingLeft="@dimen/medium_height"
38-
android:paddingRight="@dimen/medium_height"
39-
android:text="@string/skip_image"
40-
android:textAllCaps="true"
41-
android:textColor="@color/button_blue_dark"
42-
android:textStyle="bold" />
31+
android:orientation="horizontal"
32+
android:gravity="center">
33+
34+
<androidx.appcompat.widget.AppCompatButton
35+
android:id="@+id/skip_image"
36+
style="@style/Widget.AppCompat.Button.Borderless"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_gravity="center_horizontal"
40+
android:paddingHorizontal="@dimen/tiny_padding"
41+
android:text="@string/skip_image"
42+
android:textAllCaps="true"
43+
android:textColor="@color/button_blue_dark"
44+
android:textStyle="bold" />
45+
46+
<androidx.appcompat.widget.AppCompatImageButton
47+
android:id="@+id/skip_image_info"
48+
style="@style/Widget.AppCompat.Button.Borderless"
49+
android:tint="@color/button_blue_dark"
50+
android:layout_width="@dimen/half_standard_height"
51+
android:layout_height="@dimen/half_standard_height"
52+
android:layout_marginStart="@dimen/small_gap"
53+
android:src="@drawable/ic_info_outline_24dp" />
54+
55+
</LinearLayout>
4356

4457
<RelativeLayout
4558
android:layout_width="match_parent"

0 commit comments

Comments
 (0)