From 32e6b5be0e662bbac22806bcc87259fd1a2e2ed0 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 29 Dec 2017 19:39:04 -0500 Subject: 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 --- .../pitchedapps/frost/views/FrostRecyclerView.kt | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt') 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 + 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() -- cgit v1.2.3