@@ -36,7 +36,6 @@ import android.os.Bundle
3636import android.os.CountDownTimer
3737import android.os.Handler
3838import android.os.Looper
39- import android.util.Log
4039import android.view.View
4140import android.view.View.GONE
4241import android.view.View.VISIBLE
@@ -78,12 +77,9 @@ import org.akanework.symphonica.logic.service.SymphonicaPlayerService
7877import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.OPERATION_PAUSE
7978import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.OPERATION_PLAY
8079import 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
8380import org.akanework.symphonica.logic.service.SymphonicaPlayerService.Companion.updateMetadata
8481import org.akanework.symphonica.logic.util.broadcastMetaDataUpdate
8582import org.akanework.symphonica.logic.util.broadcastPlayPaused
86- import org.akanework.symphonica.logic.util.broadcastPlayStopped
8783import org.akanework.symphonica.logic.util.broadcastSliderSeek
8884import org.akanework.symphonica.logic.util.convertDurationToTimeStamp
8985import 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 }
0 commit comments