aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-12-24 01:49:57 -0500
committerGitHub <noreply@github.com>2018-12-24 01:49:57 -0500
commit2c02356c498b3db6f13bd7a3af8689c24ca224ea (patch)
tree726ad142a8a373715493cf602786361226f624ee /app/src/main/kotlin/com/pitchedapps/frost/views
parentfce0bf0a6df09de78a804dc874f48f67336d9d9c (diff)
parent697d01882ba8b1dbb85484ba3bf6e810e32448fc (diff)
downloadfrost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.tar.gz
frost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.tar.bz2
frost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.zip
Merge branch 'dev' into update/coroutines
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt69
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt66
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostContentView.kt91
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt29
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt43
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt91
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt43
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt31
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/KPrefTextSeekbar.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt37
10 files changed, 370 insertions, 148 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 7262fa17..d7a7de0e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/AccountItem.kt
@@ -1,12 +1,32 @@
+/*
+ * 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.graphics.drawable.Drawable
-import android.support.v7.widget.AppCompatTextView
-import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
+import androidx.appcompat.widget.AppCompatTextView
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.iitems.KauIItem
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.fadeIn
+import ca.allanwang.kau.utils.invisible
+import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.visible
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
@@ -23,7 +43,7 @@ import com.pitchedapps.frost.utils.Prefs
* Created by Allan Wang on 2017-06-05.
*/
class AccountItem(val cookie: CookieModel?) : KauIItem<AccountItem, AccountItem.ViewHolder>
-(R.layout.view_account, { ViewHolder(it) }, R.id.item_account) {
+ (R.layout.view_account, { ViewHolder(it) }, R.id.item_account) {
override fun bindView(viewHolder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(viewHolder, payloads)
@@ -33,20 +53,37 @@ class AccountItem(val cookie: CookieModel?) : KauIItem<AccountItem, AccountItem.
if (cookie != null) {
text.text = cookie.name
GlideApp.with(itemView).load(profilePictureUrl(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
- }
+ .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
+ }
- override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
- text.fadeIn()
- return false
- }
- }).into(image)
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any?,
+ target: Target<Drawable>?,
+ isFirstResource: Boolean
+ ): Boolean {
+ text.fadeIn()
+ return false
+ }
+ }).into(image)
} else {
text.visible()
- image.setImageDrawable(GoogleMaterial.Icon.gmd_add_circle_outline.toDrawable(itemView.context, 100, Prefs.textColor))
+ image.setImageDrawable(
+ GoogleMaterial.Icon.gmd_add_circle_outline.toDrawable(
+ itemView.context,
+ 100,
+ Prefs.textColor
+ )
+ )
text.text = itemView.context.getString(R.string.kau_add_account)
}
}
@@ -64,4 +101,4 @@ class AccountItem(val cookie: CookieModel?) : KauIItem<AccountItem, AccountItem.
val image: ImageView by bindView(R.id.account_image)
val text: AppCompatTextView by bindView(R.id.account_text)
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
index 60713034..51a7a8e9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
@@ -1,54 +1,78 @@
+/*
+ * 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.graphics.drawable.GradientDrawable
-import android.support.constraint.ConstraintLayout
import android.util.AttributeSet
-import android.widget.ImageView
-import android.widget.TextView
-import ca.allanwang.kau.utils.*
+import androidx.constraintlayout.widget.ConstraintLayout
+import ca.allanwang.kau.utils.colorToForeground
+import ca.allanwang.kau.utils.dpToPx
+import ca.allanwang.kau.utils.gone
+import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.visible
+import ca.allanwang.kau.utils.withAlpha
import com.mikepenz.iconics.typeface.IIcon
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.Prefs
-
+import kotlinx.android.synthetic.main.view_badged_icon.view.*
/**
* Created by Allan Wang on 2017-06-19.
*/
class BadgedIcon @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
- val badgeTextView: TextView by bindView(R.id.badge_text)
- val badgeImage: ImageView by bindView(R.id.badge_image)
-
init {
inflate(context, R.layout.view_badged_icon, this)
val badgeColor = Prefs.mainActivityLayout.backgroundColor().withAlpha(255).colorToForeground(0.2f)
- val badgeBackground = GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(badgeColor, badgeColor))
+ val badgeBackground =
+ GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(badgeColor, badgeColor))
badgeBackground.cornerRadius = 13.dpToPx.toFloat()
- badgeTextView.background = badgeBackground
- badgeTextView.setTextColor(Prefs.mainActivityLayout.iconColor())
+ badge_text.background = badgeBackground
+ badge_text.setTextColor(Prefs.mainActivityLayout.iconColor())
}
var iicon: IIcon? = null
set(value) {
field = value
- badgeImage.setImageDrawable(value?.toDrawable(context, sizeDp = 20, color = Prefs.mainActivityLayout.iconColor()))
+ badge_image.setImageDrawable(
+ value?.toDrawable(
+ context,
+ sizeDp = 20,
+ color = Prefs.mainActivityLayout.iconColor()
+ )
+ )
}
fun setAllAlpha(alpha: Float) {
//badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt()))
- badgeImage.drawable.alpha = alpha.toInt()
+ badge_image.drawable.alpha = alpha.toInt()
}
var badgeText: String?
- get() = badgeTextView.text.toString()
+ get() = badge_text.text.toString()
set(value) {
- if (badgeTextView.text == value) return
- badgeTextView.text = value
- if (value != null && value != "0") badgeTextView.visible()
- else badgeTextView.gone()
+ if (badge_text.text == value) return
+ badge_text.text = value
+ if (value != null && value != "0") badge_text.visible()
+ else badge_text.gone()
}
-
-} \ No newline at end of file
+}
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 19b1176e..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 android.support.v4.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
+}
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 38b09657..2b9e8f9c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt
@@ -1,10 +1,26 @@
+/*
+ * 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.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.View
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.utils.circularReveal
import ca.allanwang.kau.utils.fadeOut
import com.pitchedapps.frost.contracts.FrostContentContainer
@@ -18,9 +34,11 @@ import com.pitchedapps.frost.utils.Prefs
*
*/
class FrostRecyclerView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : RecyclerView(context, attrs, defStyleAttr),
- FrostContentCore {
+ FrostContentCore {
override fun reload(animate: Boolean) = reloadBase(animate)
@@ -102,5 +120,4 @@ class FrostRecyclerView @JvmOverloads constructor(
override fun reloadTextSizeSelf() {
// todo
}
-
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
index d7f44420..6ee34a2b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoView.kt
@@ -1,3 +1,19 @@
+/*
+ * 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.annotation.SuppressLint
@@ -27,7 +43,9 @@ import com.pitchedapps.frost.utils.Prefs
* Parent must have layout with both height & width as match_parent
*/
class FrostVideoView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : VideoView(context, attrs, defStyleAttr) {
/**
@@ -79,7 +97,7 @@ class FrostVideoView @JvmOverloads constructor(
if (!isPlaying) showControls()
else viewerContract.onControlsHidden()
}
- }.start()
+ }
} else {
hideControls()
val (scale, tX, tY) = mapBounds()
@@ -90,7 +108,7 @@ class FrostVideoView @JvmOverloads constructor(
withAnimator(origScale, scale) { scaleXY = it }
withAnimator(origX, tX) { translationX = it }
withAnimator(origY, tY) { translationY = it }
- }.start()
+ }
}
}
@@ -105,7 +123,10 @@ class FrostVideoView @JvmOverloads constructor(
videoDimensions.set(dimen, dimen)
}
val portrait = height > width
- val scale = Math.min(height / (if (portrait) 4f else 2.3f) / videoDimensions.y, width / (if (portrait) 2.3f else 4f) / videoDimensions.x)
+ val scale = Math.min(
+ height / (if (portrait) 4f else 2.3f) / videoDimensions.y,
+ width / (if (portrait) 2.3f else 4f) / videoDimensions.x
+ )
val desiredHeight = scale * videoDimensions.y
val desiredWidth = scale * videoDimensions.x
val padding = containerContract.lowerVideoPadding
@@ -151,8 +172,8 @@ class FrostVideoView @JvmOverloads constructor(
/**
* Only remap if not expanded and if dimensions have changed
*/
- val shouldRemap = !isExpanded
- && (videoDimensions.x != ratio * intrinsicWidth || videoDimensions.y != ratio * intrinsicHeight)
+ val shouldRemap = !isExpanded &&
+ (videoDimensions.x != ratio * intrinsicWidth || videoDimensions.y != ratio * intrinsicHeight)
videoDimensions.set(ratio * intrinsicWidth, ratio * intrinsicHeight)
if (shouldRemap) updateLocation()
}
@@ -210,7 +231,7 @@ class FrostVideoView @JvmOverloads constructor(
duration = FAST_ANIMATION_DURATION
withAnimator(alpha, 0f) { alpha = it }
withEndAction { onFinishedListener() }
- }.start()
+ }
else
onFinishedListener()
}
@@ -226,7 +247,8 @@ class FrostVideoView @JvmOverloads constructor(
* -------------------------------------------------------------------
*/
- private inner class FrameTouchListener(context: Context) : GestureDetector.SimpleOnGestureListener(), View.OnTouchListener {
+ private inner class FrameTouchListener(context: Context) : GestureDetector.SimpleOnGestureListener(),
+ View.OnTouchListener {
private val gestureDetector: GestureDetector = GestureDetector(context, this)
@@ -252,7 +274,8 @@ class FrostVideoView @JvmOverloads constructor(
/**
* Monitors the view click events to show and hide the video controls if they have been specified.
*/
- private inner class VideoTouchListener(context: Context) : GestureDetector.SimpleOnGestureListener(), View.OnTouchListener {
+ private inner class VideoTouchListener(context: Context) : GestureDetector.SimpleOnGestureListener(),
+ View.OnTouchListener {
private val gestureDetector: GestureDetector = GestureDetector(context, this)
private val downLoc = PointF()
@@ -315,4 +338,4 @@ class FrostVideoView @JvmOverloads constructor(
return true
}
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
index 2d5e376d..c2535940 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
@@ -1,38 +1,58 @@
+/*
+ * 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.graphics.Color
import android.graphics.PointF
import android.net.Uri
-import android.support.v7.widget.Toolbar
import android.util.AttributeSet
import android.view.MotionEvent
-import android.view.View
-import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.widget.FrameLayout
-import android.widget.ImageView
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.fadeIn
+import ca.allanwang.kau.utils.fadeOut
+import ca.allanwang.kau.utils.gone
+import ca.allanwang.kau.utils.goneIf
+import ca.allanwang.kau.utils.inflate
+import ca.allanwang.kau.utils.isColorDark
+import ca.allanwang.kau.utils.isGone
+import ca.allanwang.kau.utils.isVisible
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.setMenuIcons
+import ca.allanwang.kau.utils.visible
+import ca.allanwang.kau.utils.withMinAlpha
import com.devbrackets.android.exomedia.listener.VideoControlsVisibilityListener
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostDownload
+import kotlinx.android.synthetic.main.view_video.view.*
/**
* Created by Allan Wang on 2017-10-13.
*/
class FrostVideoViewer @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr), FrostVideoViewerContract {
- val container: ViewGroup by bindView(R.id.video_container)
- val toolbar: Toolbar by bindView(R.id.video_toolbar)
- val background: View by bindView(R.id.video_background)
- val video: FrostVideoView by bindView(R.id.video)
- val restarter: ImageView by bindView(R.id.video_restart)
-
companion object {
/**
* Matches VideoControls.CONTROL_VISIBILITY_ANIMATION_LENGTH
@@ -59,29 +79,31 @@ class FrostVideoViewer @JvmOverloads constructor(
init {
inflate(R.layout.view_video, true)
alpha = 0f
- background.setBackgroundColor(
- if (!Prefs.blackMediaBg && Prefs.bgColor.isColorDark)
- Prefs.bgColor.withMinAlpha(200)
- else
- Color.BLACK)
+ video_background.setBackgroundColor(
+ if (!Prefs.blackMediaBg && Prefs.bgColor.isColorDark)
+ Prefs.bgColor.withMinAlpha(200)
+ else
+ Color.BLACK
+ )
video.setViewerContract(this)
video.pause()
- toolbar.inflateMenu(R.menu.menu_video)
- context.setMenuIcons(toolbar.menu, Prefs.iconColor,
- R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt,
- R.id.action_download to GoogleMaterial.Icon.gmd_file_download
+ video_toolbar.inflateMenu(R.menu.menu_video)
+ context.setMenuIcons(
+ video_toolbar.menu, Prefs.iconColor,
+ R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt,
+ R.id.action_download to GoogleMaterial.Icon.gmd_file_download
)
- toolbar.setOnMenuItemClickListener {
+ video_toolbar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_pip -> video.isExpanded = false
R.id.action_download -> context.frostDownload(video.videoUri)
}
true
}
- restarter.gone().setIcon(GoogleMaterial.Icon.gmd_replay, 64)
- restarter.setOnClickListener {
+ video_restart.gone().setIcon(GoogleMaterial.Icon.gmd_replay, 64)
+ video_restart.setOnClickListener {
video.restart()
- restarter.fadeOut { restarter.gone() }
+ video_restart.fadeOut { video_restart.gone() }
}
}
@@ -115,13 +137,13 @@ class FrostVideoViewer @JvmOverloads constructor(
*/
override fun onExpand(progress: Float) {
- toolbar.goneIf(progress == 0f).alpha = progress
- background.alpha = progress
+ video_toolbar.goneIf(progress == 0f).alpha = progress
+ video_background.alpha = progress
}
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
- if (restarter.isVisible) {
- restarter.performClick()
+ if (video_restart.isVisible) {
+ video_restart.performClick()
return true
}
return false
@@ -129,7 +151,7 @@ class FrostVideoViewer @JvmOverloads constructor(
override fun onVideoComplete() {
video.jumpToStart()
- restarter.fadeIn()
+ video_restart.fadeIn()
}
fun updateLocation() {
@@ -143,14 +165,13 @@ class FrostVideoViewer @JvmOverloads constructor(
override fun onControlsShown() {
if (video.isExpanded)
- toolbar.fadeIn(duration = CONTROL_ANIMATION_DURATION, onStart = { toolbar.visible() })
+ video_toolbar.fadeIn(duration = CONTROL_ANIMATION_DURATION, onStart = { video_toolbar.visible() })
}
override fun onControlsHidden() {
- if (!toolbar.isGone)
- toolbar.fadeOut(duration = CONTROL_ANIMATION_DURATION) { toolbar.gone() }
+ if (!video_toolbar.isGone)
+ video_toolbar.fadeOut(duration = CONTROL_ANIMATION_DURATION) { video_toolbar.gone() }
}
-
}
interface FrostVideoViewerContract : VideoControlsVisibilityListener {
@@ -180,4 +201,4 @@ interface FrostVideoContainerContract {
* Called once the video has stopped & should be removed
*/
fun onVideoFinished()
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt
index 8122d362..bf2f771d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostViewPager.kt
@@ -1,10 +1,26 @@
+/*
+ * 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.annotation.SuppressLint
import android.content.Context
-import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
+import androidx.viewpager.widget.ViewPager
import com.pitchedapps.frost.utils.Prefs
/**
@@ -12,21 +28,22 @@ import com.pitchedapps.frost.utils.Prefs
*
* Basic override to allow us to control swiping
*/
-class FrostViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
+class FrostViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
+ ViewPager(context, attrs) {
var enableSwipe = true
override fun onInterceptTouchEvent(ev: MotionEvent?) =
- try {
- Prefs.viewpagerSwipe && enableSwipe && super.onInterceptTouchEvent(ev)
- } catch (e: IllegalArgumentException) {
- false
- }
+ try {
+ Prefs.viewpagerSwipe && enableSwipe && super.onInterceptTouchEvent(ev)
+ } catch (e: IllegalArgumentException) {
+ false
+ }
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent?): Boolean =
- try {
- Prefs.viewpagerSwipe && enableSwipe && super.onTouchEvent(ev)
- } catch (e: IllegalArgumentException) {
- false
- }
-} \ No newline at end of file
+ try {
+ Prefs.viewpagerSwipe && enableSwipe && super.onTouchEvent(ev)
+ } catch (e: IllegalArgumentException) {
+ false
+ }
+}
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 8230c338..b15ad5cf 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -1,3 +1,19 @@
+/*
+ * 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.animation.ValueAnimator
@@ -16,16 +32,22 @@ import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.fragments.WebFragment
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostDownload
-import com.pitchedapps.frost.web.*
+import com.pitchedapps.frost.web.FrostChromeClient
+import com.pitchedapps.frost.web.FrostJSI
+import com.pitchedapps.frost.web.FrostWebViewClient
+import com.pitchedapps.frost.web.NestedWebView
+import com.pitchedapps.frost.web.shouldUseBasicAgent
/**
* Created by Allan Wang on 2017-05-29.
*
*/
class FrostWebView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : NestedWebView(context, attrs, defStyleAttr),
- FrostContentCore {
+ FrostContentCore {
override fun reload(animate: Boolean) {
if (parent.registerTransition(false, animate))
@@ -59,7 +81,6 @@ class FrostWebView @JvmOverloads constructor(
return this
}
-
/**
* Wrapper to the main userAgentString to cache it.
* This decouples it from the UiThread
@@ -168,4 +189,4 @@ class FrostWebView @JvmOverloads constructor(
super.destroy()
}
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/KPrefTextSeekbar.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/KPrefTextSeekbar.kt
index 14f77e72..7f0d792a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/KPrefTextSeekbar.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/KPrefTextSeekbar.kt
@@ -1,3 +1,19 @@
+/*
+ * 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.annotation.SuppressLint
@@ -43,4 +59,4 @@ class KPrefTextSeekbar(builder: KPrefSeekbarContract) : KPrefSeekbar(builder) {
holder.desc?.setTextSize(TypedValue.COMPLEX_UNIT_PX, descOriginalSize)
super.unbindView(holder)
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt
index 8092133b..e63fcc21 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/Keywords.kt
@@ -1,15 +1,31 @@
+/*
+ * 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.graphics.drawable.Drawable
-import android.support.constraint.ConstraintLayout
-import android.support.v7.widget.AppCompatEditText
-import android.support.v7.widget.AppCompatTextView
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
+import androidx.appcompat.widget.AppCompatEditText
+import androidx.appcompat.widget.AppCompatTextView
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.tint
@@ -23,12 +39,13 @@ import com.mikepenz.iconics.typeface.IIcon
import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.Prefs
-
/**
* Created by Allan Wang on 2017-06-19.
*/
class Keywords @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
val editText: AppCompatEditText by bindView(R.id.edit_text)
@@ -51,7 +68,8 @@ class Keywords @JvmOverloads constructor(
recycler.layoutManager = LinearLayoutManager(context)
recycler.adapter = adapter
adapter.withEventHook(object : ClickEventHook<KeywordItem>() {
- override fun onBind(viewHolder: RecyclerView.ViewHolder): View? = (viewHolder as? KeywordItem.ViewHolder)?.delete
+ override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
+ (viewHolder as? KeywordItem.ViewHolder)?.delete
override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<KeywordItem>, item: KeywordItem) {
adapter.remove(position)
@@ -62,7 +80,6 @@ class Keywords @JvmOverloads constructor(
fun save() {
Prefs.notificationKeywords = adapter.adapterItems.mapTo(mutableSetOf()) { it.keyword }
}
-
}
private fun IIcon.keywordDrawable(context: Context): Drawable = toDrawable(context, 20, Prefs.textColor)
@@ -94,4 +111,4 @@ class KeywordItem(val keyword: String) : AbstractItem<KeywordItem, KeywordItem.V
delete.setImageDrawable(GoogleMaterial.Icon.gmd_delete.keywordDrawable(itemView.context))
}
}
-} \ No newline at end of file
+}