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 --- .../com/pitchedapps/frost/views/AccountItem.kt | 6 ++-- .../pitchedapps/frost/views/FrostRecyclerView.kt | 37 ++++++++++++---------- .../com/pitchedapps/frost/views/FrostWebView.kt | 8 +++++ 3 files changed, 32 insertions(+), 19 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views') 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 { + Glide.with(itemView).load(PROFILE_PICTURE_URL(cookie.id)) + .transform(FrostGlide.roundCorner).listener(object : RequestListener { override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, 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 + 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 -- cgit v1.2.3