diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavDrawerFragment.kt b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavDrawerFragment.kt index 8bf9bb17..1af99c13 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavDrawerFragment.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavDrawerFragment.kt @@ -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 diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavigationDrawerCallback.kt b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavigationDrawerCallback.kt index a8cc77a3..799479a8 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavigationDrawerCallback.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/BottomNavigationDrawerCallback.kt @@ -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) - } } diff --git a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/OnSlideAction.kt b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/OnSlideAction.kt index 14da6462..1e1d7834 100644 --- a/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/OnSlideAction.kt +++ b/app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/OnSlideAction.kt @@ -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. * diff --git a/common/src/main/java/com/yogeshpaliyal/common/db/DbDao.kt b/common/src/main/java/com/yogeshpaliyal/common/db/DbDao.kt index eb57146b..582d4c5e 100644 --- a/common/src/main/java/com/yogeshpaliyal/common/db/DbDao.kt +++ b/common/src/main/java/com/yogeshpaliyal/common/db/DbDao.kt @@ -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) + suspend fun insertOrUpdateAccount(accountModel: List) @Query("SELECT * FROM account ORDER BY title ASC") - abstract fun getAllAccounts(): LiveData> + fun getAllAccounts(): LiveData> @Query("SELECT * FROM account ORDER BY title ASC") - abstract suspend fun getAllAccountsList(): List + suspend fun getAllAccountsList(): List - @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> + @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> @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> + fun getTags(): Flow> @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) } diff --git a/common/src/main/java/com/yogeshpaliyal/common/di/module/AppModule.kt b/common/src/main/java/com/yogeshpaliyal/common/di/module/AppModule.kt index 2eaab302..5bfc3ab2 100644 --- a/common/src/main/java/com/yogeshpaliyal/common/di/module/AppModule.kt +++ b/common/src/main/java/com/yogeshpaliyal/common/di/module/AppModule.kt @@ -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) } } } diff --git a/common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt b/common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt index f0c48e2e..34f4812b 100644 --- a/common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt +++ b/common/src/main/java/com/yogeshpaliyal/common/utils/AnimationUtils.kt @@ -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