1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-09-19 23:21:34 +02:00

Merge pull request #1459 from AllanWang/image-swipe

Image swipe
This commit is contained in:
Allan Wang 2019-07-01 23:55:47 -07:00 committed by GitHub
commit 312f956b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 224 additions and 66 deletions

View File

@ -189,21 +189,23 @@ dependencies {
implementation kau.Dependencies.kotlin
//noinspection GradleDependency
implementation "ca.allanwang.kau:adapter:${KAU}"
implementation kau.Dependencies.kau('core', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:about:${KAU}"
implementation kau.Dependencies.kau('core-ui', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:colorpicker:${KAU}"
implementation kau.Dependencies.kau('adapter', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:mediapicker:${KAU}"
implementation kau.Dependencies.kau('fastadapter', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:kpref-activity:${KAU}"
implementation kau.Dependencies.kau('about', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:searchview:${KAU}"
implementation kau.Dependencies.kau('colorpicker', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:core:${KAU}"
implementation kau.Dependencies.kau('mediapicker', KAU)
//noinspection GradleDependency
implementation "ca.allanwang.kau:core-ui:${KAU}"
implementation kau.Dependencies.kau('kpref-activity', KAU)
//noinspection GradleDependency
implementation kau.Dependencies.kau('searchview', KAU)
implementation "androidx.core:core-ktx:${Versions.ktx}"

View File

@ -147,7 +147,7 @@
android:theme="@style/Kau.About" />
<activity
android:name=".activities.ImageActivity"
android:theme="@style/FrostTheme.Transparent" />
android:theme="@style/FrostTheme.Overlay" />
<activity android:name=".activities.DebugActivity" />
<service

View File

@ -86,7 +86,12 @@ class StartActivity : KauBaseActivity() {
FbCookie.switchBackUser()
val cookies = ArrayList(cookieDao.selectAll())
L.i { "Cookies loaded at time ${System.currentTimeMillis()}" }
L._d { "Cookies: ${cookies.joinToString("\t", transform = CookieEntity::toSensitiveString)}" }
L._d {
"Cookies: ${cookies.joinToString(
"\t",
transform = CookieEntity::toSensitiveString
)}"
}
loadAssets()
authDefer.await()
when {
@ -112,7 +117,8 @@ class StartActivity : KauBaseActivity() {
*/
private suspend fun migrate() = withContext(Dispatchers.IO) {
if (cookieDao.selectAll().isNotEmpty()) return@withContext
val cookies = (select from CookieModel::class).queryList().map { CookieEntity(it.id, it.name, it.cookie) }
val cookies = (select from CookieModel::class).queryList()
.map { CookieEntity(it.id, it.name, it.cookie) }
if (cookies.isNotEmpty()) {
cookieDao.save(cookies)
L._d { "Migrated cookies ${cookieDao.selectAll()}" }

View File

@ -23,11 +23,13 @@ import android.graphics.Color
import android.os.Bundle
import android.os.Environment
import android.view.View
import androidx.customview.widget.ViewDragHelper
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.logging.KauLoggerExtension
import ca.allanwang.kau.mediapicker.scanMedia
import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE
import ca.allanwang.kau.permissions.kauRequestPermissions
import ca.allanwang.kau.utils.adjustAlpha
import ca.allanwang.kau.utils.colorToForeground
import ca.allanwang.kau.utils.copyFromInputStream
import ca.allanwang.kau.utils.fadeOut
@ -75,6 +77,8 @@ import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import kotlin.math.abs
import kotlin.math.max
/**
* Created by Allan Wang on 2017-07-15.
@ -103,6 +107,8 @@ class ImageActivity : KauBaseActivity() {
value.update(image_fab)
}
private lateinit var dragHelper: ViewDragHelper
companion object {
/**
* Cache folder to store images
@ -135,6 +141,9 @@ class ImageActivity : KauBaseActivity() {
)}_${Math.abs(imageUrl.hashCode())}"
}
private val baseBackgroundColor = if (Prefs.blackMediaBg) Color.BLACK
else Prefs.bgColor.withMinAlpha(235)
private fun loadError(e: Throwable) {
errorRef = e
e.logFrostEvent("Image load error")
@ -158,12 +167,10 @@ class ImageActivity : KauBaseActivity() {
result
}
val layout = if (!imageText.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless
val layout =
if (!imageText.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless
setContentView(layout)
image_container.setBackgroundColor(
if (Prefs.blackMediaBg) Color.BLACK
else Prefs.bgColor.withMinAlpha(222)
)
image_container.setBackgroundColor(baseBackgroundColor)
image_text?.setTextColor(if (Prefs.blackMediaBg) Color.WHITE else Prefs.textColor)
image_text?.setBackgroundColor(
(if (Prefs.blackMediaBg) Color.BLACK else Prefs.bgColor)
@ -171,7 +178,8 @@ class ImageActivity : KauBaseActivity() {
)
image_text?.text = imageText
image_progress.tint(if (Prefs.blackMediaBg) Color.WHITE else Prefs.accentColor)
image_panel?.addPanelSlideListener(object : SlidingUpPanelLayout.SimplePanelSlideListener() {
image_panel?.addPanelSlideListener(object :
SlidingUpPanelLayout.SimplePanelSlideListener() {
override fun onPanelSlide(panel: View, slideOffset: Float) {
if (slideOffset == 0f && !image_fab.isShown) image_fab.show()
else if (slideOffset != 0f && image_fab.isShown) image_fab.hide()
@ -179,7 +187,8 @@ class ImageActivity : KauBaseActivity() {
}
})
image_fab.setOnClickListener { fabAction.onClick(this) }
image_photo.setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
image_photo.setOnImageEventListener(object :
SubsamplingScaleImageView.DefaultOnImageEventListener() {
override fun onImageLoadError(e: Exception) {
loadError(e)
}
@ -194,14 +203,73 @@ class ImageActivity : KauBaseActivity() {
image_photo.setImage(ImageSource.uri(frostUriFromFile(tempFile)))
fabAction = FabStates.DOWNLOAD
image_photo.animate().alpha(1f).scaleXY(1f).start()
dragHelper = ViewDragHelper.create(image_drag, ViewDragCallback()).apply {
setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP or ViewDragHelper.EDGE_BOTTOM)
}
image_drag.dragHelper = dragHelper
}
}
private inner class ViewDragCallback : ViewDragHelper.Callback() {
private var scrollPercent: Float = 0f
private var scrollThreshold = 0.5f
private var scrollToTop = false
override fun tryCaptureView(view: View, i: Int): Boolean {
return true
}
override fun getViewHorizontalDragRange(child: View): Int = 0
override fun getViewVerticalDragRange(child: View): Int = child.height
override fun onViewPositionChanged(
changedView: View,
left: Int,
top: Int,
dx: Int,
dy: Int
) {
super.onViewPositionChanged(changedView, left, top, dx, dy)
//make sure that we are using the proper axis
scrollPercent = abs(top.toFloat() / image_container.height)
scrollToTop = top < 0
val multiplier = max(1f - scrollPercent, 0f)
image_fab.alpha = multiplier
image_panel?.alpha = multiplier
image_container.setBackgroundColor(baseBackgroundColor.adjustAlpha(multiplier))
if (scrollPercent >= 1) {
if (!isFinishing) {
finish()
overridePendingTransition(0, 0)
}
}
}
override fun onViewReleased(releasedChild: View, xvel: Float, yvel: Float) {
val overScrolled = scrollPercent > scrollThreshold
val maxOffset = releasedChild.height + 10
val finalTop = when {
scrollToTop && (overScrolled || yvel < -dragHelper.minVelocity) -> -maxOffset
!scrollToTop && (overScrolled || yvel > dragHelper.minVelocity) -> maxOffset
else -> 0
}
dragHelper.settleCapturedViewAt(0, finalTop)
image_drag.invalidate()
}
override fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int = 0
override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int = top
}
@Throws(IOException::class)
private fun createPublicMediaFile(): File {
val timeStamp = SimpleDateFormat(TIME_FORMAT, Locale.getDefault()).format(Date())
val imageFileName = "${IMG_TAG}_${timeStamp}_"
val storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
val storageDir =
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
val frostDir = File(storageDir, IMG_TAG)
if (!frostDir.exists()) frostDir.mkdirs()
return File.createTempFile(imageFileName, IMG_EXTENSION, frostDir)

View File

@ -19,7 +19,6 @@ package com.pitchedapps.frost.utils
import android.graphics.Color
import ca.allanwang.kau.kotlin.lazyResettable
import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.kpref
import ca.allanwang.kau.utils.colorToForeground
import ca.allanwang.kau.utils.isColorVisibleOn
import ca.allanwang.kau.utils.withAlpha

View File

@ -17,8 +17,6 @@
package com.pitchedapps.frost.utils
import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.kpref
import ca.allanwang.kau.kpref.kprefSingle
/**
* Created by Allan Wang on 2017-07-03.

View File

@ -0,0 +1,58 @@
/*
* Copyright 2019 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.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import androidx.core.view.ViewCompat
import androidx.customview.widget.ViewDragHelper
class DragFrame @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
var dragHelper: ViewDragHelper? = null
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return try {
dragHelper?.shouldInterceptTouchEvent(event) ?: false
} catch (e: Exception) {
false
}
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
try {
dragHelper?.processTouchEvent(event) ?: return false
} catch (e: Exception) {
return false
}
return true
}
override fun computeScroll() {
super.computeScroll()
if (dragHelper?.continueSettling(true) == true) {
ViewCompat.postInvalidateOnAnimation(this)
}
}
}

View File

@ -1,3 +1,19 @@
/*
* Copyright 2019 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
@ -84,4 +100,4 @@ class SwipeRefreshLayout @JvmOverloads constructor(context: Context, attrs: Attr
* Alias for adding on refresh listener
*/
interface OnRefreshListener : SwipeRefreshLayout.OnRefreshListener
}
}

View File

@ -1,4 +1,5 @@
v2.3.1
* Hide all story panels if enabled
* Prevent swipe to refresh if not at the very top
* Prevent swipe to refresh if not at the very top
* Add vertical swipe to dismiss when viewing images

View File

@ -12,31 +12,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/image_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:umanoPanelHeight="44dp"
app:umanoShadowHeight="0dp">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:scaleX="0.9"
android:scaleY="0.9" />
<TextView
android:id="@+id/image_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.5"
android:padding="@dimen/kau_padding_normal" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/image_fab"
android:layout_width="wrap_content"
@ -45,4 +20,36 @@
android:layout_margin="@dimen/kau_fab_margin"
android:visibility="invisible" />
<com.pitchedapps.frost.views.DragFrame
android:id="@+id/image_drag"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/image_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:umanoPanelHeight="44dp"
app:umanoShadowHeight="0dp">
<TextView
android:id="@+id/image_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.5"
android:padding="@dimen/kau_padding_normal" />
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:scaleX="0.9"
android:scaleY="0.9" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</com.pitchedapps.frost.views.DragFrame>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -11,13 +11,20 @@
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_photo"
<com.pitchedapps.frost.views.DragFrame
android:id="@+id/image_drag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:scaleX="0.9"
android:scaleY="0.9" />
android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:scaleX="0.9"
android:scaleY="0.9" />
</com.pitchedapps.frost.views.DragFrame>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/image_fab"

View File

@ -38,6 +38,9 @@
</style>
<style name="FrostTheme.Overlay">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
@ -49,12 +52,7 @@
<item name="android:windowAnimationStyle">@style/KauFadeInFadeOut</item>
</style>
<style name="FrostTheme.Video" parent="FrostTheme.Overlay.Fade">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="FrostTheme.Video" parent="FrostTheme.Overlay.Fade" />
<style name="FrostTheme.Settings" parent="FrostTheme">
<item name="android:windowAnimationStyle">@style/KauSlideInFadeOut</item>

View File

@ -9,7 +9,7 @@
<version title="v2.3.1" />
<item text="Hide all story panels if enabled" />
<item text="Prevent swipe to refresh if not at the very top" />
<item text="" />
<item text="Add vertical swipe to dismiss when viewing images" />
<item text="" />
<item text="" />
@ -21,9 +21,6 @@
<item text="Add fingerprint unlock screen" />
<item text="Fix messenger redirect" />
<item text="Lots of internal updates" />
<item text="" />
<item text="" />
<item text="" />
<version title="v2.2.4" />
<item text="Show top bar to allow sharing posts" />

View File

@ -3,6 +3,7 @@
## v2.3.1
* Hide all story panels if enabled
* Prevent swipe to refresh if not at the very top
* Add vertical swipe to dismiss when viewing images
## v2.3.0
* Converted internals of Facebook data storage; auto migration will only work from 2.2.x to 2.3.x

View File

@ -16,7 +16,7 @@ org.gradle.daemon = true
APP_ID=Frost
APP_GROUP=com.pitchedapps
KAU=5.0.0
KAU=d91d734
android.useAndroidX=true
android.enableJetifier=true