View Binding
This commit is contained in:
parent
5772fcd812
commit
903fb97eef
11 changed files with 90 additions and 117 deletions
|
@ -14,7 +14,6 @@
|
|||
|
||||
package code.name.monkey.retromusic.preferences
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
|
@ -22,8 +21,6 @@ import android.util.AttributeSet
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||
|
@ -33,6 +30,8 @@ import androidx.viewpager.widget.ViewPager
|
|||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.PreferenceDialogNowPlayingScreenBinding
|
||||
import code.name.monkey.retromusic.databinding.PreferenceNowPlayingScreenItemBinding
|
||||
import code.name.monkey.retromusic.extensions.*
|
||||
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
|
||||
import code.name.monkey.retromusic.fragments.AlbumCoverStyle.*
|
||||
|
@ -69,14 +68,13 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
private var viewPagerPosition: Int = 0
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
@SuppressLint("InflateParams") val view =
|
||||
layoutInflater
|
||||
.inflate(R.layout.preference_dialog_now_playing_screen, null)
|
||||
val viewPager = view.findViewById<ViewPager>(R.id.now_playing_screen_view_pager)
|
||||
viewPager.adapter = AlbumCoverStyleAdapter(requireContext())
|
||||
viewPager.addOnPageChangeListener(this)
|
||||
viewPager.pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||
viewPager.currentItem = PreferenceUtil.albumCoverStyle.ordinal
|
||||
val binding = PreferenceDialogNowPlayingScreenBinding.inflate(layoutInflater)
|
||||
binding.nowPlayingScreenViewPager.apply {
|
||||
adapter = AlbumCoverStyleAdapter(requireContext())
|
||||
addOnPageChangeListener(this@AlbumCoverStylePreferenceDialog)
|
||||
pageMargin = ViewUtil.convertDpToPixel(32f, resources).toInt()
|
||||
currentItem = PreferenceUtil.albumCoverStyle.ordinal
|
||||
}
|
||||
|
||||
return materialDialog(R.string.pref_title_album_cover_style)
|
||||
.setPositiveButton(R.string.set) { _, _ ->
|
||||
|
@ -89,7 +87,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
PreferenceUtil.albumCoverStyle = coverStyle
|
||||
}
|
||||
}
|
||||
.setView(view)
|
||||
.setView(binding.root)
|
||||
.create()
|
||||
.colorButtons()
|
||||
}
|
||||
|
@ -111,25 +109,18 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
|
|||
val albumCoverStyle = values()[position]
|
||||
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val layout = inflater.inflate(
|
||||
R.layout.preference_now_playing_screen_item,
|
||||
collection,
|
||||
false
|
||||
) as ViewGroup
|
||||
collection.addView(layout)
|
||||
val binding = PreferenceNowPlayingScreenItemBinding.inflate(inflater, collection, false)
|
||||
collection.addView(binding.root)
|
||||
|
||||
val image = layout.findViewById<ImageView>(R.id.image)
|
||||
val title = layout.findViewById<TextView>(R.id.title)
|
||||
val proText = layout.findViewById<TextView>(R.id.proText)
|
||||
Glide.with(context).load(albumCoverStyle.drawableResId).into(image)
|
||||
title.setText(albumCoverStyle.titleRes)
|
||||
Glide.with(context).load(albumCoverStyle.drawableResId).into(binding.image)
|
||||
binding.title.setText(albumCoverStyle.titleRes)
|
||||
if (isAlbumCoverStyle(albumCoverStyle)) {
|
||||
proText.show()
|
||||
proText.setText(R.string.pro)
|
||||
binding.proText.show()
|
||||
binding.proText.setText(R.string.pro)
|
||||
} else {
|
||||
proText.hide()
|
||||
binding.proText.hide()
|
||||
}
|
||||
return layout
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun destroyItem(
|
||||
|
|
|
@ -2,16 +2,16 @@ package code.name.monkey.retromusic.preferences
|
|||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.PreferenceDialogAudioFadeBinding
|
||||
import code.name.monkey.retromusic.extensions.addAccentColor
|
||||
import code.name.monkey.retromusic.extensions.colorButtons
|
||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||
import code.name.monkey.retromusic.extensions.materialDialog
|
||||
|
@ -36,28 +36,23 @@ class DurationPreference @JvmOverloads constructor(
|
|||
class DurationPreferenceDialog : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = layoutInflater
|
||||
.inflate(R.layout.preference_dialog_audio_fade, null)
|
||||
val binding = PreferenceDialogAudioFadeBinding.inflate(layoutInflater)
|
||||
|
||||
|
||||
val slider = view.findViewById<Slider>(R.id.slider)
|
||||
val duration = view.findViewById<TextView>(R.id.duration)
|
||||
ColorStateList.valueOf(ThemeStore.accentColor(requireContext())).let {
|
||||
slider.trackTintList = it
|
||||
slider.thumbTintList = it
|
||||
binding.slider.apply {
|
||||
addAccentColor()
|
||||
value = PreferenceUtil.audioFadeDuration.toFloat()
|
||||
updateText(value.toInt(), binding.duration)
|
||||
addOnChangeListener(Slider.OnChangeListener { _, value, fromUser ->
|
||||
if (fromUser) {
|
||||
updateText(value.toInt(), binding.duration)
|
||||
}
|
||||
})
|
||||
}
|
||||
slider.value = PreferenceUtil.audioFadeDuration.toFloat()
|
||||
updateText(slider.value.toInt(), duration)
|
||||
slider.addOnChangeListener(Slider.OnChangeListener { _, value, fromUser ->
|
||||
if (fromUser) {
|
||||
updateText(value.toInt(), duration)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return materialDialog(R.string.audio_fade_duration)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.save) { _, _ -> updateDuration(slider.value.toInt()) }
|
||||
.setPositiveButton(R.string.save) { _, _ -> updateDuration(binding.slider.value.toInt()) }
|
||||
.setView(view)
|
||||
.create()
|
||||
.colorButtons()
|
||||
|
|
|
@ -23,10 +23,10 @@ import androidx.core.graphics.BlendModeColorFilterCompat
|
|||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.adapter.CategoryInfoAdapter
|
||||
import code.name.monkey.retromusic.databinding.PreferenceDialogLibraryCategoriesBinding
|
||||
import code.name.monkey.retromusic.extensions.colorButtons
|
||||
import code.name.monkey.retromusic.extensions.colorControlNormal
|
||||
import code.name.monkey.retromusic.extensions.materialDialog
|
||||
|
@ -51,15 +51,14 @@ class LibraryPreference @JvmOverloads constructor(
|
|||
class LibraryPreferenceDialog : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val view = layoutInflater
|
||||
.inflate(R.layout.preference_dialog_library_categories, null)
|
||||
val binding = PreferenceDialogLibraryCategoriesBinding.inflate(layoutInflater)
|
||||
|
||||
val categoryAdapter = CategoryInfoAdapter()
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.recycler_view)
|
||||
recyclerView.layoutManager = LinearLayoutManager(activity)
|
||||
recyclerView.adapter = categoryAdapter
|
||||
categoryAdapter.attachToRecyclerView(recyclerView)
|
||||
|
||||
binding.recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(activity)
|
||||
adapter = categoryAdapter
|
||||
categoryAdapter.attachToRecyclerView(this)
|
||||
}
|
||||
|
||||
return materialDialog(R.string.library_categories)
|
||||
.setNeutralButton(
|
||||
|
@ -68,8 +67,8 @@ class LibraryPreferenceDialog : DialogFragment() {
|
|||
updateCategories(PreferenceUtil.defaultCategories)
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton( R.string.done) { _, _ -> updateCategories(categoryAdapter.categoryInfos) }
|
||||
.setView(view)
|
||||
.setPositiveButton(R.string.done) { _, _ -> updateCategories(categoryAdapter.categoryInfos) }
|
||||
.setView(binding.root)
|
||||
.create()
|
||||
.colorButtons()
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import android.util.AttributeSet
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat.SRC_IN
|
||||
|
@ -32,6 +30,7 @@ import androidx.viewpager.widget.ViewPager
|
|||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.databinding.PreferenceNowPlayingScreenItemBinding
|
||||
import code.name.monkey.retromusic.extensions.*
|
||||
import code.name.monkey.retromusic.fragments.NowPlayingScreen
|
||||
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
|
||||
|
@ -116,25 +115,17 @@ private class NowPlayingScreenAdapter(private val context: Context) : PagerAdapt
|
|||
val nowPlayingScreen = values()[position]
|
||||
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val layout = inflater.inflate(
|
||||
R.layout.preference_now_playing_screen_item,
|
||||
collection,
|
||||
false
|
||||
) as ViewGroup
|
||||
collection.addView(layout)
|
||||
|
||||
val image = layout.findViewById<ImageView>(R.id.image)
|
||||
val title = layout.findViewById<TextView>(R.id.title)
|
||||
val proText = layout.findViewById<TextView>(R.id.proText)
|
||||
Glide.with(context).load(nowPlayingScreen.drawableResId).into(image)
|
||||
title.setText(nowPlayingScreen.titleRes)
|
||||
val binding = PreferenceNowPlayingScreenItemBinding.inflate(inflater, collection, false )
|
||||
collection.addView(binding.root)
|
||||
Glide.with(context).load(nowPlayingScreen.drawableResId).into(binding.image)
|
||||
binding.title.setText(nowPlayingScreen.titleRes)
|
||||
if (isNowPlayingThemes(nowPlayingScreen)) {
|
||||
proText.show()
|
||||
proText.setText(R.string.pro)
|
||||
binding.proText.show()
|
||||
binding.proText.setText(R.string.pro)
|
||||
}else{
|
||||
proText.hide()
|
||||
binding.proText.hide()
|
||||
}
|
||||
return layout
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun destroyItem(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue