aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-24 01:47:03 -0500
committerGitHub <noreply@github.com>2018-12-24 01:47:03 -0500
commit697d01882ba8b1dbb85484ba3bf6e810e32448fc (patch)
treef59d2407ffbd724200e3c79eb366a8da1efe0829 /app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
parentc45b30e28f451699f3be828a1201260ed27e321e (diff)
downloadfrost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.gz
frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.bz2
frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.zip
Enhancement/ktlint (#1259)
* Add spotless * Reformat code * Apply license header * Add remaining license headers
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt91
1 files changed, 60 insertions, 31 deletions
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 c44a8188..d17a424c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt
@@ -1,13 +1,36 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.views
import android.content.Context
import android.os.Build
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
-import ca.allanwang.kau.utils.*
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.circularReveal
+import ca.allanwang.kau.utils.fadeIn
+import ca.allanwang.kau.utils.fadeOut
+import ca.allanwang.kau.utils.invisibleIf
+import ca.allanwang.kau.utils.isVisible
+import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.withAlpha
import com.pitchedapps.frost.R
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
@@ -24,25 +47,32 @@ import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.PublishSubject
class FrostContentWeb @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
) : FrostContentView<FrostWebView>(context, attrs, defStyleAttr, defStyleRes) {
override val layoutRes: Int = R.layout.view_content_base_web
-
}
class FrostContentRecycler @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
) : FrostContentView<FrostRecyclerView>(context, attrs, defStyleAttr, defStyleRes) {
override val layoutRes: Int = R.layout.view_content_base_recycler
-
}
abstract class FrostContentView<out T> @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0,
+ defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes),
- FrostContentParent where T : View, T : FrostContentCore {
+ FrostContentParent where T : View, T : FrostContentCore {
private val refresh: SwipeRefreshLayout by bindView(R.id.content_refresh)
private val progress: ProgressBar by bindView(R.id.content_progress)
@@ -88,15 +118,14 @@ abstract class FrostContentView<out T> @JvmOverloads constructor(
}.addTo(compositeDisposable)
refreshObservable
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- refresh.isRefreshing = it
- refresh.isEnabled = true
- }.addTo(compositeDisposable)
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe {
+ refresh.isRefreshing = it
+ refresh.isEnabled = true
+ }.addTo(compositeDisposable)
refresh.setOnRefreshListener { coreView.reload(true) }
reloadThemeSelf()
-
}
override fun bind(container: FrostContentContainer) {
@@ -151,24 +180,24 @@ abstract class FrostContentView<out T> @JvmOverloads constructor(
var loading = dispose != null
dispose?.dispose()
dispose = refreshObservable
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- if (it) {
- loading = true
- transitionStart = System.currentTimeMillis()
- clearAnimation()
- if (isVisible)
- fadeOut(duration = 200L)
- } else if (loading) {
- loading = false
- if (animate && Prefs.animate) circularReveal(offset = WEB_LOAD_DELAY)
- else fadeIn(duration = 200L, offset = WEB_LOAD_DELAY)
- L.v { "Transition loaded in ${System.currentTimeMillis() - transitionStart} ms" }
- dispose?.dispose()
- dispose = null
- }
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe {
+ if (it) {
+ loading = true
+ transitionStart = System.currentTimeMillis()
+ clearAnimation()
+ if (isVisible)
+ fadeOut(duration = 200L)
+ } else if (loading) {
+ loading = false
+ if (animate && Prefs.animate) circularReveal(offset = WEB_LOAD_DELAY)
+ else fadeIn(duration = 200L, offset = WEB_LOAD_DELAY)
+ L.v { "Transition loaded in ${System.currentTimeMillis() - transitionStart} ms" }
+ dispose?.dispose()
+ dispose = null
}
+ }
}
return true
}
-} \ No newline at end of file
+}