More widget cleanup
This commit is contained in:
parent
93a3bd3b15
commit
960c645010
@ -44,7 +44,6 @@ class WidgetView : LauncherCardView {
|
||||
val widget = binding.widgetWrapper[2] as LauncherWidget
|
||||
widget.visibility = View.VISIBLE
|
||||
binding.widgetName.visibility = View.GONE
|
||||
visibility = if (widget.show) View.VISIBLE else View.GONE
|
||||
layoutTransition = ChangingLayoutTransition()
|
||||
widgetView?.layoutTransition = ChangingLayoutTransition()
|
||||
binding.widgetWrapper.layoutTransition = ChangingLayoutTransition()
|
||||
@ -111,7 +110,6 @@ class WidgetView : LauncherCardView {
|
||||
binding.widgetResizeDragHandle.resizeView = widgetView
|
||||
binding.widgetWrapper.addView(widgetView, 2)
|
||||
binding.widgetName.text = widgetView?.name
|
||||
visibility = if (widgetView?.show == true) View.VISIBLE else View.GONE
|
||||
} else {
|
||||
widgetView = ExternalWidget(context, widget, widgetHost)
|
||||
binding.widgetResizeDragHandle.resizeView = widgetView
|
||||
@ -121,10 +119,6 @@ class WidgetView : LauncherCardView {
|
||||
binding.widgetWrapper.addView(widgetView, 2)
|
||||
binding.widgetName.text = widgetView?.name
|
||||
binding.widgetActionResize.visibility = View.VISIBLE
|
||||
visibility = if (widgetView?.show == true) View.VISIBLE else View.GONE
|
||||
}
|
||||
widgetView?.onVisibilityChanged = {
|
||||
visibility = if (it) View.VISIBLE else View.GONE
|
||||
}
|
||||
widgetView?.layoutTransition = LayoutTransition().apply {
|
||||
enableTransitionType(LayoutTransition.CHANGING)
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
package de.mm20.launcher2.ui.legacy.widget
|
||||
|
||||
interface CompactView {
|
||||
|
||||
fun setTranslucent(translucent: Boolean)
|
||||
fun update() {}
|
||||
|
||||
var goToParent: (() -> Unit)?
|
||||
}
|
||||
@ -27,7 +27,6 @@ class ExternalWidget(
|
||||
init {
|
||||
val id = widget.data.toInt()
|
||||
widgetInfo = AppWidgetManager.getInstance(context.applicationContext).getAppWidgetInfo(id)
|
||||
show = widgetInfo != null
|
||||
val widgetView = host.createView(context.applicationContext, id, widgetInfo)
|
||||
?: View(context)
|
||||
if (widgetView is AppWidgetHostView && widgetView.childCount > 0) {
|
||||
|
||||
@ -18,12 +18,5 @@ abstract class LauncherWidget : FrameLayout {
|
||||
}
|
||||
abstract val canResize: Boolean
|
||||
abstract val name: String
|
||||
var show: Boolean = true
|
||||
set(value) {
|
||||
onVisibilityChanged?.invoke(value)
|
||||
field = value
|
||||
}
|
||||
|
||||
var onVisibilityChanged: ((Boolean) -> Unit)? = null
|
||||
|
||||
}
|
||||
@ -61,102 +61,3 @@ class MusicWidget : LauncherWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class MusicCompactView : FrameLayout, CompactView {
|
||||
|
||||
|
||||
private val viewModel: MusicViewModel by (context as AppCompatActivity).viewModel()
|
||||
|
||||
private val binding = CompactMusicBinding.inflate(LayoutInflater.from(context), this)
|
||||
|
||||
override fun setTranslucent(translucent: Boolean) {
|
||||
if (translucent) {
|
||||
binding.musicCompactTitle.setTextColor(Color.WHITE)
|
||||
binding.musicCompactArtist.setTextColor(Color.WHITE)
|
||||
binding.musicCompactNext.elevation = 2 * dp
|
||||
binding.musicCompactPlay.elevation = 2 * dp
|
||||
binding.musicCompactNext.alpha = 1f
|
||||
binding.musicCompactPlay.alpha = 1f
|
||||
binding.musicCompactNext.imageTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
binding.musicCompactPlay.imageTintList = ColorStateList.valueOf(Color.WHITE)
|
||||
val shadowY = resources.getDimension(R.dimen.elevation_shadow_1dp_y)
|
||||
val shadowR = resources.getDimension(R.dimen.elevation_shadow_1dp_radius)
|
||||
val shadowC = Color.argb(66, 0, 0, 0)
|
||||
binding.musicCompactTitle.setShadowLayer(shadowR, 0f, shadowY, shadowC)
|
||||
binding.musicCompactArtist.setShadowLayer(shadowR, 0f, shadowY, shadowC)
|
||||
} else {
|
||||
val primaryColor = ContextCompat.getColorStateList(context, R.color.text_color_primary)!!
|
||||
binding.musicCompactTitle.setTextColor(primaryColor)
|
||||
binding.musicCompactArtist.setTextColor(ContextCompat.getColorStateList(context, R.color.text_color_secondary))
|
||||
binding.musicCompactNext.elevation = 0f
|
||||
binding.musicCompactPlay.elevation = 0f
|
||||
binding.musicCompactNext.alpha = primaryColor.defaultColor.alpha / 255f
|
||||
binding.musicCompactPlay.alpha = primaryColor.defaultColor.alpha / 255f
|
||||
binding.musicCompactNext.imageTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.icon_color))
|
||||
binding.musicCompactPlay.imageTintList = ColorStateList.valueOf(ContextCompat.getColor(context, R.color.icon_color))
|
||||
binding.musicCompactTitle.setShadowLayer(0f, 0f, 0f, 0)
|
||||
binding.musicCompactArtist.setShadowLayer(0f, 0f, 0f, 0)
|
||||
}
|
||||
}
|
||||
|
||||
private var playPauseIcon = if (viewModel.playbackState.value == PlaybackState.Playing) R.drawable.ic_pause else R.drawable.ic_play
|
||||
set(value) {
|
||||
if (value != field) {
|
||||
val icon = context.getDrawable(value)
|
||||
binding.musicCompactPlay.setImageDrawable(icon)
|
||||
(icon as? AnimatedVectorDrawable)?.start()
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override var goToParent: (() -> Unit)? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleRes: Int) : super(context, attrs, defStyleRes)
|
||||
|
||||
init {
|
||||
clipChildren = false
|
||||
binding.musicCompactNext.setOnClickListener {
|
||||
viewModel.next()
|
||||
(binding.musicCompactNext.drawable as AnimatedVectorDrawable).start()
|
||||
}
|
||||
binding.musicCompactPlay.setOnClickListener { _ ->
|
||||
viewModel.togglePause()
|
||||
}
|
||||
binding.musicCompactMeta.setOnClickListener {
|
||||
ActivityStarter.start(context, this, pendingIntent = viewModel.getLaunchIntent(context))
|
||||
}
|
||||
viewModel.title.observe(context as AppCompatActivity, Observer {
|
||||
binding.musicCompactTitle.text = it
|
||||
})
|
||||
|
||||
viewModel.artist.observe(context as AppCompatActivity, Observer {
|
||||
binding.musicCompactArtist.text = it
|
||||
})
|
||||
|
||||
viewModel.playbackState.observe(context as AppCompatActivity, Observer {
|
||||
if (it == PlaybackState.Playing) {
|
||||
playPauseIcon = R.drawable.ic_play_to_pause
|
||||
binding.musicCompactPlay.setOnClickListener {
|
||||
viewModel.pause()
|
||||
}
|
||||
binding.musicCompactTitle.isSelected = true
|
||||
binding.musicCompactArtist.isSelected = true
|
||||
} else {
|
||||
playPauseIcon = R.drawable.ic_pause_to_play
|
||||
binding.musicCompactPlay.setOnClickListener {
|
||||
viewModel.play()
|
||||
}
|
||||
binding.musicCompactTitle.isSelected = false
|
||||
binding.musicCompactArtist.isSelected = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun update() {
|
||||
binding.musicCompactTitle.text = viewModel.title.value
|
||||
binding.musicCompactArtist.text = viewModel.artist.value
|
||||
playPauseIcon = if (viewModel.playbackState.value == PlaybackState.Playing) R.drawable.ic_pause else R.drawable.ic_play
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,15 +49,3 @@ class WeatherWidget : LauncherWidget {
|
||||
}
|
||||
|
||||
|
||||
class WeatherCompactView(context: Context) : FrameLayout(context), CompactView {
|
||||
override var goToParent: (() -> Unit)? = null
|
||||
|
||||
init {
|
||||
View.inflate(context, R.layout.compact_weather, this)
|
||||
}
|
||||
|
||||
override fun setTranslucent(translucent: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user