diff options
author | Allan Wang <me@allanwang.ca> | 2020-02-23 16:06:45 -0800 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2020-02-23 16:06:45 -0800 |
commit | c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc (patch) | |
tree | 0841d112c8c00504ce10ca72ef39e403b69c595c /app/src/main/kotlin/com/pitchedapps/frost/intro | |
parent | 4d5aaf541dbfa7d521ebbc5f011a642c83c4b9c5 (diff) | |
download | frost-c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc.tar.gz frost-c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc.tar.bz2 frost-c8b54fd10a08ed53eb7d21578a4fe990fe14e3bc.zip |
Move prefs to service locator
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/intro')
3 files changed, 30 insertions, 26 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt index 4561fa6e..06947d07 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt @@ -56,7 +56,7 @@ class IntroFragmentTheme : BaseIntroFragment(R.layout.intro_theme) { introThemeDark.setThemeClick(Theme.DARK) introThemeAmoled.setThemeClick(Theme.AMOLED) introThemeGlass.setThemeClick(Theme.GLASS) - val currentTheme = Prefs.theme - 1 + val currentTheme = prefs.theme - 1 if (currentTheme in 0..3) themeList.forEachIndexed { index, v -> v.scaleXY = if (index == currentTheme) 1.6f else 0.8f @@ -65,9 +65,9 @@ class IntroFragmentTheme : BaseIntroFragment(R.layout.intro_theme) { private fun View.setThemeClick(theme: Theme) { setOnClickListener { v -> - Prefs.theme = theme.ordinal + prefs.theme = theme.ordinal (activity as IntroActivity).apply { - binding.ripple.ripple(Prefs.bgColor, v.x + v.pivotX, v.y + v.pivotY) + binding.ripple.ripple(prefs.bgColor, v.x + v.pivotX, v.y + v.pivotY) theme() } themeList.forEach { it.animate().scaleXY(if (it == this) 1.6f else 0.8f).start() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt index 9a4ec0c1..ff48dbce 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroImageFragments.kt @@ -58,10 +58,10 @@ abstract class BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - title.setTextColor(Prefs.textColor) - desc.setTextColor(Prefs.textColor) - phone.tint(Prefs.textColor) - screen.tint(Prefs.bgColor) + title.setTextColor(prefs.textColor) + desc.setTextColor(prefs.textColor) + phone.tint(prefs.textColor) + screen.tint(prefs.bgColor) } fun themeImageComponent(color: Int, vararg id: Int) { @@ -97,9 +97,9 @@ class IntroAccountFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - themeImageComponent(Prefs.iconColor, R.id.intro_phone_avatar_1, R.id.intro_phone_avatar_2) - themeImageComponent(Prefs.bgColor.colorToForeground(), R.id.intro_phone_nav) - themeImageComponent(Prefs.headerColor, R.id.intro_phone_header) + themeImageComponent(prefs.iconColor, R.id.intro_phone_avatar_1, R.id.intro_phone_avatar_2) + themeImageComponent(prefs.bgColor.colorToForeground(), R.id.intro_phone_nav) + themeImageComponent(prefs.headerColor, R.id.intro_phone_header) } override fun onPageScrolledImpl(positionOffset: Float) { @@ -123,14 +123,14 @@ class IntroTabTouchFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() themeImageComponent( - Prefs.iconColor, + prefs.iconColor, R.id.intro_phone_icon_1, R.id.intro_phone_icon_2, R.id.intro_phone_icon_3, R.id.intro_phone_icon_4 ) - themeImageComponent(Prefs.headerColor, R.id.intro_phone_tab) - themeImageComponent(Prefs.textColor.withAlpha(80), R.id.intro_phone_icon_ripple) + themeImageComponent(prefs.headerColor, R.id.intro_phone_tab) + themeImageComponent(prefs.textColor.withAlpha(80), R.id.intro_phone_icon_ripple) } } @@ -142,21 +142,21 @@ class IntroTabContextFragment : BaseImageIntroFragment( override fun themeFragmentImpl() { super.themeFragmentImpl() - themeImageComponent(Prefs.headerColor, R.id.intro_phone_toolbar) - themeImageComponent(Prefs.bgColor.colorToForeground(0.1f), R.id.intro_phone_image) + themeImageComponent(prefs.headerColor, R.id.intro_phone_toolbar) + themeImageComponent(prefs.bgColor.colorToForeground(0.1f), R.id.intro_phone_image) themeImageComponent( - Prefs.bgColor.colorToForeground(0.2f), + prefs.bgColor.colorToForeground(0.2f), R.id.intro_phone_like, R.id.intro_phone_share ) - themeImageComponent(Prefs.bgColor.colorToForeground(0.3f), R.id.intro_phone_comment) + themeImageComponent(prefs.bgColor.colorToForeground(0.3f), R.id.intro_phone_comment) themeImageComponent( - Prefs.bgColor.colorToForeground(0.1f), + prefs.bgColor.colorToForeground(0.1f), R.id.intro_phone_card_1, R.id.intro_phone_card_2 ) themeImageComponent( - Prefs.textColor, + prefs.textColor, R.id.intro_phone_image_indicator, R.id.intro_phone_comment_indicator, R.id.intro_phone_card_indicator diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt index c86e560c..82e93e81 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroMainFragments.kt @@ -37,6 +37,8 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.activities.IntroActivity import com.pitchedapps.frost.databinding.IntroAnalyticsBinding import com.pitchedapps.frost.utils.Prefs +import org.koin.core.KoinComponent +import org.koin.core.inject import kotlin.math.abs /** @@ -48,7 +50,9 @@ import kotlin.math.abs /** * The core intro fragment for all other fragments */ -abstract class BaseIntroFragment(val layoutRes: Int) : Fragment() { +abstract class BaseIntroFragment(val layoutRes: Int) : Fragment(), KoinComponent { + + protected val prefs: Prefs by inject() val screenWidth get() = resources.displayMetrics.widthPixels @@ -105,7 +109,7 @@ abstract class BaseIntroFragment(val layoutRes: Int) : Fragment() { } protected open fun themeFragmentImpl() { - (view as? ViewGroup)?.children?.forEach { (it as? TextView)?.setTextColor(Prefs.textColor) } + (view as? ViewGroup)?.children?.forEach { (it as? TextView)?.setTextColor(prefs.textColor) } } protected val viewArray: Array<Array<out View>> by lazyResettableRegistered { viewArray() } @@ -134,7 +138,7 @@ class IntroFragmentWelcome : BaseIntroFragment(R.layout.intro_welcome) { override fun themeFragmentImpl() { super.themeFragmentImpl() - image.imageTintList = ColorStateList.valueOf(Prefs.textColor) + image.imageTintList = ColorStateList.valueOf(prefs.textColor) } } @@ -153,7 +157,7 @@ class IntroFragmentAnalytics : BaseIntroFragment(R.layout.intro_analytics) { override fun themeFragmentImpl() { super.themeFragmentImpl() - image.imageTintList = ColorStateList.valueOf(Prefs.textColor) + image.imageTintList = ColorStateList.valueOf(prefs.textColor) } @SuppressLint("ClickableViewAccessibility") @@ -165,9 +169,9 @@ class IntroFragmentAnalytics : BaseIntroFragment(R.layout.intro_analytics) { private fun IntroAnalyticsBinding.init() { image.setIcon(GoogleMaterial.Icon.gmd_bug_report, 120) - introSwitch.isSelected = Prefs.analytics + introSwitch.isSelected = prefs.analytics introSwitch.setOnCheckedChangeListener { _, isChecked -> - Prefs.analytics = isChecked + prefs.analytics = isChecked } } } @@ -180,7 +184,7 @@ class IntroFragmentEnd : BaseIntroFragment(R.layout.intro_end) { override fun themeFragmentImpl() { super.themeFragmentImpl() - image.imageTintList = ColorStateList.valueOf(Prefs.textColor) + image.imageTintList = ColorStateList.valueOf(prefs.textColor) } @SuppressLint("ClickableViewAccessibility") |