Skip to content

Commit 7045556

Browse files
authored
Merge pull request #269 from zeze0556/master
历史播放列表按照播放时间降序排列
2 parents 5efca71 + ba3691d commit 7045556

File tree

10 files changed

+39
-9
lines changed

10 files changed

+39
-9
lines changed

app/src/main/java/remix/myplayer/db/room/dao/HistoryDao.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ interface HistoryDao {
2222

2323
@Query("""
2424
SELECT * FROM History ORDER BY
25-
CASE WHEN :asc = 1 THEN play_count END ASC,
26-
CASE WHEN :asc = 0 THEN play_count END DESC
25+
CASE :orderBY WHEN 'last_play' THEN last_play END asc,
26+
CASE :orderBY WHEN 'last_play desc' THEN last_play END desc,
27+
CASE :orderBY WHEN 'play_count' THEN play_count END asc,
28+
CASE :orderBY WHEN 'play_count desc' THEN play_count END desc
2729
""")
28-
fun selectAll(asc: Boolean): Flow<List<History>>
30+
fun selectAll(orderBY: String): Flow<List<History>>
2931

3032
@Query("""
3133
SELECT * FROM History

app/src/main/java/remix/myplayer/helper/SortOrder.kt

+2
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ object SortOrder {
2424
const val GENRE_Z_A = "${Audio.Genres.DEFAULT_SORT_ORDER} DESC"
2525
const val PLAY_COUNT = "play_count"
2626
const val PLAY_COUNT_DESC= "play_count desc"
27+
const val LASTPLAY = "last_play"
28+
const val LASTPLAY_DESC = "last_play desc"
2729
}

app/src/main/java/remix/myplayer/ui/activity/HistoryActivity.kt

+9-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class HistoryActivity : MenuActivity() {
3838
HistoryAdapter(R.layout.item_song_recycle, choice, binding.recyclerview)
3939
}
4040
private val countMap = HashMap<Long, Int>()
41+
private val last_play_map = HashMap<Long, Long>()
4142
private val choice by lazy {
4243
MultipleChoice<Song>(this, Constants.SONG)
4344
}
@@ -104,15 +105,16 @@ class HistoryActivity : MenuActivity() {
104105
private fun loadHistory() {
105106
job?.cancel()
106107
job = launch(Dispatchers.IO) {
108+
val order = SPUtil.getValue(
109+
this@HistoryActivity,
110+
SPUtil.SETTING_KEY.NAME,
111+
SPUtil.SETTING_KEY.HISTORY_SORT_ORDER,
112+
SortOrder.PLAY_COUNT_DESC
113+
)
107114
AppDatabase.getInstance(App.context.applicationContext)
108115
.historyDao()
109116
.selectAll(
110-
SPUtil.getValue(
111-
this@HistoryActivity,
112-
SPUtil.SETTING_KEY.NAME,
113-
SPUtil.SETTING_KEY.HISTORY_SORT_ORDER,
114-
SortOrder.PLAY_COUNT_DESC
115-
) != SortOrder.PLAY_COUNT_DESC
117+
order
116118
)
117119
.map {
118120
val songs = ArrayList<Song>()
@@ -121,6 +123,7 @@ class HistoryActivity : MenuActivity() {
121123
if (song != Song.EMPTY_SONG) {
122124
songs.add(song)
123125
countMap[song.id] = history.play_count
126+
last_play_map[song.id] = history.last_play
124127
}
125128
}
126129
songs

app/src/main/java/remix/myplayer/ui/activity/MenuActivity.kt

+8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ abstract class MenuActivity : ToolbarActivity() {
119119
sortOrder = SortOrder.PLAY_COUNT_DESC
120120
item.isChecked = true
121121
}
122+
R.id.action_sort_order_last_play -> {
123+
sortOrder = SortOrder.LASTPLAY
124+
item.isChecked = true
125+
}
126+
R.id.action_sort_order_last_play_desc -> {
127+
sortOrder = SortOrder.LASTPLAY_DESC
128+
item.isChecked = true
129+
}
122130
}
123131
if (!TextUtils.isEmpty(sortOrder))
124132
saveSortOrder(sortOrder)

app/src/main/res/menu/menu_history.xml

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<item
1616
android:title="@string/count_desc"
1717
android:id="@+id/action_sort_order_play_count_desc"/>
18+
<item
19+
android:title="@string/last_play"
20+
android:id="@+id/action_sort_order_last_play"/>
21+
<item
22+
android:title="@string/last_play_desc"
23+
android:id="@+id/action_sort_order_last_play_desc"/>
1824
</group>
1925
</menu>
2026
</item>

app/src/main/res/values-ja-rJP/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,5 @@
473473
<string name="connect">せつぞく</string>
474474
<string name="edit">編集</string>
475475
<string name="buffering_wait">バッファリングです,ちょっと待ってください</string>
476+
<string name="last_play">最後にプレイした</string>
476477
</resources>

app/src/main/res/values-zh-rCN/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,6 @@
475475
<string name="speed_at_2x">2x倍速播放中</string>
476476
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌词文件请确保放在公共目录中(如Downloads、Music等目录)</string>
477477
<string name="buffering_wait">缓冲中,请稍后</string>
478+
<string name="last_play">最后播放</string>
479+
<string name="last_play_desc">最后播放降序</string>
478480
</resources>

app/src/main/res/values-zh-rHK/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -474,4 +474,6 @@
474474
<string name="speed_at_2x">2x倍速播放中</string>
475475
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
476476
<string name="buffering_wait">緩衝中,請稍後</string>
477+
<string name="last_play">最後播放</string>
478+
<string name="last_play_desc">最後播放降序</string>
477479
</resources>

app/src/main/res/values-zh-rTW/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,6 @@
475475
<string name="speed_at_2x">2x倍速播放中</string>
476476
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
477477
<string name="buffering_wait">緩衝中,請稍後</string>
478+
<string name="last_play">最後播放</string>
479+
<string name="last_play_desc">最後播放降序</string>
478480
</resources>

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,6 @@
475475
<string name="speed_at_2x">Playing at 2x speed</string>
476476
<string name="local_lyric_tip">If your Android version is 11 or above, please make sure the local lyrics files are placed in the public directory (such as Downloads, Music, etc. directories)</string>
477477
<string name="buffering_wait">Buffering, please wait</string>
478+
<string name="last_play">Last Play TimeAt</string>
479+
<string name="last_play_desc">Last Play TimeAt Desc</string>
478480
</resources>

0 commit comments

Comments
 (0)