diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index ccc04145..73572a44 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -72,20 +72,20 @@ import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs +import dagger.hilt.android.scopes.ActivityScoped import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.koin.core.component.KoinComponent -import org.koin.core.component.inject import java.io.File import java.io.IOException import java.net.URLEncoder import java.nio.charset.StandardCharsets import java.util.ArrayList import java.util.Locale +import javax.inject.Inject /** * Created by Allan Wang on 2017-06-03. @@ -184,25 +184,37 @@ fun WebOverlayActivity.url(): String { return intent.getStringExtra(ARG_URL) ?: FbItem.FEED.url } -fun Activity.setFrostTheme(themeProvider: ThemeProvider, forceTransparent: Boolean = false) { - val isTransparent = - forceTransparent || (Color.alpha(themeProvider.bgColor) != 255) || ( - Color.alpha( - themeProvider.headerColor - ) != 255 - ) - if (themeProvider.bgColor.isColorDark) { - setTheme(if (isTransparent) R.style.FrostTheme_Transparent else R.style.FrostTheme) - } else { - setTheme(if (isTransparent) R.style.FrostTheme_Light_Transparent else R.style.FrostTheme_Light) +@ActivityScoped +class ActivityThemer @Inject constructor( + private val activity: Activity, + private val prefs: Prefs, + private val themeProvider: ThemeProvider +) { + fun setFrostTheme(forceTransparent: Boolean = false) { + val isTransparent = + forceTransparent || (Color.alpha(themeProvider.bgColor) != 255) || ( + Color.alpha( + themeProvider.headerColor + ) != 255 + ) + if (themeProvider.bgColor.isColorDark) { + activity.setTheme(if (isTransparent) R.style.FrostTheme_Transparent else R.style.FrostTheme) + } else { + activity.setTheme(if (isTransparent) R.style.FrostTheme_Light_Transparent else R.style.FrostTheme_Light) + } } -} - -class ActivityThemeUtils : KoinComponent { - private val prefs: Prefs by inject() - private val themeProvider: ThemeProvider by inject() + fun setFrostColors(builder: ActivityThemeUtils.() -> Unit) { + val themer = ActivityThemeUtils(prefs = prefs, themeProvider = themeProvider) + themer.builder() + themer.theme(activity) + } +} +class ActivityThemeUtils( + private val prefs: Prefs, + private val themeProvider: ThemeProvider +) { private var toolbar: Toolbar? = null var themeWindow = true private var texts = mutableListOf<TextView>() @@ -240,12 +252,6 @@ class ActivityThemeUtils : KoinComponent { } } -inline fun Activity.setFrostColors(builder: ActivityThemeUtils.() -> Unit) { - val themer = ActivityThemeUtils() - themer.builder() - themer.theme(this) -} - fun frostEvent(name: String, vararg events: Pair<String, Any>) { // todo bind L.v { "Event: $name ${events.joinToString(", ")}" } |