mirror of
https://github.com/yogeshpaliyal/KeyPass.git
synced 2026-01-07 00:49:46 -06:00
security fixes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.yogeshpaliyal.keypass.ui.nav
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
@@ -59,16 +58,6 @@ class BottomNavDrawerFragment :
|
||||
elevation = resources.getDimension(R.dimen.plane_16)
|
||||
shadowCompatibilityMode = MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER
|
||||
initializeElevationOverlay(requireContext())
|
||||
/* shapeAppearanceModel = shapeAppearanceModel.toBuilder()
|
||||
.setTopEdge(
|
||||
SemiCircleEdgeCutoutTreatment(
|
||||
resources.getDimension(R.dimen.grid_1),
|
||||
resources.getDimension(R.dimen.grid_3),
|
||||
0F,
|
||||
resources.getDimension(R.dimen.navigation_drawer_profile_image_size_padded)
|
||||
)
|
||||
)
|
||||
.build()*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,11 +102,7 @@ class BottomNavDrawerFragment :
|
||||
// Scrim view transforms
|
||||
addOnSlideAction(AlphaSlideAction(scrimView))
|
||||
addOnStateChangedAction(VisibilityStateAction(scrimView))
|
||||
// Foreground transforms
|
||||
/* addOnSlideAction(ForegroundSheetTransformSlideAction(
|
||||
binding.foregroundContainer,
|
||||
foregroundShapeDrawable
|
||||
))*/
|
||||
|
||||
// Recycler transforms
|
||||
addOnStateChangedAction(ScrollToTopStateAction(navRecyclerView))
|
||||
// Close the sandwiching account picker if open
|
||||
|
||||
@@ -86,15 +86,7 @@ class BottomNavigationDrawerCallback : BottomSheetBehavior.BottomSheetCallback()
|
||||
return onSlideActions.add(action)
|
||||
}
|
||||
|
||||
fun removeOnSlideAction(action: OnSlideAction): Boolean {
|
||||
return onSlideActions.remove(action)
|
||||
}
|
||||
|
||||
fun addOnStateChangedAction(action: OnStateChangedAction): Boolean {
|
||||
return onStateChangedActions.add(action)
|
||||
}
|
||||
|
||||
fun removeOnStateChangedAction(action: OnStateChangedAction): Boolean {
|
||||
return onStateChangedActions.remove(action)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package com.yogeshpaliyal.keypass.ui.nav
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.updatePadding
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.yogeshpaliyal.common.utils.normalize
|
||||
import com.yogeshpaliyal.keypass.R
|
||||
|
||||
/**
|
||||
* An action to be performed when a bottom sheet's slide offset is changed.
|
||||
@@ -31,73 +26,6 @@ interface OnSlideAction {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A slide action which rotates a view counterclockwise by 180 degrees between the hidden state
|
||||
* and the half expanded state.
|
||||
*/
|
||||
class HalfClockwiseRotateSlideAction(
|
||||
private val view: View
|
||||
) : OnSlideAction {
|
||||
|
||||
override fun onSlide(sheet: View, slideOffset: Float) {
|
||||
view.rotation = slideOffset.normalize(
|
||||
-1F,
|
||||
0F,
|
||||
0F,
|
||||
180F
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A slide action which acts on the nav drawer between the half expanded state and
|
||||
* expanded state by:
|
||||
* - Scaling the user avatar
|
||||
* - Translating the foreground sheet
|
||||
* - Removing the foreground sheets rounded corners/edge treatment
|
||||
*/
|
||||
class ForegroundSheetTransformSlideAction(
|
||||
private val foregroundView: View,
|
||||
private val foregroundShapeDrawable: MaterialShapeDrawable,
|
||||
private val profileImageView: ImageView
|
||||
) : OnSlideAction {
|
||||
|
||||
private val foregroundMarginTop = foregroundView.marginTop
|
||||
private var systemTopInset: Int = 0
|
||||
private val foregroundZ = foregroundView.z
|
||||
private val profileImageOriginalZ = profileImageView.z
|
||||
|
||||
private fun getPaddingTop(): Int {
|
||||
// This view's tag might not be set immediately as it needs to wait for insets to be
|
||||
// applied. Lazily evaluate to ensure we get a value, even if we've already started slide
|
||||
// changes.
|
||||
if (systemTopInset == 0) {
|
||||
systemTopInset = foregroundView.getTag(R.id.tag_system_window_inset_top) as? Int? ?: 0
|
||||
}
|
||||
return systemTopInset
|
||||
}
|
||||
|
||||
override fun onSlide(sheet: View, slideOffset: Float) {
|
||||
val progress = slideOffset.normalize(0F, 0.25F, 1F, 0F)
|
||||
profileImageView.scaleX = progress
|
||||
profileImageView.scaleY = progress
|
||||
foregroundShapeDrawable.interpolation = progress
|
||||
|
||||
foregroundView.translationY = -(1 - progress) * foregroundMarginTop
|
||||
val topPaddingProgress = slideOffset.normalize(0F, 0.9F, 0F, 1F)
|
||||
foregroundView.updatePadding(top = (getPaddingTop() * topPaddingProgress).toInt())
|
||||
|
||||
// Modify the z ordering of the profileImage to make it easier to click when half-expanded.
|
||||
// Reset the z order if the sheet is expanding so the profile image slides under the
|
||||
// foreground sheet.
|
||||
if (slideOffset > 0 && foregroundZ <= profileImageView.z) {
|
||||
profileImageView.z = profileImageOriginalZ
|
||||
} else if (slideOffset <= 0 && foregroundZ >= profileImageView.z) {
|
||||
profileImageView.z = foregroundZ + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the alpha of [view] when a bottom sheet is slid.
|
||||
*
|
||||
|
||||
@@ -17,38 +17,48 @@ import kotlinx.coroutines.flow.Flow
|
||||
*/
|
||||
|
||||
@Dao
|
||||
abstract class DbDao {
|
||||
interface DbDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun insertOrUpdateAccount(vararg accountModel: AccountModel)
|
||||
suspend fun insertOrUpdateAccount(vararg accountModel: AccountModel)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun insertOrUpdateAccount(accountModel: List<AccountModel>)
|
||||
suspend fun insertOrUpdateAccount(accountModel: List<AccountModel>)
|
||||
|
||||
@Query("SELECT * FROM account ORDER BY title ASC")
|
||||
abstract fun getAllAccounts(): LiveData<List<AccountModel>>
|
||||
fun getAllAccounts(): LiveData<List<AccountModel>>
|
||||
|
||||
@Query("SELECT * FROM account ORDER BY title ASC")
|
||||
abstract suspend fun getAllAccountsList(): List<AccountModel>
|
||||
suspend fun getAllAccountsList(): List<AccountModel>
|
||||
|
||||
@Query("SELECT * FROM account WHERE CASE WHEN :tag IS NOT NULL THEN tags = :tag ELSE 1 END AND ((username LIKE '%'||:query||'%' ) OR (title LIKE '%'||:query||'%' ) OR (notes LIKE '%'||:query||'%' )) ORDER BY title ASC")
|
||||
abstract fun getAllAccounts(query: String?, tag: String?): LiveData<List<AccountModel>>
|
||||
@Query(
|
||||
"SELECT * FROM account " +
|
||||
"WHERE " +
|
||||
"CASE WHEN :tag IS NOT NULL " +
|
||||
"THEN tags = :tag " +
|
||||
"ELSE 1 END " +
|
||||
"AND ((username LIKE '%'||:query||'%' ) " +
|
||||
"OR (title LIKE '%'||:query||'%' ) " +
|
||||
"OR (notes LIKE '%'||:query||'%' )) " +
|
||||
"ORDER BY title ASC"
|
||||
)
|
||||
fun getAllAccounts(query: String?, tag: String?): LiveData<List<AccountModel>>
|
||||
|
||||
@Query("SELECT * FROM account WHERE id = :id")
|
||||
abstract suspend fun getAccount(id: Long?): AccountModel?
|
||||
suspend fun getAccount(id: Long?): AccountModel?
|
||||
|
||||
@Query("SELECT * FROM account WHERE unique_id = :uniqueId")
|
||||
abstract suspend fun getAccount(uniqueId: String?): AccountModel?
|
||||
suspend fun getAccount(uniqueId: String?): AccountModel?
|
||||
|
||||
@Query("SELECT DISTINCT tags FROM account")
|
||||
abstract fun getTags(): Flow<List<String>>
|
||||
fun getTags(): Flow<List<String>>
|
||||
|
||||
@Query("DELETE from account WHERE id = :id")
|
||||
abstract suspend fun deleteAccount(id: Long?)
|
||||
suspend fun deleteAccount(id: Long?)
|
||||
|
||||
@Query("DELETE from account WHERE unique_id = :uniqueId")
|
||||
abstract suspend fun deleteAccount(uniqueId: String?)
|
||||
suspend fun deleteAccount(uniqueId: String?)
|
||||
|
||||
@Delete
|
||||
abstract suspend fun deleteAccount(accountModel: AccountModel)
|
||||
suspend fun deleteAccount(accountModel: AccountModel)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ object AppModule {
|
||||
?.use {
|
||||
while (it.moveToNext()) {
|
||||
val id = it.getInt(0)
|
||||
database.execSQL("update `account` set `unique_id` = '${getRandomString()}' where `id` = '$id'")
|
||||
val query = "update `account` set `unique_id` = '${getRandomString()}' where `id` = '$id'"
|
||||
database.execSQL(query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,73 +16,6 @@
|
||||
|
||||
package com.yogeshpaliyal.common.utils
|
||||
|
||||
import androidx.annotation.FloatRange
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Linearly interpolate between two values
|
||||
*/
|
||||
fun lerp(
|
||||
startValue: Float,
|
||||
endValue: Float,
|
||||
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
|
||||
): Float {
|
||||
return startValue + fraction * (endValue - startValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolate between two values
|
||||
*/
|
||||
fun lerp(
|
||||
startValue: Int,
|
||||
endValue: Int,
|
||||
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
|
||||
): Int {
|
||||
return (startValue + fraction * (endValue - startValue)).roundToInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolate between two values when the fraction is in a given range.
|
||||
*/
|
||||
fun lerp(
|
||||
startValue: Float,
|
||||
endValue: Float,
|
||||
@FloatRange(
|
||||
from = 0.0,
|
||||
fromInclusive = true,
|
||||
to = 1.0,
|
||||
toInclusive = false
|
||||
) startFraction: Float,
|
||||
@FloatRange(from = 0.0, fromInclusive = false, to = 1.0, toInclusive = true) endFraction: Float,
|
||||
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
|
||||
): Float {
|
||||
if (fraction < startFraction) return startValue
|
||||
if (fraction > endFraction) return endValue
|
||||
|
||||
return lerp(startValue, endValue, (fraction - startFraction) / (endFraction - startFraction))
|
||||
}
|
||||
|
||||
/**
|
||||
* Linearly interpolate between two values when the fraction is in a given range.
|
||||
*/
|
||||
fun lerp(
|
||||
startValue: Int,
|
||||
endValue: Int,
|
||||
@FloatRange(
|
||||
from = 0.0,
|
||||
fromInclusive = true,
|
||||
to = 1.0,
|
||||
toInclusive = false
|
||||
) startFraction: Float,
|
||||
@FloatRange(from = 0.0, fromInclusive = false, to = 1.0, toInclusive = true) endFraction: Float,
|
||||
@FloatRange(from = 0.0, fromInclusive = true, to = 1.0, toInclusive = true) fraction: Float
|
||||
): Int {
|
||||
if (fraction < startFraction) return startValue
|
||||
if (fraction > endFraction) return endValue
|
||||
|
||||
return lerp(startValue, endValue, (fraction - startFraction) / (endFraction - startFraction))
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce the receiving Float between inputMin and inputMax and linearly interpolate to the
|
||||
* outputMin to outputMax scale. This function is able to handle ranges which span negative and
|
||||
|
||||
Reference in New Issue
Block a user