aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt37
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt8
3 files changed, 32 insertions, 19 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 2ab1d572..64cf34a1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
@@ -16,8 +16,9 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
+import com.pitchedapps.frost.glide.FrostGlide
+import com.pitchedapps.frost.glide.transform
import com.pitchedapps.frost.utils.Prefs
-import com.pitchedapps.frost.utils.withRoundIcon
/**
* Created by Allan Wang on 2017-06-05.
@@ -32,7 +33,8 @@ class AccountItem(val cookie: CookieModel?) : KauIItem<AccountItem, AccountItem.
text.setTextColor(Prefs.textColor)
if (cookie != null) {
text.text = cookie.name
- Glide.with(itemView).load(PROFILE_PICTURE_URL(cookie.id)).withRoundIcon().listener(object : RequestListener<Drawable> {
+ Glide.with(itemView).load(PROFILE_PICTURE_URL(cookie.id))
+ .transform(FrostGlide.roundCorner).listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
text.fadeIn()
return false
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
index 436f8b00..38b09657 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
@@ -1,15 +1,17 @@
package com.pitchedapps.frost.views
import android.content.Context
+import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.View
+import ca.allanwang.kau.utils.circularReveal
+import ca.allanwang.kau.utils.fadeOut
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
import com.pitchedapps.frost.contracts.FrostContentParent
import com.pitchedapps.frost.fragments.RecyclerContentContract
-import com.pitchedapps.frost.utils.L
-import java.lang.ref.WeakReference
+import com.pitchedapps.frost.utils.Prefs
/**
* Created by Allan Wang on 2017-05-29.
@@ -27,12 +29,16 @@ class FrostRecyclerView @JvmOverloads constructor(
override val currentUrl: String
get() = parent.baseUrl
- lateinit var recyclerContract: WeakReference<RecyclerContentContract>
+ lateinit var recyclerContract: RecyclerContentContract
+
+ init {
+ layoutManager = LinearLayoutManager(context)
+ }
override fun bind(container: FrostContentContainer): View {
if (container !is RecyclerContentContract)
throw IllegalStateException("FrostRecyclerView must bind to a container that is a RecyclerContentContract")
- this.recyclerContract = WeakReference(container)
+ this.recyclerContract = container
container.bind(this)
return this
}
@@ -41,15 +47,15 @@ class FrostRecyclerView @JvmOverloads constructor(
isNestedScrollingEnabled = true
}
+ var onReloadClear: () -> Unit = {}
+
override fun reloadBase(animate: Boolean) {
- val contract = recyclerContract.get()
- if (contract == null) {
- L.eThrow("Attempted to reload with invalid contract")
- return
- }
- contract.reload({ parent.progressObservable.onNext(it) }) {
+ if (Prefs.animate) fadeOut(onFinish = onReloadClear)
+ parent.refreshObservable.onNext(true)
+ recyclerContract.reload({ parent.progressObservable.onNext(it) }) {
parent.progressObservable.onNext(100)
parent.refreshObservable.onNext(false)
+ if (Prefs.animate) post { circularReveal() }
}
}
@@ -64,11 +70,12 @@ class FrostRecyclerView @JvmOverloads constructor(
override fun onBackPressed() = false
/**
- * If webview is already at the top, refresh
+ * If recycler is already at the top, refresh
* Otherwise scroll to top
*/
override fun onTabClicked() {
- if (scrollY < 5) reloadBase(true)
+ val firstPosition = (layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()
+ if (firstPosition == 0) reloadBase(true)
else scrollToTop()
}
@@ -77,12 +84,8 @@ class FrostRecyclerView @JvmOverloads constructor(
smoothScrollToPosition(0)
}
+ // nothing running in background; no need to listen
override var active: Boolean = true
- set(value) {
- if (field == value) return
- field = value
- // todo
- }
override fun reloadTheme() {
reloadThemeSelf()
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 0d04fcd9..c35f1bb8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -6,6 +6,7 @@ import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
+import android.view.ViewGroup
import ca.allanwang.kau.utils.AnimHolder
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
@@ -147,4 +148,11 @@ class FrostWebView @JvmOverloads constructor(
settings.textZoom = Prefs.webTextScaling
}
+ override fun destroy() {
+ val parent = getParent() as? ViewGroup
+ if (parent != null) {
+ parent.removeView(this)
+ super.destroy()
+ }
+ }
} \ No newline at end of file