Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.

Commit b52d4a8

Browse files
committed
Symphonica: Fixed timer and remove now playing badge on full player
Signed-off-by: Shinjo Akane <[email protected]>
1 parent a567827 commit b52d4a8

File tree

8 files changed

+46
-135
lines changed

8 files changed

+46
-135
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
minSdk 29
1616
targetSdk 34
1717
versionCode 5
18-
versionName "0.5.9"
18+
versionName "0.5.9.indev"
1919
}
2020

2121
buildTypes {

app/src/main/java/org/akanework/symphonica/MainActivity.kt

Lines changed: 32 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import android.os.Bundle
3636
import android.os.CountDownTimer
3737
import android.os.Handler
3838
import android.os.Looper
39-
import android.util.Log
4039
import android.view.View
4140
import android.view.View.GONE
4241
import android.view.View.VISIBLE
@@ -78,12 +77,9 @@ import org.akanework.symphonica.logic.service.SymphonicaPlayerService
7877
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.OPERATION_PAUSE
7978
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.OPERATION_PLAY
8079
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.setPlaybackState
81-
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.timer
82-
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.timerValue
8380
import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.updateMetadata
8481
import org.akanework.symphonica.logic.util.broadcastMetaDataUpdate
8582
import org.akanework.symphonica.logic.util.broadcastPlayPaused
86-
import org.akanework.symphonica.logic.util.broadcastPlayStopped
8783
import org.akanework.symphonica.logic.util.broadcastSliderSeek
8884
import org.akanework.symphonica.logic.util.convertDurationToTimeStamp
8985
import org.akanework.symphonica.logic.util.nextSong
@@ -153,7 +149,6 @@ class MainActivity : AppCompatActivity() {
153149
private lateinit var fullSheetArtist: TextView
154150
private lateinit var fullSheetAlbum: TextView
155151
private lateinit var fullSheetDuration: TextView
156-
private lateinit var fullSheetLocation: TextView
157152
private lateinit var fullSheetTimeStamp: TextView
158153
private lateinit var bottomSheetControlButton: MaterialButton
159154
private lateinit var fullSheetControlButton: MaterialButton
@@ -320,7 +315,6 @@ class MainActivity : AppCompatActivity() {
320315
val fullSheetBackButton = findViewById<MaterialButton>(R.id.sheet_extract_player)
321316
val fullSheetNextButton = findViewById<MaterialButton>(R.id.sheet_next_song)
322317
val fullSheetPrevButton = findViewById<MaterialButton>(R.id.sheet_previous_song)
323-
val fullSheetSongInfo = findViewById<MaterialButton>(R.id.sheet_song_info)
324318

325319
fragmentContainerView = findViewById(R.id.fragmentContainer)
326320
navigationView = findViewById(R.id.navigation_view)
@@ -333,7 +327,6 @@ class MainActivity : AppCompatActivity() {
333327
fullSheetAlbum = findViewById(R.id.sheet_album)
334328
fullSheetLoopButton = findViewById(R.id.sheet_loop)
335329
fullSheetShuffleButton = findViewById(R.id.sheet_random)
336-
fullSheetLocation = findViewById(R.id.sheet_song_location)
337330
fullSheetControlButton = findViewById(R.id.sheet_mid_button)
338331
fullSheetSlider = findViewById(R.id.sheet_slider)
339332
fullSheetSquigglyView = findViewById(R.id.squiggly)
@@ -376,9 +369,7 @@ class MainActivity : AppCompatActivity() {
376369
})
377370

378371
// The behavior of the global sheet starts here.
379-
if (timer == null) {
380-
fullSheetTimerButton.isChecked = false
381-
}
372+
fullSheetTimerButton.isChecked = playlistViewModel.timer != null
382373

383374
playerBottomSheetBehavior.isHideable = false
384375

@@ -522,7 +513,7 @@ class MainActivity : AppCompatActivity() {
522513
bottomPlayerPreview.visibility = VISIBLE
523514
}
524515

525-
fullSheetSongInfo.setOnClickListener {
516+
findViewById<ImageView>(R.id.sheet_cover).setOnLongClickListener {
526517
val rootView = MaterialAlertDialogBuilder(
527518
this,
528519
com.google.android.material.R.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
@@ -555,6 +546,8 @@ class MainActivity : AppCompatActivity() {
555546
dialogAlbum.setText(song.album)
556547
}
557548
}
549+
550+
true
558551
}
559552

560553
playlistButton.setOnClickListener {
@@ -590,7 +583,7 @@ class MainActivity : AppCompatActivity() {
590583
playerBottomSheetBehavior.addBottomSheetCallback(bottomSheetCallback)
591584

592585
fullSheetTimerButton.setOnClickListener {
593-
if (timer != null) {
586+
if (playlistViewModel.timer != null) {
594587
fullSheetTimerButton.isChecked = true
595588
}
596589
if (musicPlayer != null) {
@@ -600,44 +593,48 @@ class MainActivity : AppCompatActivity() {
600593
)
601594
.setTitle(getString(R.string.dialog_timer_title))
602595
.setView(R.layout.alert_dialog_timer)
596+
.setNeutralButton(getString(R.string.dialog_song_dismiss)) { dialog, _ ->
597+
dialog.dismiss()
598+
}
603599
.setOnDismissListener {
604-
if (timer == null) {
600+
if (playlistViewModel.timer == null) {
605601
fullSheetTimerButton.isChecked = false
606602
}
607603
}
608604
.show()
609605
val rangeSlider = rootView.findViewById<Slider>(R.id.timer_slider)!!
610-
if (timer != null)
611-
rangeSlider.value = timerValue
606+
if (playlistViewModel.timer != null) {
607+
rangeSlider.value = playlistViewModel.timerValue
608+
}
612609
rangeSlider.addOnSliderTouchListener(object : Slider.OnSliderTouchListener {
613610
override fun onStartTrackingTouch(slider: Slider) {
614611
// Keep this empty
615612
}
616613

617614
override fun onStopTrackingTouch(slider: Slider) {
618615
if (rangeSlider.value != 0f) {
619-
if (timerValue != 0f) {
620-
timer?.cancel()
621-
timer = null
622-
timerValue = 0f
616+
if (playlistViewModel.timerValue != 0f) {
617+
playlistViewModel.timer?.cancel()
618+
playlistViewModel.timer = null
619+
playlistViewModel.timerValue = 0f
623620
}
624-
timerValue = rangeSlider.value
625-
timer = object : CountDownTimer((rangeSlider.value * 3600 * 1000).toLong(), 1000) {
621+
playlistViewModel.timerValue = rangeSlider.value
622+
playlistViewModel.timer = object : CountDownTimer((rangeSlider.value * 3600 * 1000).toLong(), 1000) {
626623
override fun onTick(millisUntilFinished: Long) {
627624
}
628625

629626
override fun onFinish() {
630627
musicPlayer?.pause()
631628
broadcastPlayPaused()
632629
broadcastMetaDataUpdate()
633-
timerValue = 0f
630+
playlistViewModel.timerValue = 0f
634631
}
635632
}
636-
(timer as CountDownTimer).start()
633+
(playlistViewModel.timer as CountDownTimer).start()
637634
} else {
638-
timer?.cancel()
639-
timer = null
640-
timerValue = 0f
635+
playlistViewModel.timer?.cancel()
636+
playlistViewModel.timer = null
637+
playlistViewModel.timerValue = 0f
641638
}
642639
}
643640
})
@@ -833,8 +830,7 @@ class MainActivity : AppCompatActivity() {
833830
* It receives a broadcast from [receiverPlay] and involves
834831
* changes of various UI components including:
835832
* [bottomSheetSongName], [bottomSheetArtistAndAlbum],
836-
* [fullSheetSongName], [fullSheetAlbum], [fullSheetArtist],
837-
* [fullSheetLocation].
833+
* [fullSheetSongName], [fullSheetAlbum], [fullSheetArtist].
838834
* It also uses [updateAlbumView].
839835
*/
840836
inner class SheetPlayReceiver : BroadcastReceiver() {
@@ -860,22 +856,6 @@ class MainActivity : AppCompatActivity() {
860856
convertDurationToTimeStamp(
861857
playlistViewModel.playList[playlistViewModel.currentLocation].duration.toString()
862858
)
863-
// If you don't use a round bracket here the ViewModel would die from +1s.
864-
if (playlistViewModel.playList.size > 1) {
865-
fullSheetLocation.text =
866-
getString(
867-
R.string.full_sheet_playlist_location,
868-
((playlistViewModel.currentLocation) + 1).toString(),
869-
playlistViewModel.playList.size.toString()
870-
)
871-
} else {
872-
fullSheetLocation.text =
873-
getString(
874-
R.string.full_sheet_playlist_location_single,
875-
((playlistViewModel.currentLocation) + 1).toString(),
876-
playlistViewModel.playList.size.toString()
877-
)
878-
}
879859

880860
bottomSheetControlButton.icon =
881861
ContextCompat.getDrawable(SymphonicaApplication.context, R.drawable.ic_pause)
@@ -909,8 +889,8 @@ class MainActivity : AppCompatActivity() {
909889
if (musicPlayer != null) {
910890
updateMetadata()
911891
}
912-
timer?.cancel()
913-
timer = null
892+
playlistViewModel.timer?.cancel()
893+
playlistViewModel.timer = null
914894
fullSheetTimerButton.isChecked = false
915895
}
916896
}
@@ -930,12 +910,12 @@ class MainActivity : AppCompatActivity() {
930910
if (musicPlayer != null) {
931911
updateMetadata()
932912
}
933-
if (timer == null) {
913+
if (playlistViewModel.timer == null) {
934914
fullSheetTimerButton.isChecked = false
935-
} else if (timerValue == 0f) {
915+
} else if (playlistViewModel.timerValue == 0f) {
936916
fullSheetTimerButton.isChecked = false
937-
timer!!.cancel()
938-
timer = null
917+
playlistViewModel.timer!!.cancel()
918+
playlistViewModel.timer = null
939919
}
940920
}
941921
}
@@ -956,8 +936,7 @@ class MainActivity : AppCompatActivity() {
956936
* It receives a broadcast from [receiverUpdate] and involves
957937
* changes of various UI components including:
958938
* [bottomSheetSongName], [bottomSheetArtistAndAlbum],
959-
* [fullSheetSongName], [fullSheetAlbum], [fullSheetArtist],
960-
* [fullSheetLocation].
939+
* [fullSheetSongName], [fullSheetAlbum], [fullSheetArtist].
961940
* This receiver is used when resuming the activity.
962941
*/
963942
inner class SheetUpdateReceiver : BroadcastReceiver() {
@@ -981,22 +960,6 @@ class MainActivity : AppCompatActivity() {
981960
convertDurationToTimeStamp(
982961
playlistViewModel.playList[playlistViewModel.currentLocation].duration.toString()
983962
)
984-
// If you don't use a round bracket here the ViewModel would die from +1s.
985-
if (playlistViewModel.playList.size > 1) {
986-
fullSheetLocation.text =
987-
getString(
988-
R.string.full_sheet_playlist_location,
989-
((playlistViewModel.currentLocation) + 1).toString(),
990-
playlistViewModel.playList.size.toString()
991-
)
992-
} else {
993-
fullSheetLocation.text =
994-
getString(
995-
R.string.full_sheet_playlist_location_single,
996-
((playlistViewModel.currentLocation) + 1).toString(),
997-
playlistViewModel.playList.size.toString()
998-
)
999-
}
1000963

1001964
if (musicPlayer!!.isPlaying) {
1002965
bottomSheetControlButton.icon =
@@ -1029,17 +992,8 @@ class MainActivity : AppCompatActivity() {
1029992
convertDurationToTimeStamp(
1030993
playlistViewModel.playList[playlistViewModel.currentLocation].duration.toString()
1031994
)
1032-
// If you don't use a round bracket here the ViewModel would die from +1s.
1033-
fullSheetLocation.text =
1034-
getString(
1035-
R.string.full_sheet_playlist_location,
1036-
((playlistViewModel.currentLocation) + 1).toString(),
1037-
playlistViewModel.playList.size.toString()
1038-
)
1039-
updateAlbumView(this@MainActivity.findViewById(R.id.global_bottom_sheet))
1040-
updateMetadata()
1041995
}
1042-
if (timer == null) {
996+
if (playlistViewModel.timer == null) {
1043997
fullSheetTimerButton.isChecked = false
1044998
}
1045999
}

app/src/main/java/org/akanework/symphonica/logic/service/SymphonicaPlayerService.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,6 @@ class SymphonicaPlayerService : Service(), MediaPlayer.OnPreparedListener {
471471
.build()
472472
lateinit var playbackStateBuilder: PlaybackState.Builder
473473

474-
var timer: CountDownTimer? = null
475-
var timerValue: Float = 0f
476-
477474
/**
478475
* [setPlaybackState] sets the playback state of the
479476
* media control notification.

app/src/main/java/org/akanework/symphonica/ui/viewmodel/PlaylistViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.akanework.symphonica.ui.viewmodel
1919

20+
import android.os.CountDownTimer
2021
import androidx.lifecycle.ViewModel
2122
import org.akanework.symphonica.MainActivity.Companion.playlistDatabase
2223
import org.akanework.symphonica.logic.data.PlaylistDataEntity
@@ -36,6 +37,8 @@ class PlaylistViewModel : ViewModel() {
3637
var originalPlaylist = mutableListOf<Song>()
3738
var currentLocation: Int = 0
3839
val playlistList: MutableList<PlaylistDataEntity> = mutableListOf()
40+
var timer: CountDownTimer? = null
41+
var timerValue: Float = 0f
3942

4043
/**
4144
* @param name

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent"
21+
xmlns:app="http://schemas.android.com/apk/res-auto"
2122
android:orientation="vertical">
2223

2324
<com.google.android.material.slider.Slider
@@ -29,6 +30,7 @@
2930
android:layout_marginTop="8dp"
3031
android:valueFrom="0"
3132
android:valueTo="2.0"
32-
android:stepSize="0.5" />
33+
android:stepSize="0.5"
34+
app:labelBehavior="floating"/>
3335

3436
</LinearLayout>

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

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,8 @@
6969
app:iconGravity="textStart"
7070
app:iconPadding="0dp"
7171
app:iconSize="30sp"
72-
app:iconTint="?attr/colorControlNormal" />
73-
74-
<LinearLayout
75-
android:layout_width="wrap_content"
76-
android:layout_height="48dp"
77-
android:layout_marginStart="16dp"
78-
android:orientation="vertical">
79-
80-
<TextView
81-
android:layout_width="wrap_content"
82-
android:layout_height="24dp"
83-
android:text="@string/sheet_now_playing"
84-
android:textColor="?attr/colorOnSurface"
85-
android:textSize="18sp"
86-
android:textStyle="bold" />
87-
88-
<TextView
89-
android:id="@+id/sheet_song_location"
90-
android:layout_width="wrap_content"
91-
android:layout_height="24dp"
92-
android:text="@string/unknown_song"
93-
android:textColor="?attr/colorOnSurfaceVariant"
94-
android:textSize="14sp" />
95-
</LinearLayout>
96-
</LinearLayout>
97-
98-
<LinearLayout
99-
android:layout_width="wrap_content"
100-
android:layout_height="48dp"
101-
android:layout_gravity="end">
102-
103-
<com.google.android.material.button.MaterialButton
104-
android:id="@+id/sheet_song_info"
105-
android:layout_width="48dp"
106-
android:layout_height="48dp"
107-
android:backgroundTint="?attr/colorSurface"
108-
android:elevation="0dp"
109-
android:insetLeft="0dp"
110-
android:insetTop="0dp"
111-
android:insetRight="0dp"
112-
android:insetBottom="0dp"
113-
app:icon="@drawable/ic_more_vert"
114-
app:iconGravity="textStart"
115-
app:iconPadding="0dp"
116-
app:iconSize="30sp"
11772
app:iconTint="?attr/colorOnSurface" />
73+
11874
</LinearLayout>
11975

12076
</FrameLayout>
@@ -134,7 +90,7 @@
13490
app:layout_constraintEnd_toEndOf="parent"
13591
app:layout_constraintStart_toStartOf="parent"
13692
app:layout_constraintTop_toTopOf="parent"
137-
style="?attr/materialCardViewElevatedStyle">
93+
app:strokeWidth="0dp">
13894

13995
<ImageView
14096
android:layout_width="match_parent"

0 commit comments

Comments
 (0)