aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-29 19:39:04 -0500
committerGitHub <noreply@github.com>2017-12-29 19:39:04 -0500
commit32e6b5be0e662bbac22806bcc87259fd1a2e2ed0 (patch)
treec97f7ef11b60231bbe7337f5960413b95da0a8c2 /app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
parent8fee0629c27edee847358efc82309118f3a9a3a5 (diff)
downloadfrost-32e6b5be0e662bbac22806bcc87259fd1a2e2ed0.tar.gz
frost-32e6b5be0e662bbac22806bcc87259fd1a2e2ed0.tar.bz2
frost-32e6b5be0e662bbac22806bcc87259fd1a2e2ed0.zip
Feature/native notifs (#579)
* Improve parser and add zip test * Remove ActivityOptionsCompat, resolves #555 * Create native notifs * Add animations * Add image rounder * Improve glide transformations * Add request service * Fix parser * Fix parser * Add thumbnail and fix notification text * Update parsers and regex * Auto mark as read * Add request implementation in pending intent * Remove unnecessary return data * Simplify command retrieval * Use name keys instead * Revamp all bundle calls * Fix up thumbnail layout
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt37
1 files changed, 20 insertions, 17 deletions
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()