diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
7 files changed, 49 insertions, 34 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt index 6ba9ff4d..6eebd36f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt @@ -37,7 +37,7 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp -import com.pitchedapps.frost.prefs.Prefs +import com.pitchedapps.frost.injectors.ThemeProvider import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -48,13 +48,13 @@ class AccountItem(val cookie: CookieEntity?) : KauIItem<AccountItem.ViewHolder>(R.layout.view_account, { ViewHolder(it) }, R.id.item_account), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() override fun bindView(holder: ViewHolder, payloads: List<Any>) { super.bindView(holder, payloads) with(holder) { text.invisible() - text.setTextColor(prefs.textColor) + text.setTextColor(themeProvider.textColor) if (cookie != null) { text.text = cookie.name GlideApp.with(itemView).load(profilePictureUrl(cookie.id)) @@ -86,7 +86,7 @@ class AccountItem(val cookie: CookieEntity?) : GoogleMaterial.Icon.gmd_add_circle_outline.toDrawable( itemView.context, 100, - prefs.textColor + themeProvider.textColor ) ) text.text = itemView.context.getString(R.string.kau_add_account) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt index ed94b59f..78af4edf 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt @@ -29,6 +29,7 @@ import ca.allanwang.kau.utils.visible import ca.allanwang.kau.utils.withAlpha import com.mikepenz.iconics.typeface.IIcon import com.pitchedapps.frost.databinding.ViewBadgedIconBinding +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -43,6 +44,7 @@ class BadgedIcon @JvmOverloads constructor( ) : ConstraintLayout(context, attrs, defStyleAttr), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val binding: ViewBadgedIconBinding = ViewBadgedIconBinding.inflate(LayoutInflater.from(context), this, true) @@ -52,7 +54,7 @@ class BadgedIcon @JvmOverloads constructor( private fun ViewBadgedIconBinding.init() { val badgeColor = - prefs.mainActivityLayout.backgroundColor(prefs).withAlpha(255).colorToForeground(0.2f) + prefs.mainActivityLayout.backgroundColor(themeProvider).withAlpha(255).colorToForeground(0.2f) val badgeBackground = GradientDrawable( GradientDrawable.Orientation.BOTTOM_TOP, @@ -60,7 +62,7 @@ class BadgedIcon @JvmOverloads constructor( ) badgeBackground.cornerRadius = 13.dpToPx.toFloat() badgeText.background = badgeBackground - badgeText.setTextColor(prefs.mainActivityLayout.iconColor(prefs)) + badgeText.setTextColor(prefs.mainActivityLayout.iconColor(themeProvider)) } var iicon: IIcon? = null @@ -70,13 +72,13 @@ class BadgedIcon @JvmOverloads constructor( value?.toDrawable( context, sizeDp = 20, - color = prefs.mainActivityLayout.iconColor(prefs) + color = prefs.mainActivityLayout.iconColor(themeProvider) ) ) } fun setAllAlpha(alpha: Float) { - // badgeTextView.setTextColor(prefs.textColor.withAlpha(alpha.toInt())) + // badgeTextView.setTextColor(themeProvider.textColor.withAlpha(alpha.toInt())) binding.badgeImage.drawable.alpha = alpha.toInt() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt index 55f41807..177b8862 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt @@ -22,7 +22,6 @@ import android.util.AttributeSet import android.view.View import android.widget.FrameLayout import android.widget.ProgressBar -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import ca.allanwang.kau.utils.ContextHelper import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.circularReveal @@ -39,6 +38,7 @@ import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.WEB_LOAD_DELAY +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.kotlin.subscribeDuringJob import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L @@ -80,6 +80,7 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( FrostContentParent, KoinComponent where T : View, T : FrostContentCore { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val refresh: SwipeRefreshLayout by bindView(R.id.content_refresh) private val progress: ProgressBar by bindView(R.id.content_progress) val coreView: T by bindView(R.id.content_core) @@ -102,14 +103,26 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( protected abstract val layoutRes: Int - override var swipeEnabled = true + @Volatile + override var swipeDisabledByAction = false set(value) { - if (field == value) - return field = value - refresh.post { refresh.isEnabled = value } + updateSwipeEnabler() } + @Volatile + override var swipeAllowedByPage: Boolean = true + set(value) { + field = value + updateSwipeEnabler() + } + + private fun updateSwipeEnabler() { + val swipeEnabled = swipeAllowedByPage && !swipeDisabledByAction + if (refresh.isEnabled == swipeEnabled) return + refresh.post { refresh.isEnabled = swipeEnabled } + } + /** * Sets up everything * Called by [bind] @@ -134,7 +147,6 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( refreshChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { r -> refresh.isRefreshing = r - refresh.isEnabled = true } progressChannel.subscribeDuringJob(scope, ContextHelper.coroutineContext) { p -> @@ -156,9 +168,9 @@ abstract class FrostContentView<out T> @JvmOverloads constructor( } override fun reloadThemeSelf() { - progress.tint(prefs.textColor.withAlpha(180)) - refresh.setColorSchemeColors(prefs.iconColor) - refresh.setProgressBackgroundColorSchemeColor(prefs.headerColor.withAlpha(255)) + progress.tint(themeProvider.textColor.withAlpha(180)) + refresh.setColorSchemeColors(themeProvider.iconColor) + refresh.setProgressBackgroundColorSchemeColor(themeProvider.headerColor.withAlpha(255)) } override fun reloadTextSizeSelf() { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt index 09be1184..a76aeea0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt @@ -25,6 +25,7 @@ import android.view.LayoutInflater import android.view.MotionEvent import android.view.ViewTreeObserver import android.widget.FrameLayout +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.fadeOut import ca.allanwang.kau.utils.gone @@ -43,9 +44,9 @@ import com.pitchedapps.frost.R import com.pitchedapps.frost.databinding.ViewVideoBinding import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.currentCookie +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.frostDownload import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -88,6 +89,7 @@ class FrostVideoViewer @JvmOverloads constructor( } private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() private val cookieDao: CookieDao by inject() private val binding: ViewVideoBinding = @@ -100,8 +102,8 @@ class FrostVideoViewer @JvmOverloads constructor( fun ViewVideoBinding.init() { alpha = 0f videoBackground.setBackgroundColor( - if (!prefs.blackMediaBg && prefs.bgColor.isColorDark) - prefs.bgColor.withMinAlpha(200) + if (!prefs.blackMediaBg && themeProvider.bgColor.isColorDark) + themeProvider.bgColor.withMinAlpha(200) else Color.BLACK ) @@ -109,7 +111,7 @@ class FrostVideoViewer @JvmOverloads constructor( video.pause() videoToolbar.inflateMenu(R.menu.menu_video) context.setMenuIcons( - videoToolbar.menu, prefs.iconColor, + videoToolbar.menu, themeProvider.iconColor, R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt, R.id.action_download to GoogleMaterial.Icon.gmd_file_download ) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index 34bb5204..ecd8c093 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -24,6 +24,7 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import ca.allanwang.kau.utils.AnimHolder +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.launchMain import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore @@ -34,9 +35,9 @@ import com.pitchedapps.frost.facebook.FB_HOME_URL import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.USER_AGENT import com.pitchedapps.frost.fragments.WebFragment +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.frostDownload import com.pitchedapps.frost.web.FrostChromeClient import com.pitchedapps.frost.web.FrostJSI @@ -62,6 +63,7 @@ class FrostWebView @JvmOverloads constructor( val fbCookie: FbCookie by inject() val prefs: Prefs by inject() + val themeProvider: ThemeProvider by inject() val cookieDao: CookieDao by inject() override fun reload(animate: Boolean) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt index 0d53608b..c3d5a90e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt @@ -37,6 +37,7 @@ import com.mikepenz.fastadapter.listeners.ClickEventHook import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import org.koin.core.component.KoinComponent import org.koin.core.component.inject @@ -51,6 +52,7 @@ class Keywords @JvmOverloads constructor( ) : ConstraintLayout(context, attrs, defStyleAttr), KoinComponent { private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val editText: AppCompatEditText by bindView(R.id.edit_text) val addIcon: ImageView by bindView(R.id.add_icon) val recycler: RecyclerView by bindView(R.id.recycler) @@ -58,8 +60,8 @@ class Keywords @JvmOverloads constructor( init { inflate(context, R.layout.view_keywords, this) - editText.tint(prefs.textColor) - addIcon.setImageDrawable(GoogleMaterial.Icon.gmd_add.keywordDrawable(context, prefs)) + editText.tint(themeProvider.textColor) + addIcon.setImageDrawable(GoogleMaterial.Icon.gmd_add.keywordDrawable(context, themeProvider)) addIcon.setOnClickListener { if (editText.text.isNullOrEmpty()) editText.error = context.string(R.string.empty_keyword) @@ -91,8 +93,8 @@ class Keywords @JvmOverloads constructor( } } -private fun IIcon.keywordDrawable(context: Context, prefs: Prefs): Drawable = - toDrawable(context, 20, prefs.textColor) +private fun IIcon.keywordDrawable(context: Context, themeProvider: ThemeProvider): Drawable = + toDrawable(context, 20, themeProvider.textColor) class KeywordItem(val keyword: String) : AbstractItem<KeywordItem.ViewHolder>() { @@ -116,16 +118,16 @@ class KeywordItem(val keyword: String) : AbstractItem<KeywordItem.ViewHolder>() class ViewHolder(v: View) : RecyclerView.ViewHolder(v), KoinComponent { - private val prefs: Prefs by inject() + private val themeProvider: ThemeProvider by inject() val text: AppCompatTextView by bindView(R.id.keyword_text) val delete: ImageView by bindView(R.id.keyword_delete) init { - text.setTextColor(prefs.textColor) + text.setTextColor(themeProvider.textColor) delete.setImageDrawable( GoogleMaterial.Icon.gmd_delete.keywordDrawable( itemView.context, - prefs + themeProvider ) ) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt index 9e9c2340..f02adcf0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshLayout.kt @@ -101,9 +101,4 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed) } } - - /** - * Alias for adding on refresh listener - */ - interface OnRefreshListener : SwipeRefreshLayout.OnRefreshListener } |