diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt index 65abcc53..dcd7c193 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -7,16 +7,12 @@ import android.graphics.drawable.ColorDrawable import android.media.AudioManager import android.net.Uri import android.os.Bundle -import android.provider.MediaStore import android.view.Menu import android.view.MenuItem import androidx.appcompat.widget.SearchView +import androidx.core.content.ContextCompat import androidx.core.view.MenuItemCompat import androidx.viewpager.widget.ViewPager -import com.bumptech.glide.Glide -import com.bumptech.glide.load.resource.bitmap.CenterCrop -import com.bumptech.glide.load.resource.bitmap.RoundedCorners -import com.bumptech.glide.request.RequestOptions import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.NewAppsIconsDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog @@ -40,6 +36,7 @@ import com.simplemobiletools.musicplayer.models.Events import com.simplemobiletools.musicplayer.models.Playlist import com.simplemobiletools.musicplayer.services.MusicService import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.activity_main.view.* import kotlinx.android.synthetic.main.fragment_songs.* import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -207,6 +204,12 @@ class MainActivity : SimpleActivity(), MainActivityInterface { initFragments() initializePlayer() + + current_track_holder.setOnClickListener { + Intent(this, TrackActivity::class.java).apply { + startActivity(this) + } + } } private fun initFragments() { @@ -255,39 +258,8 @@ class MainActivity : SimpleActivity(), MainActivityInterface { } private fun updateCurrentTrackBar() { - current_track_holder.background = ColorDrawable(config.backgroundColor) - current_track_label.setTextColor(config.textColor) - - val track = MusicService.mCurrTrack - if (track == null) { - current_track_holder.beGone() - return - } else { - current_track_holder.beVisible() - } - - val artist = if (track.artist.trim().isNotEmpty() && track.artist != MediaStore.UNKNOWN_STRING) { - " • ${track.artist}" - } else { - "" - } - - current_track_label.text = "${track.title}$artist" - val currentTrackPlaceholder = resources.getColoredDrawableWithColor(R.drawable.ic_headset, config.textColor) - val options = RequestOptions() - .error(currentTrackPlaceholder) - .transform(CenterCrop(), RoundedCorners(8)) - - Glide.with(this) - .load(track.coverArt) - .apply(options) - .into(findViewById(R.id.current_track_image)) - - current_track_holder.setOnClickListener { - Intent(this, TrackActivity::class.java).apply { - startActivity(this) - } - } + current_track_holder.updateColors() + current_track_holder.updateCurrentTrack(MusicService.mCurrTrack) } private fun showSleepTimer() { @@ -510,7 +482,7 @@ class MainActivity : SimpleActivity(), MainActivityInterface { getCurrentFragment()?.songChangedEvent(event.track) } - updateCurrentTrackBar() + current_track_holder.updateCurrentTrack(event.track) } @Subscribe(threadMode = ThreadMode.MAIN) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/views/CurrentTrackBar.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/views/CurrentTrackBar.kt new file mode 100644 index 00000000..fdb833ea --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/views/CurrentTrackBar.kt @@ -0,0 +1,51 @@ +package com.simplemobiletools.musicplayer.views + +import android.content.Context +import android.graphics.drawable.ColorDrawable +import android.provider.MediaStore +import android.util.AttributeSet +import android.widget.RelativeLayout +import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.bitmap.CenterCrop +import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.bumptech.glide.request.RequestOptions +import com.simplemobiletools.commons.extensions.beGone +import com.simplemobiletools.commons.extensions.beVisible +import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor +import com.simplemobiletools.musicplayer.R +import com.simplemobiletools.musicplayer.extensions.config +import com.simplemobiletools.musicplayer.models.Track +import kotlinx.android.synthetic.main.activity_main.view.* + +class CurrentTrackBar(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) { + fun updateColors() { + background = ColorDrawable(context.config.backgroundColor) + current_track_label.setTextColor(context.config.textColor) + } + + fun updateCurrentTrack(track: Track?) { + if (track == null) { + beGone() + return + } else { + beVisible() + } + + val artist = if (track.artist.trim().isNotEmpty() && track.artist != MediaStore.UNKNOWN_STRING) { + " • ${track.artist}" + } else { + "" + } + + current_track_label.text = "${track.title}$artist" + val currentTrackPlaceholder = resources.getColoredDrawableWithColor(R.drawable.ic_headset, context.config.textColor) + val options = RequestOptions() + .error(currentTrackPlaceholder) + .transform(CenterCrop(), RoundedCorners(8)) + + Glide.with(this) + .load(track.coverArt) + .apply(options) + .into(findViewById(R.id.current_track_image)) + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f354a453..1acab5c0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,7 +22,7 @@ android:layout_height="match_parent" android:layout_below="@+id/main_tabs_holder" /> - - +