moving CurrentTrackBar into a standalone view

This commit is contained in:
tibbi 2020-10-17 11:19:29 +02:00
parent 16e033ed6c
commit 09870f89d5
3 changed files with 64 additions and 41 deletions

View file

@ -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)

View file

@ -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))
}
}

View file

@ -22,7 +22,7 @@
android:layout_height="match_parent"
android:layout_below="@+id/main_tabs_holder" />
<RelativeLayout
<com.simplemobiletools.musicplayer.views.CurrentTrackBar
android:id="@+id/current_track_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -58,7 +58,7 @@
android:textSize="@dimen/bigger_text_size"
tools:text="My Track" />
</RelativeLayout>
</com.simplemobiletools.musicplayer.views.CurrentTrackBar>
<RelativeLayout
android:id="@+id/sleep_timer_holder"