mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 11:55:31 -04:00
universal7885: FMRadio: Introduce MaterialHelper
Used for merging all those sperate material colors settings into one Also correct spelling of 'favorite'
This commit is contained in:
parent
f941c4c915
commit
f8d64352c9
6 changed files with 83 additions and 77 deletions
|
|
@ -18,7 +18,7 @@ import androidx.fragment.app.FragmentManager
|
|||
import com.eurekateam.fmradio.enums.HeadsetState
|
||||
import com.eurekateam.fmradio.enums.PowerState
|
||||
import com.eurekateam.fmradio.fragments.ChannelListFragment
|
||||
import com.eurekateam.fmradio.fragments.FavouriteFragment
|
||||
import com.eurekateam.fmradio.fragments.FavoriteFragment
|
||||
import com.eurekateam.fmradio.fragments.MainFragment
|
||||
import com.eurekateam.fmradio.utils.Log
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
|
|
@ -103,14 +103,14 @@ class MainActivity : AppCompatActivity() {
|
|||
registerReceiver(mWiredHeadsetReceiver, receiverFilter)
|
||||
val mRadioMainFragment = MainFragment()
|
||||
val mRadioChannelListFragment = ChannelListFragment()
|
||||
val mFavouriteFragment = FavouriteFragment()
|
||||
val mFavoriteFragment = FavoriteFragment()
|
||||
changeFragment(mRadioMainFragment, MainFragment::class.java.name)
|
||||
mIntent = Intent(this, FMRadioService::class.java)
|
||||
findViewById<BottomNavigationView>(R.id.bottom_nav_bar).setOnItemSelectedListener {
|
||||
when (it.itemId) {
|
||||
R.id.radio_main -> changeFragment(mRadioMainFragment, MainFragment::class.java.name)
|
||||
R.id.channel_list -> changeFragment(mRadioChannelListFragment, ChannelListFragment::class.java.name)
|
||||
R.id.fav_list -> changeFragment(mFavouriteFragment, FavouriteFragment::class.java.name)
|
||||
R.id.fav_list -> changeFragment(mFavoriteFragment, FavoriteFragment::class.java.name)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.eurekateam.fmradio.fragments
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -14,6 +13,7 @@ import com.eurekateam.fmradio.NativeFMInterface
|
|||
import com.eurekateam.fmradio.R
|
||||
import com.eurekateam.fmradio.MainActivity
|
||||
import com.eurekateam.fmradio.adapters.ListViewAdapter
|
||||
import com.eurekateam.fmradio.utils.MaterialHelper
|
||||
import com.eurekateam.fmradio.utils.IWaitUntil
|
||||
import com.eurekateam.fmradio.utils.WaitUntil
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
|
|
@ -37,21 +37,13 @@ class ChannelListFragment :
|
|||
mFloatingActionButton = mRootView.findViewById(R.id.refresh_channel_list)
|
||||
mFloatingActionButton.setOnClickListener(this)
|
||||
mListView.adapter = ListViewAdapter(requireContext())
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
Configuration.UI_MODE_NIGHT_UNDEFINED -> mIsLight = true
|
||||
}
|
||||
mRootView.findViewById<FrameLayout>(R.id.channel_list_layout).apply {
|
||||
if (mIsLight) {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_50, requireContext().theme))
|
||||
} else {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_100, requireContext().theme))
|
||||
}
|
||||
}
|
||||
mRootView.findViewById<FrameLayout>(R.id.channel_list_layout).setBackgroundColor(
|
||||
MaterialHelper.build {
|
||||
context = requireContext()
|
||||
light = android.R.color.system_accent1_50
|
||||
dark = android.R.color.system_accent1_100
|
||||
}.getValue()
|
||||
)
|
||||
return mRootView
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package com.eurekateam.fmradio.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.GridView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.eurekateam.fmradio.R
|
||||
import com.eurekateam.fmradio.utils.MaterialHelper
|
||||
import com.eurekateam.fmradio.adapters.PebbleLayoutAdapter
|
||||
|
||||
class FavoriteFragment : Fragment(R.layout.fragment_fav_list) {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val mRootView = inflater.inflate(R.layout.fragment_fav_list, container, false)
|
||||
val mGridView = mRootView.findViewById<GridView>(R.id.fav_list_grid)
|
||||
mGridView.adapter = PebbleLayoutAdapter(requireContext())
|
||||
mRootView.findViewById<GridView>(R.id.fav_list_grid).setBackgroundColor(
|
||||
MaterialHelper.build {
|
||||
context = requireContext()
|
||||
light = android.R.color.system_accent1_100
|
||||
dark = android.R.color.system_accent1_50
|
||||
}.getValue()
|
||||
)
|
||||
return mRootView
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.eurekateam.fmradio.fragments
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.GridView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.eurekateam.fmradio.R
|
||||
import com.eurekateam.fmradio.adapters.PebbleLayoutAdapter
|
||||
|
||||
class FavouriteFragment : Fragment(R.layout.fragment_fav_list) {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
val mRootView = inflater.inflate(R.layout.fragment_fav_list, container, false)
|
||||
val mGridView = mRootView.findViewById<GridView>(R.id.fav_list_grid)
|
||||
mGridView.adapter = PebbleLayoutAdapter(requireContext())
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
Configuration.UI_MODE_NIGHT_UNDEFINED -> mIsLight = true
|
||||
}
|
||||
mRootView.findViewById<GridView>(R.id.fav_list_grid).apply {
|
||||
if (mIsLight) {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_50, requireContext().theme))
|
||||
} else {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_100, requireContext().theme))
|
||||
}
|
||||
}
|
||||
return mRootView
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import com.eurekateam.fmradio.enums.HeadsetState
|
|||
import com.eurekateam.fmradio.enums.PowerState
|
||||
import com.eurekateam.fmradio.utils.IWaitUntil
|
||||
import com.eurekateam.fmradio.utils.Log
|
||||
import com.eurekateam.fmradio.utils.MaterialHelper
|
||||
import com.eurekateam.fmradio.utils.WaitUntil
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
|
|
@ -90,29 +91,21 @@ class MainFragment :
|
|||
mOutputSwitch.setOnClickListener(this)
|
||||
mFavButton.setOnClickListener(this)
|
||||
mSharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
Configuration.UI_MODE_NIGHT_UNDEFINED -> mIsLight = true
|
||||
}
|
||||
for (mResID in listOf(R.id.app_banner, R.id.fm_freq, R.id.freq_misc)) {
|
||||
mRootView.findViewById<MaterialTextView>(mResID).apply {
|
||||
if (mIsLight) {
|
||||
setTextColor(resources.getColor(android.R.color.system_accent2_500, requireContext().theme))
|
||||
} else {
|
||||
setTextColor(resources.getColor(android.R.color.system_accent2_100, requireContext().theme))
|
||||
}
|
||||
setTextColor(MaterialHelper.build {
|
||||
context = requireContext()
|
||||
light = android.R.color.system_accent2_500
|
||||
dark = android.R.color.system_accent2_100
|
||||
}.getValue())
|
||||
}
|
||||
}
|
||||
mRootView.findViewById<FrameLayout>(R.id.main_fragment).apply {
|
||||
if (mIsLight) {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_100, requireContext().theme))
|
||||
} else {
|
||||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_700, requireContext().theme))
|
||||
}
|
||||
setBackgroundColor(MaterialHelper.build {
|
||||
context = requireContext()
|
||||
light = android.R.color.system_accent1_100
|
||||
dark = android.R.color.system_accent1_700
|
||||
}.getValue())
|
||||
}
|
||||
val mVolume = mSharedPref.getInt(SharedPreferencesConst.PREF_VOLUME, 8)
|
||||
mFMInterface.mDevCtl.setValue(SetType.SET_TYPE_FM_VOLUME, mVolume)
|
||||
|
|
@ -320,7 +313,7 @@ class MainFragment :
|
|||
* @return Long array with zeros removed
|
||||
*/
|
||||
private fun removeZeros(array: IntArray): IntArray {
|
||||
val mArray: MutableList<Int> = emptyMutableList()
|
||||
val mArray: MutableList<Int> = mutableListOf()
|
||||
Log.d("removeZeros: Got array size ${array.size}")
|
||||
for (i in array.indices) {
|
||||
if (array[i] > 0L) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package com.eurekateam.fmradio.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
|
||||
class MaterialHelper (private val mContext : Context, private val mOnLight : Int, private val mOnDark : Int)
|
||||
{
|
||||
private constructor(builder: Builder) : this(builder.context, builder.light, builder.dark)
|
||||
|
||||
class Builder {
|
||||
lateinit var context: Context
|
||||
var light = 0
|
||||
var dark = 0
|
||||
|
||||
fun build() = MaterialHelper(this)
|
||||
}
|
||||
|
||||
companion object {
|
||||
inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
|
||||
}
|
||||
|
||||
fun getValue() : Int =
|
||||
when (mContext.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mContext.resources.getColor(mOnLight, mContext.theme)
|
||||
Configuration.UI_MODE_NIGHT_NO -> mContext.resources.getColor(mOnDark, mContext.theme)
|
||||
Configuration.UI_MODE_NIGHT_UNDEFINED -> mContext.resources.getColor(mOnLight, mContext.theme)
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue