Skip to content

Commit 067c95f

Browse files
lukstbitdavid-allison
authored andcommitted
Improve note types item row view in ManageNoteTypes adapter
Changes: - the behavior is the same: row click goes to note type fields editor, click on the edit cards option goes to card template editor - the edit cards options was moved to the right, making the row similar with a toolbar with a title and two actions('Edit cards' and 'More') - the previous actions 'Remove' and 'Rename' were moved to a 'More' button which shows a popup with the two options. Rename and delete feel like actions that are not often used so it would make sense to hide them. This also makes it easier to implement multi selection when those two individual actions shouldn't be available. - use material text styles to make the ui more consistent
1 parent 2d5289d commit 067c95f

5 files changed

Lines changed: 89 additions & 83 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/notetype/NotetypeAdapter.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import android.content.Context
1919
import android.view.LayoutInflater
2020
import android.view.View
2121
import android.view.ViewGroup
22-
import android.widget.Button
22+
import android.widget.PopupMenu
2323
import android.widget.TextView
2424
import androidx.recyclerview.widget.DiffUtil
2525
import androidx.recyclerview.widget.ListAdapter
2626
import androidx.recyclerview.widget.RecyclerView
27+
import com.google.android.material.button.MaterialButton
2728
import com.ichi2.anki.R
2829

2930
private val notetypeNamesAndCountDiff =
@@ -77,17 +78,28 @@ internal class NotetypeViewHolder(
7778
) : RecyclerView.ViewHolder(rowView) {
7879
val name: TextView = rowView.findViewById(R.id.note_name)
7980
val useCount: TextView = rowView.findViewById(R.id.note_use_count)
80-
private val btnDelete: Button = rowView.findViewById(R.id.note_delete)
81-
private val btnRename: Button = rowView.findViewById(R.id.note_rename)
82-
private val btnEditCards: Button = rowView.findViewById(R.id.note_edit_cards)
81+
private val btnEditCards: MaterialButton = rowView.findViewById(R.id.note_edit_cards)
82+
private val btnMoreActions: MaterialButton = rowView.findViewById(R.id.btn_more)
8383
private var noteTypeItemState: NoteTypeItemState? = null
8484
private val resources = rowView.context.resources
8585

8686
init {
8787
rowView.setOnClickListener { noteTypeItemState?.let(onItemClick) }
8888
btnEditCards.setOnClickListener { noteTypeItemState?.let(onEditCards) }
89-
btnDelete.setOnClickListener { noteTypeItemState?.let(onDelete) }
90-
btnRename.setOnClickListener { noteTypeItemState?.let(onRename) }
89+
btnMoreActions.setOnClickListener {
90+
PopupMenu(rowView.context, btnMoreActions)
91+
.apply {
92+
inflate(R.menu.note_types_more_actions)
93+
setOnMenuItemClickListener { item ->
94+
when (item.itemId) {
95+
R.id.action_rename -> noteTypeItemState?.let(onRename)
96+
R.id.action_delete -> noteTypeItemState?.let(onDelete)
97+
else -> error("Unexpected menu item!")
98+
}
99+
true
100+
}
101+
}.show()
102+
}
91103
}
92104

93105
fun bind(state: NoteTypeItemState) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportHeight="24"
6+
android:viewportWidth="24">
7+
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M3,10h11v2H3V10zM3,8h11V6H3V8zM3,16h7v-2H3V16zM18.01,12.87l0.71,-0.71c0.39,-0.39 1.02,-0.39 1.41,0l0.71,0.71c0.39,0.39 0.39,1.02 0,1.41l-0.71,0.71L18.01,12.87zM17.3,13.58l-5.3,5.3V21h2.12l5.3,-5.3L17.3,13.58z" />
11+
12+
</vector>
Lines changed: 50 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,60 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
android:layout_width="match_parent"
66
android:layout_height="wrap_content"
7+
android:minHeight="?attr/listPreferredItemHeight"
78
android:foreground="?android:attr/selectableItemBackground"
8-
style="?cardViewStyle"
9-
android:layout_margin="8dp" >
10-
<LinearLayout
11-
android:layout_width="match_parent"
12-
android:layout_height="wrap_content"
13-
android:orientation="vertical">
14-
<LinearLayout
15-
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:orientation="vertical"
18-
android:padding="16dp">
19-
20-
<TextView
21-
android:id="@+id/note_name"
22-
tools:text="Basic (and reversed card)"
23-
android:layout_width="wrap_content"
24-
android:layout_height="wrap_content"
25-
android:textAppearance="?attr/textAppearanceHeadline6" />
26-
<TextView
27-
android:id="@+id/note_use_count"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:layout_marginTop="8dp"
31-
android:textAppearance="?attr/textAppearanceBody2"
32-
android:textColor="?android:attr/textColorSecondary"
33-
tools:text="912 notes"/>
34-
</LinearLayout>
9+
android:padding="16dp">
3510

36-
<androidx.appcompat.widget.ButtonBarLayout
37-
android:layout_width="match_parent"
38-
android:layout_height="wrap_content" >
39-
<Button
40-
android:id="@+id/note_edit_cards"
41-
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
style="@style/Widget.Material3.Button.TextButton"
44-
android:textColor="?attr/colorAccent"
45-
android:text="@string/model_browser_template"
46-
app:layout_constraintTop_toTopOf="parent"
47-
app:layout_constraintBottom_toBottomOf="parent"
48-
app:layout_constraintStart_toStartOf="parent"
49-
app:layout_constraintEnd_toStartOf="@id/note_rename"
50-
app:layout_constraintHorizontal_chainStyle="packed"
51-
app:layout_constraintHorizontal_bias="0.0" />
11+
<com.ichi2.ui.FixedTextView
12+
android:id="@+id/note_name"
13+
android:layout_width="0dp"
14+
android:layout_height="wrap_content"
15+
android:textAppearance="?attr/textAppearanceListItem"
16+
app:layout_constraintTop_toTopOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintEnd_toStartOf="@id/note_edit_cards"
19+
app:layout_constraintHorizontal_bias="0.0"
20+
tools:text="Basic (and reversed card)"
21+
/>
5222

53-
<com.google.android.material.button.MaterialButton
54-
android:id="@+id/note_rename"
55-
android:layout_width="wrap_content"
56-
android:layout_height="wrap_content"
57-
style="@style/Widget.Material3.Button.TextButton"
58-
android:textColor="?attr/colorAccent"
59-
android:text="@string/model_browser_rename"
60-
app:layout_constraintTop_toTopOf="parent"
61-
app:layout_constraintBottom_toBottomOf="parent"
62-
app:layout_constraintStart_toEndOf="@id/note_edit_cards"
63-
app:layout_constraintEnd_toStartOf="@id/spacer" />
23+
<com.ichi2.ui.FixedTextView
24+
android:id="@+id/note_use_count"
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_marginTop="8dp"
28+
android:textAppearance="?attr/textAppearanceListItemSmall"
29+
android:textColor="?android:attr/textColorSecondary"
30+
app:layout_constraintTop_toBottomOf="@id/note_name"
31+
app:layout_constraintStart_toStartOf="parent"
32+
app:layout_constraintEnd_toStartOf="@id/note_edit_cards"
33+
app:layout_constraintHorizontal_bias="0.0"
34+
app:flow_horizontalBias="0.0"
35+
tools:text="912 notes"
36+
/>
6437

65-
<android.widget.Space
66-
android:id="@+id/spacer"
67-
android:layout_width="0dp"
68-
android:layout_height="0dp"
69-
android:layout_weight="1"
70-
app:layout_constraintStart_toEndOf="@id/note_rename"
71-
app:layout_constraintEnd_toStartOf="@id/note_delete"
72-
/>
38+
<com.google.android.material.button.MaterialButton
39+
android:id="@+id/note_edit_cards"
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
app:icon="@drawable/ic_edit_note"
43+
style="@style/Widget.Material3.Button.IconButton"
44+
android:contentDescription="@string/model_browser_template"
45+
app:layout_constraintTop_toTopOf="parent"
46+
app:layout_constraintBottom_toBottomOf="parent"
47+
app:layout_constraintEnd_toStartOf="@+id/btn_more"
48+
/>
7349

74-
<com.google.android.material.button.MaterialButton
75-
android:id="@+id/note_delete"
76-
android:layout_width="wrap_content"
77-
android:layout_height="wrap_content"
78-
style="@style/Widget.Material3.Button.TextButton"
79-
android:textColor="?attr/colorAccent"
80-
android:text="@string/dialog_positive_delete"
81-
app:layout_constraintTop_toTopOf="parent"
82-
app:layout_constraintBottom_toBottomOf="parent"
83-
app:layout_constraintEnd_toEndOf="parent" />
84-
</androidx.appcompat.widget.ButtonBarLayout>
85-
</LinearLayout>
86-
</androidx.cardview.widget.CardView>
50+
<com.google.android.material.button.MaterialButton
51+
android:id="@+id/btn_more"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
app:icon="@drawable/ic_more_vertical"
55+
style="@style/Widget.Material3.Button.IconButton"
56+
app:layout_constraintTop_toTopOf="parent"
57+
app:layout_constraintBottom_toBottomOf="parent"
58+
app:layout_constraintEnd_toEndOf="parent"
59+
/>
60+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:id="@+id/action_rename"
5+
android:title="@string/rename" />
6+
<item
7+
android:id="@+id/action_delete"
8+
android:title="@string/dialog_positive_delete" />
9+
</menu>

AnkiDroid/src/main/res/values/17-model-manager.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
<!--Browser-->
3131
<string name="model_browser_delete">Delete note type</string>
32-
<string name="model_browser_rename" comment="Rename a note type">Rename</string>
3332
<string name="model_browser_template">Edit cards</string>
3433

3534

0 commit comments

Comments
 (0)