Skip to content

Commit 65e64ca

Browse files
authored
Merge pull request #512 from EisiBaer/master
Added artist and album below track title and made them searchable
2 parents b05adda + da9e6f6 commit 65e64ca

File tree

6 files changed

+102
-55
lines changed

6 files changed

+102
-55
lines changed

app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TracksActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ class TracksActivity : SimpleActivity() {
361361
}
362362

363363
private fun onSearchQueryChanged(text: String) {
364-
val filtered = tracksIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList<Track>
364+
val filtered = tracksIgnoringSearch.filter {
365+
it.title.contains(text, true) || ("${it.artist} - ${it.album}").contains(text, true)
366+
}.toMutableList() as ArrayList<Track>
365367
(tracks_list.adapter as? TracksAdapter)?.updateItems(filtered, text)
366368
tracks_placeholder.beGoneIf(filtered.isNotEmpty())
367369
}

app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/AlbumsTracksAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ class AlbumsTracksAdapter(
209209
track_frame?.isSelected = selectedKeys.contains(track.hashCode())
210210
track_title.text = track.title
211211
track_title.setTextColor(textColor)
212+
track_info.text = track.album
213+
track_info.setTextColor(textColor)
212214

213215
track_id.beGone()
214216
track_image.beVisible()

app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/TracksAdapter.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ class TracksAdapter(
210210
setupViewBackground(activity)
211211
track_frame?.isSelected = selectedKeys.contains(track.hashCode())
212212
track_title.text = if (textToHighlight.isEmpty()) track.title else track.title.highlightTextPart(textToHighlight, properPrimaryColor)
213+
track_info.text = if (textToHighlight.isEmpty()) {
214+
"${track.artist} - ${track.album}"
215+
} else {
216+
("${track.artist} - ${track.album}").highlightTextPart(textToHighlight, properPrimaryColor)
217+
}
213218
track_drag_handle.beVisibleIf(isPlaylistContent && selectedKeys.isNotEmpty())
214219
track_drag_handle.applyColorFilter(textColor)
215220
track_drag_handle.setOnTouchListener { v, event ->

app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/TracksHeaderAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class TracksHeaderAdapter(activity: SimpleActivity, var items: ArrayList<ListIte
166166
setupViewBackground(activity)
167167
track_frame?.isSelected = selectedKeys.contains(track.hashCode())
168168
track_title.text = track.title
169+
track_info.beGone()
169170

170171
arrayOf(track_id, track_title, track_duration).forEach {
171172
it.setTextColor(textColor)

app/src/main/kotlin/com/simplemobiletools/musicplayer/fragments/TracksFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class TracksFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
9292
}
9393

9494
override fun onSearchQueryChanged(text: String) {
95-
val filtered = tracksIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList<Track>
95+
val filtered = tracksIgnoringSearch.filter {
96+
it.title.contains(text, true) || ("${it.artist} - ${it.album}").contains(text, true)
97+
}.toMutableList() as ArrayList<Track>
9698
(tracks_list.adapter as? TracksAdapter)?.updateItems(filtered, text)
9799
tracks_placeholder.beVisibleIf(filtered.isEmpty())
98100
}

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

Lines changed: 88 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,98 @@
1111
android:paddingEnd="@dimen/medium_margin"
1212
android:paddingBottom="@dimen/activity_margin">
1313

14-
<ImageView
15-
android:id="@+id/track_image"
16-
android:layout_width="@dimen/song_image_size"
17-
android:layout_height="@dimen/song_image_size"
14+
<RelativeLayout
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent"
1817
android:layout_marginStart="@dimen/small_margin"
19-
android:visibility="gone"
20-
app:layout_constraintStart_toStartOf="parent"
21-
app:layout_constraintTop_toTopOf="parent" />
18+
app:layout_constraintEnd_toEndOf="parent">
2219

23-
<com.simplemobiletools.commons.views.MyTextView
24-
android:id="@+id/track_id"
25-
android:layout_width="wrap_content"
26-
android:layout_height="wrap_content"
27-
android:ems="2"
28-
android:gravity="end"
29-
android:paddingEnd="@dimen/small_margin"
30-
android:textSize="@dimen/bigger_text_size"
31-
app:layout_constraintBottom_toBottomOf="parent"
32-
app:layout_constraintStart_toEndOf="@+id/track_image"
33-
app:layout_constraintTop_toTopOf="parent"
34-
tools:text="1" />
20+
<ImageView
21+
android:id="@+id/track_image"
22+
android:layout_width="@dimen/song_image_size"
23+
android:layout_height="@dimen/song_image_size"
24+
android:layout_centerVertical="true"
25+
android:visibility="gone" />
3526

36-
<com.simplemobiletools.commons.views.MyTextView
37-
android:id="@+id/track_title"
38-
android:layout_width="0dp"
39-
android:layout_height="wrap_content"
40-
android:ellipsize="end"
41-
android:maxLines="2"
42-
android:paddingStart="@dimen/normal_margin"
43-
android:textSize="@dimen/bigger_text_size"
44-
app:layout_constraintBottom_toBottomOf="parent"
45-
app:layout_constraintEnd_toStartOf="@+id/track_duration"
46-
app:layout_constraintStart_toEndOf="@+id/track_id"
47-
app:layout_constraintTop_toTopOf="parent"
48-
tools:text="Track title" />
27+
<com.simplemobiletools.commons.views.MyTextView
28+
android:id="@+id/track_id"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_centerVertical="true"
32+
android:layout_toEndOf="@id/track_image"
33+
android:ems="2"
34+
android:gravity="end"
35+
android:paddingEnd="@dimen/small_margin"
36+
android:textSize="@dimen/bigger_text_size"
37+
tools:text="1" />
4938

50-
<com.simplemobiletools.commons.views.MyTextView
51-
android:id="@+id/track_duration"
52-
android:layout_width="wrap_content"
53-
android:layout_height="wrap_content"
54-
android:paddingStart="@dimen/normal_margin"
55-
android:paddingEnd="@dimen/medium_margin"
56-
android:textSize="@dimen/bigger_text_size"
57-
app:layout_constraintBottom_toBottomOf="parent"
58-
app:layout_constraintEnd_toStartOf="@+id/track_drag_handle"
59-
app:layout_constraintTop_toTopOf="parent"
60-
tools:text="3:45" />
39+
<androidx.constraintlayout.widget.ConstraintLayout
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:layout_centerVertical="true"
43+
android:layout_toStartOf="@id/layout_duration_handle"
44+
android:layout_toEndOf="@id/track_id"
45+
android:paddingStart="@dimen/normal_margin"
46+
android:paddingEnd="@dimen/normal_margin">
6147

62-
<ImageView
63-
android:id="@+id/track_drag_handle"
64-
android:layout_width="@dimen/song_image_size"
65-
android:layout_height="@dimen/song_image_size"
66-
android:padding="@dimen/medium_margin"
67-
android:src="@drawable/ic_drag_handle_vector"
68-
android:visibility="gone"
69-
app:layout_constraintBottom_toBottomOf="parent"
70-
app:layout_constraintEnd_toEndOf="parent"
71-
app:layout_constraintTop_toTopOf="parent" />
48+
<com.simplemobiletools.commons.views.MyTextView
49+
android:id="@+id/track_title"
50+
android:layout_width="0dp"
51+
android:layout_height="wrap_content"
52+
android:ellipsize="end"
53+
android:maxLines="2"
54+
android:textSize="@dimen/bigger_text_size"
55+
app:layout_constraintBottom_toTopOf="@id/track_info"
56+
app:layout_constraintStart_toStartOf="parent"
57+
app:layout_constraintTop_toTopOf="parent"
58+
tools:text="Track title" />
7259

60+
<com.simplemobiletools.commons.views.MyTextView
61+
android:id="@+id/track_info"
62+
android:layout_width="0dp"
63+
android:layout_height="wrap_content"
64+
android:alpha="0.6"
65+
android:ellipsize="end"
66+
android:maxLines="1"
67+
android:textSize="@dimen/normal_text_size"
68+
app:layout_constraintBottom_toBottomOf="parent"
69+
app:layout_constraintEnd_toEndOf="parent"
70+
app:layout_constraintStart_toStartOf="parent"
71+
app:layout_constraintTop_toBottomOf="@id/track_title"
72+
tools:text="Track artist" />
73+
74+
</androidx.constraintlayout.widget.ConstraintLayout>
75+
76+
<androidx.constraintlayout.widget.ConstraintLayout
77+
android:id="@+id/layout_duration_handle"
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:layout_alignParentEnd="true"
81+
android:layout_centerVertical="true">
82+
83+
<com.simplemobiletools.commons.views.MyTextView
84+
android:id="@+id/track_duration"
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:paddingStart="@dimen/normal_margin"
88+
android:paddingEnd="@dimen/medium_margin"
89+
android:textSize="@dimen/bigger_text_size"
90+
app:layout_constraintBottom_toBottomOf="parent"
91+
app:layout_constraintEnd_toStartOf="@id/track_drag_handle"
92+
app:layout_constraintTop_toTopOf="parent"
93+
tools:text="3:45" />
94+
95+
<ImageView
96+
android:id="@+id/track_drag_handle"
97+
android:layout_width="@dimen/song_image_size"
98+
android:layout_height="@dimen/song_image_size"
99+
android:padding="@dimen/medium_margin"
100+
android:src="@drawable/ic_drag_handle_vector"
101+
android:visibility="gone"
102+
app:layout_constraintBottom_toBottomOf="parent"
103+
app:layout_constraintEnd_toEndOf="parent"
104+
app:layout_constraintTop_toTopOf="parent" />
105+
106+
</androidx.constraintlayout.widget.ConstraintLayout>
107+
</RelativeLayout>
73108
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)