Skip to content

Commit 2db62d7

Browse files
BrayanDSOmikehardy
authored andcommitted
refactor: replace ConstraintLayouts in reviewer2.xml
They were initially used because of the WIP nature of the reviewer, so they would be able to handle any design decisions Now that most of the reviewer is implemented, I don't see a need for using ConstraintLayouts anymore, so I am replacing them with LinearLayouts LinearLayouts are simpler to deal with, have less boilerplate, and make easier to preview changes. They also render faster
1 parent 3414c0b commit 2db62d7

File tree

3 files changed

+32
-51
lines changed

3 files changed

+32
-51
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import android.view.inputmethod.EditorInfo
2727
import android.view.inputmethod.InputMethodManager
2828
import android.webkit.WebView
2929
import android.widget.FrameLayout
30+
import android.widget.LinearLayout
3031
import androidx.activity.result.contract.ActivityResultContracts
3132
import androidx.annotation.StringRes
3233
import androidx.appcompat.view.menu.SubMenuBuilder
3334
import androidx.appcompat.widget.ActionMenuView
34-
import androidx.constraintlayout.widget.ConstraintLayout
3535
import androidx.core.content.getSystemService
3636
import androidx.core.view.ViewCompat
3737
import androidx.core.view.WindowInsetsCompat
@@ -298,7 +298,7 @@ class ReviewerFragment :
298298
viewModel.onShowAnswer(typedAnswer = typedAnswer)
299299
}
300300
}
301-
val answerButtonsLayout = view.findViewById<ConstraintLayout>(R.id.answer_buttons)
301+
val answerButtonsLayout = view.findViewById<LinearLayout>(R.id.answer_buttons)
302302

303303
// TODO add some kind of feedback/animation after tapping show answer or the answer buttons
304304
viewModel.showingAnswer.collectLatestIn(lifecycleScope) { shouldShowAnswer ->

AnkiDroid/src/main/res/layout/reviewer2.xml

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
android:fitsSystemWindows="true"
1010
tools:context=".ui.windows.reviewer.ReviewerFragment">
1111

12-
<androidx.constraintlayout.widget.ConstraintLayout
12+
<LinearLayout
1313
android:layout_width="match_parent"
1414
android:layout_height="match_parent"
15-
android:layout_marginBottom="4dp">
15+
android:layout_marginBottom="4dp"
16+
android:orientation="vertical">
1617

1718
<com.google.android.material.appbar.AppBarLayout
1819
android:id="@+id/appbar"
1920
android:layout_width="match_parent"
2021
android:layout_height="wrap_content"
21-
app:layout_constraintTop_toTopOf="parent">
22+
>
2223

2324
<com.google.android.material.appbar.MaterialToolbar
2425
android:id="@+id/toolbar"
2526
app:navigationIcon="?attr/homeAsUpIndicator"
2627
app:navigationContentDescription="@string/abc_action_bar_up_description"
2728
android:layout_width="match_parent"
28-
app:layout_constraintTop_toTopOf="parent"
2929
android:layout_height="?attr/actionBarSize"
3030
android:background="?attr/alternativeBackgroundColor"
3131
>
@@ -71,29 +71,24 @@
7171
android:id="@+id/webview_container"
7272
android:layout_width="match_parent"
7373
android:layout_height="0dp"
74-
android:layout_marginHorizontal="8dp"
74+
android:layout_marginHorizontal="@dimen/reviewer_side_margin"
7575
android:layout_marginBottom="4dp"
76-
app:layout_constraintTop_toBottomOf="@id/appbar"
77-
app:layout_constraintBottom_toTopOf="@id/type_answer_container"
78-
style="@style/CardView.ViewerStyle">
76+
style="@style/CardView.ViewerStyle"
77+
android:layout_weight="1">
7978

8079
<WebView
8180
android:id="@+id/webview"
8281
android:layout_width="match_parent"
83-
android:layout_height="match_parent">
84-
</WebView>
82+
android:layout_height="match_parent"/>
8583

8684
</com.google.android.material.card.MaterialCardView>
8785

8886
<!-- Use the same card style of the WebView -->
8987
<com.google.android.material.card.MaterialCardView
9088
android:id="@+id/type_answer_container"
91-
android:layout_width="0dp"
89+
android:layout_width="match_parent"
9290
android:layout_height="wrap_content"
93-
app:layout_constraintStart_toStartOf="@id/webview_container"
94-
app:layout_constraintEnd_toEndOf="@id/webview_container"
95-
app:layout_constraintTop_toBottomOf="@id/webview_container"
96-
app:layout_constraintBottom_toTopOf="@id/buttons_area"
91+
android:layout_marginHorizontal="8dp"
9792
style="@style/CardView.ViewerStyle"
9893
android:layout_marginTop="4dp"
9994
android:layout_marginBottom="8dp"
@@ -120,17 +115,12 @@
120115

121116
</com.google.android.material.card.MaterialCardView>
122117

123-
124-
125118
<FrameLayout
126119
android:id="@+id/buttons_area"
127-
android:layout_width="0dp"
120+
android:layout_width="match_parent"
128121
android:layout_height="@dimen/touch_target"
129122
android:layout_marginTop="2dp"
130-
app:layout_constraintBottom_toBottomOf="parent"
131-
app:layout_constraintEnd_toEndOf="@id/webview_container"
132-
app:layout_constraintStart_toStartOf="@id/webview_container"
133-
app:layout_constraintTop_toBottomOf="@id/type_answer_container"
123+
android:layout_marginHorizontal="@dimen/reviewer_side_margin"
134124
>
135125

136126
<com.google.android.material.button.MaterialButton
@@ -143,7 +133,7 @@
143133
tools:visibility="gone"
144134
/>
145135

146-
<androidx.constraintlayout.widget.ConstraintLayout
136+
<LinearLayout
147137
android:id="@+id/answer_buttons"
148138
android:layout_width="match_parent"
149139
android:layout_height="match_parent"
@@ -154,64 +144,52 @@
154144
<com.google.android.material.button.MaterialButton
155145
android:id="@+id/again_button"
156146
android:layout_width="0dp"
157-
android:layout_height="0dp"
147+
android:layout_height="match_parent"
158148
android:text="@string/ease_button_again"
159149
android:backgroundTint="@color/again_button_bg"
160150
android:textColor="@color/again_button_text"
161-
android:layout_marginHorizontal="3dp"
162-
app:layout_constraintTop_toTopOf="parent"
163-
app:layout_constraintBottom_toBottomOf="parent"
164-
app:layout_constraintStart_toStartOf="parent"
165-
app:layout_constraintEnd_toStartOf="@id/hard_button"
151+
android:layout_marginEnd="@dimen/answer_button_margin_horizontal"
166152
style="@style/AnswerButton"
153+
android:layout_weight="1"
167154
/>
168155

169156
<com.google.android.material.button.MaterialButton
170157
android:id="@+id/hard_button"
171158
android:layout_width="0dp"
172-
android:layout_height="0dp"
159+
android:layout_height="match_parent"
173160
android:text="@string/ease_button_hard"
174161
android:backgroundTint="@color/hard_button_bg"
175162
android:textColor="@color/hard_button_text"
176-
android:layout_marginHorizontal="3dp"
177-
app:layout_constraintTop_toTopOf="parent"
178-
app:layout_constraintBottom_toBottomOf="parent"
179-
app:layout_constraintStart_toEndOf="@id/again_button"
180-
app:layout_constraintEnd_toStartOf="@id/good_button"
163+
android:layout_marginHorizontal="@dimen/answer_button_margin_horizontal"
181164
style="@style/AnswerButton"
165+
android:layout_weight="1"
182166
/>
183167

184168
<com.google.android.material.button.MaterialButton
185169
android:id="@+id/good_button"
186170
android:layout_width="0dp"
187-
android:layout_height="0dp"
171+
android:layout_height="match_parent"
188172
android:text="@string/ease_button_good"
189173
android:backgroundTint="@color/good_button_bg"
190174
android:textColor="@color/good_button_text"
191-
android:layout_marginHorizontal="3dp"
192-
app:layout_constraintTop_toTopOf="parent"
193-
app:layout_constraintBottom_toBottomOf="parent"
194-
app:layout_constraintStart_toEndOf="@id/hard_button"
195-
app:layout_constraintEnd_toStartOf="@id/easy_button"
175+
android:layout_marginHorizontal="@dimen/answer_button_margin_horizontal"
196176
style="@style/AnswerButton"
177+
android:layout_weight="1"
197178
/>
198179

199180
<com.google.android.material.button.MaterialButton
200181
android:id="@+id/easy_button"
201182
android:layout_width="0dp"
202-
android:layout_height="0dp"
183+
android:layout_height="match_parent"
203184
android:padding="0dp"
204185
android:text="@string/ease_button_easy"
205186
android:backgroundTint="@color/easy_button_bg"
206187
android:textColor="@color/easy_button_text"
207-
android:layout_marginHorizontal="3dp"
208-
app:layout_constraintTop_toTopOf="parent"
209-
app:layout_constraintBottom_toBottomOf="parent"
210-
app:layout_constraintStart_toEndOf="@id/good_button"
211-
app:layout_constraintEnd_toEndOf="parent"
188+
android:layout_marginStart="@dimen/answer_button_margin_horizontal"
212189
style="@style/AnswerButton"
190+
android:layout_weight="1"
213191
/>
214-
</androidx.constraintlayout.widget.ConstraintLayout>
192+
</LinearLayout>
215193
</FrameLayout>
216-
</androidx.constraintlayout.widget.ConstraintLayout>
194+
</LinearLayout>
217195
</androidx.coordinatorlayout.widget.CoordinatorLayout>

AnkiDroid/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@
3333
<dimen name="mtrl_snackbar_background_corner_radius">8dp</dimen>
3434
<dimen name="popup_corner_radius">8dp</dimen>
3535
<dimen name="dialog_corner_radius">8dp</dimen>
36+
37+
<dimen name="reviewer_side_margin">8dp</dimen>
38+
<dimen name="answer_button_margin_horizontal">3dp</dimen>
3639
</resources>

0 commit comments

Comments
 (0)